Use QRegularExpression instead of deprecated QRegExp

Now it follows closely the definition of wildcard for glob patterns.
The backslash (\) character is not an escape char in this context.
In order to match one of the special characters, place it in square
brackets (for example, [?]).
This commit is contained in:
Vladimir Golovnev (Glassez) 2021-03-14 18:11:23 +03:00
parent ea1c4a8fc8
commit 61d2ff359b
No known key found for this signature in database
GPG key ID: 52A2C7DEE2DFA6F7
11 changed files with 53 additions and 32 deletions

View file

@ -33,10 +33,15 @@
#include <QCollator>
#include <QLocale>
#include <QRegExp>
#include <QtGlobal>
#include <QVector>
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
#include <QRegularExpression>
#else
#include <QRegExp>
#endif
#if defined(Q_OS_MACOS) || defined(__MINGW32__)
#define QBT_USES_QTHREADSTORAGE
#include <QThreadStorage>
@ -181,14 +186,21 @@ QString Utils::String::fromDouble(const double n, const int precision)
return QLocale::system().toString(std::floor(n * prec) / prec, 'f', precision);
}
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
QString Utils::String::wildcardToRegexPattern(const QString &pattern)
{
return QRegularExpression::wildcardToRegularExpression(pattern, QRegularExpression::UnanchoredWildcardConversion);
}
#else
// This is marked as internal in QRegExp.cpp, but is exported. The alternative would be to
// copy the code from QRegExp::wc2rx().
QString qt_regexp_toCanonical(const QString &pattern, QRegExp::PatternSyntax patternSyntax);
QString Utils::String::wildcardToRegex(const QString &pattern)
QString Utils::String::wildcardToRegexPattern(const QString &pattern)
{
return qt_regexp_toCanonical(pattern, QRegExp::Wildcard);
}
#endif
std::optional<bool> Utils::String::parseBool(const QString &string)
{