diff options
author | Olivier Goffart <ogoffart@trolltech.com> | 2009-07-23 11:14:23 (GMT) |
---|---|---|
committer | Olivier Goffart <ogoffart@trolltech.com> | 2009-07-23 11:39:48 (GMT) |
commit | 2792e2570b1eef7652890958dd2b48209aa1a37b (patch) | |
tree | 4630aab4b8ffb846d654f149b4429aa7106e6675 /src/corelib/tools | |
parent | 9c2a2e94f4d95b5fc26e929650e475adffbee6ae (diff) | |
download | Qt-2792e2570b1eef7652890958dd2b48209aa1a37b.zip Qt-2792e2570b1eef7652890958dd2b48209aa1a37b.tar.gz Qt-2792e2570b1eef7652890958dd2b48209aa1a37b.tar.bz2 |
Try best to convert a regexp to a ECMAScript expression
Diffstat (limited to 'src/corelib/tools')
-rw-r--r-- | src/corelib/tools/qregexp.cpp | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/src/corelib/tools/qregexp.cpp b/src/corelib/tools/qregexp.cpp index 3108f31..b0f2054 100644 --- a/src/corelib/tools/qregexp.cpp +++ b/src/corelib/tools/qregexp.cpp @@ -1252,25 +1252,33 @@ struct QRegExpLookahead }; #endif -QRegExpEngine::QRegExpEngine(const QRegExpEngineKey &key) - : cs(key.cs), greedyQuantifiers(key.patternSyntax == QRegExp::RegExp2) -{ - setup(); - - QString rx; +/*! \internal + convert the pattern string to the RegExp syntax. - switch (key.patternSyntax) { - case QRegExp::Wildcard: + This is also used by QScriptEngine::newRegExp to convert to a pattern that JavaScriptCore can understan + */ +Q_CORE_EXPORT QString qt_regexp_toCanonical(const QString &pattern, QRegExp::PatternSyntax patternSyntax) +{ + switch (patternSyntax) { #ifndef QT_NO_REGEXP_WILDCARD - rx = wc2rx(key.pattern); -#endif + case QRegExp::Wildcard: + return wc2rx(pattern); break; +#endif case QRegExp::FixedString: - rx = QRegExp::escape(key.pattern); + return QRegExp::escape(pattern); break; default: - rx = key.pattern; + return pattern; } +} + +QRegExpEngine::QRegExpEngine(const QRegExpEngineKey &key) + : cs(key.cs), greedyQuantifiers(key.patternSyntax == QRegExp::RegExp2) +{ + setup(); + + QString rx = qt_regexp_toCanonical(key.pattern, key.patternSyntax); valid = (parse(rx.unicode(), rx.length()) == rx.length()); if (!valid) { |