summaryrefslogtreecommitdiffstats
path: root/src/corelib/text/qregularexpression.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/text/qregularexpression.cpp')
-rw-r--r--src/corelib/text/qregularexpression.cpp64
1 files changed, 51 insertions, 13 deletions
diff --git a/src/corelib/text/qregularexpression.cpp b/src/corelib/text/qregularexpression.cpp
index 59d21e0a23..d74b759aa9 100644
--- a/src/corelib/text/qregularexpression.cpp
+++ b/src/corelib/text/qregularexpression.cpp
@@ -1,7 +1,7 @@
/****************************************************************************
**
-** Copyright (C) 2016 Giuseppe D'Angelo <dangelog@gmail.com>.
-** Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
+** Copyright (C) 2020 Giuseppe D'Angelo <dangelog@gmail.com>.
+** Copyright (C) 2020 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
@@ -863,7 +863,7 @@ struct QRegularExpressionPrivate : QSharedData
QRegularExpression::MatchType matchType,
QRegularExpression::MatchOptions matchOptions,
CheckSubjectStringOption checkSubjectStringOption = CheckSubjectString,
- const QRegularExpressionMatchPrivate *previous = 0) const;
+ const QRegularExpressionMatchPrivate *previous = nullptr) const;
int captureIndexForName(QStringView name) const;
@@ -944,7 +944,7 @@ QRegularExpression::QRegularExpression(QRegularExpressionPrivate &dd)
*/
QRegularExpressionPrivate::QRegularExpressionPrivate()
: QSharedData(),
- patternOptions(0),
+ patternOptions(),
pattern(),
mutex(),
compiledPattern(nullptr),
@@ -1022,7 +1022,7 @@ void QRegularExpressionPrivate::compilePattern()
options,
&errorCode,
&patternErrorOffset,
- NULL);
+ nullptr);
if (!compiledPattern) {
errorOffset = static_cast<int>(patternErrorOffset);
@@ -1081,7 +1081,7 @@ public:
{
// The default JIT stack size in PCRE is 32K,
// we allocate from 32K up to 512K.
- stack = pcre2_jit_stack_create_16(32 * 1024, 512 * 1024, NULL);
+ stack = pcre2_jit_stack_create_16(32 * 1024, 512 * 1024, nullptr);
}
/*!
\internal
@@ -1105,7 +1105,7 @@ static pcre2_jit_stack_16 *qtPcreCallback(void *)
if (jitStacks()->hasLocalData())
return jitStacks()->localData()->stack;
- return 0;
+ return nullptr;
}
/*!
@@ -1272,9 +1272,9 @@ QRegularExpressionMatchPrivate *QRegularExpressionPrivate::doMatch(const QString
previousMatchWasEmpty = true;
}
- pcre2_match_context_16 *matchContext = pcre2_match_context_create_16(NULL);
- pcre2_jit_stack_assign_16(matchContext, &qtPcreCallback, NULL);
- pcre2_match_data_16 *matchData = pcre2_match_data_create_from_pattern_16(compiledPattern, NULL);
+ pcre2_match_context_16 *matchContext = pcre2_match_context_create_16(nullptr);
+ pcre2_jit_stack_assign_16(matchContext, &qtPcreCallback, nullptr);
+ pcre2_match_data_16 *matchData = pcre2_match_data_create_from_pattern_16(compiledPattern, nullptr);
const unsigned short * const subjectUtf16 = subject.utf16() + subjectStart;
@@ -1829,7 +1829,19 @@ uint qHash(const QRegularExpression &key, uint seed) noexcept
return seed;
}
+#if QT_STRINGVIEW_LEVEL < 2
/*!
+ \overload
+*/
+QString QRegularExpression::escape(const QString &str)
+{
+ return escape(QStringView(str));
+}
+#endif // QT_STRINGVIEW_LEVEL < 2
+
+/*!
+ \since 5.15
+
Escapes all characters of \a str so that they no longer have any special
meaning when used as a regular expression pattern string, and returns
the escaped string. For instance:
@@ -1847,7 +1859,7 @@ uint qHash(const QRegularExpression &key, uint seed) noexcept
inside \a str is escaped with the sequence \c{"\\0"} (backslash +
\c{'0'}), instead of \c{"\\\0"} (backslash + \c{NUL}).
*/
-QString QRegularExpression::escape(const QString &str)
+QString QRegularExpression::escape(QStringView str)
{
QString result;
const int count = str.size();
@@ -1882,8 +1894,19 @@ QString QRegularExpression::escape(const QString &str)
return result;
}
+#if QT_STRINGVIEW_LEVEL < 2
/*!
\since 5.12
+ \overload
+*/
+QString QRegularExpression::wildcardToRegularExpression(const QString &pattern)
+{
+ return wildcardToRegularExpression(QStringView(pattern));
+}
+#endif // QT_STRINGVIEW_LEVEL < 2
+
+/*!
+ \since 5.15
Returns a regular expression representation of the given glob \a pattern.
The transformation is targeting file path globbing, which means in particular
@@ -1932,13 +1955,13 @@ QString QRegularExpression::escape(const QString &str)
\sa escape()
*/
-QString QRegularExpression::wildcardToRegularExpression(const QString &pattern)
+QString QRegularExpression::wildcardToRegularExpression(QStringView pattern)
{
const int wclen = pattern.length();
QString rx;
rx.reserve(wclen + wclen / 16);
int i = 0;
- const QChar *wc = pattern.unicode();
+ const QChar *wc = pattern.data();
#ifdef Q_OS_WIN
const QLatin1Char nativePathSeparator('\\');
@@ -2010,16 +2033,31 @@ QString QRegularExpression::wildcardToRegularExpression(const QString &pattern)
return anchoredPattern(rx);
}
+#if QT_STRINGVIEW_LEVEL < 2
/*!
\fn QRegularExpression::anchoredPattern(const QString &expression)
\since 5.12
+ \overload
+*/
+#endif // QT_STRINGVIEW_LEVEL < 2
+
+/*!
+ \since 5.15
+
Returns the \a expression wrapped between the \c{\A} and \c{\z} anchors to
be used for exact matching.
\sa {Porting from QRegExp's Exact Matching}
*/
+QString QRegularExpression::anchoredPattern(QStringView expression)
+{
+ return QString()
+ + QLatin1String("\\A(?:")
+ + expression
+ + QLatin1String(")\\z");
+}
/*!
\since 5.1