summaryrefslogtreecommitdiffstats
path: root/src/corelib/text/qregularexpression.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Fix compilation error with MSVC 2019 and C++20Sona Kurazyan2021-10-111-1/+1
| | | | | | | | Fixes: QTBUG-97425 Change-Id: Id327e3494d1deae852f953211c0409a80beafe88 Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> (cherry picked from commit 64e931246484eb36b2b921cdec38263b21167523) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
* QRegularExpression: fix matching over null/empty QString(View)Giuseppe D'Angelo2021-08-191-2/+14
| | | | | | | | | | | | | | | | | | | | | | | | An empty QString(View) is allowed to have nullptr as its data pointer (of course, only if its size is 0). This wasn't properly checked in QRegularExpression, which passed such nullptr to PCRE, and that resulted in PCRE raising an error (PCRE_ERROR_NULL). Detect this case and pass a dummy pointer to keep PCRE happy. Fixing and testing this in turn exposed a problem with QStringView support in QRegularExpression when used over a null QString: the code is supposed to use the QStringView(QString) constructor and NOT qToStringViewIgnoringNull. That's because QRE distinguishes null and empty subjects; when using qToStringViewIgnoringNull over a null QString, one gets a non-null QStringView (!). Again, this in turn exposed a problem with a QRegularExpression autotest that assumed that a null match could only mean "no match" (instead, it can happen at position 0 of a null QString(View)). Change-Id: Ifb3cf14dec42ce76fcdbcb07ea1d80784d52ef65 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> (cherry picked from commit f0d1f50e0294e5a55a0e450993e0810bd4dbf63d) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
* QRegularExpression: add move constructorIvan Solovev2021-01-261-6/+67
| | | | | | | | | | | | - Add move constructors to QRegularExpression, QRegularExpressionMatch and QRegularExpressionMatchIterator. - Update the documentation to explicitly state that only destructor and assignment operators can be called for a moved-from object Task-number: QTBUG-86634 Change-Id: I06b4f54e300541033a9a18339c97338717a06da0 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
* QRegularExpression: mention raw string literal in the docsAhmad Samir2020-12-281-0/+8
| | | | | | | | | | | | | | Raw string literals (since C++11 according to [1]), make writing/reading regex patterns easier, since one can just use e.g. "\w\d" without having to escape those backslashes e.g. "\\w\\d"; this is especially useful with longer/more complex regex patterns. [1] https://en.cppreference.com/w/cpp/language/string_literal Pick-to: 5.15 6.0 Change-Id: I119f9566d27222b915af931ee7e13e064baede61 Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> Reviewed-by: André Hartmann <aha_1980@gmx.de>
* QRE: discourage users from assuming that QRE stores the subjectGiuseppe D'Angelo2020-12-031-0/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | When matching over a QString we store a (shallow) copy of it. That has always been an implementation detail and people should've never relied on it, but Hyrum's law, we don't want to actually exploit this by NOT taking the copy. Converesely, matching over QStringView already requires that the string data is kept alive as long as QRE(Match) objects are alive. Add a doc note to give us the freedom to do the change in Qt 7. [ChangeLog][QtCore][QRegularExpression] QRegularExpression takes a shallow copy of a QString subject when matching over it. This means that users can destroy or modify the string data while still having match results over it. This behavior is deprecated; in a future version of Qt, QRegularExpression will no longer take a copy. Note that behavior has always been undocumented and users were never supposed to modify a subject string while match objects were alive on it. In practice, it's very unlikely that your code is relying on the existing behavior. Change-Id: Ibc5f900c09a007139fb12fc4d7f11e4a8f31bf38 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Revert "QRegularExpression: add move constructor(s)"Giuseppe D'Angelo2020-10-191-37/+0
| | | | | | | | | | | | The QRE classes are not ready for move construction. They would need to deal with the possibility of a null-dpointer, and they currently don't; this clashes with the policy of having moved-from classes in valid-but-unspecified state. This reverts commit 733ab10961a4d6539b4d42cf4768e9cb0b88c6a7. Change-Id: I36720dc9d0bf754a980eba373e37abf725cea174 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QRegularExpression: port to QESDPGiuseppe D'Angelo2020-10-191-3/+2
| | | | | | | | | | | | | For QRegularExpressionMatchIterator there is actually one code path that modifies the object itself. Avoid spurious calls to detach() in there by making the detach explicit, and streamline the rest of the code around it. QRegularExpressionMatch only has a const API so it "doesn't care", but port it for consistency. Change-Id: I26881b3af9ae75082dd39462115869b1a9ee1339 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Fix some bad uses of QSharedPointerData::operator T*Allan Sandfeld Jensen2020-10-161-3/+3
| | | | | | | | Avoid detaching where possible Change-Id: I438d3e66689aeef05951af86a48af2a6910da7c2 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
* QRegularExpression: add move constructor(s)Giuseppe D'Angelo2020-10-061-0/+37
| | | | | Change-Id: I599e4b7338172de5936b191f5e16383c1c31104c Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QREMatchIterator: add support for range-based forGiuseppe D'Angelo2020-09-301-0/+25
| | | | | | | | | | | | | Add begin()/end() on QRegularExpressionMatchIterator, making iterators over an iterator (like directory_iterator). [ChangeLog][QtCore][QRegularExpression] The iterator object (QRegularExpressionMatchIterator) returned by a global match is now usable in a range-based for loop. Change-Id: If3d31bd2e84e7d1fb626a0b3d2745914dff03e39 Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Fix qdoc warnings from removed enum valuesVolker Hilsheimer2020-09-231-10/+0
| | | | | Change-Id: Icd7a941ed1d8c7a4674482ace4b280a15e592c1a Reviewed-by: Paul Wicking <paul.wicking@qt.io>
* Fix some qdoc warnings: QRegularExpression parametersVolker Hilsheimer2020-09-221-5/+7
| | | | | Change-Id: Ib4d33327c6c059e11d8615bac0f72d9f028d5860 Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
* Inline some methods that only forward to another overloadLars Knoll2020-08-291-20/+8
| | | | | Change-Id: Iba74962d20c00de8996834f0a003f38c2d2cc3e8 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Use qsizetype in QRegularExpressionMarcel Krems2020-08-281-29/+29
| | | | | | | PCRE2 already uses size_t which we can now make full use of. Change-Id: Icb5efd5c6ef27f2e31a9780bf62f5671ddc603cd Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QRegularExpression: code tidiesGiuseppe D'Angelo2020-08-261-6/+2
| | | | | | | | Given QList-is-QVector, remove an historical piece of code. Change-Id: I7a8876be8ade6dbaa1822d773b092ddb3c4182d4 Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QRegularExpression: do not assume QStringViews are NUL terminatedGiuseppe D'Angelo2020-08-251-3/+18
| | | | | | | | | | | The convenience API used to look up the index of a named capturing group expects NUL terminated strings. Therefore, we can't just use it together with QStringViews, which may be not. Use the non-convenience API instead. Pick-to: 5.15 Change-Id: I25ca14de49b13ee1764525f8b19f2550c30c1afa Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Move QStringRef and remains to Qt5CompatKarsten Heimrich2020-08-201-1/+1
| | | | | | | | | Export some private functions from QUtf8 to resolve undefined symbols in Qt5Compat after moving QStringRef. Task-number: QTBUG-84437 Change-Id: I9046dcb14ed520d8868a511d79da6e721e26f72b Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* QRegularExpression: Purge deprecated PatternOption membersEdward Welbourne2020-07-201-7/+0
| | | | | | | | | They've been no-ops since (at least) 5.12. At the same time, save future readers the need to git blame to find out how long the other deprecated enum name is. Change-Id: I2081ba2859c6540651b6f6807cc6bd59890bfce5 Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
* Use QList instead of QVector in corelib implementationJarek Kobus2020-06-291-2/+2
| | | | | | | | Omitting state machine and docs for now. Task-number: QTBUG-84469 Change-Id: Ibfa5e7035515773461f6cdbff35299315ef65737 Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
* Rename snippet files to match the carved up corelib/tools/Edward Welbourne2020-06-041-32/+32
| | | | | | | | | | | This is a folllow-up to commits 548513a4bd050d3df0a85fed6e2d1a00ce06d2ab and a9aa206b7b8ac4e69f8c46233b4080e00e845ff5, renaming the snippets files referenced by the files moved out of corelib/tools/ to match the new locations of the files using them. Change-Id: I59f5d3c217ef835e9244387cc769e7212de9d8f5 Reviewed-by: Paul Wicking <paul.wicking@qt.io>
* Doc: fix some typos in QRegularExpression documentationSamuel Gaist2020-06-031-8/+8
| | | | | | Pick-to: 5.15 Change-Id: Ibf96fc775b08df4de0b20d499d8779204ff7df30 Reviewed-by: Paul Wicking <paul.wicking@qt.io>
* Port QRegularExpression to QStringView, drop QStringRefGiuseppe D'Angelo2020-05-311-171/+106
| | | | | | | | | | | | | | | | | | | | | | The idea is pretty simple -- add QRegularExpression matching over QStringView. When matching over a QString, keep the string alive (by taking a copy), and set the view onto that string. Otherwise, just use the view provided by the user (who is then responsible for ensuring the data stays valid while matching). Do just minor refactorings to support this use case in a cleaner fashion. In QRegularExpressionMatch drop the QStringRef-returning methods, as they cannot work any more -- in the general case there won't be a QString to build a QStringRef from. [ChangeLog][QtCore][QRegularExpression] All the APIs dealing with QStringRef have been ported to QStringView, following QStringRef deprecation in Qt 6.0. Change-Id: Ic367991d9583cc108c045e4387c9b7288c8f1ffd Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Long live qHashMulti(Commutative)Giuseppe D'Angelo2020-05-121-4/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | Add a helper function so that we have a shortcut. Instead of writing: QHashCombine hash; seed = hash(seed, fieldA); seed = hash(seed, fieldB); // etc. return seed; one can now simply write: return qHashMulti(seed, fieldA, fieldB, fieldC); Port a few usages inside qtbase as a demonstration. [ChangeLog][QtCore][QHash] Added the qHashMulti and qHashMultiCommutative functions as convenience helpers to calculate a hash from multiple variables (typically, data members of a class). Change-Id: I881a9ad41168df20ceecc6588a94abe7ddc6a532 Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
* QRegularExpression: cast to PCRE2_SPTR16Marc Mutz2020-05-111-4/+4
| | | | | | | | | | It seems that PCRE2_UCHAR16 is exactly ushort, even though it's documented to be uint16_t. There's no requirement for these to be the same type, nor for the PCRE typedef to continue to point to the same type, so add explicit casts. Change-Id: I89f65d29feaada84ea00688976a123364857bc58 Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
* Replace uses of QString::fromUtf16(ushort*) with (char16_t*)Marc Mutz2020-05-101-2/+2
| | | | | | | | | Ditto fromUcs4(uint*) with fromUcs4(char32_t*). The ushort/uint forms will be deprecated. Change-Id: Ia4ce45ed8679951b24af13109e3e498f51fc3c89 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Add a QRegularExpression::fromWildcard() convenience methodLars Knoll2020-05-061-0/+19
| | | | | | | | | Simplify constructing QRegularExpression objects from a glob pattern. Change-Id: I06f60b1dfea3da969e2474dedd44b6ca5d456d7d Reviewed-by: Simon Hausmann <hausmann@gmail.com> Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
* Compile QRegularExpression into qmakeLars Knoll2020-05-051-0/+8
| | | | | | | | This is required to be able to port qmake over to use QRegularExpression instead of QRegExp. Change-Id: I0ad2c19bf3c0a28e52c1e12b4d3daa0300a75ed2 Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
* Move the QRegExp porting docs into the QRegExp class documentationLars Knoll2020-04-151-129/+1
| | | | | | | | | | It used to live in QRegularExpression, but as QRegExp gets removed from Qt Core, the better place for it is to live in the QRegExp docs. Also marked QRegExp as deprecated in the docs. Change-Id: Id5b0e3040e4d46f5d806022b58fbd5b5efd58911 Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
* Add WildcardConversionOptions to QRegularExpressionLars Knoll2020-04-151-5/+24
| | | | | | | | | | 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>
* Change qHash() to work with size_t instead of uintLars Knoll2020-04-091-1/+1
| | | | | | | | | | | This is required, so that QHash and QSet can hold more than 2^32 items on 64 bit platforms. The actual hashing functions for strings are still 32bit, this will be changed in a follow-up commit. Change-Id: I4372125252486075ff3a0b45ecfa818359fe103b Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QRegularExpression: rename AnchoredMatchOption to AnchorAtOffsetMatchOptionGiuseppe D'Angelo2020-04-031-2/+9
| | | | | | | | | | | | | | | | | | The name of the option may cause confusion due to the fact that it's not _fully_ anchoring the match, only anchoring it at the offset passed to match() -- in other words, it's a "left" anchoring. Deprecate the old name and introduce a new one that should explain the situation better. [ChangeLog][QtCore][QRegularExpression] The AnchoredMatchOption match option has been deprecated in favor of AnchorAtOffsetMatchOption, which should better describe that the match is only anchored at the offset. Change-Id: Ib751e5e488f2d0309a2da6496378247dfa4648de Reviewed-by: Samuel Gaist <samuel.gaist@idiap.ch> Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
* QRegularExpression: inline some compatibility callsGiuseppe D'Angelo2020-03-131-10/+2
| | | | | | | | | The functions take QStringView now. The ones taking QString can be implemented inline (BC break). Drive-by change, use qToStringViewIgnoringNull. Change-Id: Ia3089c574446418e5ab93e08e21869ef19fbfbfd Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Merge remote-tracking branch 'origin/5.14' into 5.15Qt Forward Merge Bot2020-01-181-2/+6
|\ | | | | | | Change-Id: I12148e7b20bcdb72d9b328035d528c99633b1e92
| * QRegularExpression: fixup docs of wildcardToRegularExpressionGiuseppe D'Angelo2020-01-151-2/+6
| | | | | | | | | | | | | | | | | | | | Fix a couple of typos, and add a paragraph explaining that there is no need of anchor the pattern again; a wildcard is always anchored. Fixes: QTBUG-81396 Change-Id: Ia67dc7477a05a450bdcc3def1ebbacce2006da4d Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* | Merge remote-tracking branch 'origin/5.14' into 5.15Qt Forward Merge Bot2020-01-131-2/+2
|\| | | | | | | Change-Id: I50f70a789ab1438b40d4408be72c090fa00b801f
| * QRegularExpression: minor doc fixesGiuseppe D'Angelo2020-01-121-2/+2
| | | | | | | | | | | | | | Amends d24a1d4323e73400ef4ecca99e03ff0f41c60389 Change-Id: I108f85b174e21ef71bf269fb9f6725972e76f107 Reviewed-by: David Faure <david.faure@kdab.com>
* | QRegularExpression: make escape-like functions work on QStringViewGiuseppe D'Angelo2020-01-061-5/+43
| | | | | | | | | | | | | | | | | | | | | | They don't store the strings. [ChangeLog][QtCore][QRegularExpression] The escape(), wildcardToRegularExpression() and anchoredPattern() functions now have overloads taking a QStringView parameter. Change-Id: Icc66ba1201ef1f1064d9565900439e78912b675c Reviewed-by: Samuel Gaist <samuel.gaist@idiap.ch>
* | Merge remote-tracking branch 'origin/5.14' into 5.15Qt Forward Merge Bot2020-01-021-25/+40
|\| | | | | | | Change-Id: I7b6e6c687d8d60b4a54e6b9dada025ef66c53d96
| * QRegularExpression: adjust the error codes matching PCRE2 10.34Giuseppe D'Angelo2019-12-281-25/+40
| | | | | | | | | | | | Change-Id: I78ecda1bdc784b8d7a69a4927dbe3b0f08c1d907 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
* | Merge remote-tracking branch 'origin/5.14' into 5.15Qt Forward Merge Bot2019-12-271-0/+32
|\| | | | | | | | | | | | | | | | | Conflicts: .qmake.conf src/plugins/platforms/xcb/qxcbscreen.cpp src/widgets/accessible/qaccessiblewidget.cpp Change-Id: Ib3138e61ba7981610940509a7ff02ba2dd281bf0
| * QRegularExpression: improve docs about porting from QRegExpGiuseppe D'Angelo2019-12-241-0/+32
| | | | | | | | | | Change-Id: Ie5d737188977b0e4dc1070c2d7329d0ecb6a9308 Reviewed-by: David Faure <david.faure@kdab.com>
* | Tidy nullptr usageAllan Sandfeld Jensen2019-12-061-7/+7
| | | | | | | | | | | | | | | | | | | | | | Move away from using 0 as pointer literal. Done using clang-tidy. This is not complete as run-clang-tidy can't handle all of qtbase in one go. Change-Id: I1076a21f32aac0dab078af6f175f7508145eece0 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* | Deprecate constructing QFlags from a pointerAllan Sandfeld Jensen2019-11-201-1/+1
|/ | | | | | | | | This was used to support QFlags f = 0 initialization, but with 0 used as a pointer literal now considered bad form, it had been changed many places to QFlags f = nullptr, which is meaningless and confusing. Change-Id: I4bc592151c255dc5cab1a232615caecc520f02e8 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Doc: Remove 'f.i.'Kai Koehne2019-09-041-1/+1
| | | | | | | | Spell it out, or entirely remove it if it's not necessary. Change-Id: Idc371427e9351d948245ce7b719e3457dfc27845 Reviewed-by: Matthew Woehlke <mwoehlke.floss@gmail.com> Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
* Move text-related code out of corelib/tools/ to corelib/text/Edward Welbourne2019-07-101-0/+2986
This includes byte array, string, char, unicode, locale, collation and regular expressions. Change-Id: I8b125fa52c8c513eb57a0f1298b91910e5a0d786 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>