Remove QRegExp support from QString and StringList

Replacement methods do now exist in QRegExp, or
for QRegularExpression when porting to it.

Remove all autotests associated with the old methods.

Change-Id: I3ff1e0da4b53adb64d5a48a30aecd8b960f5e633
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Lars Knoll 2020-04-09 16:27:12 +02:00
parent 7370b60cfe
commit b2ee684a13
13 changed files with 19 additions and 891 deletions

View File

@ -350,11 +350,6 @@ void Widget::containsFunction()
void Widget::countFunction() void Widget::countFunction()
{ {
//! [18]
QString str = "banana and panama";
str.count(QRegExp("a[nm]a")); // returns 4
//! [18]
//! [95] //! [95]
QString str = "banana and panama"; QString str = "banana and panama";
str.count(QRegularExpression("a[nm]a")); // returns 4 str.count(QRegularExpression("a[nm]a")); // returns 4
@ -425,11 +420,6 @@ void Widget::indexOfFunction()
void Widget::firstIndexOfFunction() void Widget::firstIndexOfFunction()
{ {
//! [25]
QString str = "the minimum";
str.indexOf(QRegExp("m[aeiou]"), 0); // returns 4
//! [25]
//! [93] //! [93]
QString str = "the minimum"; QString str = "the minimum";
str.indexOf(QRegularExpression("m[aeiou]"), 0); // returns 4 str.indexOf(QRegularExpression("m[aeiou]"), 0); // returns 4
@ -480,11 +470,6 @@ void Widget::lastIndexOfFunction()
x.lastIndexOf(y, 1); // returns -1 x.lastIndexOf(y, 1); // returns -1
//! [29] //! [29]
//! [30]
QString str = "the minimum";
str.lastIndexOf(QRegExp("m[aeiou]")); // returns 8
//! [30]
//! [94] //! [94]
QString str = "the minimum"; QString str = "the minimum";
str.lastIndexOf(QRegularExpression("m[aeiou]")); // returns 8 str.lastIndexOf(QRegularExpression("m[aeiou]")); // returns 8
@ -559,12 +544,6 @@ void Widget::removeFunction()
// t == "li Bb" // t == "li Bb"
//! [38] //! [38]
//! [39]
QString r = "Telephone";
r.remove(QRegExp("[aeiou]."));
// r == "The"
//! [39]
//! [96] //! [96]
QString r = "Telephone"; QString r = "Telephone";
r.remove(QRegularExpression("[aeiou].")); r.remove(QRegularExpression("[aeiou]."));
@ -587,18 +566,6 @@ void Widget::replaceFunction()
// str == "color behavior flavor neighbor" // str == "color behavior flavor neighbor"
//! [41] //! [41]
//! [42]
QString s = "Banana";
s.replace(QRegExp("a[mn]"), "ox");
// s == "Boxoxa"
//! [42]
//! [43]
QString t = "A <i>bon mot</i>.";
t.replace(QRegExp("<i>([^<]*)</i>"), "\\emph{\\1}");
// t == "A \\emph{bon mot}."
//! [43]
//! [86] //! [86]
QString equis = "xxxxxx"; QString equis = "xxxxxx";
equis.replace("xx", "x"); equis.replace("xx", "x");
@ -707,13 +674,6 @@ void Widget::sectionFunction()
str = data.section("**", -3, -2); // str == "middlename**surname" str = data.section("**", -3, -2); // str == "middlename**surname"
//! [54] //! [54]
//! [55]
QString line = "forename\tmiddlename surname \t \t phone";
QRegExp sep("\\s+");
str = line.section(sep, 2, 2); // str == "surname"
str = line.section(sep, -3, -2); // str == "middlename surname"
//! [55]
//! [89] //! [89]
QString line = "forename\tmiddlename surname \t \t phone"; QString line = "forename\tmiddlename surname \t \t phone";
QRegularExpression sep("\\s+"); QRegularExpression sep("\\s+");
@ -751,27 +711,6 @@ void Widget::sizeFunction()
void Widget::splitFunction() void Widget::splitFunction()
{ {
//! [59]
QString str;
QStringList list;
str = "Some text\n\twith strange whitespace.";
list = str.split(QRegExp("\\s+"));
// list: [ "Some", "text", "with", "strange", "whitespace." ]
//! [59]
//! [60]
str = "This time, a normal English sentence.";
list = str.split(QRegExp("\\W+"), Qt::SkipEmptyParts);
// list: [ "This", "time", "a", "normal", "English", "sentence" ]
//! [60]
//! [61]
str = "Now: this sentence fragment.";
list = str.split(QRegExp("\\b"));
// list: [ "", "Now", ": ", "this", " ", "sentence", " ", "fragment", "." ]
//! [61]
//! [90] //! [90]
QString str; QString str;
QStringList list; QStringList list;

View File

@ -144,20 +144,6 @@ Widget::Widget(QWidget *parent)
// list == ["olpho", "beto", "gommo", "epsilon"] // list == ["olpho", "beto", "gommo", "epsilon"]
//! [13] //! [13]
list.clear();
//! [14]
list << "alpha" << "beta" << "gamma" << "epsilon";
list.replaceInStrings(QRegExp("^a"), "o");
// list == ["olpha", "beta", "gamma", "epsilon"]
//! [14]
list.clear();
//! [15]
list << "Bill Clinton" << "Murray, Bill";
list.replaceInStrings(QRegExp("^(.*), (.*)$"), "\\2 \\1");
// list == ["Bill Clinton", "Bill Murray"]
//! [15]
list.clear(); list.clear();
//! [16] //! [16]
list << "alpha" << "beta" << "gamma" << "epsilon"; list << "alpha" << "beta" << "gamma" << "epsilon";

View File

@ -4672,102 +4672,6 @@ int QRegExp::countIn(const QString &str) const
return count; return count;
} }
class qt_section_chunk {
public:
qt_section_chunk() {}
qt_section_chunk(int l, QStringRef s) : length(l), string(std::move(s)) {}
int length;
QStringRef string;
};
static QString extractSections(const QVector<qt_section_chunk> &sections,
int start,
int end,
QString::SectionFlags flags)
{
const int sectionsSize = sections.size();
if (!(flags & QString::SectionSkipEmpty)) {
if (start < 0)
start += sectionsSize;
if (end < 0)
end += sectionsSize;
} else {
int skip = 0;
for (int k = 0; k < sectionsSize; ++k) {
const qt_section_chunk &section = sections.at(k);
if (section.length == section.string.length())
skip++;
}
if (start < 0)
start += sectionsSize - skip;
if (end < 0)
end += sectionsSize - skip;
}
if (start >= sectionsSize || end < 0 || start > end)
return QString();
QString ret;
int x = 0;
int first_i = start, last_i = end;
for (int i = 0; x <= end && i < sectionsSize; ++i) {
const qt_section_chunk &section = sections.at(i);
const bool empty = (section.length == section.string.length());
if (x >= start) {
if (x == start)
first_i = i;
if (x == end)
last_i = i;
if (x != start)
ret += section.string;
else
ret += section.string.mid(section.length);
}
if (!empty || !(flags & QString::SectionSkipEmpty))
x++;
}
if ((flags & QString::SectionIncludeLeadingSep) && first_i >= 0) {
const qt_section_chunk &section = sections.at(first_i);
ret.prepend(section.string.left(section.length));
}
if ((flags & QString::SectionIncludeTrailingSep)
&& last_i < sectionsSize - 1) {
const qt_section_chunk &section = sections.at(last_i+1);
ret += section.string.left(section.length);
}
return ret;
}
/*!
\a str is treated as a sequence of fields separated by this
regular expression.
\sa splitString()
*/
QString QRegExp::sectionIn(const QString &str, int start, int end, QString::SectionFlags flags) const
{
if (str.isEmpty())
return str;
QRegExp sep(*this);
sep.setCaseSensitivity((flags & QString::SectionCaseInsensitiveSeps) ? Qt::CaseInsensitive
: Qt::CaseSensitive);
QVector<qt_section_chunk> sections;
int n = str.length(), m = 0, last_m = 0, last_len = 0;
while ((m = sep.indexIn(str, m)) != -1) {
sections.append(qt_section_chunk(last_len, QStringRef(&str, last_m, m - last_m)));
last_m = m;
last_len = sep.matchedLength();
m += qMax(sep.matchedLength(), 1);
}
sections.append(qt_section_chunk(last_len, QStringRef(&str, last_m, n - last_m)));
return extractSections(sections, start, end, flags);
}
/*! /*!
Splits \a str into substrings wherever this regular expression Splits \a str into substrings wherever this regular expression
matches, and returns the list of those strings. If this regular matches, and returns the list of those strings. If this regular
@ -4795,33 +4699,6 @@ QStringList QRegExp::splitString(const QString &str, Qt::SplitBehavior behavior)
return list; return list;
} }
/*!
Splits \a str into substrings wherever this regular expression
matches, and returns the list of those strings. If this regular
expression does not match anywhere in the string, split() returns a
single-element list containing \a str.
\sa QStringList::join(), section(), QString::split()
*/
QVector<QStringRef> QRegExp::splitStringAsRef(const QString &str, Qt::SplitBehavior behavior) const
{
QRegExp rx2(*this);
QVector<QStringRef> list;
int start = 0;
int extra = 0;
int end;
while ((end = rx2.indexIn(str, start + extra)) != -1) {
int matchedLen = rx2.matchedLength();
if (start != end || behavior == Qt::KeepEmptyParts)
list.append(str.midRef(start, end - start));
start = end + matchedLen;
extra = (matchedLen == 0) ? 1 : 0;
}
if (start != str.size() || behavior == Qt::KeepEmptyParts)
list.append(str.midRef(start, -1));
return list;
}
/*! /*!
\fn QStringList QStringList::filter(const QRegExp &rx) const \fn QStringList QStringList::filter(const QRegExp &rx) const
@ -4860,12 +4737,13 @@ QStringList QRegExp::replaceIn(const QStringList &stringList, const QString &aft
\sa lastIndexIn(), contains(), exactMatch() \sa lastIndexIn(), contains(), exactMatch()
*/ */
int QRegExp::indexIn(const QStringList &list, int from) int QRegExp::indexIn(const QStringList &list, int from) const
{ {
QRegExp rx2(*this);
if (from < 0) if (from < 0)
from = qMax(from + list.size(), 0); from = qMax(from + list.size(), 0);
for (int i = from; i < list.size(); ++i) { for (int i = from; i < list.size(); ++i) {
if (exactMatch(list.at(i))) if (rx2.exactMatch(list.at(i)))
return i; return i;
} }
return -1; return -1;
@ -4879,14 +4757,15 @@ int QRegExp::indexIn(const QStringList &list, int from)
\sa indexOf(), contains(), QRegExp::exactMatch() \sa indexOf(), contains(), QRegExp::exactMatch()
*/ */
int QRegExp::lastIndexIn(const QStringList &list, int from) int QRegExp::lastIndexIn(const QStringList &list, int from) const
{ {
QRegExp rx2(*this);
if (from < 0) if (from < 0)
from += list.size(); from += list.size();
else if (from >= list.size()) else if (from >= list.size())
from = list.size() - 1; from = list.size() - 1;
for (int i = from; i >= 0; --i) { for (int i = from; i >= 0; --i) {
if (exactMatch(list.at(i))) if (rx2.exactMatch(list.at(i)))
return i; return i;
} }
return -1; return -1;

View File

@ -114,13 +114,11 @@ public:
bool containedIn(const QString &str) const bool containedIn(const QString &str) const
{ return indexIn(str) != -1; } { return indexIn(str) != -1; }
int countIn(const QString &str) const; int countIn(const QString &str) const;
QString sectionIn(const QString &str, int start, int end, QString::SectionFlags flags) const;
QStringList splitString(const QString &str, Qt::SplitBehavior behavior = Qt::KeepEmptyParts) const; QStringList splitString(const QString &str, Qt::SplitBehavior behavior = Qt::KeepEmptyParts) const;
QVector<QStringRef> splitStringAsRef(const QString &str, Qt::SplitBehavior behavior = Qt::KeepEmptyParts) const;
int indexIn(const QStringList &list, int from); int indexIn(const QStringList &list, int from) const;
int lastIndexIn(const QStringList &list, int from); int lastIndexIn(const QStringList &list, int from) const;
QStringList replaceIn(const QStringList &stringList, const QString &after) const; QStringList replaceIn(const QStringList &stringList, const QString &after) const;
QStringList filterList(const QStringList &stringList) const; QStringList filterList(const QStringList &stringList) const;

View File

@ -40,7 +40,6 @@
****************************************************************************/ ****************************************************************************/
#include "qstringlist.h" #include "qstringlist.h"
#include "qregexp.h"
#if QT_CONFIG(regularexpression) #if QT_CONFIG(regularexpression)
#include "qregularexpression.h" #include "qregularexpression.h"
#endif #endif
@ -1537,7 +1536,7 @@ const QString::Null QString::null = { };
and join a list of strings into a single string with an optional and join a list of strings into a single string with an optional
separator using QStringList::join(). You can obtain a list of separator using QStringList::join(). You can obtain a list of
strings from a string list that contain a particular substring or strings from a string list that contain a particular substring or
that match a particular QRegExp using the QStringList::filter() that match a particular QRegularExpression using the QStringList::filter()
function. function.
\section1 Querying String Data \section1 Querying String Data
@ -2926,17 +2925,6 @@ QString &QString::remove(QChar ch, Qt::CaseSensitivity cs)
return *this; return *this;
} }
/*!
\fn QString &QString::remove(const QRegExp &rx)
Removes every occurrence of the regular expression \a rx in the
string, and returns a reference to the string. For example:
\snippet qstring/main.cpp 39
\sa indexOf(), lastIndexOf(), replace()
*/
/*! /*!
\fn QString &QString::remove(const QRegularExpression &re) \fn QString &QString::remove(const QRegularExpression &re)
\since 5.0 \since 5.0
@ -3887,7 +3875,7 @@ int QString::lastIndexOf(const QStringRef &str, int from, Qt::CaseSensitivity cs
*/ */
#if !(defined(QT_NO_REGEXP) && !QT_CONFIG(regularexpression)) #if QT_CONFIG(regularexpression)
struct QStringCapture struct QStringCapture
{ {
int pos; int pos;
@ -3895,35 +3883,7 @@ struct QStringCapture
int no; int no;
}; };
Q_DECLARE_TYPEINFO(QStringCapture, Q_PRIMITIVE_TYPE); Q_DECLARE_TYPEINFO(QStringCapture, Q_PRIMITIVE_TYPE);
#endif
#ifndef QT_NO_REGEXP
/*!
\overload replace()
Replaces every occurrence of the regular expression \a rx in the
string with \a after. Returns a reference to the string. For
example:
\snippet qstring/main.cpp 42
For regular expressions containing \l{capturing parentheses},
occurrences of \b{\\1}, \b{\\2}, ..., in \a after are replaced
with \a{rx}.cap(1), cap(2), ...
\snippet qstring/main.cpp 43
\sa indexOf(), lastIndexOf(), remove(), QRegExp::cap()
*/
QString& QString::replace(const QRegExp &rx, const QString &after)
{
*this = rx.replaceIn(*this, after);
return *this;
}
#endif
#if QT_CONFIG(regularexpression)
/*! /*!
\overload replace() \overload replace()
\since 5.0 \since 5.0
@ -4163,118 +4123,6 @@ int QString::count(const QStringRef &str, Qt::CaseSensitivity cs) const
\sa indexOf(), count() \sa indexOf(), count()
*/ */
/*! \fn bool QString::contains(const QRegExp &rx) const
\overload contains()
Returns \c true if the regular expression \a rx matches somewhere in
this string; otherwise returns \c false.
*/
/*! \fn bool QString::contains(QRegExp &rx) const
\overload contains()
\since 4.5
Returns \c true if the regular expression \a rx matches somewhere in
this string; otherwise returns \c false.
If there is a match, the \a rx regular expression will contain the
matched captures (see QRegExp::matchedLength, QRegExp::cap).
*/
#ifndef QT_NO_REGEXP
/*!
\overload indexOf()
Returns the index position of the first match of the regular
expression \a rx in the string, searching forward from index
position \a from. Returns -1 if \a rx didn't match anywhere.
Example:
\snippet qstring/main.cpp 25
*/
int QString::indexOf(const QRegExp& rx, int from) const
{
QRegExp rx2(rx);
return rx2.indexIn(*this, from);
}
/*!
\overload indexOf()
\since 4.5
Returns the index position of the first match of the regular
expression \a rx in the string, searching forward from index
position \a from. Returns -1 if \a rx didn't match anywhere.
If there is a match, the \a rx regular expression will contain the
matched captures (see QRegExp::matchedLength, QRegExp::cap).
Example:
\snippet qstring/main.cpp 25
*/
int QString::indexOf(QRegExp& rx, int from) const
{
return rx.indexIn(*this, from);
}
/*!
\overload lastIndexOf()
Returns the index position of the last match of the regular
expression \a rx in the string, searching backward from index
position \a from. Returns -1 if \a rx didn't match anywhere.
Example:
\snippet qstring/main.cpp 30
*/
int QString::lastIndexOf(const QRegExp& rx, int from) const
{
QRegExp rx2(rx);
return rx2.lastIndexIn(*this, from);
}
/*!
\overload lastIndexOf()
\since 4.5
Returns the index position of the last match of the regular
expression \a rx in the string, searching backward from index
position \a from. Returns -1 if \a rx didn't match anywhere.
If there is a match, the \a rx regular expression will contain the
matched captures (see QRegExp::matchedLength, QRegExp::cap).
Example:
\snippet qstring/main.cpp 30
*/
int QString::lastIndexOf(QRegExp& rx, int from) const
{
return rx.lastIndexIn(*this, from);
}
/*!
\overload count()
Returns the number of times the regular expression \a rx matches
in the string.
This function counts overlapping matches, so in the example
below, there are four instances of "ana" or "ama":
\snippet qstring/main.cpp 18
*/
int QString::count(const QRegExp& rx) const
{
return rx.countIn(*this);
}
#endif // QT_NO_REGEXP
#if QT_CONFIG(regularexpression) #if QT_CONFIG(regularexpression)
/*! /*!
\since 5.5 \since 5.5
@ -4599,26 +4447,6 @@ static QString extractSections(const QVector<qt_section_chunk> &sections,
} }
#endif #endif
#ifndef QT_NO_REGEXP
/*!
\overload section()
This string is treated as a sequence of fields separated by the
regular expression, \a reg.
\snippet qstring/main.cpp 55
\warning Using this QRegExp version is much more expensive than
the overloaded string and character versions.
\sa split(), simplified()
*/
QString QString::section(const QRegExp &reg, int start, int end, SectionFlags flags) const
{
return reg.sectionIn(*this, start, end, flags);
}
#endif
#if QT_CONFIG(regularexpression) #if QT_CONFIG(regularexpression)
/*! /*!
\overload section() \overload section()
@ -7582,82 +7410,6 @@ QVector<QStringRef> QStringRef::split(QChar sep, QString::SplitBehavior behavior
} }
#endif #endif
#ifndef QT_NO_REGEXP
/*!
\overload
\since 5.14
Splits the string into substrings wherever the regular expression
\a rx matches, and returns the list of those strings. If \a rx
does not match anywhere in the string, split() returns a
single-element list containing this string.
Here is an example where we extract the words in a sentence
using one or more whitespace characters as the separator:
\snippet qstring/main.cpp 59
Here is a similar example, but this time we use any sequence of
non-word characters as the separator:
\snippet qstring/main.cpp 60
Here is a third example where we use a zero-length assertion,
\b{\\b} (word boundary), to split the string into an
alternating sequence of non-word and word tokens:
\snippet qstring/main.cpp 61
\sa QStringList::join(), section()
*/
QStringList QString::split(const QRegExp &rx, Qt::SplitBehavior behavior) const
{
return rx.splitString(*this, behavior);
}
# if QT_DEPRECATED_SINCE(5, 15)
/*!
\overload
\obsolete
*/
QStringList QString::split(const QRegExp &rx, SplitBehavior behavior) const
{
return rx.splitString(*this, mapSplitBehavior(behavior));
}
# endif
/*!
\overload
\since 5.14
Splits the string into substring references wherever the regular expression
\a rx matches, and returns the list of those strings. If \a rx
does not match anywhere in the string, splitRef() returns a
single-element vector containing this string reference.
\note All references are valid as long this string is alive. Destroying this
string will cause all references to be dangling pointers.
\sa QStringRef split()
*/
QVector<QStringRef> QString::splitRef(const QRegExp &rx, Qt::SplitBehavior behavior) const
{
return rx.splitStringAsRef(*this, behavior);
}
# if QT_DEPRECATED_SINCE(5, 15)
/*!
\overload
\since 5.4
\obsolete
*/
QVector<QStringRef> QString::splitRef(const QRegExp &rx, SplitBehavior behavior) const
{
return rx.splitStringAsRef(*this, mapSplitBehavior(behavior));
}
# endif
#endif // QT_NO_REGEXP
#if QT_CONFIG(regularexpression) #if QT_CONFIG(regularexpression)
namespace { namespace {
template<class ResultList, typename MidMethod> template<class ResultList, typename MidMethod>

View File

@ -70,7 +70,6 @@ Q_FORWARD_DECLARE_OBJC_CLASS(NSString);
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QRegExp;
class QRegularExpression; class QRegularExpression;
class QRegularExpressionMatch; class QRegularExpressionMatch;
class QString; class QString;
@ -422,17 +421,6 @@ public:
int count(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; int count(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
int count(const QStringRef &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; int count(const QStringRef &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
#ifndef QT_NO_REGEXP
int indexOf(const QRegExp &, int from = 0) const;
int lastIndexOf(const QRegExp &, int from = -1) const;
inline bool contains(const QRegExp &rx) const { return indexOf(rx) != -1; }
int count(const QRegExp &) const;
int indexOf(QRegExp &, int from = 0) const;
int lastIndexOf(QRegExp &, int from = -1) const;
inline bool contains(QRegExp &rx) const { return indexOf(rx) != -1; }
#endif
#if QT_CONFIG(regularexpression) #if QT_CONFIG(regularexpression)
int indexOf(const QRegularExpression &re, int from = 0, int indexOf(const QRegularExpression &re, int from = 0,
QRegularExpressionMatch *rmatch = nullptr) const; QRegularExpressionMatch *rmatch = nullptr) const;
@ -453,9 +441,6 @@ public:
QString section(QChar sep, int start, int end = -1, SectionFlags flags = SectionDefault) const; QString section(QChar sep, int start, int end = -1, SectionFlags flags = SectionDefault) const;
QString section(const QString &in_sep, int start, int end = -1, SectionFlags flags = SectionDefault) const; QString section(const QString &in_sep, int start, int end = -1, SectionFlags flags = SectionDefault) const;
#ifndef QT_NO_REGEXP
QString section(const QRegExp &reg, int start, int end = -1, SectionFlags flags = SectionDefault) const;
#endif
#if QT_CONFIG(regularexpression) #if QT_CONFIG(regularexpression)
QString section(const QRegularExpression &re, int start, int end = -1, SectionFlags flags = SectionDefault) const; QString section(const QRegularExpression &re, int start, int end = -1, SectionFlags flags = SectionDefault) const;
#endif #endif
@ -592,11 +577,6 @@ public:
Qt::CaseSensitivity cs = Qt::CaseSensitive); Qt::CaseSensitivity cs = Qt::CaseSensitive);
QString &replace(QChar c, const QString &after, Qt::CaseSensitivity cs = Qt::CaseSensitive); QString &replace(QChar c, const QString &after, Qt::CaseSensitivity cs = Qt::CaseSensitive);
QString &replace(QChar c, QLatin1String after, Qt::CaseSensitivity cs = Qt::CaseSensitive); QString &replace(QChar c, QLatin1String after, Qt::CaseSensitivity cs = Qt::CaseSensitive);
#ifndef QT_NO_REGEXP
QString &replace(const QRegExp &rx, const QString &after);
inline QString &remove(const QRegExp &rx)
{ return replace(rx, QString()); }
#endif
#if QT_CONFIG(regularexpression) #if QT_CONFIG(regularexpression)
QString &replace(const QRegularExpression &re, const QString &after); QString &replace(const QRegularExpression &re, const QString &after);
inline QString &remove(const QRegularExpression &re) inline QString &remove(const QRegularExpression &re)
@ -622,12 +602,6 @@ public:
Q_REQUIRED_RESULT QT_DEPRECATED_VERSION_X_5_15("Use Qt::SplitBehavior variant instead") Q_REQUIRED_RESULT QT_DEPRECATED_VERSION_X_5_15("Use Qt::SplitBehavior variant instead")
QVector<QStringRef> splitRef(QChar sep, SplitBehavior behavior, QVector<QStringRef> splitRef(QChar sep, SplitBehavior behavior,
Qt::CaseSensitivity cs = Qt::CaseSensitive) const; Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
#ifndef QT_NO_REGEXP
Q_REQUIRED_RESULT QT_DEPRECATED_VERSION_X_5_15("Use Qt::SplitBehavior variant instead")
QStringList split(const QRegExp &sep, SplitBehavior behavior) const;
Q_REQUIRED_RESULT QT_DEPRECATED_VERSION_X_5_15("Use Qt::SplitBehavior variant instead")
QVector<QStringRef> splitRef(const QRegExp &sep, SplitBehavior behavior) const;
#endif
#if QT_CONFIG(regularexpression) #if QT_CONFIG(regularexpression)
Q_REQUIRED_RESULT QT_DEPRECATED_VERSION_X_5_15("Use Qt::SplitBehavior variant instead") Q_REQUIRED_RESULT QT_DEPRECATED_VERSION_X_5_15("Use Qt::SplitBehavior variant instead")
QStringList split(const QRegularExpression &sep, SplitBehavior behavior) const; QStringList split(const QRegularExpression &sep, SplitBehavior behavior) const;
@ -650,14 +624,6 @@ public:
Q_REQUIRED_RESULT Q_REQUIRED_RESULT
QVector<QStringRef> splitRef(QChar sep, Qt::SplitBehavior behavior = Qt::KeepEmptyParts, QVector<QStringRef> splitRef(QChar sep, Qt::SplitBehavior behavior = Qt::KeepEmptyParts,
Qt::CaseSensitivity cs = Qt::CaseSensitive) const; Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
#ifndef QT_NO_REGEXP
Q_REQUIRED_RESULT
QStringList split(const QRegExp &sep,
Qt::SplitBehavior behavior = Qt::KeepEmptyParts) const;
Q_REQUIRED_RESULT
QVector<QStringRef> splitRef(const QRegExp &sep,
Qt::SplitBehavior behavior = Qt::KeepEmptyParts) const;
#endif
#ifndef QT_NO_REGULAREXPRESSION #ifndef QT_NO_REGULAREXPRESSION
Q_REQUIRED_RESULT Q_REQUIRED_RESULT
QStringList split(const QRegularExpression &sep, QStringList split(const QRegularExpression &sep,

View File

@ -38,7 +38,6 @@
****************************************************************************/ ****************************************************************************/
#include <qstringlist.h> #include <qstringlist.h>
#include <qregexp.h>
#include <qset.h> #include <qset.h>
#if QT_CONFIG(regularexpression) #if QT_CONFIG(regularexpression)
# include <qregularexpression.h> # include <qregularexpression.h>
@ -157,8 +156,8 @@ QT_BEGIN_NAMESPACE
\snippet qstringlist/main.cpp 6 \snippet qstringlist/main.cpp 6
The argument to split can be a single character, a string, a The argument to split can be a single character, a string or a
QRegularExpression or a (deprecated) QRegExp. QRegularExpression.
In addition, the \l {QStringList::operator+()}{operator+()} In addition, the \l {QStringList::operator+()}{operator+()}
function allows you to concatenate two string lists into one. To function allows you to concatenate two string lists into one. To
@ -449,21 +448,6 @@ bool QtPrivate::QStringList_contains(const QStringList *that, QLatin1String str,
\sa indexOf(), contains() \sa indexOf(), contains()
*/ */
#ifndef QT_NO_REGEXP
/*!
\fn QStringList QStringList::filter(const QRegExp &rx) const
\overload
Returns a list of all the strings that match the regular
expression \a rx.
*/
QStringList QtPrivate::QStringList_filter(const QStringList *that, const QRegExp &rx)
{
return rx.filterList(*that);
}
#endif
#if QT_CONFIG(regularexpression) #if QT_CONFIG(regularexpression)
/*! /*!
\fn QStringList QStringList::filter(const QRegularExpression &re) const \fn QStringList QStringList::filter(const QRegularExpression &re) const
@ -536,36 +520,6 @@ void QtPrivate::QStringList_replaceInStrings(QStringList *that, const QString &b
} }
#endif #endif
#ifndef QT_NO_REGEXP
/*!
\fn QStringList &QStringList::replaceInStrings(const QRegExp &rx, const QString &after)
\overload
Replaces every occurrence of the regexp \a rx, in each of the
string lists's strings, with \a after. Returns a reference to the
string list.
For example:
\snippet qstringlist/main.cpp 5
\snippet qstringlist/main.cpp 14
For regular expressions that contain \l{capturing parentheses},
occurrences of \b{\\1}, \b{\\2}, ..., in \a after are
replaced with \a{rx}.cap(1), \a{rx}.cap(2), ...
For example:
\snippet qstringlist/main.cpp 5
\snippet qstringlist/main.cpp 15
*/
void QtPrivate::QStringList_replaceInStrings(QStringList *that, const QRegExp &rx, const QString &after)
{
*that = rx.replaceIn(*that, after);
}
#endif
#if QT_CONFIG(regularexpression) #if QT_CONFIG(regularexpression)
/*! /*!
\fn QStringList &QStringList::replaceInStrings(const QRegularExpression &re, const QString &after) \fn QStringList &QStringList::replaceInStrings(const QRegularExpression &re, const QString &after)
@ -710,78 +664,6 @@ QString QtPrivate::QStringList_join(const QStringList *that, QStringView sep)
the latter string list. the latter string list.
*/ */
#ifndef QT_NO_REGEXP
/*!
\fn int QStringList::indexOf(const QRegExp &rx, int from) const
Returns the index position of the first exact match of \a rx in
the list, searching forward from index position \a from. Returns
-1 if no item matched.
\sa lastIndexOf(), contains(), QRegExp::exactMatch()
*/
int QtPrivate::QStringList_indexOf(const QStringList *that, const QRegExp &rx, int from)
{
QRegExp rx2(rx);
return rx2.indexIn(*that, from);
}
/*!
\fn int QStringList::indexOf(QRegExp &rx, int from) const
\overload indexOf()
\since 4.5
Returns the index position of the first exact match of \a rx in
the list, searching forward from index position \a from. Returns
-1 if no item matched.
If an item matched, the \a rx regular expression will contain the
matched objects (see QRegExp::matchedLength, QRegExp::cap).
\sa lastIndexOf(), contains(), QRegExp::exactMatch()
*/
int QtPrivate::QStringList_indexOf(const QStringList *that, QRegExp &rx, int from)
{
return rx.indexIn(*that, from);
}
/*!
\fn int QStringList::lastIndexOf(const QRegExp &rx, int from) const
Returns the index position of the last exact match of \a rx in
the list, searching backward from index position \a from. If \a
from is -1 (the default), the search starts at the last item.
Returns -1 if no item matched.
\sa indexOf(), contains(), QRegExp::exactMatch()
*/
int QtPrivate::QStringList_lastIndexOf(const QStringList *that, const QRegExp &rx, int from)
{
QRegExp rx2(rx);
return rx2.lastIndexIn(*that, from);
}
/*!
\fn int QStringList::lastIndexOf(QRegExp &rx, int from) const
\overload lastIndexOf()
\since 4.5
Returns the index position of the last exact match of \a rx in
the list, searching backward from index position \a from. If \a
from is -1 (the default), the search starts at the last item.
Returns -1 if no item matched.
If an item matched, the \a rx regular expression will contain the
matched objects (see QRegExp::matchedLength, QRegExp::cap).
\sa indexOf(), contains(), QRegExp::exactMatch()
*/
int QtPrivate::QStringList_lastIndexOf(const QStringList *that, QRegExp &rx, int from)
{
return rx.lastIndexIn(*that, from);
}
#endif
#if QT_CONFIG(regularexpression) #if QT_CONFIG(regularexpression)
/*! /*!
\fn int QStringList::indexOf(const QRegularExpression &re, int from) const \fn int QStringList::indexOf(const QRegularExpression &re, int from) const

View File

@ -45,13 +45,11 @@
#include <QtCore/qalgorithms.h> #include <QtCore/qalgorithms.h>
#include <QtCore/qcontainertools_impl.h> #include <QtCore/qcontainertools_impl.h>
#include <QtCore/qregexp.h>
#include <QtCore/qstring.h> #include <QtCore/qstring.h>
#include <QtCore/qstringmatcher.h> #include <QtCore/qstringmatcher.h>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QRegExp;
class QRegularExpression; class QRegularExpression;
#if !defined(QT_NO_JAVA_STYLE_ITERATORS) #if !defined(QT_NO_JAVA_STYLE_ITERATORS)
@ -91,11 +89,6 @@ public:
inline QStringList &replaceInStrings(QStringView before, const QString &after, Qt::CaseSensitivity cs = Qt::CaseSensitive); inline QStringList &replaceInStrings(QStringView before, const QString &after, Qt::CaseSensitivity cs = Qt::CaseSensitive);
#endif #endif
#ifndef QT_NO_REGEXP
inline QStringList filter(const QRegExp &rx) const;
inline QStringList &replaceInStrings(const QRegExp &rx, const QString &after);
#endif
#if QT_CONFIG(regularexpression) #if QT_CONFIG(regularexpression)
inline QStringList filter(const QRegularExpression &re) const; inline QStringList filter(const QRegularExpression &re) const;
inline QStringList &replaceInStrings(const QRegularExpression &re, const QString &after); inline QStringList &replaceInStrings(const QRegularExpression &re, const QString &after);
@ -147,13 +140,6 @@ public:
inline int lastIndexOf(QStringView str, int from = -1) const; inline int lastIndexOf(QStringView str, int from = -1) const;
inline int lastIndexOf(QLatin1String str, int from = -1) const; inline int lastIndexOf(QLatin1String str, int from = -1) const;
#ifndef QT_NO_REGEXP
inline int indexOf(const QRegExp &rx, int from = 0) const;
inline int lastIndexOf(const QRegExp &rx, int from = -1) const;
inline int indexOf(QRegExp &rx, int from = 0) const;
inline int lastIndexOf(QRegExp &rx, int from = -1) const;
#endif
#if QT_CONFIG(regularexpression) #if QT_CONFIG(regularexpression)
inline int indexOf(const QRegularExpression &re, int from = 0) const; inline int indexOf(const QRegularExpression &re, int from = 0) const;
inline int lastIndexOf(const QRegularExpression &re, int from = -1) const; inline int lastIndexOf(const QRegularExpression &re, int from = -1) const;
@ -196,15 +182,6 @@ namespace QtPrivate {
Qt::CaseSensitivity cs); Qt::CaseSensitivity cs);
#endif #endif
#ifndef QT_NO_REGEXP
void Q_CORE_EXPORT QStringList_replaceInStrings(QStringList *that, const QRegExp &rx, const QString &after);
QStringList Q_CORE_EXPORT QStringList_filter(const QStringList *that, const QRegExp &re);
int Q_CORE_EXPORT QStringList_indexOf(const QStringList *that, const QRegExp &rx, int from);
int Q_CORE_EXPORT QStringList_lastIndexOf(const QStringList *that, const QRegExp &rx, int from);
int Q_CORE_EXPORT QStringList_indexOf(const QStringList *that, QRegExp &rx, int from);
int Q_CORE_EXPORT QStringList_lastIndexOf(const QStringList *that, QRegExp &rx, int from);
#endif
#if QT_CONFIG(regularexpression) #if QT_CONFIG(regularexpression)
void Q_CORE_EXPORT QStringList_replaceInStrings(QStringList *that, const QRegularExpression &rx, const QString &after); void Q_CORE_EXPORT QStringList_replaceInStrings(QStringList *that, const QRegularExpression &rx, const QString &after);
QStringList Q_CORE_EXPORT QStringList_filter(const QStringList *that, const QRegularExpression &re); QStringList Q_CORE_EXPORT QStringList_filter(const QStringList *that, const QRegularExpression &re);
@ -327,39 +304,6 @@ inline int QStringList::lastIndexOf(QLatin1String string, int from) const
return QtPrivate::lastIndexOf<QString, QLatin1String>(*this, string, from); return QtPrivate::lastIndexOf<QString, QLatin1String>(*this, string, from);
} }
#ifndef QT_NO_REGEXP
inline QStringList &QVectorSpecialMethods<QString>::replaceInStrings(const QRegExp &rx, const QString &after)
{
QtPrivate::QStringList_replaceInStrings(self(), rx, after);
return *self();
}
inline QStringList QVectorSpecialMethods<QString>::filter(const QRegExp &rx) const
{
return QtPrivate::QStringList_filter(self(), rx);
}
inline int QStringList::indexOf(const QRegExp &rx, int from) const
{
return QtPrivate::QStringList_indexOf(this, rx, from);
}
inline int QStringList::lastIndexOf(const QRegExp &rx, int from) const
{
return QtPrivate::QStringList_lastIndexOf(this, rx, from);
}
inline int QStringList::indexOf(QRegExp &rx, int from) const
{
return QtPrivate::QStringList_indexOf(this, rx, from);
}
inline int QStringList::lastIndexOf(QRegExp &rx, int from) const
{
return QtPrivate::QStringList_lastIndexOf(this, rx, from);
}
#endif
#if QT_CONFIG(regularexpression) #if QT_CONFIG(regularexpression)
inline QStringList &QVectorSpecialMethods<QString>::replaceInStrings(const QRegularExpression &rx, const QString &after) inline QStringList &QVectorSpecialMethods<QString>::replaceInStrings(const QRegularExpression &rx, const QString &after)
{ {

View File

@ -153,7 +153,7 @@ void QStringMatcher::updateSkipTable()
Create the QStringMatcher with the QString you want to search Create the QStringMatcher with the QString you want to search
for. Then call indexIn() on the QString that you want to search. for. Then call indexIn() on the QString that you want to search.
\sa QString, QByteArrayMatcher, QRegExp \sa QString, QByteArrayMatcher, QRegularExpression
*/ */
/*! /*!

View File

@ -895,19 +895,19 @@ void tst_QRegExp::testInvalidWildcard(){
void tst_QRegExp::caretAnchoredOptimization() void tst_QRegExp::caretAnchoredOptimization()
{ {
QString s = "---babnana----"; QString s = "---babnana----";
s.replace( QRegExp("^-*|(-*)$"), "" ); s = QRegExp("^-*|(-*)$").replaceIn(s, "" );
QCOMPARE(s, QLatin1String("babnana")); QCOMPARE(s, QLatin1String("babnana"));
s = "---babnana----"; s = "---babnana----";
s.replace( QRegExp("^-*|(-{0,})$"), "" ); s = QRegExp("^-*|(-{0,})$").replaceIn(s, "" );
QCOMPARE(s, QLatin1String("babnana")); QCOMPARE(s, QLatin1String("babnana"));
s = "---babnana----"; s = "---babnana----";
s.replace( QRegExp("^-*|(-{1,})$"), "" ); s = QRegExp("^-*|(-{1,})$").replaceIn(s, "" );
QCOMPARE(s, QLatin1String("babnana")); QCOMPARE(s, QLatin1String("babnana"));
s = "---babnana----"; s = "---babnana----";
s.replace( QRegExp("^-*|(-+)$"), "" ); s = QRegExp("^-*|(-+)$").replaceIn(s, "" );
QCOMPARE(s, QLatin1String("babnana")); QCOMPARE(s, QLatin1String("babnana"));
} }

View File

@ -39,7 +39,6 @@
#include <private/qglobal_p.h> // for the icu feature test #include <private/qglobal_p.h> // for the icu feature test
#include <QtTest/QtTest> #include <QtTest/QtTest>
#include <qregexp.h>
#include <qregularexpression.h> #include <qregularexpression.h>
#include <qtextstream.h> #include <qtextstream.h>
#include <qstringlist.h> #include <qstringlist.h>
@ -567,14 +566,10 @@ private slots:
void reverseIterators(); void reverseIterators();
void split_data(); void split_data();
void split(); void split();
void split_regexp_data();
void split_regexp();
void split_regularexpression_data(); void split_regularexpression_data();
void split_regularexpression(); void split_regularexpression();
void splitRef_data(); void splitRef_data();
void splitRef(); void splitRef();
void splitRef_regexp_data();
void splitRef_regexp();
void splitRef_regularexpression_data(); void splitRef_regularexpression_data();
void splitRef_regularexpression(); void splitRef_regularexpression();
void fromUtf16_data(); void fromUtf16_data();
@ -1442,26 +1437,6 @@ void tst_QString::indexOf()
QCOMPARE( haystack.indexOf(needle.toLatin1().data(), startpos, cs), resultpos ); QCOMPARE( haystack.indexOf(needle.toLatin1().data(), startpos, cs), resultpos );
} }
{
QRegExp rx1 = QRegExp(QRegExp::escape(needle), cs);
QRegExp rx2 = QRegExp(needle, cs, QRegExp::FixedString);
QCOMPARE( haystack.indexOf(rx1, startpos), resultpos );
QCOMPARE( haystack.indexOf(rx2, startpos), resultpos );
// these QRegExp must have been modified
QVERIFY( resultpos == -1 || rx1.matchedLength() > 0);
QVERIFY( resultpos == -1 || rx2.matchedLength() > 0);
}
{
const QRegExp rx1 = QRegExp(QRegExp::escape(needle), cs);
const QRegExp rx2 = QRegExp(needle, cs, QRegExp::FixedString);
QCOMPARE( haystack.indexOf(rx1, startpos), resultpos );
QCOMPARE( haystack.indexOf(rx2, startpos), resultpos );
// our QRegExp mustn't have been modified
QCOMPARE( rx1.matchedLength(), -1 );
QCOMPARE( rx2.matchedLength(), -1 );
}
{ {
QRegularExpression::PatternOptions options = QRegularExpression::NoPatternOption; QRegularExpression::PatternOptions options = QRegularExpression::NoPatternOption;
if (!bcs) if (!bcs)
@ -1665,26 +1640,6 @@ void tst_QString::lastIndexOf()
if (from >= -1 && from < haystack.size()) { if (from >= -1 && from < haystack.size()) {
// unfortunately, QString and QRegExp don't have the same out of bound semantics // unfortunately, QString and QRegExp don't have the same out of bound semantics
// I think QString is wrong -- See file log for contact information. // I think QString is wrong -- See file log for contact information.
{
QRegExp rx1 = QRegExp(QRegExp::escape(needle), cs);
QRegExp rx2 = QRegExp(needle, cs, QRegExp::FixedString);
QCOMPARE(haystack.lastIndexOf(rx1, from), expected);
QCOMPARE(haystack.lastIndexOf(rx2, from), expected);
// our QRegExp mustn't have been modified
QVERIFY(expected == -1 || rx1.matchedLength() > 0);
QVERIFY(expected == -1 || rx2.matchedLength() > 0);
}
{
const QRegExp rx1 = QRegExp(QRegExp::escape(needle), cs);
const QRegExp rx2 = QRegExp(needle, cs, QRegExp::FixedString);
QCOMPARE(haystack.lastIndexOf(rx1, from), expected);
QCOMPARE(haystack.lastIndexOf(rx2, from), expected);
// our QRegExp mustn't have been modified
QCOMPARE(rx1.matchedLength(), -1);
QCOMPARE(rx2.matchedLength(), -1);
}
{ {
QRegularExpression::PatternOptions options = QRegularExpression::NoPatternOption; QRegularExpression::PatternOptions options = QRegularExpression::NoPatternOption;
if (!caseSensitive) if (!caseSensitive)
@ -1751,8 +1706,6 @@ void tst_QString::count()
QCOMPARE(a.count("FG",Qt::CaseInsensitive),3); QCOMPARE(a.count("FG",Qt::CaseInsensitive),3);
QCOMPARE(a.count( QString(), Qt::CaseInsensitive), 16); QCOMPARE(a.count( QString(), Qt::CaseInsensitive), 16);
QCOMPARE(a.count( "", Qt::CaseInsensitive), 16); QCOMPARE(a.count( "", Qt::CaseInsensitive), 16);
QCOMPARE(a.count(QRegExp("[FG][HI]")),1);
QCOMPARE(a.count(QRegExp("[G][HE]")),2);
QCOMPARE(a.count(QRegularExpression("[FG][HI]")), 1); QCOMPARE(a.count(QRegularExpression("[FG][HI]")), 1);
QCOMPARE(a.count(QRegularExpression("[G][HE]")), 2); QCOMPARE(a.count(QRegularExpression("[G][HE]")), 2);
QTest::ignoreMessage(QtWarningMsg, "QString::count: invalid QRegularExpression object"); QTest::ignoreMessage(QtWarningMsg, "QString::count: invalid QRegularExpression object");
@ -1782,8 +1735,6 @@ void tst_QString::contains()
QVERIFY(a.contains(QLatin1String("fg"),Qt::CaseInsensitive)); QVERIFY(a.contains(QLatin1String("fg"),Qt::CaseInsensitive));
QVERIFY(a.contains( QString(), Qt::CaseInsensitive)); QVERIFY(a.contains( QString(), Qt::CaseInsensitive));
QVERIFY(a.contains( "", Qt::CaseInsensitive)); QVERIFY(a.contains( "", Qt::CaseInsensitive));
QVERIFY(a.contains(QRegExp("[FG][HI]")));
QVERIFY(a.contains(QRegExp("[G][HE]")));
QVERIFY(a.contains(QRegularExpression("[FG][HI]"))); QVERIFY(a.contains(QRegularExpression("[FG][HI]")));
QVERIFY(a.contains(QRegularExpression("[G][HE]"))); QVERIFY(a.contains(QRegularExpression("[G][HE]")));
@ -2993,14 +2944,6 @@ void tst_QString::replace_string()
QString s3 = string; QString s3 = string;
s3.replace( before, after, cs ); s3.replace( before, after, cs );
QTEST( s3, "result" ); QTEST( s3, "result" );
QString s4 = string;
s4.replace( QRegExp(QRegExp::escape(before), cs), after );
QTEST( s4, "result" );
QString s5 = string;
s5.replace(QRegExp(before, cs, QRegExp::FixedString), after);
QTEST( s5, "result" );
} }
void tst_QString::replace_regexp() void tst_QString::replace_regexp()
@ -3010,9 +2953,6 @@ void tst_QString::replace_regexp()
QFETCH( QString, after ); QFETCH( QString, after );
QString s2 = string; QString s2 = string;
s2.replace( QRegExp(regexp), after );
QTEST( s2, "result" );
s2 = string;
QRegularExpression regularExpression(regexp); QRegularExpression regularExpression(regexp);
if (!regularExpression.isValid()) if (!regularExpression.isValid())
QTest::ignoreMessage(QtWarningMsg, "QString::replace: invalid QRegularExpression object"); QTest::ignoreMessage(QtWarningMsg, "QString::replace: invalid QRegularExpression object");
@ -3063,14 +3003,6 @@ void tst_QString::remove_string()
s3.remove( before, cs ); s3.remove( before, cs );
QTEST( s3, "result" ); QTEST( s3, "result" );
QString s4 = string;
s4.replace( QRegExp(QRegExp::escape(before), cs), after );
QTEST( s4, "result" );
QString s5 = string;
s5.replace( QRegExp(before, cs, QRegExp::FixedString), after );
QTEST( s5, "result" );
if (QtPrivate::isLatin1(before)) { if (QtPrivate::isLatin1(before)) {
QString s6 = string; QString s6 = string;
s6.remove( QLatin1String(before.toLatin1()), cs ); s6.remove( QLatin1String(before.toLatin1()), cs );
@ -3089,10 +3021,6 @@ void tst_QString::remove_regexp()
if ( after.length() == 0 ) { if ( after.length() == 0 ) {
QString s2 = string; QString s2 = string;
s2.remove( QRegExp(regexp) );
QTEST( s2, "result" );
s2 = string;
s2.remove( QRegularExpression(regexp) ); s2.remove( QRegularExpression(regexp) );
QTEST( s2, "result" ); QTEST( s2, "result" );
} else { } else {
@ -5135,13 +5063,11 @@ void tst_QString::section()
QFETCH( QString, sectionString ); QFETCH( QString, sectionString );
QFETCH( bool, regexp ); QFETCH( bool, regexp );
if (regexp) { if (regexp) {
QCOMPARE( wholeString.section( QRegExp(sep), start, end, QString::SectionFlag(flags) ), sectionString );
QCOMPARE( wholeString.section( QRegularExpression(sep), start, end, QString::SectionFlag(flags) ), sectionString ); QCOMPARE( wholeString.section( QRegularExpression(sep), start, end, QString::SectionFlag(flags) ), sectionString );
} else { } else {
if (sep.size() == 1) if (sep.size() == 1)
QCOMPARE( wholeString.section( sep[0], start, end, QString::SectionFlag(flags) ), sectionString ); QCOMPARE( wholeString.section( sep[0], start, end, QString::SectionFlag(flags) ), sectionString );
QCOMPARE( wholeString.section( sep, start, end, QString::SectionFlag(flags) ), sectionString ); QCOMPARE( wholeString.section( sep, start, end, QString::SectionFlag(flags) ), sectionString );
QCOMPARE( wholeString.section( QRegExp(QRegExp::escape(sep)), start, end, QString::SectionFlag(flags) ), sectionString );
QCOMPARE( wholeString.section( QRegularExpression(QRegularExpression::escape(sep)), start, end, QString::SectionFlag(flags) ), sectionString ); QCOMPARE( wholeString.section( QRegularExpression(QRegularExpression::escape(sep)), start, end, QString::SectionFlag(flags) ), sectionString );
} }
@ -5751,7 +5677,6 @@ template<> struct StringSplitWrapper<QString>
QStringList split(const QString &sep, QString::SplitBehavior behavior = QString::KeepEmptyParts, Qt::CaseSensitivity cs = Qt::CaseSensitive) const { return string.split(sep, behavior, cs); } QStringList split(const QString &sep, QString::SplitBehavior behavior = QString::KeepEmptyParts, Qt::CaseSensitivity cs = Qt::CaseSensitive) const { return string.split(sep, behavior, cs); }
QStringList split(QChar sep, QString::SplitBehavior behavior = QString::KeepEmptyParts, Qt::CaseSensitivity cs = Qt::CaseSensitive) const { return string.split(sep, behavior, cs); } QStringList split(QChar sep, QString::SplitBehavior behavior = QString::KeepEmptyParts, Qt::CaseSensitivity cs = Qt::CaseSensitive) const { return string.split(sep, behavior, cs); }
QStringList split(const QRegExp &sep, QString::SplitBehavior behavior = QString::KeepEmptyParts) const { return string.split(sep, behavior); }
QStringList split(const QRegularExpression &sep, QString::SplitBehavior behavior = QString::KeepEmptyParts) const { return string.split(sep, behavior); } QStringList split(const QRegularExpression &sep, QString::SplitBehavior behavior = QString::KeepEmptyParts) const { return string.split(sep, behavior); }
}; };
@ -5760,7 +5685,6 @@ template<> struct StringSplitWrapper<QStringRef>
const QString &string; const QString &string;
QVector<QStringRef> split(const QString &sep, QString::SplitBehavior behavior = QString::KeepEmptyParts, Qt::CaseSensitivity cs = Qt::CaseSensitive) const { return string.splitRef(sep, behavior, cs); } QVector<QStringRef> split(const QString &sep, QString::SplitBehavior behavior = QString::KeepEmptyParts, Qt::CaseSensitivity cs = Qt::CaseSensitive) const { return string.splitRef(sep, behavior, cs); }
QVector<QStringRef> split(QChar sep, QString::SplitBehavior behavior = QString::KeepEmptyParts, Qt::CaseSensitivity cs = Qt::CaseSensitive) const { return string.splitRef(sep, behavior, cs); } QVector<QStringRef> split(QChar sep, QString::SplitBehavior behavior = QString::KeepEmptyParts, Qt::CaseSensitivity cs = Qt::CaseSensitive) const { return string.splitRef(sep, behavior, cs); }
QVector<QStringRef> split(const QRegExp &sep, QString::SplitBehavior behavior = QString::KeepEmptyParts) const { return string.splitRef(sep, behavior); }
QVector<QStringRef> split(const QRegularExpression &sep, QString::SplitBehavior behavior = QString::KeepEmptyParts) const { return string.splitRef(sep, behavior); } QVector<QStringRef> split(const QRegularExpression &sep, QString::SplitBehavior behavior = QString::KeepEmptyParts) const { return string.splitRef(sep, behavior); }
}; };
@ -5782,7 +5706,6 @@ static inline bool operator ==(const QVector<QStringRef> &left, const QStringLis
template<class List> template<class List>
void tst_QString::split(const QString &string, const QString &sep, QStringList result) void tst_QString::split(const QString &string, const QString &sep, QStringList result)
{ {
QRegExp rx = QRegExp(QRegExp::escape(sep));
QRegularExpression re(QRegularExpression::escape(sep)); QRegularExpression re(QRegularExpression::escape(sep));
List list; List list;
@ -5790,8 +5713,6 @@ void tst_QString::split(const QString &string, const QString &sep, QStringList r
list = str.split(sep); list = str.split(sep);
QVERIFY(list == result); QVERIFY(list == result);
list = str.split(rx);
QVERIFY(list == result);
list = str.split(re); list = str.split(re);
QVERIFY(list == result); QVERIFY(list == result);
if (sep.size() == 1) { if (sep.size() == 1) {
@ -5803,8 +5724,6 @@ QT_WARNING_PUSH
QT_WARNING_DISABLE_DEPRECATED QT_WARNING_DISABLE_DEPRECATED
list = str.split(sep, QString::KeepEmptyParts); list = str.split(sep, QString::KeepEmptyParts);
QVERIFY(list == result); QVERIFY(list == result);
list = str.split(rx, QString::KeepEmptyParts);
QVERIFY(list == result);
list = str.split(re, QString::KeepEmptyParts); list = str.split(re, QString::KeepEmptyParts);
QVERIFY(list == result); QVERIFY(list == result);
if (sep.size() == 1) { if (sep.size() == 1) {
@ -5815,8 +5734,6 @@ QT_WARNING_DISABLE_DEPRECATED
result.removeAll(""); result.removeAll("");
list = str.split(sep, QString::SkipEmptyParts); list = str.split(sep, QString::SkipEmptyParts);
QVERIFY(list == result); QVERIFY(list == result);
list = str.split(rx, QString::SkipEmptyParts);
QVERIFY(list == result);
list = str.split(re, QString::SkipEmptyParts); list = str.split(re, QString::SkipEmptyParts);
QVERIFY(list == result); QVERIFY(list == result);
if (sep.size() == 1) { if (sep.size() == 1) {
@ -5847,7 +5764,7 @@ void tst_QString::splitRef()
split<QVector<QStringRef> >(str, sep, result); split<QVector<QStringRef> >(str, sep, result);
} }
void tst_QString::split_regexp_data() void tst_QString::split_regularexpression_data()
{ {
QTest::addColumn<QString>("string"); QTest::addColumn<QString>("string");
QTest::addColumn<QString>("pattern"); QTest::addColumn<QString>("pattern");
@ -5881,19 +5798,6 @@ void tst_QString::split_regexp(const QString &_string, const QString &pattern, Q
QVERIFY(list == result); QVERIFY(list == result);
} }
void tst_QString::split_regexp()
{
QFETCH(QString, string);
QFETCH(QString, pattern);
QFETCH(QStringList, result);
split_regexp<QStringList, QRegExp>(string, pattern, result);
}
void tst_QString::split_regularexpression_data()
{
split_regexp_data();
}
void tst_QString::split_regularexpression() void tst_QString::split_regularexpression()
{ {
QFETCH(QString, string); QFETCH(QString, string);
@ -5904,7 +5808,7 @@ void tst_QString::split_regularexpression()
void tst_QString::splitRef_regularexpression_data() void tst_QString::splitRef_regularexpression_data()
{ {
split_regexp_data(); split_regularexpression_data();
} }
void tst_QString::splitRef_regularexpression() void tst_QString::splitRef_regularexpression()
@ -5915,19 +5819,6 @@ void tst_QString::splitRef_regularexpression()
split_regexp<QVector<QStringRef>, QRegularExpression>(string, pattern, result); split_regexp<QVector<QStringRef>, QRegularExpression>(string, pattern, result);
} }
void tst_QString::splitRef_regexp_data()
{
split_regexp_data();
}
void tst_QString::splitRef_regexp()
{
QFETCH(QString, string);
QFETCH(QString, pattern);
QFETCH(QStringList, result);
split_regexp<QVector<QStringRef>, QRegExp>(string, pattern, result);
}
void tst_QString::fromUtf16_data() void tst_QString::fromUtf16_data()
{ {
QTest::addColumn<QString>("ucs2"); QTest::addColumn<QString>("ucs2");
@ -6415,15 +6306,6 @@ void tst_QString::truncateWithNegative() const
string.truncate(-9099); string.truncate(-9099);
QCOMPARE(string, QString()); QCOMPARE(string, QString());
} }
{
/* Example code from customer. */
QString test(QLatin1String("c"));
test.replace(QRegExp(QLatin1String("c")), QLatin1String("z"));
test.truncate(-1);
QCOMPARE(test, QString());
}
} }
void tst_QString::QCharRefMutableUnicode() const void tst_QString::QCharRefMutableUnicode() const

View File

@ -27,7 +27,6 @@
****************************************************************************/ ****************************************************************************/
#include <QtTest/QtTest> #include <QtTest/QtTest>
#include <qregexp.h>
#include <qregularexpression.h> #include <qregularexpression.h>
#include <qstringlist.h> #include <qstringlist.h>
#include <qvector.h> #include <qvector.h>
@ -52,9 +51,6 @@ private slots:
void lastIndexOf_data(); void lastIndexOf_data();
void lastIndexOf(); void lastIndexOf();
void indexOf_regExp();
void lastIndexOf_regExp();
void streamingOperator(); void streamingOperator();
void assignmentOperator(); void assignmentOperator();
void join() const; void join() const;
@ -101,83 +97,6 @@ void tst_QStringList::constructors()
} }
} }
void tst_QStringList::indexOf_regExp()
{
QStringList list;
list << "harald" << "trond" << "vohi" << "harald";
{
QRegExp re(".*o.*");
QCOMPARE(list.indexOf(re), 1);
QCOMPARE(list.indexOf(re, 2), 2);
QCOMPARE(list.indexOf(re, 3), -1);
QCOMPARE(list.indexOf(QRegExp(".*x.*")), -1);
QCOMPARE(list.indexOf(re, -1), -1);
QCOMPARE(list.indexOf(re, -3), 1);
QCOMPARE(list.indexOf(re, -9999), 1);
QCOMPARE(list.indexOf(re, 9999), -1);
QCOMPARE(list.indexOf(QRegExp("[aeiou]")), -1);
}
{
QRegularExpression re(".*o.*");
QCOMPARE(list.indexOf(re), 1);
QCOMPARE(list.indexOf(re, 2), 2);
QCOMPARE(list.indexOf(re, 3), -1);
QCOMPARE(list.indexOf(QRegularExpression(".*x.*")), -1);
QCOMPARE(list.indexOf(re, -1), -1);
QCOMPARE(list.indexOf(re, -3), 1);
QCOMPARE(list.indexOf(re, -9999), 1);
QCOMPARE(list.indexOf(re, 9999), -1);
QCOMPARE(list.indexOf(QRegularExpression("[aeiou]")), -1);
}
}
void tst_QStringList::lastIndexOf_regExp()
{
QStringList list;
list << "harald" << "trond" << "vohi" << "harald";
{
QRegExp re(".*o.*");
QCOMPARE(list.lastIndexOf(re), 2);
QCOMPARE(list.lastIndexOf(re, 2), 2);
QCOMPARE(list.lastIndexOf(re, 1), 1);
QCOMPARE(list.lastIndexOf(QRegExp(".*x.*")), -1);
QCOMPARE(list.lastIndexOf(re, -1), 2);
QCOMPARE(list.lastIndexOf(re, -3), 1);
QCOMPARE(list.lastIndexOf(re, -9999), -1);
QCOMPARE(list.lastIndexOf(re, 9999), 2);
QCOMPARE(list.lastIndexOf(QRegExp("[aeiou]")), -1);
}
{
QRegularExpression re(".*o.*");
QCOMPARE(list.lastIndexOf(re), 2);
QCOMPARE(list.lastIndexOf(re, 2), 2);
QCOMPARE(list.lastIndexOf(re, 1), 1);
QCOMPARE(list.lastIndexOf(QRegularExpression(".*x.*")), -1);
QCOMPARE(list.lastIndexOf(re, -1), 2);
QCOMPARE(list.lastIndexOf(re, -3), 1);
QCOMPARE(list.lastIndexOf(re, -9999), -1);
QCOMPARE(list.lastIndexOf(re, 9999), 2);
QCOMPARE(list.lastIndexOf(QRegularExpression("[aeiou]")), -1);
}
}
void tst_QStringList::indexOf_data() void tst_QStringList::indexOf_data()
{ {
QTest::addColumn<QString>("search"); QTest::addColumn<QString>("search");
@ -248,12 +167,6 @@ void tst_QStringList::filter()
list2 << "Bill Gates" << "Bill Clinton"; list2 << "Bill Gates" << "Bill Clinton";
QCOMPARE( list1, list2 ); QCOMPARE( list1, list2 );
QStringList list3, list4;
list3 << "Bill Gates" << "Joe Blow" << "Bill Clinton";
list3 = list3.filter( QRegExp("[i]ll") );
list4 << "Bill Gates" << "Bill Clinton";
QCOMPARE( list3, list4 );
QStringList list5, list6; QStringList list5, list6;
list5 << "Bill Gates" << "Joe Blow" << "Bill Clinton"; list5 << "Bill Gates" << "Joe Blow" << "Bill Clinton";
list5 = list5.filter( QRegularExpression("[i]ll") ); list5 = list5.filter( QRegularExpression("[i]ll") );
@ -299,18 +212,6 @@ void tst_QStringList::replaceInStrings()
list2 << "olpho" << "beto" << "gommo" << "epsilon"; list2 << "olpho" << "beto" << "gommo" << "epsilon";
QCOMPARE( list1, list2 ); QCOMPARE( list1, list2 );
QStringList list3, list4;
list3 << "alpha" << "beta" << "gamma" << "epsilon";
list3.replaceInStrings( QRegExp("^a"), "o" );
list4 << "olpha" << "beta" << "gamma" << "epsilon";
QCOMPARE( list3, list4 );
QStringList list5, list6;
list5 << "Bill Clinton" << "Gates, Bill";
list6 << "Bill Clinton" << "Bill Gates";
list5.replaceInStrings( QRegExp("^(.*), (.*)$"), "\\2 \\1" );
QCOMPARE( list5, list6 );
QStringList list7, list8; QStringList list7, list8;
list7 << "alpha" << "beta" << "gamma" << "epsilon"; list7 << "alpha" << "beta" << "gamma" << "epsilon";
list7.replaceInStrings( QRegularExpression("^a"), "o" ); list7.replaceInStrings( QRegularExpression("^a"), "o" );

View File

@ -36,7 +36,6 @@ public:
tst_QString(); tst_QString();
private slots: private slots:
void section_regexp_data() { section_data_impl(); } void section_regexp_data() { section_data_impl(); }
void section_regexp() { section_impl<QRegExp>(); }
void section_regularexpression_data() { section_data_impl(); } void section_regularexpression_data() { section_data_impl(); }
void section_regularexpression() { section_impl<QRegularExpression>(); } void section_regularexpression() { section_impl<QRegularExpression>(); }
void section_string_data() { section_data_impl(false); } void section_string_data() { section_data_impl(false); }