[Development] QTBUG-23489: Implement the new regular expression classes using PCRE

Giuseppe D'Angelo dangelog at gmail.com
Tue Mar 13 16:26:08 CET 2012


Hi,

Some updates on this. After yesterday's discussion it was decided to
keep QRegExp in QtCore as a deprecated class. At the same time all
QRegExp-related classes or overloads get deprecated as well (although
probably not disabled with QT_DEPRECATED_SINCE because very few of
them are actually inline).

The main reason for keeping QRegExp is the possible silent breakage
due to attempting to "translate" regexps or any other behavioural
changes; especially if someone tried to outsmart QRegExp. So unless
something changes again QRegExp is going away in Qt 6.

>> There's another related issue to this bug: What do we do with the old
>> QRegExp? I've gripped through our code and removing it is a larger
>> surgical operation.
>
> Indeed. I really have no clue how hard this would be.
>
> The uses of QRegExp in qtbase and my proposals would be:
>
>  - qmake: lots of use, keep it by copying qregexp.cpp into qmake
Not needed anymore since qregexp stays there

>  - rcc: one single use, very easy to rewrite without regexes
Not needed anymore since qregexp stays there

>  - uic: #includes are unnecessary; remove immediately
Done

>  - QtCore API:
>        * QString non-const QRegExp&: use templates to support QRegExp in inline
>          code (find a way), or simply stop supporting this
Not needed anymore since qregexp stays there

>        * QMetaType & QVariant: let RegExp point to the new class
Done (+2 but not merged yet). I added new methods instead:
http://codereview.qt-project.org/19514

>        * everywhere else (including QStringList): replace with the new class
Replace or just add overloads? For now I've just started to add overloads:
- QString (+2, not merged yet) http://codereview.qt-project.org/18666
- QObject: http://codereview.qt-project.org/19723
- QStringList: http://codereview.qt-project.org/19765
- QSortFilterProxyModel: it has *four* QRegExp-like setters (!), must
find a way to keep the API sane.

>  - QtCore internal uses: use the new class or rewrite (if possible, I
>   recommend a non-regex globbing in QDir and QDirIterator).

This is (apparently) opening a Pandora's box, since both
QRegExp::Wildcard and WildcardUnix have very strange behaviours w.r.t.
to escaping, and I'm not too willing to touch them being so critically
tied to pretty much everything.

But this could lead to a discussion about the behaviour of an eventual
QRegularExpression::fromWildcard.

> If the class is
>   used in bootstrap, then the function in question must be opted out or the
>   code rewritten, like qdatetime.cpp and this comment in qxmlutils.cpp:
>    /* Right, we here have a dependency on QRegExp. Writing a manual parser to
>     * replace that regexp is probably a 70 lines so I prioritize this to when
>     * the dependency is considered alarming, or when the rest of the bugs
>     * are fixed. */
>  - QtXml: used in bootstrap, so must rewrite without regex.
Keep QtXml as-is?

>  Or refactor rcc to
>   use QXmlStreamReader instead of QDom, then remove
Done

>  - QtGui API:
>        * QTextDocument: replace with the new class
Will probably need help with this since I don't know anything about it.

>        * QRegExpValidator: move alongside QRegExp, but add a new class to QtGui
WIP (QRegularExpressionValidator).

>  - QtNetwork API:
>        * QSslSocket (globbing functions for certificates): replace with new enums
WIP; this will be a SIC

>  - QtScript API: replace with new class (same goes for QJSEngine)
>        Maybe since QtScript is done, we leave it as is. But QJSEngine should use
>        the new class.
It's unlikely that I'll touch any of these classes, but they can
switch anytime now...

> We also modify QRegExp to add:
>
>        QRegExp(const QRegularExpression &); // implicit
>        operator QRegularExpression() const;

At this point I might just work to a toRegularExpression() method for
the QRegExp->QRegularExpression conversion -- I just need to know what
I'm supposed to do with the XSD regexp syntax, i.e. if there's any
further interest in keeping it supported or not (since apparently it
has never worked properly, see my other mail).

Opinions? Comments?

Cheers,
-- 
Giuseppe D'Angelo



More information about the Development mailing list