diff options
author | Lars Knoll <lars.knoll@qt.io> | 2020-03-31 14:12:50 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2020-04-15 14:38:05 +0200 |
commit | cb1000ea02a42de0f79ff8db97219a9923d3efdf (patch) | |
tree | a8fe635c88a2870ec12aa7ef9aba576a863ce6fd /src/corelib/text/qregularexpression.cpp | |
parent | 4b37abc0c9c1a0e1bdb182e725e31daaf610dc7a (diff) |
Add WildcardConversionOptions to QRegularExpression
There are cases, where the conversion from a wildcard pattern to
a regular expression should not lead to an anchored pattern. Allow
this, but adding an optional second argument to
wildcardToRegularExpression, that allows tuning the conversion.
Change-Id: Ida7a32d65ee49bf58d5f8d9906c0a0cd8954a02a
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Diffstat (limited to 'src/corelib/text/qregularexpression.cpp')
-rw-r--r-- | src/corelib/text/qregularexpression.cpp | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/src/corelib/text/qregularexpression.cpp b/src/corelib/text/qregularexpression.cpp index 77aad5e294..cff4c1870c 100644 --- a/src/corelib/text/qregularexpression.cpp +++ b/src/corelib/text/qregularexpression.cpp @@ -1901,12 +1901,27 @@ QString QRegularExpression::escape(QStringView str) #if QT_STRINGVIEW_LEVEL < 2 /*! \since 5.12 - \fn QString QRegularExpression::wildcardToRegularExpression(const QString &pattern) + \fn QString QRegularExpression::wildcardToRegularExpression(const QString &pattern, WildcardConversionType type) \overload */ #endif // QT_STRINGVIEW_LEVEL < 2 /*! + \since 6.0 + \enum QRegularExpression::WildcardConversionOption + + The WildcardConversionOption enum defines modifiers to the way a wildcard glob + pattern gets converted to a regular expression pattern. + + \value DefaultWildcardConversion + No conversion options are set. + + \value UnanchoredWildcardConversion + The conversion will not anchor the pattern. This allows for partial string matches of + wildcard expressions. +*/ + +/*! \since 5.15 Returns a regular expression representation of the given glob \a pattern. @@ -1916,9 +1931,10 @@ QString QRegularExpression::escape(QStringView str) \snippet code/src_corelib_tools_qregularexpression.cpp 31 - The returned regular expression is already fully anchored. In other + By default, the returned regular expression is fully anchored. In other words, there is no need of calling anchoredPattern() again on the - result. + result. To get an a regular expression that is not anchored, pass + UnanchoredWildcardConversion as the conversion \a option. \warning Unlike QRegExp, this implementation follows closely the definition of wildcard for glob patterns: @@ -1956,7 +1972,7 @@ QString QRegularExpression::escape(QStringView str) \sa escape() */ -QString QRegularExpression::wildcardToRegularExpression(QStringView pattern) +QString QRegularExpression::wildcardToRegularExpression(QStringView pattern, WildcardConversionOptions options) { const int wclen = pattern.length(); QString rx; @@ -2031,7 +2047,10 @@ QString QRegularExpression::wildcardToRegularExpression(QStringView pattern) } } - return anchoredPattern(rx); + if (!(options & UnanchoredWildcardConversion)) + rx = anchoredPattern(rx); + + return rx; } #if QT_STRINGVIEW_LEVEL < 2 |