Move QRegExp and its remaining mentions out of QtCore
Task-number: QTBUG-85235 Change-Id: Ibd6c98d952c1bb9916b64715c6430fb0d3fe3843 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
This commit is contained in:
parent
ac14858e85
commit
361dc074f2
@ -77,7 +77,6 @@ qt_add_tool(${target_name}
|
||||
../src/corelib/text/qchar.h
|
||||
../src/corelib/text/qlocale.cpp ../src/corelib/text/qlocale.h
|
||||
../src/corelib/text/qlocale_tools.cpp ../src/corelib/text/qlocale_tools_p.h
|
||||
../src/corelib/text/qregexp.cpp ../src/corelib/text/qregexp.h
|
||||
../src/corelib/text/qregularexpression.cpp ../src/corelib/text/qregularexpression.h
|
||||
../src/corelib/text/qstring.cpp ../src/corelib/text/qstring.h
|
||||
../src/corelib/text/qstringbuilder.cpp ../src/corelib/text/qstringbuilder.h
|
||||
|
@ -85,7 +85,6 @@ qt_add_tool(${target_name}
|
||||
../src/corelib/text/qchar.h
|
||||
../src/corelib/text/qlocale.cpp ../src/corelib/text/qlocale.h
|
||||
../src/corelib/text/qlocale_tools.cpp ../src/corelib/text/qlocale_tools_p.h
|
||||
../src/corelib/text/qregexp.cpp ../src/corelib/text/qregexp.h
|
||||
../src/corelib/text/qregularexpression.cpp ../src/corelib/text/qregularexpression.h
|
||||
../src/corelib/text/qstring.cpp ../src/corelib/text/qstring.h
|
||||
../src/corelib/text/qstringbuilder.cpp ../src/corelib/text/qstringbuilder.h
|
||||
@ -114,7 +113,6 @@ qt_add_tool(${target_name}
|
||||
../src/corelib/text/qlocale.cpp ../src/corelib/text/qlocale.h
|
||||
../src/corelib/text/qlocale_tools.cpp ../src/corelib/text/qlocale_tools_p.h
|
||||
../src/corelib/tools/qmap.cpp ../src/corelib/tools/qmap.h
|
||||
../src/corelib/text/qregexp.cpp ../src/corelib/text/qregexp.h
|
||||
../src/corelib/text/qregularexpression.cpp ../src/corelib/text/qregularexpression.h
|
||||
../src/corelib/tools/qringbuffer.cpp # special case
|
||||
../src/corelib/text/qstring.cpp ../src/corelib/text/qstring.h
|
||||
|
@ -30,7 +30,7 @@ QOBJS = \
|
||||
qarraydata.o qbitarray.o qbytearray.o qbytearraylist.o qbytearraymatcher.o \
|
||||
qcalendar.o qgregoriancalendar.o qromancalendar.o \
|
||||
qcryptographichash.o qdatetime.o qhash.o \
|
||||
qlocale.o qlocale_tools.o qmap.o qregularexpression.o qregexp.o qringbuffer.o \
|
||||
qlocale.o qlocale_tools.o qmap.o qregularexpression.o qringbuffer.o \
|
||||
qstringbuilder.o qstring.o qstringconverter.o qstringlist.o qversionnumber.o \
|
||||
qvsnprintf.o \
|
||||
pcre2_auto_possess.o pcre2_chartables.o pcre2_compile.o pcre2_config.o \
|
||||
@ -116,7 +116,6 @@ DEPEND_SRC = \
|
||||
$(SOURCE_PATH)/src/corelib/text/qlocale.cpp \
|
||||
$(SOURCE_PATH)/src/corelib/text/qlocale_tools.cpp \
|
||||
$(SOURCE_PATH)/src/corelib/text/qregularexpression.cpp \
|
||||
$(SOURCE_PATH)/src/corelib/text/qregexp.cpp \
|
||||
$(SOURCE_PATH)/src/corelib/text/qstringbuilder.cpp \
|
||||
$(SOURCE_PATH)/src/corelib/text/qstringconverter.cpp \
|
||||
$(SOURCE_PATH)/src/corelib/text/qstring.cpp \
|
||||
@ -449,9 +448,6 @@ qtemporaryfile.o: $(SOURCE_PATH)/src/corelib/io/qtemporaryfile.cpp
|
||||
qregularexpression.o: $(SOURCE_PATH)/src/corelib/text/qregularexpression.cpp
|
||||
$(CXX) -c -o $@ $(CXXFLAGS) $<
|
||||
|
||||
qregexp.o: $(SOURCE_PATH)/src/corelib/text/qregexp.cpp
|
||||
$(CXX) -c -o $@ $(CXXFLAGS) $<
|
||||
|
||||
qbitarray.o: $(SOURCE_PATH)/src/corelib/tools/qbitarray.cpp
|
||||
$(CXX) -c -o $@ $(CXXFLAGS) $<
|
||||
|
||||
|
@ -102,7 +102,6 @@ QTOBJS= \
|
||||
qmap.obj \
|
||||
qoperatingsystemversion.obj \
|
||||
qoperatingsystemversion_win.obj \
|
||||
qregexp.obj \
|
||||
qromancalendar.obj \
|
||||
qstring.obj \
|
||||
qstringconverter.obj \
|
||||
|
@ -3535,7 +3535,8 @@
|
||||
\section2 re_escape(string)
|
||||
|
||||
Returns the \c string with every special regular expression character
|
||||
escaped with a backslash. This function is a wrapper around QRegExp::escape.
|
||||
escaped with a backslash. This function is a wrapper around
|
||||
QRegularExpression::escape.
|
||||
|
||||
\section2 read_registry(tree, key[, flag])
|
||||
|
||||
|
@ -41,7 +41,6 @@
|
||||
#include <qdebug.h>
|
||||
#include <qbuffer.h>
|
||||
#include <qdatetime.h>
|
||||
#include <qregexp.h>
|
||||
|
||||
#if defined(Q_OS_UNIX)
|
||||
#include <unistd.h>
|
||||
|
@ -110,7 +110,7 @@ static int doSed(int argc, char **argv)
|
||||
&& (c == QLatin1Char('+') || c == QLatin1Char('?') || c == QLatin1Char('|')
|
||||
|| c == QLatin1Char('{') || c == QLatin1Char('}')
|
||||
|| c == QLatin1Char('(') || c == QLatin1Char(')'))) {
|
||||
// translate sed rx to QRegExp
|
||||
// translate sed rx to QRegularExpression
|
||||
escaped ^= 1;
|
||||
}
|
||||
if (escaped) {
|
||||
|
@ -152,7 +152,6 @@ SOURCES += \
|
||||
qmap.cpp \
|
||||
qmetatype.cpp \
|
||||
qnumeric.cpp \
|
||||
qregexp.cpp \
|
||||
qregularexpression.cpp \
|
||||
qromancalendar.cpp \
|
||||
qsettings.cpp \
|
||||
@ -209,7 +208,6 @@ HEADERS += \
|
||||
qmap.h \
|
||||
qmetatype.h \
|
||||
qnumeric.h \
|
||||
qregexp.h \
|
||||
qregularexpression.h \
|
||||
qromancalendar_p.h \
|
||||
qstring.h \
|
||||
|
@ -52,7 +52,6 @@
|
||||
#include <qhash.h>
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
#include <qregexp.h>
|
||||
|
||||
//#include <qdir.h>
|
||||
//#include "option.h"
|
||||
|
@ -145,7 +145,6 @@ qt_add_module(Core
|
||||
text/qlocale.cpp text/qlocale.h text/qlocale_p.h
|
||||
text/qlocale_data_p.h
|
||||
text/qlocale_tools.cpp text/qlocale_tools_p.h
|
||||
text/qregexp.cpp text/qregexp.h
|
||||
text/qstring.cpp text/qstring.h
|
||||
text/qstring_compat.cpp
|
||||
text/qstringalgorithms.h text/qstringalgorithms_p.h
|
||||
|
@ -164,7 +164,6 @@ qt_add_module(Core
|
||||
text/qlocale.cpp text/qlocale.h text/qlocale_p.h
|
||||
text/qlocale_data_p.h
|
||||
text/qlocale_tools.cpp text/qlocale_tools_p.h
|
||||
text/qregexp.cpp text/qregexp.h
|
||||
text/qstring.cpp text/qstring.h
|
||||
text/qstring_compat.cpp
|
||||
text/qstringalgorithms.h text/qstringalgorithms_p.h
|
||||
|
@ -1,243 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of the documentation of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:BSD$
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** BSD License Usage
|
||||
** Alternatively, you may use this file under the terms of the BSD license
|
||||
** as follows:
|
||||
**
|
||||
** "Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions are
|
||||
** met:
|
||||
** * Redistributions of source code must retain the above copyright
|
||||
** notice, this list of conditions and the following disclaimer.
|
||||
** * Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in
|
||||
** the documentation and/or other materials provided with the
|
||||
** distribution.
|
||||
** * Neither the name of The Qt Company Ltd nor the names of its
|
||||
** contributors may be used to endorse or promote products derived
|
||||
** from this software without specific prior written permission.
|
||||
**
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
//! [0]
|
||||
QRegExp rx("(\\d+)");
|
||||
QString str = "Offsets: 12 14 99 231 7";
|
||||
QStringList list;
|
||||
int pos = 0;
|
||||
|
||||
while ((pos = rx.indexIn(str, pos)) != -1) {
|
||||
list << rx.cap(1);
|
||||
pos += rx.matchedLength();
|
||||
}
|
||||
// list: ["12", "14", "99", "231", "7"]
|
||||
//! [0]
|
||||
|
||||
|
||||
//! [1]
|
||||
QRegExp rx("*.txt");
|
||||
rx.setPatternSyntax(QRegExp::Wildcard);
|
||||
rx.exactMatch("README.txt"); // returns true
|
||||
rx.exactMatch("welcome.txt.bak"); // returns false
|
||||
//! [1]
|
||||
|
||||
|
||||
//! [2]
|
||||
QRegExp rx("ro+m");
|
||||
rx.setMinimal(true);
|
||||
//! [2]
|
||||
|
||||
|
||||
//! [3]
|
||||
QRegExp mark("\\b" // word boundary
|
||||
"[Mm]ark" // the word we want to match
|
||||
);
|
||||
//! [3]
|
||||
|
||||
|
||||
//! [4]
|
||||
QRegExp rx("^\\d\\d?$"); // match integers 0 to 99
|
||||
rx.indexIn("123"); // returns -1 (no match)
|
||||
rx.indexIn("-6"); // returns -1 (no match)
|
||||
rx.indexIn("6"); // returns 0 (matched at position 0)
|
||||
//! [4]
|
||||
|
||||
|
||||
//! [5]
|
||||
QRegExp rx("^\\S+$"); // match strings without whitespace
|
||||
rx.indexIn("Hello world"); // returns -1 (no match)
|
||||
rx.indexIn("This_is-OK"); // returns 0 (matched at position 0)
|
||||
//! [5]
|
||||
|
||||
|
||||
//! [6]
|
||||
QRegExp rx("\\b(mail|letter|correspondence)\\b");
|
||||
rx.indexIn("I sent you an email"); // returns -1 (no match)
|
||||
rx.indexIn("Please write the letter"); // returns 17
|
||||
//! [6]
|
||||
|
||||
|
||||
//! [7]
|
||||
QString captured = rx.cap(1); // captured == "letter"
|
||||
//! [7]
|
||||
|
||||
|
||||
//! [8]
|
||||
QRegExp rx("&(?!amp;)"); // match ampersands but not &
|
||||
QString line1 = "This & that";
|
||||
line1.replace(rx, "&");
|
||||
// line1 == "This & that"
|
||||
QString line2 = "His & hers & theirs";
|
||||
line2.replace(rx, "&");
|
||||
// line2 == "His & hers & theirs"
|
||||
//! [8]
|
||||
|
||||
|
||||
//! [9]
|
||||
QString str = "One Eric another Eirik, and an Ericsson. "
|
||||
"How many Eiriks, Eric?";
|
||||
QRegExp rx("\\b(Eric|Eirik)\\b"); // match Eric or Eirik
|
||||
int pos = 0; // where we are in the string
|
||||
int count = 0; // how many Eric and Eirik's we've counted
|
||||
while (pos >= 0) {
|
||||
pos = rx.indexIn(str, pos);
|
||||
if (pos >= 0) {
|
||||
++pos; // move along in str
|
||||
++count; // count our Eric or Eirik
|
||||
}
|
||||
}
|
||||
//! [9]
|
||||
|
||||
|
||||
//! [10]
|
||||
str = "The Qt Company Ltd\tqt.io\tFinland";
|
||||
QString company, web, country;
|
||||
rx.setPattern("^([^\t]+)\t([^\t]+)\t([^\t]+)$");
|
||||
if (rx.indexIn(str) != -1) {
|
||||
company = rx.cap(1);
|
||||
web = rx.cap(2);
|
||||
country = rx.cap(3);
|
||||
}
|
||||
//! [10]
|
||||
|
||||
|
||||
//! [11]
|
||||
QStringList field = str.split("\t");
|
||||
//! [11]
|
||||
|
||||
|
||||
//! [12]
|
||||
QRegExp rx("*.html");
|
||||
rx.setPatternSyntax(QRegExp::Wildcard);
|
||||
rx.exactMatch("index.html"); // returns true
|
||||
rx.exactMatch("default.htm"); // returns false
|
||||
rx.exactMatch("readme.txt"); // returns false
|
||||
//! [12]
|
||||
|
||||
|
||||
//! [13]
|
||||
QString str = "offsets: 1.23 .50 71.00 6.00";
|
||||
QRegExp rx("\\d*\\.\\d+"); // primitive floating point matching
|
||||
int count = 0;
|
||||
int pos = 0;
|
||||
while ((pos = rx.indexIn(str, pos)) != -1) {
|
||||
++count;
|
||||
pos += rx.matchedLength();
|
||||
}
|
||||
// pos will be 9, 14, 18 and finally 24; count will end up as 4
|
||||
//! [13]
|
||||
|
||||
|
||||
//! [14]
|
||||
QRegExp rx("(\\d+)(\\s*)(cm|inch(es)?)");
|
||||
int pos = rx.indexIn("Length: 36 inches");
|
||||
QStringList list = rx.capturedTexts();
|
||||
// list is now ("36 inches", "36", " ", "inches", "es")
|
||||
//! [14]
|
||||
|
||||
|
||||
//! [15]
|
||||
QRegExp rx("(\\d+)(?:\\s*)(cm|inch(?:es)?)");
|
||||
int pos = rx.indexIn("Length: 36 inches");
|
||||
QStringList list = rx.capturedTexts();
|
||||
// list is now ("36 inches", "36", "inches")
|
||||
//! [15]
|
||||
|
||||
|
||||
//! [16]
|
||||
QStringList list = rx.capturedTexts();
|
||||
QStringList::iterator it = list.begin();
|
||||
while (it != list.end()) {
|
||||
myProcessing(*it);
|
||||
++it;
|
||||
}
|
||||
//! [16]
|
||||
|
||||
|
||||
//! [17]
|
||||
QRegExp rxlen("(\\d+)(?:\\s*)(cm|inch)");
|
||||
int pos = rxlen.indexIn("Length: 189cm");
|
||||
if (pos > -1) {
|
||||
QString value = rxlen.cap(1); // "189"
|
||||
QString unit = rxlen.cap(2); // "cm"
|
||||
// ...
|
||||
}
|
||||
//! [17]
|
||||
|
||||
|
||||
//! [18]
|
||||
QRegExp rx("/([a-z]+)/([a-z]+)");
|
||||
rx.indexIn("Output /dev/null"); // returns 7 (position of /dev/null)
|
||||
rx.pos(0); // returns 7 (position of /dev/null)
|
||||
rx.pos(1); // returns 8 (position of dev)
|
||||
rx.pos(2); // returns 12 (position of null)
|
||||
//! [18]
|
||||
|
||||
|
||||
//! [19]
|
||||
s1 = QRegExp::escape("bingo"); // s1 == "bingo"
|
||||
s2 = QRegExp::escape("f(x)"); // s2 == "f\\(x\\)"
|
||||
//! [19]
|
||||
|
||||
|
||||
//! [20]
|
||||
QRegExp rx("(" + QRegExp::escape(name) +
|
||||
"|" + QRegExp::escape(alias) + ")");
|
||||
//! [20]
|
||||
|
||||
{
|
||||
//! [21]
|
||||
QString p("a .*|pattern");
|
||||
|
||||
// re matches exactly the pattern string p
|
||||
QRegularExpression re(QRegularExpression::anchoredPattern(p));
|
||||
//! [21]
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -1,151 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of the QtCore module of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL3 included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 3 requirements
|
||||
** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 2.0 or (at your option) the GNU General
|
||||
** Public license version 3 or any later version approved by the KDE Free
|
||||
** Qt Foundation. The licenses are as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-2.0.html and
|
||||
** https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QREGEXP_H
|
||||
#define QREGEXP_H
|
||||
|
||||
#include <QtCore/qglobal.h>
|
||||
|
||||
#ifndef QT_NO_REGEXP
|
||||
|
||||
#include <QtCore/qstring.h>
|
||||
#include <QtCore/qvariant.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
|
||||
struct QRegExpPrivate;
|
||||
class QStringList;
|
||||
class QRegExp;
|
||||
|
||||
Q_CORE_EXPORT size_t qHash(const QRegExp &key, size_t seed = 0) noexcept;
|
||||
|
||||
class Q_CORE_EXPORT QRegExp
|
||||
{
|
||||
public:
|
||||
enum PatternSyntax {
|
||||
RegExp,
|
||||
Wildcard,
|
||||
FixedString,
|
||||
RegExp2,
|
||||
WildcardUnix,
|
||||
W3CXmlSchema11 };
|
||||
enum CaretMode { CaretAtZero, CaretAtOffset, CaretWontMatch };
|
||||
|
||||
QRegExp();
|
||||
explicit QRegExp(const QString &pattern, Qt::CaseSensitivity cs = Qt::CaseSensitive,
|
||||
PatternSyntax syntax = RegExp);
|
||||
QRegExp(const QRegExp &rx);
|
||||
~QRegExp();
|
||||
QRegExp &operator=(const QRegExp &rx);
|
||||
QRegExp &operator=(QRegExp &&other) noexcept { swap(other); return *this; }
|
||||
void swap(QRegExp &other) noexcept { qSwap(priv, other.priv); }
|
||||
|
||||
bool operator==(const QRegExp &rx) const;
|
||||
inline bool operator!=(const QRegExp &rx) const { return !operator==(rx); }
|
||||
|
||||
bool isEmpty() const;
|
||||
bool isValid() const;
|
||||
QString pattern() const;
|
||||
void setPattern(const QString &pattern);
|
||||
Qt::CaseSensitivity caseSensitivity() const;
|
||||
void setCaseSensitivity(Qt::CaseSensitivity cs);
|
||||
PatternSyntax patternSyntax() const;
|
||||
void setPatternSyntax(PatternSyntax syntax);
|
||||
|
||||
bool isMinimal() const;
|
||||
void setMinimal(bool minimal);
|
||||
|
||||
bool exactMatch(const QString &str) const;
|
||||
|
||||
operator QVariant() const;
|
||||
|
||||
int indexIn(const QString &str, int offset = 0, CaretMode caretMode = CaretAtZero) const;
|
||||
int lastIndexIn(const QString &str, int offset = -1, CaretMode caretMode = CaretAtZero) const;
|
||||
int matchedLength() const;
|
||||
#ifndef QT_NO_REGEXP_CAPTURE
|
||||
int captureCount() const;
|
||||
QStringList capturedTexts() const;
|
||||
QStringList capturedTexts();
|
||||
QString cap(int nth = 0) const;
|
||||
QString cap(int nth = 0);
|
||||
int pos(int nth = 0) const;
|
||||
int pos(int nth = 0);
|
||||
QString errorString() const;
|
||||
QString errorString();
|
||||
#endif
|
||||
|
||||
QString replaceIn(const QString &str, const QString &after) const;
|
||||
QString removeIn(const QString &str) const
|
||||
{ return replaceIn(str, QString()); }
|
||||
bool containedIn(const QString &str) const
|
||||
{ return indexIn(str) != -1; }
|
||||
int countIn(const QString &str) const;
|
||||
|
||||
QStringList splitString(const QString &str, Qt::SplitBehavior behavior = Qt::KeepEmptyParts) const;
|
||||
|
||||
int indexIn(const QStringList &list, int from) const;
|
||||
int lastIndexIn(const QStringList &list, int from) const;
|
||||
QStringList replaceIn(const QStringList &stringList, const QString &after) const;
|
||||
QStringList filterList(const QStringList &stringList) const;
|
||||
|
||||
static QString escape(const QString &str);
|
||||
|
||||
friend Q_CORE_EXPORT size_t qHash(const QRegExp &key, size_t seed) noexcept;
|
||||
|
||||
private:
|
||||
QRegExpPrivate *priv;
|
||||
};
|
||||
|
||||
#ifndef QT_NO_DATASTREAM
|
||||
Q_CORE_EXPORT QDataStream &operator<<(QDataStream &out, const QRegExp ®Exp);
|
||||
Q_CORE_EXPORT QDataStream &operator>>(QDataStream &in, QRegExp ®Exp);
|
||||
#endif
|
||||
|
||||
#ifndef QT_NO_DEBUG_STREAM
|
||||
Q_CORE_EXPORT QDebug operator<<(QDebug, const QRegExp &);
|
||||
#endif
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
Q_DECLARE_METATYPE(QRegExp)
|
||||
|
||||
#endif // QT_NO_REGEXP
|
||||
|
||||
#endif // QREGEXP_H
|
@ -16,7 +16,6 @@ HEADERS += \
|
||||
text/qlocale_p.h \
|
||||
text/qlocale_tools_p.h \
|
||||
text/qlocale_data_p.h \
|
||||
text/qregexp.h \
|
||||
text/qstring.h \
|
||||
text/qstringalgorithms.h \
|
||||
text/qstringalgorithms_p.h \
|
||||
@ -41,7 +40,6 @@ SOURCES += \
|
||||
text/qcollator.cpp \
|
||||
text/qlocale.cpp \
|
||||
text/qlocale_tools.cpp \
|
||||
text/qregexp.cpp \
|
||||
text/qstring.cpp \
|
||||
text/qstringbuilder.cpp \
|
||||
text/qstringconverter.cpp \
|
||||
|
@ -214,7 +214,6 @@ QT_CLASS_LIB(QPointF, QtCore, qpoint.h)
|
||||
QT_CLASS_LIB(QQueue, QtCore, qqueue.h)
|
||||
QT_CLASS_LIB(QRect, QtCore, qrect.h)
|
||||
QT_CLASS_LIB(QRectF, QtCore, qrect.h)
|
||||
QT_CLASS_LIB(QRegExp, QtCore, qregexp.h)
|
||||
QT_CLASS_LIB(QScopedPointerDeleter, QtCore, qscopedpointer.h)
|
||||
QT_CLASS_LIB(QScopedPointerArrayDeleter, QtCore, qscopedpointer.h)
|
||||
QT_CLASS_LIB(QScopedPointerPodDeleter, QtCore, qscopedpointer.h)
|
||||
|
@ -8,7 +8,6 @@ add_subdirectory(qchar)
|
||||
add_subdirectory(qcollator)
|
||||
add_subdirectory(qlatin1string)
|
||||
add_subdirectory(qlocale)
|
||||
add_subdirectory(qregexp)
|
||||
add_subdirectory(qregularexpression)
|
||||
add_subdirectory(qstring)
|
||||
add_subdirectory(qstring_no_cast_from_bytearray)
|
||||
|
@ -10,7 +10,6 @@ add_subdirectory(qchar)
|
||||
add_subdirectory(qcollator)
|
||||
add_subdirectory(qlatin1string)
|
||||
add_subdirectory(qlocale)
|
||||
add_subdirectory(qregexp)
|
||||
add_subdirectory(qregularexpression)
|
||||
add_subdirectory(qstring)
|
||||
add_subdirectory(qstring_no_cast_from_bytearray)
|
||||
|
1
tests/auto/corelib/text/qregexp/.gitignore
vendored
1
tests/auto/corelib/text/qregexp/.gitignore
vendored
@ -1 +0,0 @@
|
||||
tst_qregexp
|
@ -1,24 +0,0 @@
|
||||
# Generated from qregexp.pro.
|
||||
|
||||
#####################################################################
|
||||
## tst_qregexp Test:
|
||||
#####################################################################
|
||||
|
||||
qt_add_test(tst_qregexp
|
||||
SOURCES
|
||||
tst_qregexp.cpp
|
||||
)
|
||||
|
||||
# Resources:
|
||||
set(qregexp_resource_files
|
||||
"data/qdatastream_4.9.bin"
|
||||
"data/qdatastream_5.0.bin"
|
||||
)
|
||||
|
||||
qt_add_resource(tst_qregexp "qregexp"
|
||||
PREFIX
|
||||
"/"
|
||||
FILES
|
||||
${qregexp_resource_files}
|
||||
)
|
||||
|
Binary file not shown.
Binary file not shown.
@ -1,5 +0,0 @@
|
||||
CONFIG += testcase
|
||||
TARGET = tst_qregexp
|
||||
QT = core testlib
|
||||
SOURCES = tst_qregexp.cpp
|
||||
RESOURCES += qregexp.qrc
|
@ -1,6 +0,0 @@
|
||||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file>data/qdatastream_4.9.bin</file>
|
||||
<file>data/qdatastream_5.0.bin</file>
|
||||
</qresource>
|
||||
</RCC>
|
File diff suppressed because it is too large
Load Diff
@ -1631,7 +1631,7 @@ void tst_QString::lastIndexOf()
|
||||
QCOMPARE(haystack.lastIndexOf(needle.toLatin1().data(), from, cs), expected);
|
||||
|
||||
if (from >= -1 && from < haystack.size()) {
|
||||
// unfortunately, QString and QRegExp don't have the same out of bound semantics
|
||||
// unfortunately, QString and QRegularExpression don't have the same out of bound semantics
|
||||
// I think QString is wrong -- See file log for contact information.
|
||||
{
|
||||
QRegularExpression::PatternOptions options = QRegularExpression::NoPatternOption;
|
||||
|
@ -11,7 +11,6 @@ SUBDIRS = \
|
||||
qcollator \
|
||||
qlatin1string \
|
||||
qlocale \
|
||||
qregexp \
|
||||
qregularexpression \
|
||||
qstring \
|
||||
qstring_no_cast_from_bytearray \
|
||||
|
@ -1,46 +0,0 @@
|
||||
# Generated from qregexp.pro.
|
||||
|
||||
#####################################################################
|
||||
## tst_bench_qregexp Binary:
|
||||
#####################################################################
|
||||
|
||||
qt_add_benchmark(tst_bench_qregexp
|
||||
EXCEPTIONS
|
||||
SOURCES
|
||||
main.cpp
|
||||
PUBLIC_LIBRARIES
|
||||
Qt::Test
|
||||
)
|
||||
|
||||
# Resources:
|
||||
set(qregexp_resource_files
|
||||
"main.cpp"
|
||||
)
|
||||
|
||||
qt_add_resource(tst_bench_qregexp "qregexp"
|
||||
PREFIX
|
||||
"/"
|
||||
FILES
|
||||
${qregexp_resource_files}
|
||||
)
|
||||
|
||||
|
||||
#### Keys ignored in scope 1:.:.:qregexp.pro:<TRUE>:
|
||||
# TEMPLATE = "app"
|
||||
|
||||
## Scopes:
|
||||
#####################################################################
|
||||
|
||||
qt_extend_target(tst_bench_qregexp CONDITION TARGET Qt::Script AND NOT pcre
|
||||
DEFINES
|
||||
HAVE_JSC
|
||||
PUBLIC_LIBRARIES
|
||||
Qt::Script
|
||||
)
|
||||
|
||||
qt_extend_target(tst_bench_qregexp CONDITION (NOT QNX) AND (EXISTS _ss_[QT_SYSROOT]/usr/include/boost/regex.hpp)
|
||||
DEFINES
|
||||
HAVE_BOOST
|
||||
PUBLIC_LIBRARIES
|
||||
boost_regex
|
||||
)
|
@ -1,615 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of the test suite of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include <QDebug>
|
||||
#include <QRegExp>
|
||||
#include <QString>
|
||||
#include <QFile>
|
||||
|
||||
#include <qtest.h>
|
||||
#ifdef HAVE_BOOST
|
||||
#include <boost/regex.hpp>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_JSC
|
||||
#include <QtScript>
|
||||
#include "pcre/pcre.h"
|
||||
#endif
|
||||
#define ZLIB_VERSION "1.2.3.4"
|
||||
|
||||
class tst_qregexp : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
tst_qregexp();
|
||||
private slots:
|
||||
void escape_old();
|
||||
void escape_old_data() { escape_data(); }
|
||||
void escape_new1();
|
||||
void escape_new1_data() { escape_data(); }
|
||||
void escape_new2();
|
||||
void escape_new2_data() { escape_data(); }
|
||||
void escape_new3();
|
||||
void escape_new3_data() { escape_data(); }
|
||||
void escape_new4();
|
||||
void escape_new4_data() { escape_data(); }
|
||||
/*
|
||||
JSC outperforms everything.
|
||||
Boost is less impressive then expected.
|
||||
*/
|
||||
void simpleFind1();
|
||||
void rangeReplace1();
|
||||
void matchReplace1();
|
||||
|
||||
void simpleFind2();
|
||||
void rangeReplace2();
|
||||
void matchReplace2();
|
||||
|
||||
void simpleFindJSC();
|
||||
void rangeReplaceJSC();
|
||||
void matchReplaceJSC();
|
||||
|
||||
void simpleFindBoost();
|
||||
void rangeReplaceBoost();
|
||||
void matchReplaceBoost();
|
||||
|
||||
/* those apply an (incorrect) regexp on entire source
|
||||
(this main.cpp). JSC appears to handle this
|
||||
(ab)use case best. QRegExp performs extremly bad.
|
||||
*/
|
||||
void horribleWrongReplace1();
|
||||
void horribleReplace1();
|
||||
void horribleReplace2();
|
||||
void horribleWrongReplace2();
|
||||
void horribleWrongReplaceJSC();
|
||||
void horribleReplaceJSC();
|
||||
void horribleWrongReplaceBoost();
|
||||
void horribleReplaceBoost();
|
||||
private:
|
||||
QString str1;
|
||||
QString str2;
|
||||
void escape_data();
|
||||
};
|
||||
|
||||
tst_qregexp::tst_qregexp()
|
||||
:QObject()
|
||||
,str1("We are all happy monkeys")
|
||||
{
|
||||
QFile f(":/main.cpp");
|
||||
f.open(QFile::ReadOnly);
|
||||
str2=f.readAll();
|
||||
}
|
||||
|
||||
static void verify(const QString "ed, const QString &expected)
|
||||
{
|
||||
if (quoted != expected)
|
||||
qDebug() << "ERROR:" << quoted << expected;
|
||||
}
|
||||
|
||||
void tst_qregexp::escape_data()
|
||||
{
|
||||
QTest::addColumn<QString>("pattern");
|
||||
QTest::addColumn<QString>("expected");
|
||||
|
||||
QTest::newRow("escape 0") << "Hello world" << "Hello world";
|
||||
QTest::newRow("escape 1") << "(Hello world)" << "\\(Hello world\\)";
|
||||
{
|
||||
QString s;
|
||||
for (int i = 0; i < 10; ++i)
|
||||
s += "(escape)";
|
||||
QTest::newRow("escape 10") << s << QRegExp::escape(s);
|
||||
}
|
||||
{
|
||||
QString s;
|
||||
for (int i = 0; i < 100; ++i)
|
||||
s += "(escape)";
|
||||
QTest::newRow("escape 100") << s << QRegExp::escape(s);
|
||||
}
|
||||
}
|
||||
|
||||
void tst_qregexp::escape_old()
|
||||
{
|
||||
QFETCH(QString, pattern);
|
||||
QFETCH(QString, expected);
|
||||
|
||||
QBENCHMARK {
|
||||
static const char meta[] = "$()*+.?[\\]^{|}";
|
||||
QString quoted = pattern;
|
||||
int i = 0;
|
||||
|
||||
while (i < quoted.length()) {
|
||||
if (strchr(meta, quoted.at(i).toLatin1()) != 0)
|
||||
quoted.insert(i++, QLatin1Char('\\'));
|
||||
++i;
|
||||
}
|
||||
|
||||
verify(quoted, expected);
|
||||
}
|
||||
}
|
||||
|
||||
void tst_qregexp::escape_new1()
|
||||
{
|
||||
QFETCH(QString, pattern);
|
||||
QFETCH(QString, expected);
|
||||
|
||||
QBENCHMARK {
|
||||
QString quoted;
|
||||
const int count = pattern.count();
|
||||
quoted.reserve(count * 2);
|
||||
const QLatin1Char backslash('\\');
|
||||
for (int i = 0; i < count; i++) {
|
||||
switch (pattern.at(i).toLatin1()) {
|
||||
case '$':
|
||||
case '(':
|
||||
case ')':
|
||||
case '*':
|
||||
case '+':
|
||||
case '.':
|
||||
case '?':
|
||||
case '[':
|
||||
case '\\':
|
||||
case ']':
|
||||
case '^':
|
||||
case '{':
|
||||
case '|':
|
||||
case '}':
|
||||
quoted.append(backslash);
|
||||
}
|
||||
quoted.append(pattern.at(i));
|
||||
}
|
||||
verify(quoted, expected);
|
||||
}
|
||||
}
|
||||
|
||||
void tst_qregexp::escape_new2()
|
||||
{
|
||||
QFETCH(QString, pattern);
|
||||
QFETCH(QString, expected);
|
||||
|
||||
QBENCHMARK {
|
||||
int count = pattern.count();
|
||||
const QLatin1Char backslash('\\');
|
||||
QString quoted(count * 2, backslash);
|
||||
const QChar *patternData = pattern.data();
|
||||
QChar *quotedData = quoted.data();
|
||||
int escaped = 0;
|
||||
for ( ; --count >= 0; ++patternData) {
|
||||
const QChar c = *patternData;
|
||||
switch (c.unicode()) {
|
||||
case '$':
|
||||
case '(':
|
||||
case ')':
|
||||
case '*':
|
||||
case '+':
|
||||
case '.':
|
||||
case '?':
|
||||
case '[':
|
||||
case '\\':
|
||||
case ']':
|
||||
case '^':
|
||||
case '{':
|
||||
case '|':
|
||||
case '}':
|
||||
++escaped;
|
||||
++quotedData;
|
||||
}
|
||||
*quotedData = c;
|
||||
++quotedData;
|
||||
}
|
||||
quoted.resize(pattern.size() + escaped);
|
||||
|
||||
verify(quoted, expected);
|
||||
}
|
||||
}
|
||||
|
||||
void tst_qregexp::escape_new3()
|
||||
{
|
||||
QFETCH(QString, pattern);
|
||||
QFETCH(QString, expected);
|
||||
|
||||
QBENCHMARK {
|
||||
QString quoted;
|
||||
const int count = pattern.count();
|
||||
quoted.reserve(count * 2);
|
||||
const QLatin1Char backslash('\\');
|
||||
for (int i = 0; i < count; i++) {
|
||||
switch (pattern.at(i).toLatin1()) {
|
||||
case '$':
|
||||
case '(':
|
||||
case ')':
|
||||
case '*':
|
||||
case '+':
|
||||
case '.':
|
||||
case '?':
|
||||
case '[':
|
||||
case '\\':
|
||||
case ']':
|
||||
case '^':
|
||||
case '{':
|
||||
case '|':
|
||||
case '}':
|
||||
quoted += backslash;
|
||||
}
|
||||
quoted += pattern.at(i);
|
||||
}
|
||||
|
||||
verify(quoted, expected);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static inline bool needsEscaping(int c)
|
||||
{
|
||||
switch (c) {
|
||||
case '$':
|
||||
case '(':
|
||||
case ')':
|
||||
case '*':
|
||||
case '+':
|
||||
case '.':
|
||||
case '?':
|
||||
case '[':
|
||||
case '\\':
|
||||
case ']':
|
||||
case '^':
|
||||
case '{':
|
||||
case '|':
|
||||
case '}':
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void tst_qregexp::escape_new4()
|
||||
{
|
||||
QFETCH(QString, pattern);
|
||||
QFETCH(QString, expected);
|
||||
|
||||
QBENCHMARK {
|
||||
const int n = pattern.size();
|
||||
const QChar *patternData = pattern.data();
|
||||
// try to prevent copy if no escape is needed
|
||||
int i = 0;
|
||||
for (int i = 0; i != n; ++i) {
|
||||
const QChar c = patternData[i];
|
||||
if (needsEscaping(c.unicode()))
|
||||
break;
|
||||
}
|
||||
if (i == n) {
|
||||
verify(pattern, expected);
|
||||
// no escaping needed, "return pattern" should be done here.
|
||||
return;
|
||||
}
|
||||
const QLatin1Char backslash('\\');
|
||||
QString quoted(n * 2, backslash);
|
||||
QChar *quotedData = quoted.data();
|
||||
for (int j = 0; j != i; ++j)
|
||||
*quotedData++ = *patternData++;
|
||||
int escaped = 0;
|
||||
for (; i != n; ++i) {
|
||||
const QChar c = *patternData;
|
||||
if (needsEscaping(c.unicode())) {
|
||||
++escaped;
|
||||
++quotedData;
|
||||
}
|
||||
*quotedData = c;
|
||||
++quotedData;
|
||||
++patternData;
|
||||
}
|
||||
quoted.resize(n + escaped);
|
||||
verify(quoted, expected);
|
||||
// "return quoted"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void tst_qregexp::simpleFind1()
|
||||
{
|
||||
int roff;
|
||||
QRegExp rx("happy");
|
||||
rx.setPatternSyntax(QRegExp::RegExp);
|
||||
QBENCHMARK{
|
||||
roff = rx.indexIn(str1);
|
||||
}
|
||||
QCOMPARE(roff, 11);
|
||||
}
|
||||
|
||||
void tst_qregexp::rangeReplace1()
|
||||
{
|
||||
QString r;
|
||||
QRegExp rx("[a-f]");
|
||||
rx.setPatternSyntax(QRegExp::RegExp);
|
||||
QBENCHMARK{
|
||||
r = QString(str1).replace(rx, "-");
|
||||
}
|
||||
QCOMPARE(r, QString("W- -r- -ll h-ppy monk-ys"));
|
||||
}
|
||||
|
||||
void tst_qregexp::matchReplace1()
|
||||
{
|
||||
QString r;
|
||||
QRegExp rx("[^a-f]*([a-f]+)[^a-f]*");
|
||||
rx.setPatternSyntax(QRegExp::RegExp);
|
||||
QBENCHMARK{
|
||||
r = QString(str1).replace(rx, "\\1");
|
||||
}
|
||||
QCOMPARE(r, QString("eaeaae"));
|
||||
}
|
||||
|
||||
void tst_qregexp::horribleWrongReplace1()
|
||||
{
|
||||
QString r;
|
||||
QRegExp rx(".*#""define ZLIB_VERSION \"([0-9]+)\\.([0-9]+)\\.([0-9]+)\".*");
|
||||
rx.setPatternSyntax(QRegExp::RegExp);
|
||||
QBENCHMARK{
|
||||
r = QString(str2).replace(rx, "\\1.\\2.\\3");
|
||||
}
|
||||
QCOMPARE(r, str2);
|
||||
}
|
||||
|
||||
void tst_qregexp::horribleReplace1()
|
||||
{
|
||||
QString r;
|
||||
QRegExp rx(".*#""define ZLIB_VERSION \"([0-9]+)\\.([0-9]+)\\.([0-9]+).*");
|
||||
rx.setPatternSyntax(QRegExp::RegExp);
|
||||
QBENCHMARK{
|
||||
r = QString(str2).replace(rx, "\\1.\\2.\\3");
|
||||
}
|
||||
QCOMPARE(r, QString("1.2.3"));
|
||||
}
|
||||
|
||||
|
||||
void tst_qregexp::simpleFind2()
|
||||
{
|
||||
int roff;
|
||||
QRegExp rx("happy");
|
||||
rx.setPatternSyntax(QRegExp::RegExp2);
|
||||
QBENCHMARK{
|
||||
roff = rx.indexIn(str1);
|
||||
}
|
||||
QCOMPARE(roff, 11);
|
||||
}
|
||||
|
||||
void tst_qregexp::rangeReplace2()
|
||||
{
|
||||
QString r;
|
||||
QRegExp rx("[a-f]");
|
||||
rx.setPatternSyntax(QRegExp::RegExp2);
|
||||
QBENCHMARK{
|
||||
r = QString(str1).replace(rx, "-");
|
||||
}
|
||||
QCOMPARE(r, QString("W- -r- -ll h-ppy monk-ys"));
|
||||
}
|
||||
|
||||
void tst_qregexp::matchReplace2()
|
||||
{
|
||||
QString r;
|
||||
QRegExp rx("[^a-f]*([a-f]+)[^a-f]*");
|
||||
rx.setPatternSyntax(QRegExp::RegExp2);
|
||||
QBENCHMARK{
|
||||
r = QString(str1).replace(rx, "\\1");
|
||||
}
|
||||
QCOMPARE(r, QString("eaeaae"));
|
||||
}
|
||||
|
||||
void tst_qregexp::horribleWrongReplace2()
|
||||
{
|
||||
QString r;
|
||||
QRegExp rx(".*#""define ZLIB_VERSION \"([0-9]+)\\.([0-9]+)\\.([0-9]+)\".*");
|
||||
rx.setPatternSyntax(QRegExp::RegExp2);
|
||||
QBENCHMARK{
|
||||
r = QString(str2).replace(rx, "\\1.\\2.\\3");
|
||||
}
|
||||
QCOMPARE(r, str2);
|
||||
}
|
||||
|
||||
void tst_qregexp::horribleReplace2()
|
||||
{
|
||||
QString r;
|
||||
QRegExp rx(".*#""define ZLIB_VERSION \"([0-9]+)\\.([0-9]+)\\.([0-9]+).*");
|
||||
rx.setPatternSyntax(QRegExp::RegExp2);
|
||||
QBENCHMARK{
|
||||
r = QString(str2).replace(rx, "\\1.\\2.\\3");
|
||||
}
|
||||
QCOMPARE(r, QString("1.2.3"));
|
||||
}
|
||||
void tst_qregexp::simpleFindJSC()
|
||||
{
|
||||
#ifdef HAVE_JSC
|
||||
int numr;
|
||||
const char * errmsg=" ";
|
||||
QString rxs("happy");
|
||||
JSRegExp *rx = jsRegExpCompile(rxs.utf16(), rxs.length(), JSRegExpDoNotIgnoreCase, JSRegExpSingleLine, 0, &errmsg);
|
||||
QVERIFY(rx != 0);
|
||||
QString s(str1);
|
||||
int offsetVector[3];
|
||||
QBENCHMARK{
|
||||
numr = jsRegExpExecute(rx, s.utf16(), s.length(), 0, offsetVector, 3);
|
||||
}
|
||||
jsRegExpFree(rx);
|
||||
QCOMPARE(numr, 1);
|
||||
QCOMPARE(offsetVector[0], 11);
|
||||
#else
|
||||
QSKIP("JSC is not enabled for this platform");
|
||||
#endif
|
||||
}
|
||||
|
||||
void tst_qregexp::rangeReplaceJSC()
|
||||
{
|
||||
#ifdef HAVE_JSC
|
||||
QScriptValue r;
|
||||
QScriptEngine engine;
|
||||
engine.globalObject().setProperty("s", str1);
|
||||
QScriptValue replaceFunc = engine.evaluate("(function() { return s.replace(/[a-f]/g, '-') } )");
|
||||
QVERIFY(replaceFunc.isFunction());
|
||||
QBENCHMARK{
|
||||
r = replaceFunc.call(QScriptValue());
|
||||
}
|
||||
QCOMPARE(r.toString(), QString("W- -r- -ll h-ppy monk-ys"));
|
||||
#else
|
||||
QSKIP("JSC is not enabled for this platform");
|
||||
#endif
|
||||
}
|
||||
|
||||
void tst_qregexp::matchReplaceJSC()
|
||||
{
|
||||
#ifdef HAVE_JSC
|
||||
QScriptValue r;
|
||||
QScriptEngine engine;
|
||||
engine.globalObject().setProperty("s", str1);
|
||||
QScriptValue replaceFunc = engine.evaluate("(function() { return s.replace(/[^a-f]*([a-f]+)[^a-f]*/g, '$1') } )");
|
||||
QVERIFY(replaceFunc.isFunction());
|
||||
QBENCHMARK{
|
||||
r = replaceFunc.call(QScriptValue());
|
||||
}
|
||||
QCOMPARE(r.toString(), QString("eaeaae"));
|
||||
#else
|
||||
QSKIP("JSC is not enabled for this platform");
|
||||
#endif
|
||||
}
|
||||
|
||||
void tst_qregexp::horribleWrongReplaceJSC()
|
||||
{
|
||||
#ifdef HAVE_JSC
|
||||
QScriptValue r;
|
||||
QScriptEngine engine;
|
||||
engine.globalObject().setProperty("s", str2);
|
||||
QScriptValue replaceFunc = engine.evaluate("(function() { return s.replace(/.*#""define ZLIB_VERSION \"([0-9]+)\\.([0-9]+)\\.([0-9]+)\".*/gm, '$1.$2.$3') } )");
|
||||
QVERIFY(replaceFunc.isFunction());
|
||||
QBENCHMARK{
|
||||
r = replaceFunc.call(QScriptValue());
|
||||
}
|
||||
QCOMPARE(r.toString(), str2);
|
||||
#else
|
||||
QSKIP("JSC is not enabled for this platform");
|
||||
#endif
|
||||
}
|
||||
|
||||
void tst_qregexp::horribleReplaceJSC()
|
||||
{
|
||||
#ifdef HAVE_JSC
|
||||
QScriptValue r;
|
||||
QScriptEngine engine;
|
||||
// the m flag doesn't actually work here; dunno
|
||||
engine.globalObject().setProperty("s", str2.replace('\n', ' '));
|
||||
QScriptValue replaceFunc = engine.evaluate("(function() { return s.replace(/.*#""define ZLIB_VERSION \"([0-9]+)\\.([0-9]+)\\.([0-9]+).*/gm, '$1.$2.$3') } )");
|
||||
QVERIFY(replaceFunc.isFunction());
|
||||
QBENCHMARK{
|
||||
r = replaceFunc.call(QScriptValue());
|
||||
}
|
||||
QCOMPARE(r.toString(), QString("1.2.3"));
|
||||
#else
|
||||
QSKIP("JSC is not enabled for this platform");
|
||||
#endif
|
||||
}
|
||||
|
||||
void tst_qregexp::simpleFindBoost()
|
||||
{
|
||||
#ifdef HAVE_BOOST
|
||||
int roff;
|
||||
boost::regex rx ("happy", boost::regex_constants::perl);
|
||||
std::string s = str1.toStdString();
|
||||
std::string::const_iterator start, end;
|
||||
start = s.begin();
|
||||
end = s.end();
|
||||
boost::match_flag_type flags = boost::match_default;
|
||||
QBENCHMARK{
|
||||
boost::match_results<std::string::const_iterator> what;
|
||||
regex_search(start, end, what, rx, flags);
|
||||
roff = (what[0].first)-start;
|
||||
}
|
||||
QCOMPARE(roff, 11);
|
||||
#else
|
||||
QSKIP("Boost is not enabled for this platform");
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
void tst_qregexp::rangeReplaceBoost()
|
||||
{
|
||||
#ifdef HAVE_BOOST
|
||||
boost::regex pattern ("[a-f]", boost::regex_constants::perl);
|
||||
std::string s = str1.toStdString();
|
||||
std::string r;
|
||||
QBENCHMARK{
|
||||
r = boost::regex_replace (s, pattern, "-");
|
||||
}
|
||||
QCOMPARE(r, std::string("W- -r- -ll h-ppy monk-ys"));
|
||||
#else
|
||||
QSKIP("Boost is not enabled for this platform");
|
||||
#endif
|
||||
}
|
||||
|
||||
void tst_qregexp::matchReplaceBoost()
|
||||
{
|
||||
#ifdef HAVE_BOOST
|
||||
boost::regex pattern ("[^a-f]*([a-f]+)[^a-f]*",boost::regex_constants::perl);
|
||||
std::string s = str1.toStdString();
|
||||
std::string r;
|
||||
QBENCHMARK{
|
||||
r = boost::regex_replace (s, pattern, "$1");
|
||||
}
|
||||
QCOMPARE(r, std::string("eaeaae"));
|
||||
#else
|
||||
QSKIP("Boost is not enabled for this platform");
|
||||
#endif
|
||||
}
|
||||
|
||||
void tst_qregexp::horribleWrongReplaceBoost()
|
||||
{
|
||||
#ifdef HAVE_BOOST
|
||||
boost::regex pattern (".*#""define ZLIB_VERSION \"([0-9]+)\\.([0-9]+)\\.([0-9]+)\".*", boost::regex_constants::perl);
|
||||
std::string s = str2.toStdString();
|
||||
std::string r;
|
||||
QBENCHMARK{
|
||||
r = boost::regex_replace (s, pattern, "$1.$2.$3");
|
||||
}
|
||||
QCOMPARE(r, s);
|
||||
#else
|
||||
QSKIP("Boost is not enabled for this platform");
|
||||
#endif
|
||||
}
|
||||
|
||||
void tst_qregexp::horribleReplaceBoost()
|
||||
{
|
||||
#ifdef HAVE_BOOST
|
||||
boost::regex pattern (".*#""define ZLIB_VERSION \"([0-9]+)\\.([0-9]+)\\.([0-9]+).*", boost::regex_constants::perl);
|
||||
std::string s = str2.toStdString();
|
||||
std::string r;
|
||||
QBENCHMARK{
|
||||
r = boost::regex_replace (s, pattern, "$1.$2.$3");
|
||||
}
|
||||
QCOMPARE(r, std::string("1.2.3"));
|
||||
#else
|
||||
QSKIP("Boost is not enabled for this platform");
|
||||
#endif
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_qregexp)
|
||||
|
||||
#include "main.moc"
|
@ -1,20 +0,0 @@
|
||||
TEMPLATE = app
|
||||
CONFIG += benchmark
|
||||
CONFIG += exceptions
|
||||
QT = core testlib
|
||||
|
||||
TARGET = tst_bench_qregexp
|
||||
SOURCES += main.cpp
|
||||
RESOURCES += qregexp.qrc
|
||||
|
||||
qtHaveModule(script):!pcre {
|
||||
DEFINES += HAVE_JSC
|
||||
QT += script
|
||||
}
|
||||
|
||||
!qnx {
|
||||
exists($$[QT_SYSROOT]/usr/include/boost/regex.hpp) {
|
||||
DEFINES += HAVE_BOOST
|
||||
LIBS += -lboost_regex
|
||||
}
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
<!DOCTYPE RCC><RCC version="1.0">
|
||||
<qresource>
|
||||
<file>main.cpp</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
Loading…
Reference in New Issue
Block a user