Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/tools/qregularexpression.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||||||||||||||
2 | ** | - | ||||||||||||||||||
3 | ** Copyright (C) 2015 Giuseppe D'Angelo <dangelog@gmail.com>. | - | ||||||||||||||||||
4 | ** Copyright (C) 2015 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | - | ||||||||||||||||||
5 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||||||||||||||
6 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||||||||
7 | ** | - | ||||||||||||||||||
8 | ** This file is part of the QtCore module of the Qt Toolkit. | - | ||||||||||||||||||
9 | ** | - | ||||||||||||||||||
10 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||||||||
11 | ** Commercial License Usage | - | ||||||||||||||||||
12 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||||||||
13 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||||||||
14 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||||||||
15 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||||||||
16 | ** and conditions see http://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||
17 | ** information use the contact form at http://www.qt.io/contact-us. | - | ||||||||||||||||||
18 | ** | - | ||||||||||||||||||
19 | ** GNU Lesser General Public License Usage | - | ||||||||||||||||||
20 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||||||||
21 | ** General Public License version 2.1 or version 3 as published by the Free | - | ||||||||||||||||||
22 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||||||||
23 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||||||||
24 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||||||||
25 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||||||||
26 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||||||||
27 | ** | - | ||||||||||||||||||
28 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||||||||
29 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||||||||
30 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||||||||
31 | ** | - | ||||||||||||||||||
32 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||
33 | ** | - | ||||||||||||||||||
34 | ****************************************************************************/ | - | ||||||||||||||||||
35 | - | |||||||||||||||||||
36 | #include "qregularexpression.h" | - | ||||||||||||||||||
37 | - | |||||||||||||||||||
38 | #ifndef QT_NO_REGULAREXPRESSION | - | ||||||||||||||||||
39 | - | |||||||||||||||||||
40 | #include <QtCore/qcoreapplication.h> | - | ||||||||||||||||||
41 | #include <QtCore/qhashfunctions.h> | - | ||||||||||||||||||
42 | #include <QtCore/qmutex.h> | - | ||||||||||||||||||
43 | #include <QtCore/qvector.h> | - | ||||||||||||||||||
44 | #include <QtCore/qstringlist.h> | - | ||||||||||||||||||
45 | #include <QtCore/qdebug.h> | - | ||||||||||||||||||
46 | #include <QtCore/qthreadstorage.h> | - | ||||||||||||||||||
47 | #include <QtCore/qglobal.h> | - | ||||||||||||||||||
48 | #include <QtCore/qatomic.h> | - | ||||||||||||||||||
49 | #include <QtCore/qdatastream.h> | - | ||||||||||||||||||
50 | - | |||||||||||||||||||
51 | #include <pcre.h> | - | ||||||||||||||||||
52 | - | |||||||||||||||||||
53 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
54 | - | |||||||||||||||||||
55 | /*! | - | ||||||||||||||||||
56 | \class QRegularExpression | - | ||||||||||||||||||
57 | \inmodule QtCore | - | ||||||||||||||||||
58 | \reentrant | - | ||||||||||||||||||
59 | - | |||||||||||||||||||
60 | \brief The QRegularExpression class provides pattern matching using regular | - | ||||||||||||||||||
61 | expressions. | - | ||||||||||||||||||
62 | - | |||||||||||||||||||
63 | \since 5.0 | - | ||||||||||||||||||
64 | - | |||||||||||||||||||
65 | \ingroup tools | - | ||||||||||||||||||
66 | \ingroup shared | - | ||||||||||||||||||
67 | - | |||||||||||||||||||
68 | \keyword regular expression | - | ||||||||||||||||||
69 | - | |||||||||||||||||||
70 | Regular expressions, or \e{regexps}, are a very powerful tool to handle | - | ||||||||||||||||||
71 | strings and texts. This is useful in many contexts, e.g., | - | ||||||||||||||||||
72 | - | |||||||||||||||||||
73 | \table | - | ||||||||||||||||||
74 | \row \li Validation | - | ||||||||||||||||||
75 | \li A regexp can test whether a substring meets some criteria, | - | ||||||||||||||||||
76 | e.g. is an integer or contains no whitespace. | - | ||||||||||||||||||
77 | \row \li Searching | - | ||||||||||||||||||
78 | \li A regexp provides more powerful pattern matching than | - | ||||||||||||||||||
79 | simple substring matching, e.g., match one of the words | - | ||||||||||||||||||
80 | \e{mail}, \e{letter} or \e{correspondence}, but none of the | - | ||||||||||||||||||
81 | words \e{email}, \e{mailman}, \e{mailer}, \e{letterbox}, etc. | - | ||||||||||||||||||
82 | \row \li Search and Replace | - | ||||||||||||||||||
83 | \li A regexp can replace all occurrences of a substring with a | - | ||||||||||||||||||
84 | different substring, e.g., replace all occurrences of \e{&} | - | ||||||||||||||||||
85 | with \e{\&} except where the \e{&} is already followed by | - | ||||||||||||||||||
86 | an \e{amp;}. | - | ||||||||||||||||||
87 | \row \li String Splitting | - | ||||||||||||||||||
88 | \li A regexp can be used to identify where a string should be | - | ||||||||||||||||||
89 | split apart, e.g. splitting tab-delimited strings. | - | ||||||||||||||||||
90 | \endtable | - | ||||||||||||||||||
91 | - | |||||||||||||||||||
92 | This document is by no means a complete reference to pattern matching using | - | ||||||||||||||||||
93 | regular expressions, and the following parts will require the reader to | - | ||||||||||||||||||
94 | have some basic knowledge about Perl-like regular expressions and their | - | ||||||||||||||||||
95 | pattern syntax. | - | ||||||||||||||||||
96 | - | |||||||||||||||||||
97 | Good references about regular expressions include: | - | ||||||||||||||||||
98 | - | |||||||||||||||||||
99 | \list | - | ||||||||||||||||||
100 | \li \e {Mastering Regular Expressions} (Third Edition) by Jeffrey E. F. | - | ||||||||||||||||||
101 | Friedl, ISBN 0-596-52812-4; | - | ||||||||||||||||||
102 | \li the \l{http://pcre.org/pcre.txt} {pcrepattern(3)} man page, describing | - | ||||||||||||||||||
103 | the pattern syntax supported by PCRE (the reference implementation of | - | ||||||||||||||||||
104 | Perl-compatible regular expressions); | - | ||||||||||||||||||
105 | \li the \l{http://perldoc.perl.org/perlre.html} {Perl's regular expression | - | ||||||||||||||||||
106 | documentation} and the \l{http://perldoc.perl.org/perlretut.html} {Perl's | - | ||||||||||||||||||
107 | regular expression tutorial}. | - | ||||||||||||||||||
108 | \endlist | - | ||||||||||||||||||
109 | - | |||||||||||||||||||
110 | \tableofcontents | - | ||||||||||||||||||
111 | - | |||||||||||||||||||
112 | \section1 Introduction | - | ||||||||||||||||||
113 | - | |||||||||||||||||||
114 | QRegularExpression implements Perl-compatible regular expressions. It fully | - | ||||||||||||||||||
115 | supports Unicode. For an overview of the regular expression syntax | - | ||||||||||||||||||
116 | supported by QRegularExpression, please refer to the aforementioned | - | ||||||||||||||||||
117 | pcrepattern(3) man page. A regular expression is made up of two things: a | - | ||||||||||||||||||
118 | \b{pattern string} and a set of \b{pattern options} that change the | - | ||||||||||||||||||
119 | meaning of the pattern string. | - | ||||||||||||||||||
120 | - | |||||||||||||||||||
121 | You can set the pattern string by passing a string to the QRegularExpression | - | ||||||||||||||||||
122 | constructor: | - | ||||||||||||||||||
123 | - | |||||||||||||||||||
124 | \snippet code/src_corelib_tools_qregularexpression.cpp 0 | - | ||||||||||||||||||
125 | - | |||||||||||||||||||
126 | This sets the pattern string to \c{a pattern}. You can also use the | - | ||||||||||||||||||
127 | setPattern() function to set a pattern on an existing QRegularExpression | - | ||||||||||||||||||
128 | object: | - | ||||||||||||||||||
129 | - | |||||||||||||||||||
130 | \snippet code/src_corelib_tools_qregularexpression.cpp 1 | - | ||||||||||||||||||
131 | - | |||||||||||||||||||
132 | Note that due to C++ literal strings rules, you must escape all backslashes | - | ||||||||||||||||||
133 | inside the pattern string with another backslash: | - | ||||||||||||||||||
134 | - | |||||||||||||||||||
135 | \snippet code/src_corelib_tools_qregularexpression.cpp 2 | - | ||||||||||||||||||
136 | - | |||||||||||||||||||
137 | The pattern() function returns the pattern that is currently set for a | - | ||||||||||||||||||
138 | QRegularExpression object: | - | ||||||||||||||||||
139 | - | |||||||||||||||||||
140 | \snippet code/src_corelib_tools_qregularexpression.cpp 3 | - | ||||||||||||||||||
141 | - | |||||||||||||||||||
142 | \section1 Pattern Options | - | ||||||||||||||||||
143 | - | |||||||||||||||||||
144 | The meaning of the pattern string can be modified by setting one or more | - | ||||||||||||||||||
145 | \e{pattern options}. For instance, it is possible to set a pattern to match | - | ||||||||||||||||||
146 | case insensitively by setting the QRegularExpression::CaseInsensitiveOption. | - | ||||||||||||||||||
147 | - | |||||||||||||||||||
148 | You can set the options by passing them to the QRegularExpression | - | ||||||||||||||||||
149 | constructor, as in: | - | ||||||||||||||||||
150 | - | |||||||||||||||||||
151 | \snippet code/src_corelib_tools_qregularexpression.cpp 4 | - | ||||||||||||||||||
152 | - | |||||||||||||||||||
153 | Alternatively, you can use the setPatternOptions() function on an existing | - | ||||||||||||||||||
154 | QRegularExpressionObject: | - | ||||||||||||||||||
155 | - | |||||||||||||||||||
156 | \snippet code/src_corelib_tools_qregularexpression.cpp 5 | - | ||||||||||||||||||
157 | - | |||||||||||||||||||
158 | It is possible to get the pattern options currently set on a | - | ||||||||||||||||||
159 | QRegularExpression object by using the patternOptions() function: | - | ||||||||||||||||||
160 | - | |||||||||||||||||||
161 | \snippet code/src_corelib_tools_qregularexpression.cpp 6 | - | ||||||||||||||||||
162 | - | |||||||||||||||||||
163 | Please refer to the QRegularExpression::PatternOption enum documentation for | - | ||||||||||||||||||
164 | more information about each pattern option. | - | ||||||||||||||||||
165 | - | |||||||||||||||||||
166 | \section1 Match Type and Match Options | - | ||||||||||||||||||
167 | - | |||||||||||||||||||
168 | The last two arguments of the match() and the globalMatch() functions set | - | ||||||||||||||||||
169 | the match type and the match options. The match type is a value of the | - | ||||||||||||||||||
170 | QRegularExpression::MatchType enum; the "traditional" matching algorithm is | - | ||||||||||||||||||
171 | chosen by using the NormalMatch match type (the default). It is also | - | ||||||||||||||||||
172 | possible to enable partial matching of the regular expression against a | - | ||||||||||||||||||
173 | subject string: see the \l{partial matching} section for more details. | - | ||||||||||||||||||
174 | - | |||||||||||||||||||
175 | The match options are a set of one or more QRegularExpression::MatchOption | - | ||||||||||||||||||
176 | values. They change the way a specific match of a regular expression | - | ||||||||||||||||||
177 | against a subject string is done. Please refer to the | - | ||||||||||||||||||
178 | QRegularExpression::MatchOption enum documentation for more details. | - | ||||||||||||||||||
179 | - | |||||||||||||||||||
180 | \target normal matching | - | ||||||||||||||||||
181 | \section1 Normal Matching | - | ||||||||||||||||||
182 | - | |||||||||||||||||||
183 | In order to perform a match you can simply invoke the match() function | - | ||||||||||||||||||
184 | passing a string to match against. We refer to this string as the | - | ||||||||||||||||||
185 | \e{subject string}. The result of the match() function is a | - | ||||||||||||||||||
186 | QRegularExpressionMatch object that can be used to inspect the results of | - | ||||||||||||||||||
187 | the match. For instance: | - | ||||||||||||||||||
188 | - | |||||||||||||||||||
189 | \snippet code/src_corelib_tools_qregularexpression.cpp 7 | - | ||||||||||||||||||
190 | - | |||||||||||||||||||
191 | If a match is successful, the (implicit) capturing group number 0 can be | - | ||||||||||||||||||
192 | used to retrieve the substring matched by the entire pattern (see also the | - | ||||||||||||||||||
193 | section about \l{extracting captured substrings}): | - | ||||||||||||||||||
194 | - | |||||||||||||||||||
195 | \snippet code/src_corelib_tools_qregularexpression.cpp 8 | - | ||||||||||||||||||
196 | - | |||||||||||||||||||
197 | It's also possible to start a match at an arbitrary offset inside the | - | ||||||||||||||||||
198 | subject string by passing the offset as an argument of the | - | ||||||||||||||||||
199 | match() function. In the following example \c{"12 abc"} | - | ||||||||||||||||||
200 | is not matched because the match is started at offset 1: | - | ||||||||||||||||||
201 | - | |||||||||||||||||||
202 | \snippet code/src_corelib_tools_qregularexpression.cpp 9 | - | ||||||||||||||||||
203 | - | |||||||||||||||||||
204 | \target extracting captured substrings | - | ||||||||||||||||||
205 | \section2 Extracting captured substrings | - | ||||||||||||||||||
206 | - | |||||||||||||||||||
207 | The QRegularExpressionMatch object contains also information about the | - | ||||||||||||||||||
208 | substrings captured by the capturing groups in the pattern string. The | - | ||||||||||||||||||
209 | \l{QRegularExpressionMatch::}{captured()} function will return the string | - | ||||||||||||||||||
210 | captured by the n-th capturing group: | - | ||||||||||||||||||
211 | - | |||||||||||||||||||
212 | \snippet code/src_corelib_tools_qregularexpression.cpp 10 | - | ||||||||||||||||||
213 | - | |||||||||||||||||||
214 | Capturing groups in the pattern are numbered starting from 1, and the | - | ||||||||||||||||||
215 | implicit capturing group 0 is used to capture the substring that matched | - | ||||||||||||||||||
216 | the entire pattern. | - | ||||||||||||||||||
217 | - | |||||||||||||||||||
218 | It's also possible to retrieve the starting and the ending offsets (inside | - | ||||||||||||||||||
219 | the subject string) of each captured substring, by using the | - | ||||||||||||||||||
220 | \l{QRegularExpressionMatch::}{capturedStart()} and the | - | ||||||||||||||||||
221 | \l{QRegularExpressionMatch::}{capturedEnd()} functions: | - | ||||||||||||||||||
222 | - | |||||||||||||||||||
223 | \snippet code/src_corelib_tools_qregularexpression.cpp 11 | - | ||||||||||||||||||
224 | - | |||||||||||||||||||
225 | All of these functions have an overload taking a QString as a parameter | - | ||||||||||||||||||
226 | in order to extract \e{named} captured substrings. For instance: | - | ||||||||||||||||||
227 | - | |||||||||||||||||||
228 | \snippet code/src_corelib_tools_qregularexpression.cpp 12 | - | ||||||||||||||||||
229 | - | |||||||||||||||||||
230 | \target global matching | - | ||||||||||||||||||
231 | \section1 Global Matching | - | ||||||||||||||||||
232 | - | |||||||||||||||||||
233 | \e{Global matching} is useful to find all the occurrences of a given | - | ||||||||||||||||||
234 | regular expression inside a subject string. Suppose that we want to extract | - | ||||||||||||||||||
235 | all the words from a given string, where a word is a substring matching | - | ||||||||||||||||||
236 | the pattern \c{\w+}. | - | ||||||||||||||||||
237 | - | |||||||||||||||||||
238 | QRegularExpression::globalMatch returns a QRegularExpressionMatchIterator, | - | ||||||||||||||||||
239 | which is a Java-like forward iterator that can be used to iterate over the | - | ||||||||||||||||||
240 | results. For instance: | - | ||||||||||||||||||
241 | - | |||||||||||||||||||
242 | \snippet code/src_corelib_tools_qregularexpression.cpp 13 | - | ||||||||||||||||||
243 | - | |||||||||||||||||||
244 | Since it's a Java-like iterator, the QRegularExpressionMatchIterator will | - | ||||||||||||||||||
245 | point immediately before the first result. Every result is returned as a | - | ||||||||||||||||||
246 | QRegularExpressionMatch object. The | - | ||||||||||||||||||
247 | \l{QRegularExpressionMatchIterator::}{hasNext()} function will return true | - | ||||||||||||||||||
248 | if there's at least one more result, and | - | ||||||||||||||||||
249 | \l{QRegularExpressionMatchIterator::}{next()} will return the next result | - | ||||||||||||||||||
250 | and advance the iterator. Continuing from the previous example: | - | ||||||||||||||||||
251 | - | |||||||||||||||||||
252 | \snippet code/src_corelib_tools_qregularexpression.cpp 14 | - | ||||||||||||||||||
253 | - | |||||||||||||||||||
254 | You can also use \l{QRegularExpressionMatchIterator::}{peekNext()} to get | - | ||||||||||||||||||
255 | the next result without advancing the iterator. | - | ||||||||||||||||||
256 | - | |||||||||||||||||||
257 | It is possible to pass a starting offset and one or more match options to | - | ||||||||||||||||||
258 | the globalMatch() function, exactly like normal matching with match(). | - | ||||||||||||||||||
259 | - | |||||||||||||||||||
260 | \target partial matching | - | ||||||||||||||||||
261 | \section1 Partial Matching | - | ||||||||||||||||||
262 | - | |||||||||||||||||||
263 | A \e{partial match} is obtained when the end of the subject string is | - | ||||||||||||||||||
264 | reached, but more characters are needed to successfully complete the match. | - | ||||||||||||||||||
265 | Note that a partial match is usually much more inefficient than a normal | - | ||||||||||||||||||
266 | match because many optimizations of the matching algorithm cannot be | - | ||||||||||||||||||
267 | employed. | - | ||||||||||||||||||
268 | - | |||||||||||||||||||
269 | A partial match must be explicitly requested by specifying a match type of | - | ||||||||||||||||||
270 | PartialPreferCompleteMatch or PartialPreferFirstMatch when calling | - | ||||||||||||||||||
271 | QRegularExpression::match or QRegularExpression::globalMatch. If a partial | - | ||||||||||||||||||
272 | match is found, then calling the \l{QRegularExpressionMatch::}{hasMatch()} | - | ||||||||||||||||||
273 | function on the QRegularExpressionMatch object returned by match() will | - | ||||||||||||||||||
274 | return \c{false}, but \l{QRegularExpressionMatch::}{hasPartialMatch()} will return | - | ||||||||||||||||||
275 | \c{true}. | - | ||||||||||||||||||
276 | - | |||||||||||||||||||
277 | When a partial match is found, no captured substrings are returned, and the | - | ||||||||||||||||||
278 | (implicit) capturing group 0 corresponding to the whole match captures the | - | ||||||||||||||||||
279 | partially matched substring of the subject string. | - | ||||||||||||||||||
280 | - | |||||||||||||||||||
281 | Note that asking for a partial match can still lead to a complete match, if | - | ||||||||||||||||||
282 | one is found; in this case, \l{QRegularExpressionMatch::}{hasMatch()} will | - | ||||||||||||||||||
283 | return \c{true} and \l{QRegularExpressionMatch::}{hasPartialMatch()} | - | ||||||||||||||||||
284 | \c{false}. It never happens that a QRegularExpressionMatch reports both a | - | ||||||||||||||||||
285 | partial and a complete match. | - | ||||||||||||||||||
286 | - | |||||||||||||||||||
287 | Partial matching is mainly useful in two scenarios: validating user input | - | ||||||||||||||||||
288 | in real time and incremental/multi-segment matching. | - | ||||||||||||||||||
289 | - | |||||||||||||||||||
290 | \target validating user input | - | ||||||||||||||||||
291 | \section2 Validating user input | - | ||||||||||||||||||
292 | - | |||||||||||||||||||
293 | Suppose that we would like the user to input a date in a specific | - | ||||||||||||||||||
294 | format, for instance "MMM dd, yyyy". We can check the input validity with | - | ||||||||||||||||||
295 | a pattern like: | - | ||||||||||||||||||
296 | - | |||||||||||||||||||
297 | \c{^(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) \d\d?, \d\d\d\d$} | - | ||||||||||||||||||
298 | - | |||||||||||||||||||
299 | (This pattern doesn't catch invalid days, but let's keep it for the | - | ||||||||||||||||||
300 | example's purposes). | - | ||||||||||||||||||
301 | - | |||||||||||||||||||
302 | We would like to validate the input with this regular expression \e{while} | - | ||||||||||||||||||
303 | the user is typing it, so that we can report an error in the input as soon | - | ||||||||||||||||||
304 | as it is committed (for instance, the user typed the wrong key). In order | - | ||||||||||||||||||
305 | to do so we must distinguish three cases: | - | ||||||||||||||||||
306 | - | |||||||||||||||||||
307 | \list | - | ||||||||||||||||||
308 | \li the input cannot possibly match the regular expression; | - | ||||||||||||||||||
309 | \li the input does match the regular expression; | - | ||||||||||||||||||
310 | \li the input does not match the regular expression right now, | - | ||||||||||||||||||
311 | but it will if more characters will be added to it. | - | ||||||||||||||||||
312 | \endlist | - | ||||||||||||||||||
313 | - | |||||||||||||||||||
314 | Note that these three cases represent exactly the possible states of a | - | ||||||||||||||||||
315 | QValidator (see the QValidator::State enum). | - | ||||||||||||||||||
316 | - | |||||||||||||||||||
317 | In particular, in the last case we want the regular expression engine to | - | ||||||||||||||||||
318 | report a partial match: we are successfully matching the pattern against | - | ||||||||||||||||||
319 | the subject string but the matching cannot continue because the end of the | - | ||||||||||||||||||
320 | subject is encountered. Notice, however, that the matching algorithm should | - | ||||||||||||||||||
321 | continue and try all possibilities, and in case a complete (non-partial) | - | ||||||||||||||||||
322 | match is found, then this one should be reported, and the input string | - | ||||||||||||||||||
323 | accepted as fully valid. | - | ||||||||||||||||||
324 | - | |||||||||||||||||||
325 | This behaviour is implemented by the PartialPreferCompleteMatch match type. | - | ||||||||||||||||||
326 | For instance: | - | ||||||||||||||||||
327 | - | |||||||||||||||||||
328 | \snippet code/src_corelib_tools_qregularexpression.cpp 15 | - | ||||||||||||||||||
329 | - | |||||||||||||||||||
330 | If matching the same regular expression against the subject string leads to | - | ||||||||||||||||||
331 | a complete match, it is reported as usual: | - | ||||||||||||||||||
332 | - | |||||||||||||||||||
333 | \snippet code/src_corelib_tools_qregularexpression.cpp 16 | - | ||||||||||||||||||
334 | - | |||||||||||||||||||
335 | Another example with a different pattern, showing the behaviour of | - | ||||||||||||||||||
336 | preferring a complete match over a partial one: | - | ||||||||||||||||||
337 | - | |||||||||||||||||||
338 | \snippet code/src_corelib_tools_qregularexpression.cpp 17 | - | ||||||||||||||||||
339 | - | |||||||||||||||||||
340 | In this case, the subpattern \c{abc\\w+X} partially matches the subject | - | ||||||||||||||||||
341 | string; however, the subpattern \c{def} matches the subject string | - | ||||||||||||||||||
342 | completely, and therefore a complete match is reported. | - | ||||||||||||||||||
343 | - | |||||||||||||||||||
344 | If multiple partial matches are found when matching (but no complete | - | ||||||||||||||||||
345 | match), then the QRegularExpressionMatch object will report the first one | - | ||||||||||||||||||
346 | that is found. For instance: | - | ||||||||||||||||||
347 | - | |||||||||||||||||||
348 | \snippet code/src_corelib_tools_qregularexpression.cpp 18 | - | ||||||||||||||||||
349 | - | |||||||||||||||||||
350 | \section2 Incremental/multi-segment matching | - | ||||||||||||||||||
351 | - | |||||||||||||||||||
352 | Incremental matching is another use case of partial matching. Suppose that | - | ||||||||||||||||||
353 | we want to find the occurrences of a regular expression inside a large text | - | ||||||||||||||||||
354 | (that is, substrings matching the regular expression). In order to do so we | - | ||||||||||||||||||
355 | would like to "feed" the large text to the regular expression engines in | - | ||||||||||||||||||
356 | smaller chunks. The obvious problem is what happens if the substring that | - | ||||||||||||||||||
357 | matches the regular expression spans across two or more chunks. | - | ||||||||||||||||||
358 | - | |||||||||||||||||||
359 | In this case, the regular expression engine should report a partial match, | - | ||||||||||||||||||
360 | so that we can match again adding new data and (eventually) get a complete | - | ||||||||||||||||||
361 | match. This implies that the regular expression engine may assume that | - | ||||||||||||||||||
362 | there are other characters \e{beyond the end} of the subject string. This | - | ||||||||||||||||||
363 | is not to be taken literally -- the engine will never try to access | - | ||||||||||||||||||
364 | any character after the last one in the subject. | - | ||||||||||||||||||
365 | - | |||||||||||||||||||
366 | QRegularExpression implements this behaviour when using the | - | ||||||||||||||||||
367 | PartialPreferFirstMatch match type. This match type reports a partial match | - | ||||||||||||||||||
368 | as soon as it is found, and other match alternatives are not tried | - | ||||||||||||||||||
369 | (even if they could lead to a complete match). For instance: | - | ||||||||||||||||||
370 | - | |||||||||||||||||||
371 | \snippet code/src_corelib_tools_qregularexpression.cpp 19 | - | ||||||||||||||||||
372 | - | |||||||||||||||||||
373 | This happens because when matching the first branch of the alternation | - | ||||||||||||||||||
374 | operator a partial match is found, and therefore matching stops, without | - | ||||||||||||||||||
375 | trying the second branch. Another example: | - | ||||||||||||||||||
376 | - | |||||||||||||||||||
377 | \snippet code/src_corelib_tools_qregularexpression.cpp 20 | - | ||||||||||||||||||
378 | - | |||||||||||||||||||
379 | This shows what could seem a counterintuitve behaviour of quantifiers: | - | ||||||||||||||||||
380 | since \c{?} is greedy, then the engine tries first to continue the match | - | ||||||||||||||||||
381 | after having matched \c{"abc"}; but then the matching reaches the end of the | - | ||||||||||||||||||
382 | subject string, and therefore a partial match is reported. This is | - | ||||||||||||||||||
383 | even more surprising in the following example: | - | ||||||||||||||||||
384 | - | |||||||||||||||||||
385 | \snippet code/src_corelib_tools_qregularexpression.cpp 21 | - | ||||||||||||||||||
386 | - | |||||||||||||||||||
387 | It's easy to understand this behaviour if we remember that the engine | - | ||||||||||||||||||
388 | expects the subject string to be only a substring of the whole text we're | - | ||||||||||||||||||
389 | looking for a match into (that is, how we said before, that the engine | - | ||||||||||||||||||
390 | assumes that there are other characters beyond the end of the subject | - | ||||||||||||||||||
391 | string). | - | ||||||||||||||||||
392 | - | |||||||||||||||||||
393 | Since the \c{*} quantifier is greedy, then reporting a complete match could | - | ||||||||||||||||||
394 | be an error, because after the current subject \c{"abc"} there may be other | - | ||||||||||||||||||
395 | occurrences of \c{"abc"}. For instance, the complete text could have been | - | ||||||||||||||||||
396 | "abcabcX", and therefore the \e{right} match to report (in the complete | - | ||||||||||||||||||
397 | text) would have been \c{"abcabc"}; by matching only against the leading | - | ||||||||||||||||||
398 | \c{"abc"} we instead get a partial match. | - | ||||||||||||||||||
399 | - | |||||||||||||||||||
400 | \section1 Error Handling | - | ||||||||||||||||||
401 | - | |||||||||||||||||||
402 | It is possible for a QRegularExpression object to be invalid because of | - | ||||||||||||||||||
403 | syntax errors in the pattern string. The isValid() function will return | - | ||||||||||||||||||
404 | true if the regular expression is valid, or false otherwise: | - | ||||||||||||||||||
405 | - | |||||||||||||||||||
406 | \snippet code/src_corelib_tools_qregularexpression.cpp 22 | - | ||||||||||||||||||
407 | - | |||||||||||||||||||
408 | You can get more information about the specific error by calling the | - | ||||||||||||||||||
409 | errorString() function; moreover, the patternErrorOffset() function | - | ||||||||||||||||||
410 | will return the offset inside the pattern string | - | ||||||||||||||||||
411 | - | |||||||||||||||||||
412 | \snippet code/src_corelib_tools_qregularexpression.cpp 23 | - | ||||||||||||||||||
413 | - | |||||||||||||||||||
414 | If a match is attempted with an invalid QRegularExpression, then the | - | ||||||||||||||||||
415 | returned QRegularExpressionMatch object will be invalid as well (that is, | - | ||||||||||||||||||
416 | its \l{QRegularExpressionMatch::}{isValid()} function will return false). | - | ||||||||||||||||||
417 | The same applies for attempting a global match. | - | ||||||||||||||||||
418 | - | |||||||||||||||||||
419 | \section1 Unsupported Perl-compatible Regular Expressions Features | - | ||||||||||||||||||
420 | - | |||||||||||||||||||
421 | QRegularExpression does not support all the features available in | - | ||||||||||||||||||
422 | Perl-compatible regular expressions. The most notable one is the fact that | - | ||||||||||||||||||
423 | duplicated names for capturing groups are not supported, and using them can | - | ||||||||||||||||||
424 | lead to undefined behaviour. | - | ||||||||||||||||||
425 | - | |||||||||||||||||||
426 | This may change in a future version of Qt. | - | ||||||||||||||||||
427 | - | |||||||||||||||||||
428 | \section1 Notes for QRegExp Users | - | ||||||||||||||||||
429 | - | |||||||||||||||||||
430 | The QRegularExpression class introduced in Qt 5 is a big improvement upon | - | ||||||||||||||||||
431 | QRegExp, in terms of APIs offered, supported pattern syntax and speed of | - | ||||||||||||||||||
432 | execution. The biggest difference is that QRegularExpression simply holds a | - | ||||||||||||||||||
433 | regular expression, and it's \e{not} modified when a match is requested. | - | ||||||||||||||||||
434 | Instead, a QRegularExpressionMatch object is returned, in order to check | - | ||||||||||||||||||
435 | the result of a match and extract the captured substring. The same applies | - | ||||||||||||||||||
436 | with global matching and QRegularExpressionMatchIterator. | - | ||||||||||||||||||
437 | - | |||||||||||||||||||
438 | Other differences are outlined below. | - | ||||||||||||||||||
439 | - | |||||||||||||||||||
440 | \section2 Exact matching | - | ||||||||||||||||||
441 | - | |||||||||||||||||||
442 | QRegExp::exactMatch() in Qt 4 served two purposes: it exactly matched | - | ||||||||||||||||||
443 | a regular expression against a subject string, and it implemented partial | - | ||||||||||||||||||
444 | matching. In fact, if an exact match was not found, one could still find | - | ||||||||||||||||||
445 | out how much of the subject string was matched by the regular expression | - | ||||||||||||||||||
446 | by calling QRegExp::matchedLength(). If the returned length was equal | - | ||||||||||||||||||
447 | to the subject string's length, then one could desume that a partial match | - | ||||||||||||||||||
448 | was found. | - | ||||||||||||||||||
449 | - | |||||||||||||||||||
450 | QRegularExpression supports partial matching explicitly by means of the | - | ||||||||||||||||||
451 | appropriate MatchType. If instead you simply want to be sure that the | - | ||||||||||||||||||
452 | subject string matches the regular expression exactly, you can wrap the | - | ||||||||||||||||||
453 | pattern between a couple of anchoring expressions. Simply | - | ||||||||||||||||||
454 | putting the pattern between the \c{^} and the \c{$} anchors is enough | - | ||||||||||||||||||
455 | in most cases: | - | ||||||||||||||||||
456 | - | |||||||||||||||||||
457 | \snippet code/src_corelib_tools_qregularexpression.cpp 24 | - | ||||||||||||||||||
458 | - | |||||||||||||||||||
459 | However, remember that the \c{$} anchor not only matches at the end of the | - | ||||||||||||||||||
460 | string, but also at a newline character right before the end of the string; | - | ||||||||||||||||||
461 | that is, the previous pattern matches against the string "this pattern must | - | ||||||||||||||||||
462 | match exactly\\n". Also, the behaviour of both the \c{^} and the \c{$} | - | ||||||||||||||||||
463 | anchors changes if the MultiLineOption is set either explicitly (as a | - | ||||||||||||||||||
464 | pattern option) or implicitly (as a directive inside the pattern string). | - | ||||||||||||||||||
465 | - | |||||||||||||||||||
466 | Therefore, in the most general case, you should wrap the pattern between | - | ||||||||||||||||||
467 | the \c{\A} and the \c{\z} anchors: | - | ||||||||||||||||||
468 | - | |||||||||||||||||||
469 | \snippet code/src_corelib_tools_qregularexpression.cpp 25 | - | ||||||||||||||||||
470 | - | |||||||||||||||||||
471 | Note the usage of the non-capturing group in order to preserve the meaning | - | ||||||||||||||||||
472 | of the branch operator inside the pattern. | - | ||||||||||||||||||
473 | - | |||||||||||||||||||
474 | \section2 Global matching | - | ||||||||||||||||||
475 | - | |||||||||||||||||||
476 | Due to limitations of the QRegExp API it was impossible to implement global | - | ||||||||||||||||||
477 | matching correctly (that is, like Perl does). In particular, patterns that | - | ||||||||||||||||||
478 | can match 0 characters (like \c{"a*"}) are problematic. | - | ||||||||||||||||||
479 | - | |||||||||||||||||||
480 | QRegularExpression::globalMatch() implements Perl global match correctly, and | - | ||||||||||||||||||
481 | the returned iterator can be used to examine each result. | - | ||||||||||||||||||
482 | - | |||||||||||||||||||
483 | \section2 Unicode properties support | - | ||||||||||||||||||
484 | - | |||||||||||||||||||
485 | When using QRegExp, character classes such as \c{\w}, \c{\d}, etc. match | - | ||||||||||||||||||
486 | characters with the corresponding Unicode property: for instance, \c{\d} | - | ||||||||||||||||||
487 | matches any character with the Unicode Nd (decimal digit) property. | - | ||||||||||||||||||
488 | - | |||||||||||||||||||
489 | Those character classes only match ASCII characters by default when using | - | ||||||||||||||||||
490 | QRegularExpression: for instance, \c{\d} matches exactly a character in the | - | ||||||||||||||||||
491 | \c{0-9} ASCII range. It is possible to change this behaviour by using the | - | ||||||||||||||||||
492 | UseUnicodePropertiesOption pattern option. | - | ||||||||||||||||||
493 | - | |||||||||||||||||||
494 | \section2 Wildcard matching | - | ||||||||||||||||||
495 | - | |||||||||||||||||||
496 | There is no equivalent of wildcard matching in QRegularExpression. | - | ||||||||||||||||||
497 | Nevertheless, rewriting a regular expression in wildcard syntax to a | - | ||||||||||||||||||
498 | Perl-compatible regular expression is a very easy task, given the fact | - | ||||||||||||||||||
499 | that wildcard syntax supported by QRegExp is very simple. | - | ||||||||||||||||||
500 | - | |||||||||||||||||||
501 | \section2 Other pattern syntaxes | - | ||||||||||||||||||
502 | - | |||||||||||||||||||
503 | QRegularExpression supports only Perl-compatible regular expressions. | - | ||||||||||||||||||
504 | - | |||||||||||||||||||
505 | \section2 Minimal matching | - | ||||||||||||||||||
506 | - | |||||||||||||||||||
507 | QRegExp::setMinimal() implemented minimal matching by simply reversing the | - | ||||||||||||||||||
508 | greediness of the quantifiers (QRegExp did not support lazy quantifiers, | - | ||||||||||||||||||
509 | like \c{*?}, \c{+?}, etc.). QRegularExpression instead does support greedy, | - | ||||||||||||||||||
510 | lazy and possessive quantifiers. The InvertedGreedinessOption | - | ||||||||||||||||||
511 | pattern option can be useful to emulate the effects of QRegExp::setMinimal(): | - | ||||||||||||||||||
512 | if enabled, it inverts the greediness of quantifiers (greedy ones become | - | ||||||||||||||||||
513 | lazy and vice versa). | - | ||||||||||||||||||
514 | - | |||||||||||||||||||
515 | \section2 Caret modes | - | ||||||||||||||||||
516 | - | |||||||||||||||||||
517 | The AnchoredMatchOption match option can be used to emulate the | - | ||||||||||||||||||
518 | QRegExp::CaretAtOffset behaviour. There is no equivalent for the other | - | ||||||||||||||||||
519 | QRegExp::CaretMode modes. | - | ||||||||||||||||||
520 | - | |||||||||||||||||||
521 | \section1 Debugging Code that Uses QRegularExpression | - | ||||||||||||||||||
522 | - | |||||||||||||||||||
523 | QRegularExpression internally uses a just in time compiler (JIT) to | - | ||||||||||||||||||
524 | optimize the execution of the matching algorithm. The JIT makes extensive | - | ||||||||||||||||||
525 | usage of self-modifying code, which can lead debugging tools such as | - | ||||||||||||||||||
526 | Valgrind to crash. You must enable all checks for self-modifying code if | - | ||||||||||||||||||
527 | you want to debug programs using QRegularExpression (f.i., see Valgrind's | - | ||||||||||||||||||
528 | \c{--smc-check} command line option). The downside of enabling such checks | - | ||||||||||||||||||
529 | is that your program will run considerably slower. | - | ||||||||||||||||||
530 | - | |||||||||||||||||||
531 | To avoid that, the JIT is disabled by default if you compile Qt in debug | - | ||||||||||||||||||
532 | mode. It is possible to override the default and enable or disable the JIT | - | ||||||||||||||||||
533 | usage (both in debug or release mode) by setting the | - | ||||||||||||||||||
534 | \c{QT_ENABLE_REGEXP_JIT} environment variable to a non-zero or zero value | - | ||||||||||||||||||
535 | respectively. | - | ||||||||||||||||||
536 | - | |||||||||||||||||||
537 | \sa QRegularExpressionMatch, QRegularExpressionMatchIterator | - | ||||||||||||||||||
538 | */ | - | ||||||||||||||||||
539 | - | |||||||||||||||||||
540 | /*! | - | ||||||||||||||||||
541 | \class QRegularExpressionMatch | - | ||||||||||||||||||
542 | \inmodule QtCore | - | ||||||||||||||||||
543 | \reentrant | - | ||||||||||||||||||
544 | - | |||||||||||||||||||
545 | \brief The QRegularExpressionMatch class provides the results of matching | - | ||||||||||||||||||
546 | a QRegularExpression against a string. | - | ||||||||||||||||||
547 | - | |||||||||||||||||||
548 | \since 5.0 | - | ||||||||||||||||||
549 | - | |||||||||||||||||||
550 | \ingroup tools | - | ||||||||||||||||||
551 | \ingroup shared | - | ||||||||||||||||||
552 | - | |||||||||||||||||||
553 | \keyword regular expression match | - | ||||||||||||||||||
554 | - | |||||||||||||||||||
555 | A QRegularExpressionMatch object can be obtained by calling the | - | ||||||||||||||||||
556 | QRegularExpression::match() function, or as a single result of a global | - | ||||||||||||||||||
557 | match from a QRegularExpressionMatchIterator. | - | ||||||||||||||||||
558 | - | |||||||||||||||||||
559 | The success or the failure of a match attempt can be inspected by calling | - | ||||||||||||||||||
560 | the hasMatch() function. QRegularExpressionMatch also reports a successful | - | ||||||||||||||||||
561 | partial match through the hasPartialMatch() function. | - | ||||||||||||||||||
562 | - | |||||||||||||||||||
563 | In addition, QRegularExpressionMatch returns the substrings captured by the | - | ||||||||||||||||||
564 | capturing groups in the pattern string. The implicit capturing group with | - | ||||||||||||||||||
565 | index 0 captures the result of the whole match. The captured() function | - | ||||||||||||||||||
566 | returns each substring captured, either by the capturing group's index or | - | ||||||||||||||||||
567 | by its name: | - | ||||||||||||||||||
568 | - | |||||||||||||||||||
569 | \snippet code/src_corelib_tools_qregularexpression.cpp 29 | - | ||||||||||||||||||
570 | - | |||||||||||||||||||
571 | For each captured substring it is possible to query its starting and ending | - | ||||||||||||||||||
572 | offsets in the subject string by calling the capturedStart() and the | - | ||||||||||||||||||
573 | capturedEnd() function, respectively. The length of each captured | - | ||||||||||||||||||
574 | substring is available using the capturedLength() function. | - | ||||||||||||||||||
575 | - | |||||||||||||||||||
576 | The convenience function capturedTexts() will return \e{all} the captured | - | ||||||||||||||||||
577 | substrings at once (including the substring matched by the entire pattern) | - | ||||||||||||||||||
578 | in the order they have been captured by captring groups; that is, | - | ||||||||||||||||||
579 | \c{captured(i) == capturedTexts().at(i)}. | - | ||||||||||||||||||
580 | - | |||||||||||||||||||
581 | You can retrieve the QRegularExpression object the subject string was | - | ||||||||||||||||||
582 | matched against by calling the regularExpression() function; the | - | ||||||||||||||||||
583 | match type and the match options are available as well by calling | - | ||||||||||||||||||
584 | the matchType() and the matchOptions() respectively. | - | ||||||||||||||||||
585 | - | |||||||||||||||||||
586 | Please refer to the QRegularExpression documentation for more information | - | ||||||||||||||||||
587 | about the Qt regular expression classes. | - | ||||||||||||||||||
588 | - | |||||||||||||||||||
589 | \sa QRegularExpression | - | ||||||||||||||||||
590 | */ | - | ||||||||||||||||||
591 | - | |||||||||||||||||||
592 | /*! | - | ||||||||||||||||||
593 | \class QRegularExpressionMatchIterator | - | ||||||||||||||||||
594 | \inmodule QtCore | - | ||||||||||||||||||
595 | \reentrant | - | ||||||||||||||||||
596 | - | |||||||||||||||||||
597 | \brief The QRegularExpressionMatchIterator class provides an iterator on | - | ||||||||||||||||||
598 | the results of a global match of a QRegularExpression object against a string. | - | ||||||||||||||||||
599 | - | |||||||||||||||||||
600 | \since 5.0 | - | ||||||||||||||||||
601 | - | |||||||||||||||||||
602 | \ingroup tools | - | ||||||||||||||||||
603 | \ingroup shared | - | ||||||||||||||||||
604 | - | |||||||||||||||||||
605 | \keyword regular expression iterator | - | ||||||||||||||||||
606 | - | |||||||||||||||||||
607 | A QRegularExpressionMatchIterator object is a forward only Java-like | - | ||||||||||||||||||
608 | iterator; it can be obtained by calling the | - | ||||||||||||||||||
609 | QRegularExpression::globalMatch() function. A new | - | ||||||||||||||||||
610 | QRegularExpressionMatchIterator will be positioned before the first result. | - | ||||||||||||||||||
611 | You can then call the hasNext() function to check if there are more | - | ||||||||||||||||||
612 | results available; if so, the next() function will return the next | - | ||||||||||||||||||
613 | result and advance the iterator. | - | ||||||||||||||||||
614 | - | |||||||||||||||||||
615 | Each result is a QRegularExpressionMatch object holding all the information | - | ||||||||||||||||||
616 | for that result (including captured substrings). | - | ||||||||||||||||||
617 | - | |||||||||||||||||||
618 | For instance: | - | ||||||||||||||||||
619 | - | |||||||||||||||||||
620 | \snippet code/src_corelib_tools_qregularexpression.cpp 30 | - | ||||||||||||||||||
621 | - | |||||||||||||||||||
622 | Moreover, QRegularExpressionMatchIterator offers a peekNext() function | - | ||||||||||||||||||
623 | to get the next result \e{without} advancing the iterator. | - | ||||||||||||||||||
624 | - | |||||||||||||||||||
625 | You can retrieve the QRegularExpression object the subject string was | - | ||||||||||||||||||
626 | matched against by calling the regularExpression() function; the | - | ||||||||||||||||||
627 | match type and the match options are available as well by calling | - | ||||||||||||||||||
628 | the matchType() and the matchOptions() respectively. | - | ||||||||||||||||||
629 | - | |||||||||||||||||||
630 | Please refer to the QRegularExpression documentation for more information | - | ||||||||||||||||||
631 | about the Qt regular expression classes. | - | ||||||||||||||||||
632 | - | |||||||||||||||||||
633 | \sa QRegularExpression, QRegularExpressionMatch | - | ||||||||||||||||||
634 | */ | - | ||||||||||||||||||
635 | - | |||||||||||||||||||
636 | - | |||||||||||||||||||
637 | /*! | - | ||||||||||||||||||
638 | \enum QRegularExpression::PatternOption | - | ||||||||||||||||||
639 | - | |||||||||||||||||||
640 | The PatternOption enum defines modifiers to the way the pattern string | - | ||||||||||||||||||
641 | should be interpreted, and therefore the way the pattern matches against a | - | ||||||||||||||||||
642 | subject string. | - | ||||||||||||||||||
643 | - | |||||||||||||||||||
644 | \value NoPatternOption | - | ||||||||||||||||||
645 | No pattern options are set. | - | ||||||||||||||||||
646 | - | |||||||||||||||||||
647 | \value CaseInsensitiveOption | - | ||||||||||||||||||
648 | The pattern should match against the subject string in a case | - | ||||||||||||||||||
649 | insensitive way. This option corresponds to the /i modifier in Perl | - | ||||||||||||||||||
650 | regular expressions. | - | ||||||||||||||||||
651 | - | |||||||||||||||||||
652 | \value DotMatchesEverythingOption | - | ||||||||||||||||||
653 | The dot metacharacter (\c{.}) in the pattern string is allowed to match | - | ||||||||||||||||||
654 | any character in the subject string, including newlines (normally, the | - | ||||||||||||||||||
655 | dot does not match newlines). This option corresponds to the \c{/s} | - | ||||||||||||||||||
656 | modifier in Perl regular expressions. | - | ||||||||||||||||||
657 | - | |||||||||||||||||||
658 | \value MultilineOption | - | ||||||||||||||||||
659 | The caret (\c{^}) and the dollar (\c{$}) metacharacters in the pattern | - | ||||||||||||||||||
660 | string are allowed to match, respectively, immediately after and | - | ||||||||||||||||||
661 | immediately before any newline in the subject string, as well as at the | - | ||||||||||||||||||
662 | very beginning and at the very end of the subject string. This option | - | ||||||||||||||||||
663 | corresponds to the \c{/m} modifier in Perl regular expressions. | - | ||||||||||||||||||
664 | - | |||||||||||||||||||
665 | \value ExtendedPatternSyntaxOption | - | ||||||||||||||||||
666 | Any whitespace in the pattern string which is not escaped and outside a | - | ||||||||||||||||||
667 | character class is ignored. Moreover, an unescaped sharp (\b{#}) | - | ||||||||||||||||||
668 | outside a character class causes all the following characters, until | - | ||||||||||||||||||
669 | the first newline (included), to be ignored. This can be used to | - | ||||||||||||||||||
670 | increase the readability of a pattern string as well as put comments | - | ||||||||||||||||||
671 | inside regular expressions; this is particulary useful if the pattern | - | ||||||||||||||||||
672 | string is loaded from a file or written by the user, because in C++ | - | ||||||||||||||||||
673 | code it is always possible to use the rules for string literals to put | - | ||||||||||||||||||
674 | comments outside the pattern string. This option corresponds to the \c{/x} | - | ||||||||||||||||||
675 | modifier in Perl regular expressions. | - | ||||||||||||||||||
676 | - | |||||||||||||||||||
677 | \value InvertedGreedinessOption | - | ||||||||||||||||||
678 | The greediness of the quantifiers is inverted: \c{*}, \c{+}, \c{?}, | - | ||||||||||||||||||
679 | \c{{m,n}}, etc. become lazy, while their lazy versions (\c{*?}, | - | ||||||||||||||||||
680 | \c{+?}, \c{??}, \c{{m,n}?}, etc.) become greedy. There is no equivalent | - | ||||||||||||||||||
681 | for this option in Perl regular expressions. | - | ||||||||||||||||||
682 | - | |||||||||||||||||||
683 | \value DontCaptureOption | - | ||||||||||||||||||
684 | The non-named capturing groups do not capture substrings; named | - | ||||||||||||||||||
685 | capturing groups still work as intended, as well as the implicit | - | ||||||||||||||||||
686 | capturing group number 0 corresponding to the entire match. There is no | - | ||||||||||||||||||
687 | equivalent for this option in Perl regular expressions. | - | ||||||||||||||||||
688 | - | |||||||||||||||||||
689 | \value UseUnicodePropertiesOption | - | ||||||||||||||||||
690 | The meaning of the \c{\w}, \c{\d}, etc., character classes, as well as | - | ||||||||||||||||||
691 | the meaning of their counterparts (\c{\W}, \c{\D}, etc.), is changed | - | ||||||||||||||||||
692 | from matching ASCII characters only to matching any character with the | - | ||||||||||||||||||
693 | corresponding Unicode property. For instance, \c{\d} is changed to | - | ||||||||||||||||||
694 | match any character with the Unicode Nd (decimal digit) property; | - | ||||||||||||||||||
695 | \c{\w} to match any character with either the Unicode L (letter) or N | - | ||||||||||||||||||
696 | (digit) property, plus underscore, and so on. This option corresponds | - | ||||||||||||||||||
697 | to the \c{/u} modifier in Perl regular expressions. | - | ||||||||||||||||||
698 | - | |||||||||||||||||||
699 | \value OptimizeOnFirstUsageOption | - | ||||||||||||||||||
700 | The regular expression will be optimized (and possibly | - | ||||||||||||||||||
701 | JIT-compiled) on its first usage, instead of after a certain (undefined) | - | ||||||||||||||||||
702 | number of usages. See also \l{QRegularExpression::}{optimize()}. | - | ||||||||||||||||||
703 | This enum value has been introduced in Qt 5.4. | - | ||||||||||||||||||
704 | - | |||||||||||||||||||
705 | \value DontAutomaticallyOptimizeOption | - | ||||||||||||||||||
706 | Regular expressions are automatically optimized after a | - | ||||||||||||||||||
707 | certain number of usages; setting this option prevents such | - | ||||||||||||||||||
708 | optimizations, therefore avoiding possible unpredictable spikes in | - | ||||||||||||||||||
709 | CPU and memory usage. If both this option and the | - | ||||||||||||||||||
710 | \c{OptimizeOnFirstUsageOption} option are set, then this option takes | - | ||||||||||||||||||
711 | precedence. Note: this option will still let the regular expression | - | ||||||||||||||||||
712 | to be optimized by manually calling | - | ||||||||||||||||||
713 | \l{QRegularExpression::}{optimize()}. This enum value has been | - | ||||||||||||||||||
714 | introduced in Qt 5.4. | - | ||||||||||||||||||
715 | */ | - | ||||||||||||||||||
716 | - | |||||||||||||||||||
717 | /*! | - | ||||||||||||||||||
718 | \enum QRegularExpression::MatchType | - | ||||||||||||||||||
719 | - | |||||||||||||||||||
720 | The MatchType enum defines the type of the match that should be attempted | - | ||||||||||||||||||
721 | against the subject string. | - | ||||||||||||||||||
722 | - | |||||||||||||||||||
723 | \value NormalMatch | - | ||||||||||||||||||
724 | A normal match is done. | - | ||||||||||||||||||
725 | - | |||||||||||||||||||
726 | \value PartialPreferCompleteMatch | - | ||||||||||||||||||
727 | The pattern string is matched partially against the subject string. If | - | ||||||||||||||||||
728 | a partial match is found, then it is recorded, and other matching | - | ||||||||||||||||||
729 | alternatives are tried as usual. If a complete match is then found, | - | ||||||||||||||||||
730 | then it's preferred to the partial match; in this case only the | - | ||||||||||||||||||
731 | complete match is reported. If instead no complete match is found (but | - | ||||||||||||||||||
732 | only the partial one), then the partial one is reported. | - | ||||||||||||||||||
733 | - | |||||||||||||||||||
734 | \value PartialPreferFirstMatch | - | ||||||||||||||||||
735 | The pattern string is matched partially against the subject string. If | - | ||||||||||||||||||
736 | a partial match is found, then matching stops and the partial match is | - | ||||||||||||||||||
737 | reported. In this case, other matching alternatives (potentially | - | ||||||||||||||||||
738 | leading to a complete match) are not tried. Moreover, this match type | - | ||||||||||||||||||
739 | assumes that the subject string only a substring of a larger text, and | - | ||||||||||||||||||
740 | that (in this text) there are other characters beyond the end of the | - | ||||||||||||||||||
741 | subject string. This can lead to surprising results; see the discussion | - | ||||||||||||||||||
742 | in the \l{partial matching} section for more details. | - | ||||||||||||||||||
743 | - | |||||||||||||||||||
744 | \value NoMatch | - | ||||||||||||||||||
745 | No matching is done. This value is returned as the match type by a | - | ||||||||||||||||||
746 | default constructed QRegularExpressionMatch or | - | ||||||||||||||||||
747 | QRegularExpressionMatchIterator. Using this match type is not very | - | ||||||||||||||||||
748 | useful for the user, as no matching ever happens. This enum value | - | ||||||||||||||||||
749 | has been introduced in Qt 5.1. | - | ||||||||||||||||||
750 | */ | - | ||||||||||||||||||
751 | - | |||||||||||||||||||
752 | /*! | - | ||||||||||||||||||
753 | \enum QRegularExpression::MatchOption | - | ||||||||||||||||||
754 | - | |||||||||||||||||||
755 | \value NoMatchOption | - | ||||||||||||||||||
756 | No match options are set. | - | ||||||||||||||||||
757 | - | |||||||||||||||||||
758 | \value AnchoredMatchOption | - | ||||||||||||||||||
759 | The match is constrained to start exactly at the offset passed to | - | ||||||||||||||||||
760 | match() in order to be successful, even if the pattern string does not | - | ||||||||||||||||||
761 | contain any metacharacter that anchors the match at that point. | - | ||||||||||||||||||
762 | - | |||||||||||||||||||
763 | \value DontCheckSubjectStringMatchOption | - | ||||||||||||||||||
764 | The subject string is not checked for UTF-16 validity before | - | ||||||||||||||||||
765 | attempting a match. Use this option with extreme caution, as | - | ||||||||||||||||||
766 | attempting to match an invalid string may crash the program and/or | - | ||||||||||||||||||
767 | constitute a security issue. This enum value has been introduced in | - | ||||||||||||||||||
768 | Qt 5.4. | - | ||||||||||||||||||
769 | */ | - | ||||||||||||||||||
770 | - | |||||||||||||||||||
771 | // after how many usages we optimize the regexp | - | ||||||||||||||||||
772 | #ifdef QT_BUILD_INTERNAL | - | ||||||||||||||||||
773 | Q_AUTOTEST_EXPORT unsigned int qt_qregularexpression_optimize_after_use_count = 10; | - | ||||||||||||||||||
774 | #else | - | ||||||||||||||||||
775 | static const unsigned int qt_qregularexpression_optimize_after_use_count = 10; | - | ||||||||||||||||||
776 | #endif // QT_BUILD_INTERNAL | - | ||||||||||||||||||
777 | - | |||||||||||||||||||
778 | /*! | - | ||||||||||||||||||
779 | \internal | - | ||||||||||||||||||
780 | */ | - | ||||||||||||||||||
781 | static int convertToPcreOptions(QRegularExpression::PatternOptions patternOptions) | - | ||||||||||||||||||
782 | { | - | ||||||||||||||||||
783 | int options = 0; | - | ||||||||||||||||||
784 | - | |||||||||||||||||||
785 | if (patternOptions & QRegularExpression::CaseInsensitiveOption)
| 89-981 | ||||||||||||||||||
786 | options |= PCRE_CASELESS; executed 89 times by 5 tests: options |= 0x00000001; Executed by:
| 89 | ||||||||||||||||||
787 | if (patternOptions & QRegularExpression::DotMatchesEverythingOption)
| 105-965 | ||||||||||||||||||
788 | options |= PCRE_DOTALL; executed 105 times by 4 tests: options |= 0x00000004; Executed by:
| 105 | ||||||||||||||||||
789 | if (patternOptions & QRegularExpression::MultilineOption)
| 37-1033 | ||||||||||||||||||
790 | options |= PCRE_MULTILINE; executed 37 times by 6 tests: options |= 0x00000002; Executed by:
| 37 | ||||||||||||||||||
791 | if (patternOptions & QRegularExpression::ExtendedPatternSyntaxOption)
| 10-1060 | ||||||||||||||||||
792 | options |= PCRE_EXTENDED; executed 10 times by 3 tests: options |= 0x00000008; Executed by:
| 10 | ||||||||||||||||||
793 | if (patternOptions & QRegularExpression::InvertedGreedinessOption)
| 24-1046 | ||||||||||||||||||
794 | options |= PCRE_UNGREEDY; executed 24 times by 3 tests: options |= 0x00000200; Executed by:
| 24 | ||||||||||||||||||
795 | if (patternOptions & QRegularExpression::DontCaptureOption)
| 10-1060 | ||||||||||||||||||
796 | options |= PCRE_NO_AUTO_CAPTURE; executed 10 times by 3 tests: options |= 0x00001000; Executed by:
| 10 | ||||||||||||||||||
797 | if (patternOptions & QRegularExpression::UseUnicodePropertiesOption)
| 3-1067 | ||||||||||||||||||
798 | options |= PCRE_UCP; executed 3 times by 3 tests: options |= 0x20000000; Executed by:
| 3 | ||||||||||||||||||
799 | - | |||||||||||||||||||
800 | return options; executed 1070 times by 21 tests: return options; Executed by:
| 1070 | ||||||||||||||||||
801 | } | - | ||||||||||||||||||
802 | - | |||||||||||||||||||
803 | /*! | - | ||||||||||||||||||
804 | \internal | - | ||||||||||||||||||
805 | */ | - | ||||||||||||||||||
806 | static int convertToPcreOptions(QRegularExpression::MatchOptions matchOptions) | - | ||||||||||||||||||
807 | { | - | ||||||||||||||||||
808 | int options = 0; | - | ||||||||||||||||||
809 | - | |||||||||||||||||||
810 | if (matchOptions & QRegularExpression::AnchoredMatchOption)
| 60-6175 | ||||||||||||||||||
811 | options |= PCRE_ANCHORED; executed 60 times by 3 tests: options |= 0x00000010; Executed by:
| 60 | ||||||||||||||||||
812 | - | |||||||||||||||||||
813 | return options; executed 6235 times by 21 tests: return options; Executed by:
| 6235 | ||||||||||||||||||
814 | } | - | ||||||||||||||||||
815 | - | |||||||||||||||||||
816 | struct QRegularExpressionPrivate : QSharedData | - | ||||||||||||||||||
817 | { | - | ||||||||||||||||||
818 | QRegularExpressionPrivate(); | - | ||||||||||||||||||
819 | ~QRegularExpressionPrivate(); | - | ||||||||||||||||||
820 | QRegularExpressionPrivate(const QRegularExpressionPrivate &other); | - | ||||||||||||||||||
821 | - | |||||||||||||||||||
822 | void cleanCompiledPattern(); | - | ||||||||||||||||||
823 | void compilePattern(); | - | ||||||||||||||||||
824 | void getPatternInfo(); | - | ||||||||||||||||||
825 | - | |||||||||||||||||||
826 | enum OptimizePatternOption { | - | ||||||||||||||||||
827 | LazyOptimizeOption, | - | ||||||||||||||||||
828 | ImmediateOptimizeOption | - | ||||||||||||||||||
829 | }; | - | ||||||||||||||||||
830 | - | |||||||||||||||||||
831 | void optimizePattern(OptimizePatternOption option); | - | ||||||||||||||||||
832 | - | |||||||||||||||||||
833 | enum CheckSubjectStringOption { | - | ||||||||||||||||||
834 | CheckSubjectString, | - | ||||||||||||||||||
835 | DontCheckSubjectString | - | ||||||||||||||||||
836 | }; | - | ||||||||||||||||||
837 | - | |||||||||||||||||||
838 | QRegularExpressionMatchPrivate *doMatch(const QString &subject, | - | ||||||||||||||||||
839 | int subjectStartPos, | - | ||||||||||||||||||
840 | int subjectLength, | - | ||||||||||||||||||
841 | int offset, | - | ||||||||||||||||||
842 | QRegularExpression::MatchType matchType, | - | ||||||||||||||||||
843 | QRegularExpression::MatchOptions matchOptions, | - | ||||||||||||||||||
844 | CheckSubjectStringOption checkSubjectStringOption = CheckSubjectString, | - | ||||||||||||||||||
845 | const QRegularExpressionMatchPrivate *previous = 0) const; | - | ||||||||||||||||||
846 | - | |||||||||||||||||||
847 | int captureIndexForName(const QString &name) const; | - | ||||||||||||||||||
848 | - | |||||||||||||||||||
849 | // sizeof(QSharedData) == 4, so start our members with an enum | - | ||||||||||||||||||
850 | QRegularExpression::PatternOptions patternOptions; | - | ||||||||||||||||||
851 | QString pattern; | - | ||||||||||||||||||
852 | - | |||||||||||||||||||
853 | // *All* of the following members are set managed while holding this mutex, | - | ||||||||||||||||||
854 | // except for isDirty which is set to true by QRegularExpression setters | - | ||||||||||||||||||
855 | // (right after a detach happened). | - | ||||||||||||||||||
856 | // On the other hand, after the compilation and studying, | - | ||||||||||||||||||
857 | // it's safe to *use* (i.e. read) them from multiple threads at the same time. | - | ||||||||||||||||||
858 | // Therefore, doMatch doesn't need to lock this mutex. | - | ||||||||||||||||||
859 | QMutex mutex; | - | ||||||||||||||||||
860 | - | |||||||||||||||||||
861 | // The PCRE pointers are reference-counted by the QRegularExpressionPrivate | - | ||||||||||||||||||
862 | // objects themselves; when the private is copied (i.e. a detach happened) | - | ||||||||||||||||||
863 | // they are set to 0 | - | ||||||||||||||||||
864 | pcre16 *compiledPattern; | - | ||||||||||||||||||
865 | QAtomicPointer<pcre16_extra> studyData; | - | ||||||||||||||||||
866 | const char *errorString; | - | ||||||||||||||||||
867 | int errorOffset; | - | ||||||||||||||||||
868 | int capturingCount; | - | ||||||||||||||||||
869 | unsigned int usedCount; | - | ||||||||||||||||||
870 | bool usingCrLfNewlines; | - | ||||||||||||||||||
871 | bool isDirty; | - | ||||||||||||||||||
872 | }; | - | ||||||||||||||||||
873 | - | |||||||||||||||||||
874 | struct QRegularExpressionMatchPrivate : QSharedData | - | ||||||||||||||||||
875 | { | - | ||||||||||||||||||
876 | QRegularExpressionMatchPrivate(const QRegularExpression &re, | - | ||||||||||||||||||
877 | const QString &subject, | - | ||||||||||||||||||
878 | int subjectStart, | - | ||||||||||||||||||
879 | int subjectLength, | - | ||||||||||||||||||
880 | QRegularExpression::MatchType matchType, | - | ||||||||||||||||||
881 | QRegularExpression::MatchOptions matchOptions, | - | ||||||||||||||||||
882 | int capturingCount = 0); | - | ||||||||||||||||||
883 | - | |||||||||||||||||||
884 | QRegularExpressionMatch nextMatch() const; | - | ||||||||||||||||||
885 | - | |||||||||||||||||||
886 | const QRegularExpression regularExpression; | - | ||||||||||||||||||
887 | const QString subject; | - | ||||||||||||||||||
888 | // the capturedOffsets vector contains pairs of (start, end) positions | - | ||||||||||||||||||
889 | // for each captured substring | - | ||||||||||||||||||
890 | QVector<int> capturedOffsets; | - | ||||||||||||||||||
891 | - | |||||||||||||||||||
892 | const int subjectStart; | - | ||||||||||||||||||
893 | const int subjectLength; | - | ||||||||||||||||||
894 | - | |||||||||||||||||||
895 | const QRegularExpression::MatchType matchType; | - | ||||||||||||||||||
896 | const QRegularExpression::MatchOptions matchOptions; | - | ||||||||||||||||||
897 | - | |||||||||||||||||||
898 | int capturedCount; | - | ||||||||||||||||||
899 | - | |||||||||||||||||||
900 | bool hasMatch; | - | ||||||||||||||||||
901 | bool hasPartialMatch; | - | ||||||||||||||||||
902 | bool isValid; | - | ||||||||||||||||||
903 | }; | - | ||||||||||||||||||
904 | - | |||||||||||||||||||
905 | struct QRegularExpressionMatchIteratorPrivate : QSharedData | - | ||||||||||||||||||
906 | { | - | ||||||||||||||||||
907 | QRegularExpressionMatchIteratorPrivate(const QRegularExpression &re, | - | ||||||||||||||||||
908 | QRegularExpression::MatchType matchType, | - | ||||||||||||||||||
909 | QRegularExpression::MatchOptions matchOptions, | - | ||||||||||||||||||
910 | const QRegularExpressionMatch &next); | - | ||||||||||||||||||
911 | - | |||||||||||||||||||
912 | bool hasNext() const; | - | ||||||||||||||||||
913 | QRegularExpressionMatch next; | - | ||||||||||||||||||
914 | const QRegularExpression regularExpression; | - | ||||||||||||||||||
915 | const QRegularExpression::MatchType matchType; | - | ||||||||||||||||||
916 | const QRegularExpression::MatchOptions matchOptions; | - | ||||||||||||||||||
917 | }; | - | ||||||||||||||||||
918 | - | |||||||||||||||||||
919 | /*! | - | ||||||||||||||||||
920 | \internal | - | ||||||||||||||||||
921 | */ | - | ||||||||||||||||||
922 | QRegularExpression::QRegularExpression(QRegularExpressionPrivate &dd) | - | ||||||||||||||||||
923 | : d(&dd) | - | ||||||||||||||||||
924 | { | - | ||||||||||||||||||
925 | } executed 6733 times by 21 tests: end of block Executed by:
| 6733 | ||||||||||||||||||
926 | - | |||||||||||||||||||
927 | /*! | - | ||||||||||||||||||
928 | \internal | - | ||||||||||||||||||
929 | */ | - | ||||||||||||||||||
930 | QRegularExpressionPrivate::QRegularExpressionPrivate() | - | ||||||||||||||||||
931 | : patternOptions(0), pattern(), | - | ||||||||||||||||||
932 | mutex(), | - | ||||||||||||||||||
933 | compiledPattern(0), studyData(0), | - | ||||||||||||||||||
934 | errorString(0), errorOffset(-1), | - | ||||||||||||||||||
935 | capturingCount(0), | - | ||||||||||||||||||
936 | usedCount(0), | - | ||||||||||||||||||
937 | usingCrLfNewlines(false), | - | ||||||||||||||||||
938 | isDirty(true) | - | ||||||||||||||||||
939 | { | - | ||||||||||||||||||
940 | } executed 1670 times by 21 tests: end of block Executed by:
| 1670 | ||||||||||||||||||
941 | - | |||||||||||||||||||
942 | /*! | - | ||||||||||||||||||
943 | \internal | - | ||||||||||||||||||
944 | */ | - | ||||||||||||||||||
945 | QRegularExpressionPrivate::~QRegularExpressionPrivate() | - | ||||||||||||||||||
946 | { | - | ||||||||||||||||||
947 | cleanCompiledPattern(); | - | ||||||||||||||||||
948 | } executed 1719 times by 22 tests: end of block Executed by:
| 1719 | ||||||||||||||||||
949 | - | |||||||||||||||||||
950 | /*! | - | ||||||||||||||||||
951 | \internal | - | ||||||||||||||||||
952 | - | |||||||||||||||||||
953 | Copies the private, which means copying only the pattern and the pattern | - | ||||||||||||||||||
954 | options. The compiledPattern and the studyData pointers are NOT copied (we | - | ||||||||||||||||||
955 | do not own them any more), and in general all the members set when | - | ||||||||||||||||||
956 | compiling a pattern are set to default values. isDirty is set back to true | - | ||||||||||||||||||
957 | so that the pattern has to be recompiled again. | - | ||||||||||||||||||
958 | */ | - | ||||||||||||||||||
959 | QRegularExpressionPrivate::QRegularExpressionPrivate(const QRegularExpressionPrivate &other) | - | ||||||||||||||||||
960 | : QSharedData(other), | - | ||||||||||||||||||
961 | patternOptions(other.patternOptions), pattern(other.pattern), | - | ||||||||||||||||||
962 | mutex(), | - | ||||||||||||||||||
963 | compiledPattern(0), studyData(0), | - | ||||||||||||||||||
964 | errorString(0), | - | ||||||||||||||||||
965 | errorOffset(-1), capturingCount(0), | - | ||||||||||||||||||
966 | usedCount(0), | - | ||||||||||||||||||
967 | usingCrLfNewlines(false), isDirty(true) | - | ||||||||||||||||||
968 | { | - | ||||||||||||||||||
969 | } executed 50 times by 6 tests: end of block Executed by:
| 50 | ||||||||||||||||||
970 | - | |||||||||||||||||||
971 | /*! | - | ||||||||||||||||||
972 | \internal | - | ||||||||||||||||||
973 | */ | - | ||||||||||||||||||
974 | void QRegularExpressionPrivate::cleanCompiledPattern() | - | ||||||||||||||||||
975 | { | - | ||||||||||||||||||
976 | pcre16_free(compiledPattern); | - | ||||||||||||||||||
977 | pcre16_free_study(studyData.load()); | - | ||||||||||||||||||
978 | usedCount = 0; | - | ||||||||||||||||||
979 | compiledPattern = 0; | - | ||||||||||||||||||
980 | studyData.store(0); | - | ||||||||||||||||||
981 | usingCrLfNewlines = false; | - | ||||||||||||||||||
982 | errorOffset = -1; | - | ||||||||||||||||||
983 | capturingCount = 0; | - | ||||||||||||||||||
984 | } executed 2789 times by 26 tests: end of block Executed by:
| 2789 | ||||||||||||||||||
985 | - | |||||||||||||||||||
986 | /*! | - | ||||||||||||||||||
987 | \internal | - | ||||||||||||||||||
988 | */ | - | ||||||||||||||||||
989 | void QRegularExpressionPrivate::compilePattern() | - | ||||||||||||||||||
990 | { | - | ||||||||||||||||||
991 | QMutexLocker lock(&mutex); | - | ||||||||||||||||||
992 | - | |||||||||||||||||||
993 | if (!isDirty)
| 1070-7831 | ||||||||||||||||||
994 | return; executed 7831 times by 19 tests: return; Executed by:
| 7831 | ||||||||||||||||||
995 | - | |||||||||||||||||||
996 | isDirty = false; | - | ||||||||||||||||||
997 | cleanCompiledPattern(); | - | ||||||||||||||||||
998 | - | |||||||||||||||||||
999 | int options = convertToPcreOptions(patternOptions); | - | ||||||||||||||||||
1000 | options |= PCRE_UTF16; | - | ||||||||||||||||||
1001 | - | |||||||||||||||||||
1002 | int errorCode; | - | ||||||||||||||||||
1003 | compiledPattern = pcre16_compile2(pattern.utf16(), options, | - | ||||||||||||||||||
1004 | &errorCode, &errorString, &errorOffset, 0); | - | ||||||||||||||||||
1005 | - | |||||||||||||||||||
1006 | if (!compiledPattern)
| 49-1021 | ||||||||||||||||||
1007 | return; executed 49 times by 4 tests: return; Executed by:
| 49 | ||||||||||||||||||
1008 | - | |||||||||||||||||||
1009 | Q_ASSERT(errorCode == 0); | - | ||||||||||||||||||
1010 | Q_ASSERT(studyData.load() == 0); // studying (=>optimizing) is always done later | - | ||||||||||||||||||
1011 | errorOffset = -1; | - | ||||||||||||||||||
1012 | - | |||||||||||||||||||
1013 | getPatternInfo(); | - | ||||||||||||||||||
1014 | } executed 1021 times by 21 tests: end of block Executed by:
| 1021 | ||||||||||||||||||
1015 | - | |||||||||||||||||||
1016 | /*! | - | ||||||||||||||||||
1017 | \internal | - | ||||||||||||||||||
1018 | */ | - | ||||||||||||||||||
1019 | void QRegularExpressionPrivate::getPatternInfo() | - | ||||||||||||||||||
1020 | { | - | ||||||||||||||||||
1021 | Q_ASSERT(compiledPattern); | - | ||||||||||||||||||
1022 | Q_ASSERT(studyData.load() == 0); | - | ||||||||||||||||||
1023 | - | |||||||||||||||||||
1024 | pcre16_fullinfo(compiledPattern, 0, PCRE_INFO_CAPTURECOUNT, &capturingCount); | - | ||||||||||||||||||
1025 | - | |||||||||||||||||||
1026 | // detect the settings for the newline | - | ||||||||||||||||||
1027 | unsigned long int patternNewlineSetting; | - | ||||||||||||||||||
1028 | pcre16_fullinfo(compiledPattern, 0, PCRE_INFO_OPTIONS, &patternNewlineSetting); | - | ||||||||||||||||||
1029 | patternNewlineSetting &= PCRE_NEWLINE_CR | PCRE_NEWLINE_LF | PCRE_NEWLINE_CRLF | - | ||||||||||||||||||
1030 | | PCRE_NEWLINE_ANY | PCRE_NEWLINE_ANYCRLF; | - | ||||||||||||||||||
1031 | if (patternNewlineSetting == 0) {
| 9-1012 | ||||||||||||||||||
1032 | // no option was specified in the regexp, grab PCRE build defaults | - | ||||||||||||||||||
1033 | int pcreNewlineSetting; | - | ||||||||||||||||||
1034 | pcre16_config(PCRE_CONFIG_NEWLINE, &pcreNewlineSetting); | - | ||||||||||||||||||
1035 | switch (pcreNewlineSetting) { | - | ||||||||||||||||||
1036 | case 13: never executed: case 13: | 0 | ||||||||||||||||||
1037 | patternNewlineSetting = PCRE_NEWLINE_CR; break; never executed: break; | 0 | ||||||||||||||||||
1038 | case 10: executed 1012 times by 21 tests: case 10: Executed by:
| 1012 | ||||||||||||||||||
1039 | patternNewlineSetting = PCRE_NEWLINE_LF; break; executed 1012 times by 21 tests: break; Executed by:
| 1012 | ||||||||||||||||||
1040 | case 3338: // (13<<8 | 10) never executed: case 3338: | 0 | ||||||||||||||||||
1041 | patternNewlineSetting = PCRE_NEWLINE_CRLF; break; never executed: break; | 0 | ||||||||||||||||||
1042 | case -2: never executed: case -2: | 0 | ||||||||||||||||||
1043 | patternNewlineSetting = PCRE_NEWLINE_ANYCRLF; break; never executed: break; | 0 | ||||||||||||||||||
1044 | case -1: never executed: case -1: | 0 | ||||||||||||||||||
1045 | patternNewlineSetting = PCRE_NEWLINE_ANY; break; never executed: break; | 0 | ||||||||||||||||||
1046 | default: never executed: default: | 0 | ||||||||||||||||||
1047 | qWarning("QRegularExpressionPrivate::compilePattern(): " | - | ||||||||||||||||||
1048 | "PCRE_CONFIG_NEWLINE returned an unknown newline"); | - | ||||||||||||||||||
1049 | break; never executed: break; | 0 | ||||||||||||||||||
1050 | } | - | ||||||||||||||||||
1051 | } | - | ||||||||||||||||||
1052 | - | |||||||||||||||||||
1053 | usingCrLfNewlines = (patternNewlineSetting == PCRE_NEWLINE_CRLF) ||
| 6-1015 | ||||||||||||||||||
1054 | (patternNewlineSetting == PCRE_NEWLINE_ANY) ||
| 0-1015 | ||||||||||||||||||
1055 | (patternNewlineSetting == PCRE_NEWLINE_ANYCRLF);
| 3-1012 | ||||||||||||||||||
1056 | - | |||||||||||||||||||
1057 | int hasJOptionChanged; | - | ||||||||||||||||||
1058 | pcre16_fullinfo(compiledPattern, 0, PCRE_INFO_JCHANGED, &hasJOptionChanged); | - | ||||||||||||||||||
1059 | if (hasJOptionChanged) {
| 9-1012 | ||||||||||||||||||
1060 | qWarning("QRegularExpressionPrivate::getPatternInfo(): the pattern '%s'\n" | - | ||||||||||||||||||
1061 | " is using the (?J) option; duplicate capturing group names are not supported by Qt", | - | ||||||||||||||||||
1062 | qPrintable(pattern)); | - | ||||||||||||||||||
1063 | } executed 9 times by 3 tests: end of block Executed by:
| 9 | ||||||||||||||||||
1064 | } executed 1021 times by 21 tests: end of block Executed by:
| 1021 | ||||||||||||||||||
1065 | - | |||||||||||||||||||
1066 | - | |||||||||||||||||||
1067 | /* | - | ||||||||||||||||||
1068 | Simple "smartpointer" wrapper around a pcre_jit_stack, to be used with | - | ||||||||||||||||||
1069 | QThreadStorage. | - | ||||||||||||||||||
1070 | */ | - | ||||||||||||||||||
1071 | class QPcreJitStackPointer | - | ||||||||||||||||||
1072 | { | - | ||||||||||||||||||
1073 | Q_DISABLE_COPY(QPcreJitStackPointer) | - | ||||||||||||||||||
1074 | - | |||||||||||||||||||
1075 | public: | - | ||||||||||||||||||
1076 | /*! | - | ||||||||||||||||||
1077 | \internal | - | ||||||||||||||||||
1078 | */ | - | ||||||||||||||||||
1079 | QPcreJitStackPointer() | - | ||||||||||||||||||
1080 | { | - | ||||||||||||||||||
1081 | // The default JIT stack size in PCRE is 32K, | - | ||||||||||||||||||
1082 | // we allocate from 32K up to 512K. | - | ||||||||||||||||||
1083 | stack = pcre16_jit_stack_alloc(32*1024, 512*1024); | - | ||||||||||||||||||
1084 | } never executed: end of block | 0 | ||||||||||||||||||
1085 | /*! | - | ||||||||||||||||||
1086 | \internal | - | ||||||||||||||||||
1087 | */ | - | ||||||||||||||||||
1088 | ~QPcreJitStackPointer() | - | ||||||||||||||||||
1089 | { | - | ||||||||||||||||||
1090 | if (stack)
| 0 | ||||||||||||||||||
1091 | pcre16_jit_stack_free(stack); never executed: pcre16_jit_stack_free(stack); | 0 | ||||||||||||||||||
1092 | } never executed: end of block | 0 | ||||||||||||||||||
1093 | - | |||||||||||||||||||
1094 | pcre16_jit_stack *stack; | - | ||||||||||||||||||
1095 | }; | - | ||||||||||||||||||
1096 | - | |||||||||||||||||||
1097 | Q_GLOBAL_STATIC(QThreadStorage<QPcreJitStackPointer *>, jitStacks) never executed: end of block never executed: guard.store(QtGlobalStatic::Destroyed); never executed: return &holder.value;
| 0 | ||||||||||||||||||
1098 | - | |||||||||||||||||||
1099 | /*! | - | ||||||||||||||||||
1100 | \internal | - | ||||||||||||||||||
1101 | */ | - | ||||||||||||||||||
1102 | static pcre16_jit_stack *qtPcreCallback(void *) | - | ||||||||||||||||||
1103 | { | - | ||||||||||||||||||
1104 | if (jitStacks()->hasLocalData())
| 0 | ||||||||||||||||||
1105 | return jitStacks()->localData()->stack; never executed: return jitStacks()->localData()->stack; | 0 | ||||||||||||||||||
1106 | - | |||||||||||||||||||
1107 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
1108 | } | - | ||||||||||||||||||
1109 | - | |||||||||||||||||||
1110 | /*! | - | ||||||||||||||||||
1111 | \internal | - | ||||||||||||||||||
1112 | */ | - | ||||||||||||||||||
1113 | static bool isJitEnabled() | - | ||||||||||||||||||
1114 | { | - | ||||||||||||||||||
1115 | QByteArray jitEnvironment = qgetenv("QT_ENABLE_REGEXP_JIT"); | - | ||||||||||||||||||
1116 | if (!jitEnvironment.isEmpty()) {
| 0-12 | ||||||||||||||||||
1117 | bool ok; | - | ||||||||||||||||||
1118 | int enableJit = jitEnvironment.toInt(&ok); | - | ||||||||||||||||||
1119 | return ok ? (enableJit != 0) : true; never executed: return ok ? (enableJit != 0) : true;
| 0 | ||||||||||||||||||
1120 | } | - | ||||||||||||||||||
1121 | - | |||||||||||||||||||
1122 | #ifdef QT_DEBUG | - | ||||||||||||||||||
1123 | return false; executed 12 times by 11 tests: return false; Executed by:
| 12 | ||||||||||||||||||
1124 | #else | - | ||||||||||||||||||
1125 | return true; | - | ||||||||||||||||||
1126 | #endif | - | ||||||||||||||||||
1127 | } | - | ||||||||||||||||||
1128 | - | |||||||||||||||||||
1129 | /*! | - | ||||||||||||||||||
1130 | \internal | - | ||||||||||||||||||
1131 | - | |||||||||||||||||||
1132 | The purpose of the function is to call pcre16_study (which allows some | - | ||||||||||||||||||
1133 | optimizations to be performed, including JIT-compiling the pattern), and | - | ||||||||||||||||||
1134 | setting the studyData member variable to the result of the study. It gets | - | ||||||||||||||||||
1135 | called by doMatch() every time a match is performed. As of now, the | - | ||||||||||||||||||
1136 | optimizations on the pattern are performed after a certain number of usages | - | ||||||||||||||||||
1137 | (i.e. the qt_qregularexpression_optimize_after_use_count constant) unless | - | ||||||||||||||||||
1138 | the DontAutomaticallyOptimizeOption option is set on the QRegularExpression | - | ||||||||||||||||||
1139 | object, or anyhow by calling optimize() (which will pass | - | ||||||||||||||||||
1140 | ImmediateOptimizeOption). | - | ||||||||||||||||||
1141 | - | |||||||||||||||||||
1142 | Notice that although the method is protected by a mutex, one thread may | - | ||||||||||||||||||
1143 | invoke this function and return immediately (i.e. not study the pattern, | - | ||||||||||||||||||
1144 | leaving studyData to NULL); but before calling pcre16_exec to perform the | - | ||||||||||||||||||
1145 | match, another thread performs the studying and sets studyData to something | - | ||||||||||||||||||
1146 | else. Although the assignment to studyData is itself atomic, the release of | - | ||||||||||||||||||
1147 | the memory pointed by studyData isn't. Therefore, we work on a local copy | - | ||||||||||||||||||
1148 | (localStudyData) before using storeRelease on studyData. In doMatch there's | - | ||||||||||||||||||
1149 | the corresponding loadAcquire. | - | ||||||||||||||||||
1150 | */ | - | ||||||||||||||||||
1151 | void QRegularExpressionPrivate::optimizePattern(OptimizePatternOption option) | - | ||||||||||||||||||
1152 | { | - | ||||||||||||||||||
1153 | Q_ASSERT(compiledPattern); | - | ||||||||||||||||||
1154 | - | |||||||||||||||||||
1155 | QMutexLocker lock(&mutex); | - | ||||||||||||||||||
1156 | - | |||||||||||||||||||
1157 | if (studyData.load()) // already optimized
| 2993-3537 | ||||||||||||||||||
1158 | return; executed 3537 times by 10 tests: return; Executed by:
| 3537 | ||||||||||||||||||
1159 | - | |||||||||||||||||||
1160 | if ((option == LazyOptimizeOption) && (++usedCount != qt_qregularexpression_optimize_after_use_count))
| 154-2693 | ||||||||||||||||||
1161 | return; executed 2539 times by 18 tests: return; Executed by:
| 2539 | ||||||||||||||||||
1162 | - | |||||||||||||||||||
1163 | static const bool enableJit = isJitEnabled(); | - | ||||||||||||||||||
1164 | - | |||||||||||||||||||
1165 | int studyOptions = 0; | - | ||||||||||||||||||
1166 | if (enableJit)
| 0-454 | ||||||||||||||||||
1167 | studyOptions |= (PCRE_STUDY_JIT_COMPILE | PCRE_STUDY_JIT_PARTIAL_SOFT_COMPILE | PCRE_STUDY_JIT_PARTIAL_HARD_COMPILE); never executed: studyOptions |= (0x0001 | 0x0002 | 0x0004); | 0 | ||||||||||||||||||
1168 | - | |||||||||||||||||||
1169 | const char *err; | - | ||||||||||||||||||
1170 | pcre16_extra * const localStudyData = pcre16_study(compiledPattern, studyOptions, &err); | - | ||||||||||||||||||
1171 | - | |||||||||||||||||||
1172 | if (localStudyData && localStudyData->flags & PCRE_EXTRA_EXECUTABLE_JIT)
| 0-309 | ||||||||||||||||||
1173 | pcre16_assign_jit_stack(localStudyData, qtPcreCallback, 0); never executed: pcre16_assign_jit_stack(localStudyData, qtPcreCallback, 0); | 0 | ||||||||||||||||||
1174 | - | |||||||||||||||||||
1175 | if (!localStudyData && err)
| 0-309 | ||||||||||||||||||
1176 | qWarning("QRegularExpressionPrivate::optimizePattern(): pcre_study failed: %s", err); never executed: QMessageLogger(__FILE__, 1176, __PRETTY_FUNCTION__).warning("QRegularExpressionPrivate::optimizePattern(): pcre_study failed: %s", err); | 0 | ||||||||||||||||||
1177 | - | |||||||||||||||||||
1178 | studyData.storeRelease(localStudyData); | - | ||||||||||||||||||
1179 | } executed 454 times by 11 tests: end of block Executed by:
| 454 | ||||||||||||||||||
1180 | - | |||||||||||||||||||
1181 | /*! | - | ||||||||||||||||||
1182 | \internal | - | ||||||||||||||||||
1183 | - | |||||||||||||||||||
1184 | Returns the capturing group number for the given name. Duplicated names for | - | ||||||||||||||||||
1185 | capturing groups are not supported. | - | ||||||||||||||||||
1186 | */ | - | ||||||||||||||||||
1187 | int QRegularExpressionPrivate::captureIndexForName(const QString &name) const | - | ||||||||||||||||||
1188 | { | - | ||||||||||||||||||
1189 | Q_ASSERT(!name.isEmpty()); | - | ||||||||||||||||||
1190 | - | |||||||||||||||||||
1191 | if (!compiledPattern)
| 0-63 | ||||||||||||||||||
1192 | return -1; never executed: return -1; | 0 | ||||||||||||||||||
1193 | - | |||||||||||||||||||
1194 | int index = pcre16_get_stringnumber(compiledPattern, name.utf16()); | - | ||||||||||||||||||
1195 | if (index >= 0)
| 30-33 | ||||||||||||||||||
1196 | return index; executed 33 times by 3 tests: return index; Executed by:
| 33 | ||||||||||||||||||
1197 | - | |||||||||||||||||||
1198 | return -1; executed 30 times by 3 tests: return -1; Executed by:
| 30 | ||||||||||||||||||
1199 | } | - | ||||||||||||||||||
1200 | - | |||||||||||||||||||
1201 | /*! | - | ||||||||||||||||||
1202 | \internal | - | ||||||||||||||||||
1203 | - | |||||||||||||||||||
1204 | This is a simple wrapper for pcre16_exec for handling the case in which the | - | ||||||||||||||||||
1205 | JIT runs out of memory. In that case, we allocate a thread-local JIT stack | - | ||||||||||||||||||
1206 | and re-run pcre16_exec. | - | ||||||||||||||||||
1207 | */ | - | ||||||||||||||||||
1208 | static int pcre16SafeExec(const pcre16 *code, const pcre16_extra *extra, | - | ||||||||||||||||||
1209 | const unsigned short *subject, int length, | - | ||||||||||||||||||
1210 | int startOffset, int options, | - | ||||||||||||||||||
1211 | int *ovector, int ovecsize) | - | ||||||||||||||||||
1212 | { | - | ||||||||||||||||||
1213 | int result = pcre16_exec(code, extra, subject, length, | - | ||||||||||||||||||
1214 | startOffset, options, ovector, ovecsize); | - | ||||||||||||||||||
1215 | - | |||||||||||||||||||
1216 | if (result == PCRE_ERROR_JIT_STACKLIMIT && !jitStacks()->hasLocalData()) {
| 0-6614 | ||||||||||||||||||
1217 | QPcreJitStackPointer *p = new QPcreJitStackPointer; | - | ||||||||||||||||||
1218 | jitStacks()->setLocalData(p); | - | ||||||||||||||||||
1219 | - | |||||||||||||||||||
1220 | result = pcre16_exec(code, extra, subject, length, | - | ||||||||||||||||||
1221 | startOffset, options, ovector, ovecsize); | - | ||||||||||||||||||
1222 | } never executed: end of block | 0 | ||||||||||||||||||
1223 | - | |||||||||||||||||||
1224 | return result; executed 6614 times by 21 tests: return result; Executed by:
| 6614 | ||||||||||||||||||
1225 | } | - | ||||||||||||||||||
1226 | - | |||||||||||||||||||
1227 | /*! | - | ||||||||||||||||||
1228 | \internal | - | ||||||||||||||||||
1229 | - | |||||||||||||||||||
1230 | Performs a match on the substring of the given \a subject string, | - | ||||||||||||||||||
1231 | substring which starts from \a subjectStart and up to | - | ||||||||||||||||||
1232 | (but not including) \a subjectStart + \a subjectLength. The match | - | ||||||||||||||||||
1233 | will be of type \a matchType and using the options \a matchOptions; | - | ||||||||||||||||||
1234 | the matching \a offset is relative the substring, | - | ||||||||||||||||||
1235 | and if negative, it's taken as an offset from the end of the substring. | - | ||||||||||||||||||
1236 | - | |||||||||||||||||||
1237 | It also advances a match if a previous result is given as \a | - | ||||||||||||||||||
1238 | previous. The \a subject string goes a Unicode validity check if | - | ||||||||||||||||||
1239 | \a checkSubjectString is CheckSubjectString and the match options don't | - | ||||||||||||||||||
1240 | include DontCheckSubjectStringMatchOption (PCRE doesn't like illegal | - | ||||||||||||||||||
1241 | UTF-16 sequences). | - | ||||||||||||||||||
1242 | - | |||||||||||||||||||
1243 | Returns the QRegularExpressionMatchPrivate of the result. | - | ||||||||||||||||||
1244 | - | |||||||||||||||||||
1245 | Advancing a match is a tricky algorithm. If the previous match matched a | - | ||||||||||||||||||
1246 | non-empty string, we just do an ordinary match at the offset position. | - | ||||||||||||||||||
1247 | - | |||||||||||||||||||
1248 | If the previous match matched an empty string, then an anchored, non-empty | - | ||||||||||||||||||
1249 | match is attempted at the offset position. If that succeeds, then we got | - | ||||||||||||||||||
1250 | the next match and we can return it. Otherwise, we advance by 1 position | - | ||||||||||||||||||
1251 | (which can be one or two code units in UTF-16!) and reattempt a "normal" | - | ||||||||||||||||||
1252 | match. We also have the problem of detecting the current newline format: if | - | ||||||||||||||||||
1253 | the new advanced offset is pointing to the beginning of a CRLF sequence, we | - | ||||||||||||||||||
1254 | must advance over it. | - | ||||||||||||||||||
1255 | */ | - | ||||||||||||||||||
1256 | QRegularExpressionMatchPrivate *QRegularExpressionPrivate::doMatch(const QString &subject, | - | ||||||||||||||||||
1257 | int subjectStart, | - | ||||||||||||||||||
1258 | int subjectLength, | - | ||||||||||||||||||
1259 | int offset, | - | ||||||||||||||||||
1260 | QRegularExpression::MatchType matchType, | - | ||||||||||||||||||
1261 | QRegularExpression::MatchOptions matchOptions, | - | ||||||||||||||||||
1262 | CheckSubjectStringOption checkSubjectStringOption, | - | ||||||||||||||||||
1263 | const QRegularExpressionMatchPrivate *previous) const | - | ||||||||||||||||||
1264 | { | - | ||||||||||||||||||
1265 | if (offset < 0)
| 60-6673 | ||||||||||||||||||
1266 | offset += subjectLength; executed 60 times by 3 tests: offset += subjectLength; Executed by:
| 60 | ||||||||||||||||||
1267 | - | |||||||||||||||||||
1268 | QRegularExpression re(*const_cast<QRegularExpressionPrivate *>(this)); | - | ||||||||||||||||||
1269 | - | |||||||||||||||||||
1270 | if (offset < 0 || offset > subjectLength)
| 0-6733 | ||||||||||||||||||
1271 | return new QRegularExpressionMatchPrivate(re, subject, subjectStart, subjectLength, matchType, matchOptions); never executed: return new QRegularExpressionMatchPrivate(re, subject, subjectStart, subjectLength, matchType, matchOptions); | 0 | ||||||||||||||||||
1272 | - | |||||||||||||||||||
1273 | if (!compiledPattern) {
| 24-6709 | ||||||||||||||||||
1274 | qWarning("QRegularExpressionPrivate::doMatch(): called on an invalid QRegularExpression object"); | - | ||||||||||||||||||
1275 | return new QRegularExpressionMatchPrivate(re, subject, subjectStart, subjectLength, matchType, matchOptions); executed 24 times by 3 tests: return new QRegularExpressionMatchPrivate(re, subject, subjectStart, subjectLength, matchType, matchOptions); Executed by:
| 24 | ||||||||||||||||||
1276 | } | - | ||||||||||||||||||
1277 | - | |||||||||||||||||||
1278 | // skip optimizing and doing the actual matching if NoMatch type was requested | - | ||||||||||||||||||
1279 | if (matchType == QRegularExpression::NoMatch) {
| 474-6235 | ||||||||||||||||||
1280 | QRegularExpressionMatchPrivate *priv = new QRegularExpressionMatchPrivate(re, subject, | - | ||||||||||||||||||
1281 | subjectStart, subjectLength, | - | ||||||||||||||||||
1282 | matchType, matchOptions); | - | ||||||||||||||||||
1283 | priv->isValid = true; | - | ||||||||||||||||||
1284 | return priv; executed 474 times by 3 tests: return priv; Executed by:
| 474 | ||||||||||||||||||
1285 | } | - | ||||||||||||||||||
1286 | - | |||||||||||||||||||
1287 | // capturingCount doesn't include the implicit "0" capturing group | - | ||||||||||||||||||
1288 | QRegularExpressionMatchPrivate *priv = new QRegularExpressionMatchPrivate(re, subject, | - | ||||||||||||||||||
1289 | subjectStart, subjectLength, | - | ||||||||||||||||||
1290 | matchType, matchOptions, | - | ||||||||||||||||||
1291 | capturingCount + 1); | - | ||||||||||||||||||
1292 | - | |||||||||||||||||||
1293 | if (!(patternOptions & QRegularExpression::DontAutomaticallyOptimizeOption)) {
| 0-6235 | ||||||||||||||||||
1294 | const OptimizePatternOption optimizePatternOption = | - | ||||||||||||||||||
1295 | (patternOptions & QRegularExpression::OptimizeOnFirstUsageOption)
| 222-6013 | ||||||||||||||||||
1296 | ? ImmediateOptimizeOption | - | ||||||||||||||||||
1297 | : LazyOptimizeOption; | - | ||||||||||||||||||
1298 | - | |||||||||||||||||||
1299 | // this is mutex protected | - | ||||||||||||||||||
1300 | const_cast<QRegularExpressionPrivate *>(this)->optimizePattern(optimizePatternOption); | - | ||||||||||||||||||
1301 | } executed 6235 times by 21 tests: end of block Executed by:
| 6235 | ||||||||||||||||||
1302 | - | |||||||||||||||||||
1303 | // work with a local copy of the study data, as we are running pcre_exec | - | ||||||||||||||||||
1304 | // potentially more than once, and we don't want to run call it | - | ||||||||||||||||||
1305 | // with different study data | - | ||||||||||||||||||
1306 | const pcre16_extra * const currentStudyData = studyData.loadAcquire(); | - | ||||||||||||||||||
1307 | - | |||||||||||||||||||
1308 | int pcreOptions = convertToPcreOptions(matchOptions); | - | ||||||||||||||||||
1309 | - | |||||||||||||||||||
1310 | if (matchType == QRegularExpression::PartialPreferCompleteMatch)
| 307-5928 | ||||||||||||||||||
1311 | pcreOptions |= PCRE_PARTIAL_SOFT; executed 307 times by 7 tests: pcreOptions |= 0x00008000; Executed by:
| 307 | ||||||||||||||||||
1312 | else if (matchType == QRegularExpression::PartialPreferFirstMatch)
| 84-5844 | ||||||||||||||||||
1313 | pcreOptions |= PCRE_PARTIAL_HARD; executed 84 times by 3 tests: pcreOptions |= 0x08000000; Executed by:
| 84 | ||||||||||||||||||
1314 | - | |||||||||||||||||||
1315 | if (checkSubjectStringOption == DontCheckSubjectString
| 1636-4599 | ||||||||||||||||||
1316 | || matchOptions & QRegularExpression::DontCheckSubjectStringMatchOption) { | - | ||||||||||||||||||
1317 | pcreOptions |= PCRE_NO_UTF16_CHECK; | - | ||||||||||||||||||
1318 | } executed 1636 times by 7 tests: end of block Executed by:
| 1636 | ||||||||||||||||||
1319 | - | |||||||||||||||||||
1320 | bool previousMatchWasEmpty = false; | - | ||||||||||||||||||
1321 | if (previous && previous->hasMatch &&
| 0-4599 | ||||||||||||||||||
1322 | (previous->capturedOffsets.at(0) == previous->capturedOffsets.at(1))) {
| 403-1233 | ||||||||||||||||||
1323 | previousMatchWasEmpty = true; | - | ||||||||||||||||||
1324 | } executed 403 times by 4 tests: end of block Executed by:
| 403 | ||||||||||||||||||
1325 | - | |||||||||||||||||||
1326 | int * const captureOffsets = priv->capturedOffsets.data(); | - | ||||||||||||||||||
1327 | const int captureOffsetsCount = priv->capturedOffsets.size(); | - | ||||||||||||||||||
1328 | - | |||||||||||||||||||
1329 | const unsigned short * const subjectUtf16 = subject.utf16() + subjectStart; | - | ||||||||||||||||||
1330 | - | |||||||||||||||||||
1331 | int result; | - | ||||||||||||||||||
1332 | - | |||||||||||||||||||
1333 | if (!previousMatchWasEmpty) {
| 403-5832 | ||||||||||||||||||
1334 | result = pcre16SafeExec(compiledPattern, currentStudyData, | - | ||||||||||||||||||
1335 | subjectUtf16, subjectLength, | - | ||||||||||||||||||
1336 | offset, pcreOptions, | - | ||||||||||||||||||
1337 | captureOffsets, captureOffsetsCount); | - | ||||||||||||||||||
1338 | } else { executed 5832 times by 21 tests: end of block Executed by:
| 5832 | ||||||||||||||||||
1339 | result = pcre16SafeExec(compiledPattern, currentStudyData, | - | ||||||||||||||||||
1340 | subjectUtf16, subjectLength, | - | ||||||||||||||||||
1341 | offset, pcreOptions | PCRE_NOTEMPTY_ATSTART | PCRE_ANCHORED, | - | ||||||||||||||||||
1342 | captureOffsets, captureOffsetsCount); | - | ||||||||||||||||||
1343 | - | |||||||||||||||||||
1344 | if (result == PCRE_ERROR_NOMATCH) {
| 24-379 | ||||||||||||||||||
1345 | ++offset; | - | ||||||||||||||||||
1346 | - | |||||||||||||||||||
1347 | if (usingCrLfNewlines
| 132-247 | ||||||||||||||||||
1348 | && offset < subjectLength
| 36-96 | ||||||||||||||||||
1349 | && subjectUtf16[offset - 1] == QLatin1Char('\r')
| 12-84 | ||||||||||||||||||
1350 | && subjectUtf16[offset] == QLatin1Char('\n')) {
| 12-72 | ||||||||||||||||||
1351 | ++offset; | - | ||||||||||||||||||
1352 | } else if (offset < subjectLength executed 72 times by 3 tests: end of block Executed by:
| 72-161 | ||||||||||||||||||
1353 | && QChar::isLowSurrogate(subjectUtf16[offset])) {
| 36-125 | ||||||||||||||||||
1354 | ++offset; | - | ||||||||||||||||||
1355 | } executed 36 times by 3 tests: end of block Executed by:
| 36 | ||||||||||||||||||
1356 | - | |||||||||||||||||||
1357 | result = pcre16SafeExec(compiledPattern, currentStudyData, | - | ||||||||||||||||||
1358 | subjectUtf16, subjectLength, | - | ||||||||||||||||||
1359 | offset, pcreOptions, | - | ||||||||||||||||||
1360 | captureOffsets, captureOffsetsCount); | - | ||||||||||||||||||
1361 | } executed 379 times by 4 tests: end of block Executed by:
| 379 | ||||||||||||||||||
1362 | } executed 403 times by 4 tests: end of block Executed by:
| 403 | ||||||||||||||||||
1363 | - | |||||||||||||||||||
1364 | #ifdef QREGULAREXPRESSION_DEBUG | - | ||||||||||||||||||
1365 | qDebug() << "Matching" << pattern << "against" << subject | - | ||||||||||||||||||
1366 | << "starting at" << subjectStart << "len" << subjectLength | - | ||||||||||||||||||
1367 | << "offset" << offset | - | ||||||||||||||||||
1368 | << matchType << matchOptions << previousMatchWasEmpty | - | ||||||||||||||||||
1369 | << "result" << result; | - | ||||||||||||||||||
1370 | #endif | - | ||||||||||||||||||
1371 | - | |||||||||||||||||||
1372 | // result == 0 means not enough space in captureOffsets; should never happen | - | ||||||||||||||||||
1373 | Q_ASSERT(result != 0); | - | ||||||||||||||||||
1374 | - | |||||||||||||||||||
1375 | if (result > 0) {
| 1293-4942 | ||||||||||||||||||
1376 | // full match | - | ||||||||||||||||||
1377 | priv->isValid = true; | - | ||||||||||||||||||
1378 | priv->hasMatch = true; | - | ||||||||||||||||||
1379 | priv->capturedCount = result; | - | ||||||||||||||||||
1380 | priv->capturedOffsets.resize(result * 2); | - | ||||||||||||||||||
1381 | } else { executed 4942 times by 18 tests: end of block Executed by:
| 4942 | ||||||||||||||||||
1382 | // no match, partial match or error | - | ||||||||||||||||||
1383 | priv->hasPartialMatch = (result == PCRE_ERROR_PARTIAL); | - | ||||||||||||||||||
1384 | priv->isValid = (result == PCRE_ERROR_NOMATCH || result == PCRE_ERROR_PARTIAL);
| 124-932 | ||||||||||||||||||
1385 | - | |||||||||||||||||||
1386 | if (result == PCRE_ERROR_PARTIAL) {
| 237-1056 | ||||||||||||||||||
1387 | // partial match: | - | ||||||||||||||||||
1388 | // leave the start and end capture offsets (i.e. cap(0)) | - | ||||||||||||||||||
1389 | priv->capturedCount = 1; | - | ||||||||||||||||||
1390 | priv->capturedOffsets.resize(2); | - | ||||||||||||||||||
1391 | } else { executed 237 times by 5 tests: end of block Executed by:
| 237 | ||||||||||||||||||
1392 | // no match or error | - | ||||||||||||||||||
1393 | priv->capturedCount = 0; | - | ||||||||||||||||||
1394 | priv->capturedOffsets.clear(); | - | ||||||||||||||||||
1395 | } executed 1056 times by 14 tests: end of block Executed by:
| 1056 | ||||||||||||||||||
1396 | } | - | ||||||||||||||||||
1397 | - | |||||||||||||||||||
1398 | return priv; executed 6235 times by 21 tests: return priv; Executed by:
| 6235 | ||||||||||||||||||
1399 | } | - | ||||||||||||||||||
1400 | - | |||||||||||||||||||
1401 | /*! | - | ||||||||||||||||||
1402 | \internal | - | ||||||||||||||||||
1403 | */ | - | ||||||||||||||||||
1404 | QRegularExpressionMatchPrivate::QRegularExpressionMatchPrivate(const QRegularExpression &re, | - | ||||||||||||||||||
1405 | const QString &subject, | - | ||||||||||||||||||
1406 | int subjectStart, | - | ||||||||||||||||||
1407 | int subjectLength, | - | ||||||||||||||||||
1408 | QRegularExpression::MatchType matchType, | - | ||||||||||||||||||
1409 | QRegularExpression::MatchOptions matchOptions, | - | ||||||||||||||||||
1410 | int capturingCount) | - | ||||||||||||||||||
1411 | : regularExpression(re), subject(subject), | - | ||||||||||||||||||
1412 | subjectStart(subjectStart), subjectLength(subjectLength), | - | ||||||||||||||||||
1413 | matchType(matchType), matchOptions(matchOptions), | - | ||||||||||||||||||
1414 | capturedCount(0), | - | ||||||||||||||||||
1415 | hasMatch(false), hasPartialMatch(false), isValid(false) | - | ||||||||||||||||||
1416 | { | - | ||||||||||||||||||
1417 | Q_ASSERT(capturingCount >= 0); | - | ||||||||||||||||||
1418 | if (capturingCount > 0) {
| 596-6235 | ||||||||||||||||||
1419 | const int captureOffsetsCount = capturingCount * 3; | - | ||||||||||||||||||
1420 | capturedOffsets.resize(captureOffsetsCount); | - | ||||||||||||||||||
1421 | } executed 6235 times by 21 tests: end of block Executed by:
| 6235 | ||||||||||||||||||
1422 | } executed 6831 times by 21 tests: end of block Executed by:
| 6831 | ||||||||||||||||||
1423 | - | |||||||||||||||||||
1424 | - | |||||||||||||||||||
1425 | /*! | - | ||||||||||||||||||
1426 | \internal | - | ||||||||||||||||||
1427 | */ | - | ||||||||||||||||||
1428 | QRegularExpressionMatch QRegularExpressionMatchPrivate::nextMatch() const | - | ||||||||||||||||||
1429 | { | - | ||||||||||||||||||
1430 | Q_ASSERT(isValid); | - | ||||||||||||||||||
1431 | Q_ASSERT(hasMatch || hasPartialMatch); | - | ||||||||||||||||||
1432 | - | |||||||||||||||||||
1433 | // Note the DontCheckSubjectString passed for the check of the subject string: | - | ||||||||||||||||||
1434 | // if we're advancing a match on the same subject, | - | ||||||||||||||||||
1435 | // then that subject was already checked at least once (when this object | - | ||||||||||||||||||
1436 | // was created, or when the object that created this one was created, etc.) | - | ||||||||||||||||||
1437 | QRegularExpressionMatchPrivate *nextPrivate = regularExpression.d->doMatch(subject, | - | ||||||||||||||||||
1438 | subjectStart, | - | ||||||||||||||||||
1439 | subjectLength, | - | ||||||||||||||||||
1440 | capturedOffsets.at(1), | - | ||||||||||||||||||
1441 | matchType, | - | ||||||||||||||||||
1442 | matchOptions, | - | ||||||||||||||||||
1443 | QRegularExpressionPrivate::DontCheckSubjectString, | - | ||||||||||||||||||
1444 | this); | - | ||||||||||||||||||
1445 | return QRegularExpressionMatch(*nextPrivate); executed 1636 times by 7 tests: return QRegularExpressionMatch(*nextPrivate); Executed by:
| 1636 | ||||||||||||||||||
1446 | } | - | ||||||||||||||||||
1447 | - | |||||||||||||||||||
1448 | /*! | - | ||||||||||||||||||
1449 | \internal | - | ||||||||||||||||||
1450 | */ | - | ||||||||||||||||||
1451 | QRegularExpressionMatchIteratorPrivate::QRegularExpressionMatchIteratorPrivate(const QRegularExpression &re, | - | ||||||||||||||||||
1452 | QRegularExpression::MatchType matchType, | - | ||||||||||||||||||
1453 | QRegularExpression::MatchOptions matchOptions, | - | ||||||||||||||||||
1454 | const QRegularExpressionMatch &next) | - | ||||||||||||||||||
1455 | : next(next), | - | ||||||||||||||||||
1456 | regularExpression(re), | - | ||||||||||||||||||
1457 | matchType(matchType), matchOptions(matchOptions) | - | ||||||||||||||||||
1458 | { | - | ||||||||||||||||||
1459 | } executed 528 times by 7 tests: end of block Executed by:
| 528 | ||||||||||||||||||
1460 | - | |||||||||||||||||||
1461 | /*! | - | ||||||||||||||||||
1462 | \internal | - | ||||||||||||||||||
1463 | */ | - | ||||||||||||||||||
1464 | bool QRegularExpressionMatchIteratorPrivate::hasNext() const | - | ||||||||||||||||||
1465 | { | - | ||||||||||||||||||
1466 | return next.isValid() && (next.hasMatch() || next.hasPartialMatch()); executed 4563 times by 7 tests: return next.isValid() && (next.hasMatch() || next.hasPartialMatch()); Executed by:
| 0-4563 | ||||||||||||||||||
1467 | } | - | ||||||||||||||||||
1468 | - | |||||||||||||||||||
1469 | // PUBLIC API | - | ||||||||||||||||||
1470 | - | |||||||||||||||||||
1471 | /*! | - | ||||||||||||||||||
1472 | Constructs a QRegularExpression object with an empty pattern and no pattern | - | ||||||||||||||||||
1473 | options. | - | ||||||||||||||||||
1474 | - | |||||||||||||||||||
1475 | \sa setPattern(), setPatternOptions() | - | ||||||||||||||||||
1476 | */ | - | ||||||||||||||||||
1477 | QRegularExpression::QRegularExpression() | - | ||||||||||||||||||
1478 | : d(new QRegularExpressionPrivate) | - | ||||||||||||||||||
1479 | { | - | ||||||||||||||||||
1480 | } executed 354 times by 11 tests: end of block Executed by:
| 354 | ||||||||||||||||||
1481 | - | |||||||||||||||||||
1482 | /*! | - | ||||||||||||||||||
1483 | Constructs a QRegularExpression object using the given \a pattern as | - | ||||||||||||||||||
1484 | pattern and the \a options as the pattern options. | - | ||||||||||||||||||
1485 | - | |||||||||||||||||||
1486 | \sa setPattern(), setPatternOptions() | - | ||||||||||||||||||
1487 | */ | - | ||||||||||||||||||
1488 | QRegularExpression::QRegularExpression(const QString &pattern, PatternOptions options) | - | ||||||||||||||||||
1489 | : d(new QRegularExpressionPrivate) | - | ||||||||||||||||||
1490 | { | - | ||||||||||||||||||
1491 | d->pattern = pattern; | - | ||||||||||||||||||
1492 | d->patternOptions = options; | - | ||||||||||||||||||
1493 | } executed 1316 times by 21 tests: end of block Executed by:
| 1316 | ||||||||||||||||||
1494 | - | |||||||||||||||||||
1495 | /*! | - | ||||||||||||||||||
1496 | Constructs a QRegularExpression object as a copy of \a re. | - | ||||||||||||||||||
1497 | - | |||||||||||||||||||
1498 | \sa operator=() | - | ||||||||||||||||||
1499 | */ | - | ||||||||||||||||||
1500 | QRegularExpression::QRegularExpression(const QRegularExpression &re) | - | ||||||||||||||||||
1501 | : d(re.d) | - | ||||||||||||||||||
1502 | { | - | ||||||||||||||||||
1503 | } executed 12748 times by 22 tests: end of block Executed by:
| 12748 | ||||||||||||||||||
1504 | - | |||||||||||||||||||
1505 | /*! | - | ||||||||||||||||||
1506 | Destroys the QRegularExpression object. | - | ||||||||||||||||||
1507 | */ | - | ||||||||||||||||||
1508 | QRegularExpression::~QRegularExpression() | - | ||||||||||||||||||
1509 | { | - | ||||||||||||||||||
1510 | } | - | ||||||||||||||||||
1511 | - | |||||||||||||||||||
1512 | /*! | - | ||||||||||||||||||
1513 | Assigns the regular expression \a re to this object, and returns a reference | - | ||||||||||||||||||
1514 | to the copy. Both the pattern and the pattern options are copied. | - | ||||||||||||||||||
1515 | */ | - | ||||||||||||||||||
1516 | QRegularExpression &QRegularExpression::operator=(const QRegularExpression &re) | - | ||||||||||||||||||
1517 | { | - | ||||||||||||||||||
1518 | d = re.d; | - | ||||||||||||||||||
1519 | return *this; executed 219 times by 7 tests: return *this; Executed by:
| 219 | ||||||||||||||||||
1520 | } | - | ||||||||||||||||||
1521 | - | |||||||||||||||||||
1522 | /*! | - | ||||||||||||||||||
1523 | \fn void QRegularExpression::swap(QRegularExpression &other) | - | ||||||||||||||||||
1524 | - | |||||||||||||||||||
1525 | Swaps the regular expression \a other with this regular expression. This | - | ||||||||||||||||||
1526 | operation is very fast and never fails. | - | ||||||||||||||||||
1527 | */ | - | ||||||||||||||||||
1528 | - | |||||||||||||||||||
1529 | /*! | - | ||||||||||||||||||
1530 | Returns the pattern string of the regular expression. | - | ||||||||||||||||||
1531 | - | |||||||||||||||||||
1532 | \sa setPattern(), patternOptions() | - | ||||||||||||||||||
1533 | */ | - | ||||||||||||||||||
1534 | QString QRegularExpression::pattern() const | - | ||||||||||||||||||
1535 | { | - | ||||||||||||||||||
1536 | return d->pattern; executed 677 times by 12 tests: return d->pattern; Executed by:
| 677 | ||||||||||||||||||
1537 | } | - | ||||||||||||||||||
1538 | - | |||||||||||||||||||
1539 | /*! | - | ||||||||||||||||||
1540 | Sets the pattern string of the regular expression to \a pattern. The | - | ||||||||||||||||||
1541 | pattern options are left unchanged. | - | ||||||||||||||||||
1542 | - | |||||||||||||||||||
1543 | \sa pattern(), setPatternOptions() | - | ||||||||||||||||||
1544 | */ | - | ||||||||||||||||||
1545 | void QRegularExpression::setPattern(const QString &pattern) | - | ||||||||||||||||||
1546 | { | - | ||||||||||||||||||
1547 | d.detach(); | - | ||||||||||||||||||
1548 | d->isDirty = true; | - | ||||||||||||||||||
1549 | d->pattern = pattern; | - | ||||||||||||||||||
1550 | } executed 139 times by 9 tests: end of block Executed by:
| 139 | ||||||||||||||||||
1551 | - | |||||||||||||||||||
1552 | /*! | - | ||||||||||||||||||
1553 | Returns the pattern options for the regular expression. | - | ||||||||||||||||||
1554 | - | |||||||||||||||||||
1555 | \sa setPatternOptions(), pattern() | - | ||||||||||||||||||
1556 | */ | - | ||||||||||||||||||
1557 | QRegularExpression::PatternOptions QRegularExpression::patternOptions() const | - | ||||||||||||||||||
1558 | { | - | ||||||||||||||||||
1559 | return d->patternOptions; executed 259 times by 8 tests: return d->patternOptions; Executed by:
| 259 | ||||||||||||||||||
1560 | } | - | ||||||||||||||||||
1561 | - | |||||||||||||||||||
1562 | /*! | - | ||||||||||||||||||
1563 | Sets the given \a options as the pattern options of the regular expression. | - | ||||||||||||||||||
1564 | The pattern string is left unchanged. | - | ||||||||||||||||||
1565 | - | |||||||||||||||||||
1566 | \sa patternOptions(), setPattern() | - | ||||||||||||||||||
1567 | */ | - | ||||||||||||||||||
1568 | void QRegularExpression::setPatternOptions(PatternOptions options) | - | ||||||||||||||||||
1569 | { | - | ||||||||||||||||||
1570 | d.detach(); | - | ||||||||||||||||||
1571 | d->isDirty = true; | - | ||||||||||||||||||
1572 | d->patternOptions = options; | - | ||||||||||||||||||
1573 | } executed 105 times by 7 tests: end of block Executed by:
| 105 | ||||||||||||||||||
1574 | - | |||||||||||||||||||
1575 | /*! | - | ||||||||||||||||||
1576 | Returns the number of capturing groups inside the pattern string, | - | ||||||||||||||||||
1577 | or -1 if the regular expression is not valid. | - | ||||||||||||||||||
1578 | - | |||||||||||||||||||
1579 | \note The implicit capturing group 0 is \e{not} included in the returned number. | - | ||||||||||||||||||
1580 | - | |||||||||||||||||||
1581 | \sa isValid() | - | ||||||||||||||||||
1582 | */ | - | ||||||||||||||||||
1583 | int QRegularExpression::captureCount() const | - | ||||||||||||||||||
1584 | { | - | ||||||||||||||||||
1585 | if (!isValid()) // will compile the pattern
| 30-207 | ||||||||||||||||||
1586 | return -1; executed 30 times by 3 tests: return -1; Executed by:
| 30 | ||||||||||||||||||
1587 | return d->capturingCount; executed 207 times by 6 tests: return d->capturingCount; Executed by:
| 207 | ||||||||||||||||||
1588 | } | - | ||||||||||||||||||
1589 | - | |||||||||||||||||||
1590 | /*! | - | ||||||||||||||||||
1591 | \since 5.1 | - | ||||||||||||||||||
1592 | - | |||||||||||||||||||
1593 | Returns a list of captureCount() + 1 elements, containing the names of the | - | ||||||||||||||||||
1594 | named capturing groups in the pattern string. The list is sorted such that | - | ||||||||||||||||||
1595 | the element of the list at position \c{i} is the name of the \c{i}-th | - | ||||||||||||||||||
1596 | capturing group, if it has a name, or an empty string if that capturing | - | ||||||||||||||||||
1597 | group is unnamed. | - | ||||||||||||||||||
1598 | - | |||||||||||||||||||
1599 | For instance, given the regular expression | - | ||||||||||||||||||
1600 | - | |||||||||||||||||||
1601 | \code | - | ||||||||||||||||||
1602 | (?<day>\d\d)-(?<month>\d\d)-(?<year>\d\d\d\d) (\w+) (?<name>\w+) | - | ||||||||||||||||||
1603 | \endcode | - | ||||||||||||||||||
1604 | - | |||||||||||||||||||
1605 | namedCaptureGroups() will return the following list: | - | ||||||||||||||||||
1606 | - | |||||||||||||||||||
1607 | \code | - | ||||||||||||||||||
1608 | ("", "day", "month", "year", "", "name") | - | ||||||||||||||||||
1609 | \endcode | - | ||||||||||||||||||
1610 | - | |||||||||||||||||||
1611 | which corresponds to the fact that the capturing group #0 (corresponding to | - | ||||||||||||||||||
1612 | the whole match) has no name, the capturing group #1 has name "day", the | - | ||||||||||||||||||
1613 | capturing group #2 has name "month", etc. | - | ||||||||||||||||||
1614 | - | |||||||||||||||||||
1615 | If the regular expression is not valid, returns an empty list. | - | ||||||||||||||||||
1616 | - | |||||||||||||||||||
1617 | \sa isValid(), QRegularExpressionMatch::captured(), QString::isEmpty() | - | ||||||||||||||||||
1618 | */ | - | ||||||||||||||||||
1619 | QStringList QRegularExpression::namedCaptureGroups() const | - | ||||||||||||||||||
1620 | { | - | ||||||||||||||||||
1621 | if (!isValid()) // isValid() will compile the pattern
| 12-33 | ||||||||||||||||||
1622 | return QStringList(); executed 12 times by 3 tests: return QStringList(); Executed by:
| 12 | ||||||||||||||||||
1623 | - | |||||||||||||||||||
1624 | // namedCapturingTable will point to a table of | - | ||||||||||||||||||
1625 | // namedCapturingTableEntryCount entries, each one of which | - | ||||||||||||||||||
1626 | // contains one ushort followed by the name, NUL terminated. | - | ||||||||||||||||||
1627 | // The ushort is the numerical index of the name in the pattern. | - | ||||||||||||||||||
1628 | // The length of each entry is namedCapturingTableEntrySize. | - | ||||||||||||||||||
1629 | ushort *namedCapturingTable; | - | ||||||||||||||||||
1630 | int namedCapturingTableEntryCount; | - | ||||||||||||||||||
1631 | int namedCapturingTableEntrySize; | - | ||||||||||||||||||
1632 | - | |||||||||||||||||||
1633 | pcre16_fullinfo(d->compiledPattern, 0, PCRE_INFO_NAMETABLE, &namedCapturingTable); | - | ||||||||||||||||||
1634 | pcre16_fullinfo(d->compiledPattern, 0, PCRE_INFO_NAMECOUNT, &namedCapturingTableEntryCount); | - | ||||||||||||||||||
1635 | pcre16_fullinfo(d->compiledPattern, 0, PCRE_INFO_NAMEENTRYSIZE, &namedCapturingTableEntrySize); | - | ||||||||||||||||||
1636 | - | |||||||||||||||||||
1637 | QStringList result; | - | ||||||||||||||||||
1638 | - | |||||||||||||||||||
1639 | // no QList::resize nor fill is available. The +1 is for the implicit group #0 | - | ||||||||||||||||||
1640 | result.reserve(d->capturingCount + 1); | - | ||||||||||||||||||
1641 | for (int i = 0; i < d->capturingCount + 1; ++i)
| 33-90 | ||||||||||||||||||
1642 | result.append(QString()); executed 90 times by 3 tests: result.append(QString()); Executed by:
| 90 | ||||||||||||||||||
1643 | - | |||||||||||||||||||
1644 | for (int i = 0; i < namedCapturingTableEntryCount; ++i) {
| 33-39 | ||||||||||||||||||
1645 | const ushort * const currentNamedCapturingTableRow = namedCapturingTable + | - | ||||||||||||||||||
1646 | namedCapturingTableEntrySize * i; | - | ||||||||||||||||||
1647 | - | |||||||||||||||||||
1648 | const int index = *currentNamedCapturingTableRow; | - | ||||||||||||||||||
1649 | result[index] = QString::fromUtf16(currentNamedCapturingTableRow + 1); | - | ||||||||||||||||||
1650 | } executed 39 times by 3 tests: end of block Executed by:
| 39 | ||||||||||||||||||
1651 | - | |||||||||||||||||||
1652 | return result; executed 33 times by 3 tests: return result; Executed by:
| 33 | ||||||||||||||||||
1653 | } | - | ||||||||||||||||||
1654 | - | |||||||||||||||||||
1655 | /*! | - | ||||||||||||||||||
1656 | Returns \c true if the regular expression is a valid regular expression (that | - | ||||||||||||||||||
1657 | is, it contains no syntax errors, etc.), or false otherwise. Use | - | ||||||||||||||||||
1658 | errorString() to obtain a textual description of the error. | - | ||||||||||||||||||
1659 | - | |||||||||||||||||||
1660 | \sa errorString(), patternErrorOffset() | - | ||||||||||||||||||
1661 | */ | - | ||||||||||||||||||
1662 | bool QRegularExpression::isValid() const | - | ||||||||||||||||||
1663 | { | - | ||||||||||||||||||
1664 | d.data()->compilePattern(); | - | ||||||||||||||||||
1665 | return d->compiledPattern; executed 3564 times by 11 tests: return d->compiledPattern; Executed by:
| 3564 | ||||||||||||||||||
1666 | } | - | ||||||||||||||||||
1667 | - | |||||||||||||||||||
1668 | /*! | - | ||||||||||||||||||
1669 | Returns a textual description of the error found when checking the validity | - | ||||||||||||||||||
1670 | of the regular expression, or "no error" if no error was found. | - | ||||||||||||||||||
1671 | - | |||||||||||||||||||
1672 | \sa isValid(), patternErrorOffset() | - | ||||||||||||||||||
1673 | */ | - | ||||||||||||||||||
1674 | QString QRegularExpression::errorString() const | - | ||||||||||||||||||
1675 | { | - | ||||||||||||||||||
1676 | d.data()->compilePattern(); | - | ||||||||||||||||||
1677 | if (d->errorString)
| 0-240 | ||||||||||||||||||
1678 | return QCoreApplication::translate("QRegularExpression", d->errorString); never executed: return QCoreApplication::translate("QRegularExpression", d->errorString); | 0 | ||||||||||||||||||
1679 | return QCoreApplication::translate("QRegularExpression", "no error"); executed 240 times by 1 test: return QCoreApplication::translate("QRegularExpression", "no error"); Executed by:
| 240 | ||||||||||||||||||
1680 | } | - | ||||||||||||||||||
1681 | - | |||||||||||||||||||
1682 | /*! | - | ||||||||||||||||||
1683 | Returns the offset, inside the pattern string, at which an error was found | - | ||||||||||||||||||
1684 | when checking the validity of the regular expression. If no error was | - | ||||||||||||||||||
1685 | found, then -1 is returned. | - | ||||||||||||||||||
1686 | - | |||||||||||||||||||
1687 | \sa pattern(), isValid(), errorString() | - | ||||||||||||||||||
1688 | */ | - | ||||||||||||||||||
1689 | int QRegularExpression::patternErrorOffset() const | - | ||||||||||||||||||
1690 | { | - | ||||||||||||||||||
1691 | d.data()->compilePattern(); | - | ||||||||||||||||||
1692 | return d->errorOffset; never executed: return d->errorOffset; | 0 | ||||||||||||||||||
1693 | } | - | ||||||||||||||||||
1694 | - | |||||||||||||||||||
1695 | /*! | - | ||||||||||||||||||
1696 | Attempts to match the regular expression against the given \a subject | - | ||||||||||||||||||
1697 | string, starting at the position \a offset inside the subject, using a | - | ||||||||||||||||||
1698 | match of type \a matchType and honoring the given \a matchOptions. | - | ||||||||||||||||||
1699 | - | |||||||||||||||||||
1700 | The returned QRegularExpressionMatch object contains the results of the | - | ||||||||||||||||||
1701 | match. | - | ||||||||||||||||||
1702 | - | |||||||||||||||||||
1703 | \sa QRegularExpressionMatch, {normal matching} | - | ||||||||||||||||||
1704 | */ | - | ||||||||||||||||||
1705 | QRegularExpressionMatch QRegularExpression::match(const QString &subject, | - | ||||||||||||||||||
1706 | int offset, | - | ||||||||||||||||||
1707 | MatchType matchType, | - | ||||||||||||||||||
1708 | MatchOptions matchOptions) const | - | ||||||||||||||||||
1709 | { | - | ||||||||||||||||||
1710 | d.data()->compilePattern(); | - | ||||||||||||||||||
1711 | - | |||||||||||||||||||
1712 | QRegularExpressionMatchPrivate *priv = d->doMatch(subject, 0, subject.length(), offset, matchType, matchOptions); | - | ||||||||||||||||||
1713 | return QRegularExpressionMatch(*priv); executed 4584 times by 21 tests: return QRegularExpressionMatch(*priv); Executed by:
| 4584 | ||||||||||||||||||
1714 | } | - | ||||||||||||||||||
1715 | - | |||||||||||||||||||
1716 | /*! | - | ||||||||||||||||||
1717 | \since 5.5 | - | ||||||||||||||||||
1718 | \overload | - | ||||||||||||||||||
1719 | - | |||||||||||||||||||
1720 | Attempts to match the regular expression against the given \a subjectRef | - | ||||||||||||||||||
1721 | string reference, starting at the position \a offset inside the subject, using a | - | ||||||||||||||||||
1722 | match of type \a matchType and honoring the given \a matchOptions. | - | ||||||||||||||||||
1723 | - | |||||||||||||||||||
1724 | The returned QRegularExpressionMatch object contains the results of the | - | ||||||||||||||||||
1725 | match. | - | ||||||||||||||||||
1726 | - | |||||||||||||||||||
1727 | \sa QRegularExpressionMatch, {normal matching} | - | ||||||||||||||||||
1728 | */ | - | ||||||||||||||||||
1729 | QRegularExpressionMatch QRegularExpression::match(const QStringRef &subjectRef, | - | ||||||||||||||||||
1730 | int offset, | - | ||||||||||||||||||
1731 | MatchType matchType, | - | ||||||||||||||||||
1732 | MatchOptions matchOptions) const | - | ||||||||||||||||||
1733 | { | - | ||||||||||||||||||
1734 | d.data()->compilePattern(); | - | ||||||||||||||||||
1735 | - | |||||||||||||||||||
1736 | const QString subject = subjectRef.string() ? *subjectRef.string() : QString();
| 0-513 | ||||||||||||||||||
1737 | - | |||||||||||||||||||
1738 | QRegularExpressionMatchPrivate *priv = d->doMatch(subject, subjectRef.position(), subjectRef.length(), offset, matchType, matchOptions); | - | ||||||||||||||||||
1739 | return QRegularExpressionMatch(*priv); executed 513 times by 3 tests: return QRegularExpressionMatch(*priv); Executed by:
| 513 | ||||||||||||||||||
1740 | } | - | ||||||||||||||||||
1741 | - | |||||||||||||||||||
1742 | /*! | - | ||||||||||||||||||
1743 | Attempts to perform a global match of the regular expression against the | - | ||||||||||||||||||
1744 | given \a subject string, starting at the position \a offset inside the | - | ||||||||||||||||||
1745 | subject, using a match of type \a matchType and honoring the given \a | - | ||||||||||||||||||
1746 | matchOptions. | - | ||||||||||||||||||
1747 | - | |||||||||||||||||||
1748 | The returned QRegularExpressionMatchIterator is positioned before the | - | ||||||||||||||||||
1749 | first match result (if any). | - | ||||||||||||||||||
1750 | - | |||||||||||||||||||
1751 | \sa QRegularExpressionMatchIterator, {global matching} | - | ||||||||||||||||||
1752 | */ | - | ||||||||||||||||||
1753 | QRegularExpressionMatchIterator QRegularExpression::globalMatch(const QString &subject, | - | ||||||||||||||||||
1754 | int offset, | - | ||||||||||||||||||
1755 | MatchType matchType, | - | ||||||||||||||||||
1756 | MatchOptions matchOptions) const | - | ||||||||||||||||||
1757 | { | - | ||||||||||||||||||
1758 | QRegularExpressionMatchIteratorPrivate *priv = | - | ||||||||||||||||||
1759 | new QRegularExpressionMatchIteratorPrivate(*this, | - | ||||||||||||||||||
1760 | matchType, | - | ||||||||||||||||||
1761 | matchOptions, | - | ||||||||||||||||||
1762 | match(subject, offset, matchType, matchOptions)); | - | ||||||||||||||||||
1763 | - | |||||||||||||||||||
1764 | return QRegularExpressionMatchIterator(*priv); executed 432 times by 7 tests: return QRegularExpressionMatchIterator(*priv); Executed by:
| 432 | ||||||||||||||||||
1765 | } | - | ||||||||||||||||||
1766 | - | |||||||||||||||||||
1767 | /*! | - | ||||||||||||||||||
1768 | \since 5.5 | - | ||||||||||||||||||
1769 | \overload | - | ||||||||||||||||||
1770 | - | |||||||||||||||||||
1771 | Attempts to perform a global match of the regular expression against the | - | ||||||||||||||||||
1772 | given \a subjectRef string reference, starting at the position \a offset inside the | - | ||||||||||||||||||
1773 | subject, using a match of type \a matchType and honoring the given \a | - | ||||||||||||||||||
1774 | matchOptions. | - | ||||||||||||||||||
1775 | - | |||||||||||||||||||
1776 | The returned QRegularExpressionMatchIterator is positioned before the | - | ||||||||||||||||||
1777 | first match result (if any). | - | ||||||||||||||||||
1778 | - | |||||||||||||||||||
1779 | \sa QRegularExpressionMatchIterator, {global matching} | - | ||||||||||||||||||
1780 | */ | - | ||||||||||||||||||
1781 | QRegularExpressionMatchIterator QRegularExpression::globalMatch(const QStringRef &subjectRef, | - | ||||||||||||||||||
1782 | int offset, | - | ||||||||||||||||||
1783 | MatchType matchType, | - | ||||||||||||||||||
1784 | MatchOptions matchOptions) const | - | ||||||||||||||||||
1785 | { | - | ||||||||||||||||||
1786 | QRegularExpressionMatchIteratorPrivate *priv = | - | ||||||||||||||||||
1787 | new QRegularExpressionMatchIteratorPrivate(*this, | - | ||||||||||||||||||
1788 | matchType, | - | ||||||||||||||||||
1789 | matchOptions, | - | ||||||||||||||||||
1790 | match(subjectRef, offset, matchType, matchOptions)); | - | ||||||||||||||||||
1791 | - | |||||||||||||||||||
1792 | return QRegularExpressionMatchIterator(*priv); executed 93 times by 3 tests: return QRegularExpressionMatchIterator(*priv); Executed by:
| 93 | ||||||||||||||||||
1793 | } | - | ||||||||||||||||||
1794 | - | |||||||||||||||||||
1795 | /*! | - | ||||||||||||||||||
1796 | \since 5.4 | - | ||||||||||||||||||
1797 | - | |||||||||||||||||||
1798 | Forces an immediate optimization of the pattern, including | - | ||||||||||||||||||
1799 | JIT-compiling it (if the JIT compiler is enabled). | - | ||||||||||||||||||
1800 | - | |||||||||||||||||||
1801 | Patterns are normally optimized only after a certain number of usages. | - | ||||||||||||||||||
1802 | If you can predict that this QRegularExpression object is going to be | - | ||||||||||||||||||
1803 | used for several matches, it may be convenient to optimize it in | - | ||||||||||||||||||
1804 | advance by calling this function. | - | ||||||||||||||||||
1805 | - | |||||||||||||||||||
1806 | \sa QRegularExpression::OptimizeOnFirstUsageOption | - | ||||||||||||||||||
1807 | */ | - | ||||||||||||||||||
1808 | void QRegularExpression::optimize() const | - | ||||||||||||||||||
1809 | { | - | ||||||||||||||||||
1810 | if (!isValid()) // will compile the pattern
| 13-295 | ||||||||||||||||||
1811 | return; executed 13 times by 1 test: return; Executed by:
| 13 | ||||||||||||||||||
1812 | - | |||||||||||||||||||
1813 | d->optimizePattern(QRegularExpressionPrivate::ImmediateOptimizeOption); | - | ||||||||||||||||||
1814 | } executed 295 times by 1 test: end of block Executed by:
| 295 | ||||||||||||||||||
1815 | - | |||||||||||||||||||
1816 | /*! | - | ||||||||||||||||||
1817 | Returns \c true if the regular expression is equal to \a re, or false | - | ||||||||||||||||||
1818 | otherwise. Two QRegularExpression objects are equal if they have | - | ||||||||||||||||||
1819 | the same pattern string and the same pattern options. | - | ||||||||||||||||||
1820 | - | |||||||||||||||||||
1821 | \sa operator!=() | - | ||||||||||||||||||
1822 | */ | - | ||||||||||||||||||
1823 | bool QRegularExpression::operator==(const QRegularExpression &re) const | - | ||||||||||||||||||
1824 | { | - | ||||||||||||||||||
1825 | return (d == re.d) || executed 4252 times by 9 tests: return (d == re.d) || (d->pattern == re.d->pattern && d->patternOptions == re.d->patternOptions); Executed by:
| 1752-4252 | ||||||||||||||||||
1826 | (d->pattern == re.d->pattern && d->patternOptions == re.d->patternOptions); executed 4252 times by 9 tests: return (d == re.d) || (d->pattern == re.d->pattern && d->patternOptions == re.d->patternOptions); Executed by:
| 0-4252 | ||||||||||||||||||
1827 | } | - | ||||||||||||||||||
1828 | - | |||||||||||||||||||
1829 | /*! | - | ||||||||||||||||||
1830 | \fn QRegularExpression & QRegularExpression::operator=(QRegularExpression && re) | - | ||||||||||||||||||
1831 | - | |||||||||||||||||||
1832 | Move-assigns the regular expression \a re to this object, and returns a reference | - | ||||||||||||||||||
1833 | to the copy. Both the pattern and the pattern options are copied. | - | ||||||||||||||||||
1834 | */ | - | ||||||||||||||||||
1835 | - | |||||||||||||||||||
1836 | /*! | - | ||||||||||||||||||
1837 | \fn bool QRegularExpression::operator!=(const QRegularExpression &re) const | - | ||||||||||||||||||
1838 | - | |||||||||||||||||||
1839 | Returns \c true if the regular expression is different from \a re, or | - | ||||||||||||||||||
1840 | false otherwise. | - | ||||||||||||||||||
1841 | - | |||||||||||||||||||
1842 | \sa operator==() | - | ||||||||||||||||||
1843 | */ | - | ||||||||||||||||||
1844 | - | |||||||||||||||||||
1845 | /*! | - | ||||||||||||||||||
1846 | \since 5.6 | - | ||||||||||||||||||
1847 | \relates QRegularExpression | - | ||||||||||||||||||
1848 | - | |||||||||||||||||||
1849 | Returns the hash value for \a key, using | - | ||||||||||||||||||
1850 | \a seed to seed the calculation. | - | ||||||||||||||||||
1851 | */ | - | ||||||||||||||||||
1852 | uint qHash(const QRegularExpression &key, uint seed) Q_DECL_NOTHROW | - | ||||||||||||||||||
1853 | { | - | ||||||||||||||||||
1854 | QtPrivate::QHashCombine hash; | - | ||||||||||||||||||
1855 | seed = hash(seed, key.d->pattern); | - | ||||||||||||||||||
1856 | seed = hash(seed, key.d->patternOptions); | - | ||||||||||||||||||
1857 | return seed; executed 1350 times by 3 tests: return seed; Executed by:
| 1350 | ||||||||||||||||||
1858 | } | - | ||||||||||||||||||
1859 | - | |||||||||||||||||||
1860 | /*! | - | ||||||||||||||||||
1861 | Escapes all characters of \a str so that they no longer have any special | - | ||||||||||||||||||
1862 | meaning when used as a regular expression pattern string, and returns | - | ||||||||||||||||||
1863 | the escaped string. For instance: | - | ||||||||||||||||||
1864 | - | |||||||||||||||||||
1865 | \snippet code/src_corelib_tools_qregularexpression.cpp 26 | - | ||||||||||||||||||
1866 | - | |||||||||||||||||||
1867 | This is very convenient in order to build patterns from arbitrary strings: | - | ||||||||||||||||||
1868 | - | |||||||||||||||||||
1869 | \snippet code/src_corelib_tools_qregularexpression.cpp 27 | - | ||||||||||||||||||
1870 | - | |||||||||||||||||||
1871 | \note This function implements Perl's quotemeta algorithm and escapes with | - | ||||||||||||||||||
1872 | a backslash all characters in \a str, except for the characters in the | - | ||||||||||||||||||
1873 | \c{[A-Z]}, \c{[a-z]} and \c{[0-9]} ranges, as well as the underscore | - | ||||||||||||||||||
1874 | (\c{_}) character. The only difference with Perl is that a literal NUL | - | ||||||||||||||||||
1875 | inside \a str is escaped with the sequence \c{"\\0"} (backslash + | - | ||||||||||||||||||
1876 | \c{'0'}), instead of \c{"\\\0"} (backslash + \c{NUL}). | - | ||||||||||||||||||
1877 | */ | - | ||||||||||||||||||
1878 | QString QRegularExpression::escape(const QString &str) | - | ||||||||||||||||||
1879 | { | - | ||||||||||||||||||
1880 | QString result; | - | ||||||||||||||||||
1881 | const int count = str.size(); | - | ||||||||||||||||||
1882 | result.reserve(count * 2); | - | ||||||||||||||||||
1883 | - | |||||||||||||||||||
1884 | // everything but [a-zA-Z0-9_] gets escaped, | - | ||||||||||||||||||
1885 | // cf. perldoc -f quotemeta | - | ||||||||||||||||||
1886 | for (int i = 0; i < count; ++i) {
| 146-4659 | ||||||||||||||||||
1887 | const QChar current = str.at(i); | - | ||||||||||||||||||
1888 | - | |||||||||||||||||||
1889 | if (current == QChar::Null) {
| 18-4641 | ||||||||||||||||||
1890 | // unlike Perl, a literal NUL must be escaped with | - | ||||||||||||||||||
1891 | // "\\0" (backslash + 0) and not "\\\0" (backslash + NUL), | - | ||||||||||||||||||
1892 | // because pcre16_compile uses a NUL-terminated string | - | ||||||||||||||||||
1893 | result.append(QLatin1Char('\\')); | - | ||||||||||||||||||
1894 | result.append(QLatin1Char('0')); | - | ||||||||||||||||||
1895 | } else if ( (current < QLatin1Char('a') || current > QLatin1Char('z')) && executed 18 times by 3 tests: end of block Executed by:
| 18-4357 | ||||||||||||||||||
1896 | (current < QLatin1Char('A') || current > QLatin1Char('Z')) &&
| 70-213 | ||||||||||||||||||
1897 | (current < QLatin1Char('0') || current > QLatin1Char('9')) &&
| 33-115 | ||||||||||||||||||
1898 | current != QLatin1Char('_') )
| 3-151 | ||||||||||||||||||
1899 | { | - | ||||||||||||||||||
1900 | result.append(QLatin1Char('\\')); | - | ||||||||||||||||||
1901 | result.append(current); | - | ||||||||||||||||||
1902 | if (current.isHighSurrogate() && i < (count - 1))
| 0-142 | ||||||||||||||||||
1903 | result.append(str.at(++i)); executed 9 times by 3 tests: result.append(str.at(++i)); Executed by:
| 9 | ||||||||||||||||||
1904 | } else { executed 151 times by 4 tests: end of block Executed by:
| 151 | ||||||||||||||||||
1905 | result.append(current); | - | ||||||||||||||||||
1906 | } executed 4490 times by 4 tests: end of block Executed by:
| 4490 | ||||||||||||||||||
1907 | } | - | ||||||||||||||||||
1908 | - | |||||||||||||||||||
1909 | result.squeeze(); | - | ||||||||||||||||||
1910 | return result; executed 146 times by 4 tests: return result; Executed by:
| 146 | ||||||||||||||||||
1911 | } | - | ||||||||||||||||||
1912 | - | |||||||||||||||||||
1913 | /*! | - | ||||||||||||||||||
1914 | \since 5.1 | - | ||||||||||||||||||
1915 | - | |||||||||||||||||||
1916 | Constructs a valid, empty QRegularExpressionMatch object. The regular | - | ||||||||||||||||||
1917 | expression is set to a default-constructed one; the match type to | - | ||||||||||||||||||
1918 | QRegularExpression::NoMatch and the match options to | - | ||||||||||||||||||
1919 | QRegularExpression::NoMatchOption. | - | ||||||||||||||||||
1920 | - | |||||||||||||||||||
1921 | The object will report no match through the hasMatch() and the | - | ||||||||||||||||||
1922 | hasPartialMatch() member functions. | - | ||||||||||||||||||
1923 | */ | - | ||||||||||||||||||
1924 | QRegularExpressionMatch::QRegularExpressionMatch() | - | ||||||||||||||||||
1925 | : d(new QRegularExpressionMatchPrivate(QRegularExpression(), | - | ||||||||||||||||||
1926 | QString(), | - | ||||||||||||||||||
1927 | 0, | - | ||||||||||||||||||
1928 | 0, | - | ||||||||||||||||||
1929 | QRegularExpression::NoMatch, | - | ||||||||||||||||||
1930 | QRegularExpression::NoMatchOption)) | - | ||||||||||||||||||
1931 | { | - | ||||||||||||||||||
1932 | d->isValid = true; | - | ||||||||||||||||||
1933 | } executed 98 times by 5 tests: end of block Executed by:
| 98 | ||||||||||||||||||
1934 | - | |||||||||||||||||||
1935 | /*! | - | ||||||||||||||||||
1936 | Destroys the match result. | - | ||||||||||||||||||
1937 | */ | - | ||||||||||||||||||
1938 | QRegularExpressionMatch::~QRegularExpressionMatch() | - | ||||||||||||||||||
1939 | { | - | ||||||||||||||||||
1940 | } | - | ||||||||||||||||||
1941 | - | |||||||||||||||||||
1942 | /*! | - | ||||||||||||||||||
1943 | Constructs a match result by copying the result of the given \a match. | - | ||||||||||||||||||
1944 | - | |||||||||||||||||||
1945 | \sa operator=() | - | ||||||||||||||||||
1946 | */ | - | ||||||||||||||||||
1947 | QRegularExpressionMatch::QRegularExpressionMatch(const QRegularExpressionMatch &match) | - | ||||||||||||||||||
1948 | : d(match.d) | - | ||||||||||||||||||
1949 | { | - | ||||||||||||||||||
1950 | } executed 4460 times by 7 tests: end of block Executed by:
| 4460 | ||||||||||||||||||
1951 | - | |||||||||||||||||||
1952 | /*! | - | ||||||||||||||||||
1953 | Assigns the match result \a match to this object, and returns a reference | - | ||||||||||||||||||
1954 | to the copy. | - | ||||||||||||||||||
1955 | */ | - | ||||||||||||||||||
1956 | QRegularExpressionMatch &QRegularExpressionMatch::operator=(const QRegularExpressionMatch &match) | - | ||||||||||||||||||
1957 | { | - | ||||||||||||||||||
1958 | d = match.d; | - | ||||||||||||||||||
1959 | return *this; never executed: return *this; | 0 | ||||||||||||||||||
1960 | } | - | ||||||||||||||||||
1961 | - | |||||||||||||||||||
1962 | /*! | - | ||||||||||||||||||
1963 | \fn QRegularExpressionMatch &QRegularExpressionMatch::operator=(QRegularExpressionMatch &&match) | - | ||||||||||||||||||
1964 | - | |||||||||||||||||||
1965 | Move-assigns the match result \a match to this object, and returns a reference | - | ||||||||||||||||||
1966 | to the copy. | - | ||||||||||||||||||
1967 | */ | - | ||||||||||||||||||
1968 | - | |||||||||||||||||||
1969 | /*! | - | ||||||||||||||||||
1970 | \fn void QRegularExpressionMatch::swap(QRegularExpressionMatch &other) | - | ||||||||||||||||||
1971 | - | |||||||||||||||||||
1972 | Swaps the match result \a other with this match result. This | - | ||||||||||||||||||
1973 | operation is very fast and never fails. | - | ||||||||||||||||||
1974 | */ | - | ||||||||||||||||||
1975 | - | |||||||||||||||||||
1976 | /*! | - | ||||||||||||||||||
1977 | \internal | - | ||||||||||||||||||
1978 | */ | - | ||||||||||||||||||
1979 | QRegularExpressionMatch::QRegularExpressionMatch(QRegularExpressionMatchPrivate &dd) | - | ||||||||||||||||||
1980 | : d(&dd) | - | ||||||||||||||||||
1981 | { | - | ||||||||||||||||||
1982 | } executed 6733 times by 21 tests: end of block Executed by:
| 6733 | ||||||||||||||||||
1983 | - | |||||||||||||||||||
1984 | /*! | - | ||||||||||||||||||
1985 | Returns the QRegularExpression object whose match() function returned this | - | ||||||||||||||||||
1986 | object. | - | ||||||||||||||||||
1987 | - | |||||||||||||||||||
1988 | \sa QRegularExpression::match(), matchType(), matchOptions() | - | ||||||||||||||||||
1989 | */ | - | ||||||||||||||||||
1990 | QRegularExpression QRegularExpressionMatch::regularExpression() const | - | ||||||||||||||||||
1991 | { | - | ||||||||||||||||||
1992 | return d->regularExpression; executed 3090 times by 3 tests: return d->regularExpression; Executed by:
| 3090 | ||||||||||||||||||
1993 | } | - | ||||||||||||||||||
1994 | - | |||||||||||||||||||
1995 | - | |||||||||||||||||||
1996 | /*! | - | ||||||||||||||||||
1997 | Returns the match type that was used to get this QRegularExpressionMatch | - | ||||||||||||||||||
1998 | object, that is, the match type that was passed to | - | ||||||||||||||||||
1999 | QRegularExpression::match() or QRegularExpression::globalMatch(). | - | ||||||||||||||||||
2000 | - | |||||||||||||||||||
2001 | \sa QRegularExpression::match(), regularExpression(), matchOptions() | - | ||||||||||||||||||
2002 | */ | - | ||||||||||||||||||
2003 | QRegularExpression::MatchType QRegularExpressionMatch::matchType() const | - | ||||||||||||||||||
2004 | { | - | ||||||||||||||||||
2005 | return d->matchType; executed 1257 times by 3 tests: return d->matchType; Executed by:
| 1257 | ||||||||||||||||||
2006 | } | - | ||||||||||||||||||
2007 | - | |||||||||||||||||||
2008 | /*! | - | ||||||||||||||||||
2009 | Returns the match options that were used to get this | - | ||||||||||||||||||
2010 | QRegularExpressionMatch object, that is, the match options that were passed | - | ||||||||||||||||||
2011 | to QRegularExpression::match() or QRegularExpression::globalMatch(). | - | ||||||||||||||||||
2012 | - | |||||||||||||||||||
2013 | \sa QRegularExpression::match(), regularExpression(), matchType() | - | ||||||||||||||||||
2014 | */ | - | ||||||||||||||||||
2015 | QRegularExpression::MatchOptions QRegularExpressionMatch::matchOptions() const | - | ||||||||||||||||||
2016 | { | - | ||||||||||||||||||
2017 | return d->matchOptions; executed 1257 times by 3 tests: return d->matchOptions; Executed by:
| 1257 | ||||||||||||||||||
2018 | } | - | ||||||||||||||||||
2019 | - | |||||||||||||||||||
2020 | /*! | - | ||||||||||||||||||
2021 | Returns the index of the last capturing group that captured something, | - | ||||||||||||||||||
2022 | including the implicit capturing group 0. This can be used to extract all | - | ||||||||||||||||||
2023 | the substrings that were captured: | - | ||||||||||||||||||
2024 | - | |||||||||||||||||||
2025 | \snippet code/src_corelib_tools_qregularexpression.cpp 28 | - | ||||||||||||||||||
2026 | - | |||||||||||||||||||
2027 | Note that some of the capturing groups with an index less than | - | ||||||||||||||||||
2028 | lastCapturedIndex() could have not matched, and therefore captured nothing. | - | ||||||||||||||||||
2029 | - | |||||||||||||||||||
2030 | If the regular expression did not match, this function returns -1. | - | ||||||||||||||||||
2031 | - | |||||||||||||||||||
2032 | \sa captured(), capturedStart(), capturedEnd(), capturedLength() | - | ||||||||||||||||||
2033 | */ | - | ||||||||||||||||||
2034 | int QRegularExpressionMatch::lastCapturedIndex() const | - | ||||||||||||||||||
2035 | { | - | ||||||||||||||||||
2036 | return d->capturedCount - 1; executed 41136 times by 8 tests: return d->capturedCount - 1; Executed by:
| 41136 | ||||||||||||||||||
2037 | } | - | ||||||||||||||||||
2038 | - | |||||||||||||||||||
2039 | /*! | - | ||||||||||||||||||
2040 | Returns the substring captured by the \a nth capturing group. If the \a nth | - | ||||||||||||||||||
2041 | capturing group did not capture a string or doesn't exist, returns a null | - | ||||||||||||||||||
2042 | QString. | - | ||||||||||||||||||
2043 | - | |||||||||||||||||||
2044 | \sa capturedRef(), lastCapturedIndex(), capturedStart(), capturedEnd(), | - | ||||||||||||||||||
2045 | capturedLength(), QString::isNull() | - | ||||||||||||||||||
2046 | */ | - | ||||||||||||||||||
2047 | QString QRegularExpressionMatch::captured(int nth) const | - | ||||||||||||||||||
2048 | { | - | ||||||||||||||||||
2049 | if (nth < 0 || nth > lastCapturedIndex())
| 0-3936 | ||||||||||||||||||
2050 | return QString(); executed 30 times by 3 tests: return QString(); Executed by:
| 30 | ||||||||||||||||||
2051 | - | |||||||||||||||||||
2052 | int start = capturedStart(nth); | - | ||||||||||||||||||
2053 | - | |||||||||||||||||||
2054 | if (start == -1) // didn't capture
| 12-3894 | ||||||||||||||||||
2055 | return QString(); executed 12 times by 3 tests: return QString(); Executed by:
| 12 | ||||||||||||||||||
2056 | - | |||||||||||||||||||
2057 | return d->subject.mid(start + d->subjectStart, capturedLength(nth)); executed 3894 times by 5 tests: return d->subject.mid(start + d->subjectStart, capturedLength(nth)); Executed by:
| 3894 | ||||||||||||||||||
2058 | } | - | ||||||||||||||||||
2059 | - | |||||||||||||||||||
2060 | /*! | - | ||||||||||||||||||
2061 | Returns a reference to the substring captured by the \a nth capturing group. | - | ||||||||||||||||||
2062 | If the \a nth capturing group did not capture a string or doesn't exist, | - | ||||||||||||||||||
2063 | returns a null QStringRef. | - | ||||||||||||||||||
2064 | - | |||||||||||||||||||
2065 | \sa captured(), lastCapturedIndex(), capturedStart(), capturedEnd(), | - | ||||||||||||||||||
2066 | capturedLength(), QStringRef::isNull() | - | ||||||||||||||||||
2067 | */ | - | ||||||||||||||||||
2068 | QStringRef QRegularExpressionMatch::capturedRef(int nth) const | - | ||||||||||||||||||
2069 | { | - | ||||||||||||||||||
2070 | if (nth < 0 || nth > lastCapturedIndex())
| 0-1591 | ||||||||||||||||||
2071 | return QStringRef(); never executed: return QStringRef(); | 0 | ||||||||||||||||||
2072 | - | |||||||||||||||||||
2073 | int start = capturedStart(nth); | - | ||||||||||||||||||
2074 | - | |||||||||||||||||||
2075 | if (start == -1) // didn't capture
| 6-1585 | ||||||||||||||||||
2076 | return QStringRef(); executed 6 times by 3 tests: return QStringRef(); Executed by:
| 6 | ||||||||||||||||||
2077 | - | |||||||||||||||||||
2078 | return d->subject.midRef(start + d->subjectStart, capturedLength(nth)); executed 1585 times by 4 tests: return d->subject.midRef(start + d->subjectStart, capturedLength(nth)); Executed by:
| 1585 | ||||||||||||||||||
2079 | } | - | ||||||||||||||||||
2080 | - | |||||||||||||||||||
2081 | /*! | - | ||||||||||||||||||
2082 | Returns the substring captured by the capturing group named \a name. If the | - | ||||||||||||||||||
2083 | capturing group named \a name did not capture a string or doesn't exist, | - | ||||||||||||||||||
2084 | returns a null QString. | - | ||||||||||||||||||
2085 | - | |||||||||||||||||||
2086 | \sa capturedRef(), capturedStart(), capturedEnd(), capturedLength(), | - | ||||||||||||||||||
2087 | QString::isNull() | - | ||||||||||||||||||
2088 | */ | - | ||||||||||||||||||
2089 | QString QRegularExpressionMatch::captured(const QString &name) const | - | ||||||||||||||||||
2090 | { | - | ||||||||||||||||||
2091 | if (name.isEmpty()) {
| 12-63 | ||||||||||||||||||
2092 | qWarning("QRegularExpressionMatch::captured: empty capturing group name passed"); | - | ||||||||||||||||||
2093 | return QString(); executed 12 times by 3 tests: return QString(); Executed by:
| 12 | ||||||||||||||||||
2094 | } | - | ||||||||||||||||||
2095 | int nth = d->regularExpression.d->captureIndexForName(name); | - | ||||||||||||||||||
2096 | if (nth == -1)
| 30-33 | ||||||||||||||||||
2097 | return QString(); executed 30 times by 3 tests: return QString(); Executed by:
| 30 | ||||||||||||||||||
2098 | return captured(nth); executed 33 times by 3 tests: return captured(nth); Executed by:
| 33 | ||||||||||||||||||
2099 | } | - | ||||||||||||||||||
2100 | - | |||||||||||||||||||
2101 | /*! | - | ||||||||||||||||||
2102 | Returns a reference to the string captured by the capturing group named \a | - | ||||||||||||||||||
2103 | name. If the capturing group named \a name did not capture a string or | - | ||||||||||||||||||
2104 | doesn't exist, returns a null QStringRef. | - | ||||||||||||||||||
2105 | - | |||||||||||||||||||
2106 | \sa captured(), capturedStart(), capturedEnd(), capturedLength(), | - | ||||||||||||||||||
2107 | QStringRef::isNull() | - | ||||||||||||||||||
2108 | */ | - | ||||||||||||||||||
2109 | QStringRef QRegularExpressionMatch::capturedRef(const QString &name) const | - | ||||||||||||||||||
2110 | { | - | ||||||||||||||||||
2111 | if (name.isEmpty()) {
| 0 | ||||||||||||||||||
2112 | qWarning("QRegularExpressionMatch::capturedRef: empty capturing group name passed"); | - | ||||||||||||||||||
2113 | return QStringRef(); never executed: return QStringRef(); | 0 | ||||||||||||||||||
2114 | } | - | ||||||||||||||||||
2115 | int nth = d->regularExpression.d->captureIndexForName(name); | - | ||||||||||||||||||
2116 | if (nth == -1)
| 0 | ||||||||||||||||||
2117 | return QStringRef(); never executed: return QStringRef(); | 0 | ||||||||||||||||||
2118 | return capturedRef(nth); never executed: return capturedRef(nth); | 0 | ||||||||||||||||||
2119 | } | - | ||||||||||||||||||
2120 | - | |||||||||||||||||||
2121 | /*! | - | ||||||||||||||||||
2122 | Returns a list of all strings captured by capturing groups, in the order | - | ||||||||||||||||||
2123 | the groups themselves appear in the pattern string. | - | ||||||||||||||||||
2124 | */ | - | ||||||||||||||||||
2125 | QStringList QRegularExpressionMatch::capturedTexts() const | - | ||||||||||||||||||
2126 | { | - | ||||||||||||||||||
2127 | QStringList texts; | - | ||||||||||||||||||
2128 | texts.reserve(d->capturedCount); | - | ||||||||||||||||||
2129 | for (int i = 0; i < d->capturedCount; ++i)
| 0 | ||||||||||||||||||
2130 | texts << captured(i); never executed: texts << captured(i); | 0 | ||||||||||||||||||
2131 | return texts; never executed: return texts; | 0 | ||||||||||||||||||
2132 | } | - | ||||||||||||||||||
2133 | - | |||||||||||||||||||
2134 | /*! | - | ||||||||||||||||||
2135 | Returns the offset inside the subject string corresponding to the | - | ||||||||||||||||||
2136 | starting position of the substring captured by the \a nth capturing group. | - | ||||||||||||||||||
2137 | If the \a nth capturing group did not capture a string or doesn't exist, | - | ||||||||||||||||||
2138 | returns -1. | - | ||||||||||||||||||
2139 | - | |||||||||||||||||||
2140 | \sa capturedEnd(), capturedLength(), captured() | - | ||||||||||||||||||
2141 | */ | - | ||||||||||||||||||
2142 | int QRegularExpressionMatch::capturedStart(int nth) const | - | ||||||||||||||||||
2143 | { | - | ||||||||||||||||||
2144 | if (nth < 0 || nth > lastCapturedIndex())
| 0-16647 | ||||||||||||||||||
2145 | return -1; executed 60 times by 3 tests: return -1; Executed by:
| 60 | ||||||||||||||||||
2146 | - | |||||||||||||||||||
2147 | return d->capturedOffsets.at(nth * 2); executed 16587 times by 8 tests: return d->capturedOffsets.at(nth * 2); Executed by:
| 16587 | ||||||||||||||||||
2148 | } | - | ||||||||||||||||||
2149 | - | |||||||||||||||||||
2150 | /*! | - | ||||||||||||||||||
2151 | Returns the length of the substring captured by the \a nth capturing group. | - | ||||||||||||||||||
2152 | - | |||||||||||||||||||
2153 | \note This function returns 0 if the \a nth capturing group did not capture | - | ||||||||||||||||||
2154 | a string or doesn't exist. | - | ||||||||||||||||||
2155 | - | |||||||||||||||||||
2156 | \sa capturedStart(), capturedEnd(), captured() | - | ||||||||||||||||||
2157 | */ | - | ||||||||||||||||||
2158 | int QRegularExpressionMatch::capturedLength(int nth) const | - | ||||||||||||||||||
2159 | { | - | ||||||||||||||||||
2160 | // bound checking performed by these two functions | - | ||||||||||||||||||
2161 | return capturedEnd(nth) - capturedStart(nth); executed 7435 times by 7 tests: return capturedEnd(nth) - capturedStart(nth); Executed by:
| 7435 | ||||||||||||||||||
2162 | } | - | ||||||||||||||||||
2163 | - | |||||||||||||||||||
2164 | /*! | - | ||||||||||||||||||
2165 | Returns the offset inside the subject string immediately after the ending | - | ||||||||||||||||||
2166 | position of the substring captured by the \a nth capturing group. If the \a | - | ||||||||||||||||||
2167 | nth capturing group did not capture a string or doesn't exist, returns -1. | - | ||||||||||||||||||
2168 | - | |||||||||||||||||||
2169 | \sa capturedStart(), capturedLength(), captured() | - | ||||||||||||||||||
2170 | */ | - | ||||||||||||||||||
2171 | int QRegularExpressionMatch::capturedEnd(int nth) const | - | ||||||||||||||||||
2172 | { | - | ||||||||||||||||||
2173 | if (nth < 0 || nth > lastCapturedIndex())
| 0-10481 | ||||||||||||||||||
2174 | return -1; executed 60 times by 3 tests: return -1; Executed by:
| 60 | ||||||||||||||||||
2175 | - | |||||||||||||||||||
2176 | return d->capturedOffsets.at(nth * 2 + 1); executed 10421 times by 8 tests: return d->capturedOffsets.at(nth * 2 + 1); Executed by:
| 10421 | ||||||||||||||||||
2177 | } | - | ||||||||||||||||||
2178 | - | |||||||||||||||||||
2179 | /*! | - | ||||||||||||||||||
2180 | Returns the offset inside the subject string corresponding to the starting | - | ||||||||||||||||||
2181 | position of the substring captured by the capturing group named \a name. | - | ||||||||||||||||||
2182 | If the capturing group named \a name did not capture a string or doesn't | - | ||||||||||||||||||
2183 | exist, returns -1. | - | ||||||||||||||||||
2184 | - | |||||||||||||||||||
2185 | \sa capturedEnd(), capturedLength(), captured() | - | ||||||||||||||||||
2186 | */ | - | ||||||||||||||||||
2187 | int QRegularExpressionMatch::capturedStart(const QString &name) const | - | ||||||||||||||||||
2188 | { | - | ||||||||||||||||||
2189 | if (name.isEmpty()) {
| 0 | ||||||||||||||||||
2190 | qWarning("QRegularExpressionMatch::capturedStart: empty capturing group name passed"); | - | ||||||||||||||||||
2191 | return -1; never executed: return -1; | 0 | ||||||||||||||||||
2192 | } | - | ||||||||||||||||||
2193 | int nth = d->regularExpression.d->captureIndexForName(name); | - | ||||||||||||||||||
2194 | if (nth == -1)
| 0 | ||||||||||||||||||
2195 | return -1; never executed: return -1; | 0 | ||||||||||||||||||
2196 | return capturedStart(nth); never executed: return capturedStart(nth); | 0 | ||||||||||||||||||
2197 | } | - | ||||||||||||||||||
2198 | - | |||||||||||||||||||
2199 | /*! | - | ||||||||||||||||||
2200 | Returns the offset inside the subject string corresponding to the starting | - | ||||||||||||||||||
2201 | position of the substring captured by the capturing group named \a name. | - | ||||||||||||||||||
2202 | - | |||||||||||||||||||
2203 | \note This function returns 0 if the capturing group named \a name did not | - | ||||||||||||||||||
2204 | capture a string or doesn't exist. | - | ||||||||||||||||||
2205 | - | |||||||||||||||||||
2206 | \sa capturedStart(), capturedEnd(), captured() | - | ||||||||||||||||||
2207 | */ | - | ||||||||||||||||||
2208 | int QRegularExpressionMatch::capturedLength(const QString &name) const | - | ||||||||||||||||||
2209 | { | - | ||||||||||||||||||
2210 | if (name.isEmpty()) {
| 0 | ||||||||||||||||||
2211 | qWarning("QRegularExpressionMatch::capturedLength: empty capturing group name passed"); | - | ||||||||||||||||||
2212 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
2213 | } | - | ||||||||||||||||||
2214 | int nth = d->regularExpression.d->captureIndexForName(name); | - | ||||||||||||||||||
2215 | if (nth == -1)
| 0 | ||||||||||||||||||
2216 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
2217 | return capturedLength(nth); never executed: return capturedLength(nth); | 0 | ||||||||||||||||||
2218 | } | - | ||||||||||||||||||
2219 | - | |||||||||||||||||||
2220 | /*! | - | ||||||||||||||||||
2221 | Returns the offset inside the subject string immediately after the ending | - | ||||||||||||||||||
2222 | position of the substring captured by the capturing group named \a name. If | - | ||||||||||||||||||
2223 | the capturing group named \a name did not capture a string or doesn't | - | ||||||||||||||||||
2224 | exist, returns -1. | - | ||||||||||||||||||
2225 | - | |||||||||||||||||||
2226 | \sa capturedStart(), capturedLength(), captured() | - | ||||||||||||||||||
2227 | */ | - | ||||||||||||||||||
2228 | int QRegularExpressionMatch::capturedEnd(const QString &name) const | - | ||||||||||||||||||
2229 | { | - | ||||||||||||||||||
2230 | if (name.isEmpty()) {
| 0 | ||||||||||||||||||
2231 | qWarning("QRegularExpressionMatch::capturedEnd: empty capturing group name passed"); | - | ||||||||||||||||||
2232 | return -1; never executed: return -1; | 0 | ||||||||||||||||||
2233 | } | - | ||||||||||||||||||
2234 | int nth = d->regularExpression.d->captureIndexForName(name); | - | ||||||||||||||||||
2235 | if (nth == -1)
| 0 | ||||||||||||||||||
2236 | return -1; never executed: return -1; | 0 | ||||||||||||||||||
2237 | return capturedEnd(nth); never executed: return capturedEnd(nth); | 0 | ||||||||||||||||||
2238 | } | - | ||||||||||||||||||
2239 | - | |||||||||||||||||||
2240 | /*! | - | ||||||||||||||||||
2241 | Returns \c true if the regular expression matched against the subject string, | - | ||||||||||||||||||
2242 | or false otherwise. | - | ||||||||||||||||||
2243 | - | |||||||||||||||||||
2244 | \sa QRegularExpression::match(), hasPartialMatch() | - | ||||||||||||||||||
2245 | */ | - | ||||||||||||||||||
2246 | bool QRegularExpressionMatch::hasMatch() const | - | ||||||||||||||||||
2247 | { | - | ||||||||||||||||||
2248 | return d->hasMatch; executed 15833 times by 21 tests: return d->hasMatch; Executed by:
| 15833 | ||||||||||||||||||
2249 | } | - | ||||||||||||||||||
2250 | - | |||||||||||||||||||
2251 | /*! | - | ||||||||||||||||||
2252 | Returns \c true if the regular expression partially matched against the | - | ||||||||||||||||||
2253 | subject string, or false otherwise. | - | ||||||||||||||||||
2254 | - | |||||||||||||||||||
2255 | \note Only a match that explicitly used the one of the partial match types | - | ||||||||||||||||||
2256 | can yield a partial match. Still, if such a match succeeds totally, this | - | ||||||||||||||||||
2257 | function will return false, while hasMatch() will return true. | - | ||||||||||||||||||
2258 | - | |||||||||||||||||||
2259 | \sa QRegularExpression::match(), QRegularExpression::MatchType, hasMatch() | - | ||||||||||||||||||
2260 | */ | - | ||||||||||||||||||
2261 | bool QRegularExpressionMatch::hasPartialMatch() const | - | ||||||||||||||||||
2262 | { | - | ||||||||||||||||||
2263 | return d->hasPartialMatch; executed 6610 times by 9 tests: return d->hasPartialMatch; Executed by:
| 6610 | ||||||||||||||||||
2264 | } | - | ||||||||||||||||||
2265 | - | |||||||||||||||||||
2266 | /*! | - | ||||||||||||||||||
2267 | Returns \c true if the match object was obtained as a result from the | - | ||||||||||||||||||
2268 | QRegularExpression::match() function invoked on a valid QRegularExpression | - | ||||||||||||||||||
2269 | object; returns \c false if the QRegularExpression was invalid. | - | ||||||||||||||||||
2270 | - | |||||||||||||||||||
2271 | \sa QRegularExpression::match(), QRegularExpression::isValid() | - | ||||||||||||||||||
2272 | */ | - | ||||||||||||||||||
2273 | bool QRegularExpressionMatch::isValid() const | - | ||||||||||||||||||
2274 | { | - | ||||||||||||||||||
2275 | return d->isValid; executed 10605 times by 7 tests: return d->isValid; Executed by:
| 10605 | ||||||||||||||||||
2276 | } | - | ||||||||||||||||||
2277 | - | |||||||||||||||||||
2278 | /*! | - | ||||||||||||||||||
2279 | \internal | - | ||||||||||||||||||
2280 | */ | - | ||||||||||||||||||
2281 | QRegularExpressionMatchIterator::QRegularExpressionMatchIterator(QRegularExpressionMatchIteratorPrivate &dd) | - | ||||||||||||||||||
2282 | : d(&dd) | - | ||||||||||||||||||
2283 | { | - | ||||||||||||||||||
2284 | } executed 525 times by 7 tests: end of block Executed by:
| 525 | ||||||||||||||||||
2285 | - | |||||||||||||||||||
2286 | /*! | - | ||||||||||||||||||
2287 | \since 5.1 | - | ||||||||||||||||||
2288 | - | |||||||||||||||||||
2289 | Constructs an empty, valid QRegularExpressionMatchIterator object. The | - | ||||||||||||||||||
2290 | regular expression is set to a default-constructed one; the match type to | - | ||||||||||||||||||
2291 | QRegularExpression::NoMatch and the match options to | - | ||||||||||||||||||
2292 | QRegularExpression::NoMatchOption. | - | ||||||||||||||||||
2293 | - | |||||||||||||||||||
2294 | Invoking the hasNext() member function on the constructed object will | - | ||||||||||||||||||
2295 | return false, as the iterator is not iterating on a valid sequence of | - | ||||||||||||||||||
2296 | matches. | - | ||||||||||||||||||
2297 | */ | - | ||||||||||||||||||
2298 | QRegularExpressionMatchIterator::QRegularExpressionMatchIterator() | - | ||||||||||||||||||
2299 | : d(new QRegularExpressionMatchIteratorPrivate(QRegularExpression(), | - | ||||||||||||||||||
2300 | QRegularExpression::NoMatch, | - | ||||||||||||||||||
2301 | QRegularExpression::NoMatchOption, | - | ||||||||||||||||||
2302 | QRegularExpressionMatch())) | - | ||||||||||||||||||
2303 | { | - | ||||||||||||||||||
2304 | } executed 3 times by 3 tests: end of block Executed by:
| 3 | ||||||||||||||||||
2305 | - | |||||||||||||||||||
2306 | /*! | - | ||||||||||||||||||
2307 | Destroys the QRegularExpressionMatchIterator object. | - | ||||||||||||||||||
2308 | */ | - | ||||||||||||||||||
2309 | QRegularExpressionMatchIterator::~QRegularExpressionMatchIterator() | - | ||||||||||||||||||
2310 | { | - | ||||||||||||||||||
2311 | } | - | ||||||||||||||||||
2312 | - | |||||||||||||||||||
2313 | /*! | - | ||||||||||||||||||
2314 | Constructs a QRegularExpressionMatchIterator object as a copy of \a | - | ||||||||||||||||||
2315 | iterator. | - | ||||||||||||||||||
2316 | - | |||||||||||||||||||
2317 | \sa operator=() | - | ||||||||||||||||||
2318 | */ | - | ||||||||||||||||||
2319 | QRegularExpressionMatchIterator::QRegularExpressionMatchIterator(const QRegularExpressionMatchIterator &iterator) | - | ||||||||||||||||||
2320 | : d(iterator.d) | - | ||||||||||||||||||
2321 | { | - | ||||||||||||||||||
2322 | } executed 348 times by 3 tests: end of block Executed by:
| 348 | ||||||||||||||||||
2323 | - | |||||||||||||||||||
2324 | /*! | - | ||||||||||||||||||
2325 | Assigns the iterator \a iterator to this object, and returns a reference to | - | ||||||||||||||||||
2326 | the copy. | - | ||||||||||||||||||
2327 | */ | - | ||||||||||||||||||
2328 | QRegularExpressionMatchIterator &QRegularExpressionMatchIterator::operator=(const QRegularExpressionMatchIterator &iterator) | - | ||||||||||||||||||
2329 | { | - | ||||||||||||||||||
2330 | d = iterator.d; | - | ||||||||||||||||||
2331 | return *this; never executed: return *this; | 0 | ||||||||||||||||||
2332 | } | - | ||||||||||||||||||
2333 | - | |||||||||||||||||||
2334 | /*! | - | ||||||||||||||||||
2335 | \fn QRegularExpressionMatchIterator &QRegularExpressionMatchIterator::operator=(QRegularExpressionMatchIterator &&iterator) | - | ||||||||||||||||||
2336 | - | |||||||||||||||||||
2337 | Move-assigns the \a iterator to this object. | - | ||||||||||||||||||
2338 | */ | - | ||||||||||||||||||
2339 | - | |||||||||||||||||||
2340 | /*! | - | ||||||||||||||||||
2341 | \fn void QRegularExpressionMatchIterator::swap(QRegularExpressionMatchIterator &other) | - | ||||||||||||||||||
2342 | - | |||||||||||||||||||
2343 | Swaps the iterator \a other with this iterator object. This operation is | - | ||||||||||||||||||
2344 | very fast and never fails. | - | ||||||||||||||||||
2345 | */ | - | ||||||||||||||||||
2346 | - | |||||||||||||||||||
2347 | /*! | - | ||||||||||||||||||
2348 | Returns \c true if the iterator object was obtained as a result from the | - | ||||||||||||||||||
2349 | QRegularExpression::globalMatch() function invoked on a valid | - | ||||||||||||||||||
2350 | QRegularExpression object; returns \c false if the QRegularExpression was | - | ||||||||||||||||||
2351 | invalid. | - | ||||||||||||||||||
2352 | - | |||||||||||||||||||
2353 | \sa QRegularExpression::globalMatch(), QRegularExpression::isValid() | - | ||||||||||||||||||
2354 | */ | - | ||||||||||||||||||
2355 | bool QRegularExpressionMatchIterator::isValid() const | - | ||||||||||||||||||
2356 | { | - | ||||||||||||||||||
2357 | return d->next.isValid(); executed 276 times by 3 tests: return d->next.isValid(); Executed by:
| 276 | ||||||||||||||||||
2358 | } | - | ||||||||||||||||||
2359 | - | |||||||||||||||||||
2360 | /*! | - | ||||||||||||||||||
2361 | Returns \c true if there is at least one match result ahead of the iterator; | - | ||||||||||||||||||
2362 | otherwise it returns \c false. | - | ||||||||||||||||||
2363 | - | |||||||||||||||||||
2364 | \sa next() | - | ||||||||||||||||||
2365 | */ | - | ||||||||||||||||||
2366 | bool QRegularExpressionMatchIterator::hasNext() const | - | ||||||||||||||||||
2367 | { | - | ||||||||||||||||||
2368 | return d->hasNext(); executed 4563 times by 7 tests: return d->hasNext(); Executed by:
| 4563 | ||||||||||||||||||
2369 | } | - | ||||||||||||||||||
2370 | - | |||||||||||||||||||
2371 | /*! | - | ||||||||||||||||||
2372 | Returns the next match result without moving the iterator. | - | ||||||||||||||||||
2373 | - | |||||||||||||||||||
2374 | \note Calling this function when the iterator is at the end of the result | - | ||||||||||||||||||
2375 | set leads to undefined results. | - | ||||||||||||||||||
2376 | */ | - | ||||||||||||||||||
2377 | QRegularExpressionMatch QRegularExpressionMatchIterator::peekNext() const | - | ||||||||||||||||||
2378 | { | - | ||||||||||||||||||
2379 | if (!hasNext())
| 6-450 | ||||||||||||||||||
2380 | qWarning("QRegularExpressionMatchIterator::peekNext() called on an iterator already at end"); executed 6 times by 3 tests: QMessageLogger(__FILE__, 2380, __PRETTY_FUNCTION__).warning("QRegularExpressionMatchIterator::peekNext() called on an iterator already at end"); Executed by:
| 6 | ||||||||||||||||||
2381 | - | |||||||||||||||||||
2382 | return d->next; executed 456 times by 3 tests: return d->next; Executed by:
| 456 | ||||||||||||||||||
2383 | } | - | ||||||||||||||||||
2384 | - | |||||||||||||||||||
2385 | /*! | - | ||||||||||||||||||
2386 | Returns the next match result and advances the iterator by one position. | - | ||||||||||||||||||
2387 | - | |||||||||||||||||||
2388 | \note Calling this function when the iterator is at the end of the result | - | ||||||||||||||||||
2389 | set leads to undefined results. | - | ||||||||||||||||||
2390 | */ | - | ||||||||||||||||||
2391 | QRegularExpressionMatch QRegularExpressionMatchIterator::next() | - | ||||||||||||||||||
2392 | { | - | ||||||||||||||||||
2393 | if (!hasNext()) {
| 6-1636 | ||||||||||||||||||
2394 | qWarning("QRegularExpressionMatchIterator::next() called on an iterator already at end"); | - | ||||||||||||||||||
2395 | return d->next; executed 6 times by 3 tests: return d->next; Executed by:
| 6 | ||||||||||||||||||
2396 | } | - | ||||||||||||||||||
2397 | - | |||||||||||||||||||
2398 | QRegularExpressionMatch current = d->next; | - | ||||||||||||||||||
2399 | d->next = d->next.d.constData()->nextMatch(); | - | ||||||||||||||||||
2400 | return current; executed 1636 times by 7 tests: return current; Executed by:
| 1636 | ||||||||||||||||||
2401 | } | - | ||||||||||||||||||
2402 | - | |||||||||||||||||||
2403 | /*! | - | ||||||||||||||||||
2404 | Returns the QRegularExpression object whose globalMatch() function returned | - | ||||||||||||||||||
2405 | this object. | - | ||||||||||||||||||
2406 | - | |||||||||||||||||||
2407 | \sa QRegularExpression::globalMatch(), matchType(), matchOptions() | - | ||||||||||||||||||
2408 | */ | - | ||||||||||||||||||
2409 | QRegularExpression QRegularExpressionMatchIterator::regularExpression() const | - | ||||||||||||||||||
2410 | { | - | ||||||||||||||||||
2411 | return d->regularExpression; executed 600 times by 3 tests: return d->regularExpression; Executed by:
| 600 | ||||||||||||||||||
2412 | } | - | ||||||||||||||||||
2413 | - | |||||||||||||||||||
2414 | /*! | - | ||||||||||||||||||
2415 | Returns the match type that was used to get this | - | ||||||||||||||||||
2416 | QRegularExpressionMatchIterator object, that is, the match type that was | - | ||||||||||||||||||
2417 | passed to QRegularExpression::globalMatch(). | - | ||||||||||||||||||
2418 | - | |||||||||||||||||||
2419 | \sa QRegularExpression::globalMatch(), regularExpression(), matchOptions() | - | ||||||||||||||||||
2420 | */ | - | ||||||||||||||||||
2421 | QRegularExpression::MatchType QRegularExpressionMatchIterator::matchType() const | - | ||||||||||||||||||
2422 | { | - | ||||||||||||||||||
2423 | return d->matchType; executed 597 times by 3 tests: return d->matchType; Executed by:
| 597 | ||||||||||||||||||
2424 | } | - | ||||||||||||||||||
2425 | - | |||||||||||||||||||
2426 | /*! | - | ||||||||||||||||||
2427 | Returns the match options that were used to get this | - | ||||||||||||||||||
2428 | QRegularExpressionMatchIterator object, that is, the match options that | - | ||||||||||||||||||
2429 | were passed to QRegularExpression::globalMatch(). | - | ||||||||||||||||||
2430 | - | |||||||||||||||||||
2431 | \sa QRegularExpression::globalMatch(), regularExpression(), matchType() | - | ||||||||||||||||||
2432 | */ | - | ||||||||||||||||||
2433 | QRegularExpression::MatchOptions QRegularExpressionMatchIterator::matchOptions() const | - | ||||||||||||||||||
2434 | { | - | ||||||||||||||||||
2435 | return d->matchOptions; executed 597 times by 3 tests: return d->matchOptions; Executed by:
| 597 | ||||||||||||||||||
2436 | } | - | ||||||||||||||||||
2437 | - | |||||||||||||||||||
2438 | #ifndef QT_NO_DATASTREAM | - | ||||||||||||||||||
2439 | /*! | - | ||||||||||||||||||
2440 | \relates QRegularExpression | - | ||||||||||||||||||
2441 | - | |||||||||||||||||||
2442 | Writes the regular expression \a re to stream \a out. | - | ||||||||||||||||||
2443 | - | |||||||||||||||||||
2444 | \sa {Serializing Qt Data Types} | - | ||||||||||||||||||
2445 | */ | - | ||||||||||||||||||
2446 | QDataStream &operator<<(QDataStream &out, const QRegularExpression &re) | - | ||||||||||||||||||
2447 | { | - | ||||||||||||||||||
2448 | out << re.pattern() << quint32(re.patternOptions()); | - | ||||||||||||||||||
2449 | return out; executed 49 times by 5 tests: return out; Executed by:
| 49 | ||||||||||||||||||
2450 | } | - | ||||||||||||||||||
2451 | - | |||||||||||||||||||
2452 | /*! | - | ||||||||||||||||||
2453 | \relates QRegularExpression | - | ||||||||||||||||||
2454 | - | |||||||||||||||||||
2455 | Reads a regular expression from stream \a in into \a re. | - | ||||||||||||||||||
2456 | - | |||||||||||||||||||
2457 | \sa {Serializing Qt Data Types} | - | ||||||||||||||||||
2458 | */ | - | ||||||||||||||||||
2459 | QDataStream &operator>>(QDataStream &in, QRegularExpression &re) | - | ||||||||||||||||||
2460 | { | - | ||||||||||||||||||
2461 | QString pattern; | - | ||||||||||||||||||
2462 | quint32 patternOptions; | - | ||||||||||||||||||
2463 | in >> pattern >> patternOptions; | - | ||||||||||||||||||
2464 | re.setPattern(pattern); | - | ||||||||||||||||||
2465 | re.setPatternOptions(QRegularExpression::PatternOptions(patternOptions)); | - | ||||||||||||||||||
2466 | return in; executed 52 times by 5 tests: return in; Executed by:
| 52 | ||||||||||||||||||
2467 | } | - | ||||||||||||||||||
2468 | #endif | - | ||||||||||||||||||
2469 | - | |||||||||||||||||||
2470 | #ifndef QT_NO_DEBUG_STREAM | - | ||||||||||||||||||
2471 | /*! | - | ||||||||||||||||||
2472 | \relates QRegularExpression | - | ||||||||||||||||||
2473 | - | |||||||||||||||||||
2474 | Writes the regular expression \a re into the debug object \a debug for | - | ||||||||||||||||||
2475 | debugging purposes. | - | ||||||||||||||||||
2476 | - | |||||||||||||||||||
2477 | \sa {Debugging Techniques} | - | ||||||||||||||||||
2478 | */ | - | ||||||||||||||||||
2479 | QDebug operator<<(QDebug debug, const QRegularExpression &re) | - | ||||||||||||||||||
2480 | { | - | ||||||||||||||||||
2481 | QDebugStateSaver saver(debug); | - | ||||||||||||||||||
2482 | debug.nospace() << "QRegularExpression(" << re.pattern() << ", " << re.patternOptions() << ')'; | - | ||||||||||||||||||
2483 | return debug; executed 1 time by 1 test: return debug; Executed by:
| 1 | ||||||||||||||||||
2484 | } | - | ||||||||||||||||||
2485 | - | |||||||||||||||||||
2486 | /*! | - | ||||||||||||||||||
2487 | \relates QRegularExpression | - | ||||||||||||||||||
2488 | - | |||||||||||||||||||
2489 | Writes the pattern options \a patternOptions into the debug object \a debug | - | ||||||||||||||||||
2490 | for debugging purposes. | - | ||||||||||||||||||
2491 | - | |||||||||||||||||||
2492 | \sa {Debugging Techniques} | - | ||||||||||||||||||
2493 | */ | - | ||||||||||||||||||
2494 | QDebug operator<<(QDebug debug, QRegularExpression::PatternOptions patternOptions) | - | ||||||||||||||||||
2495 | { | - | ||||||||||||||||||
2496 | QDebugStateSaver saver(debug); | - | ||||||||||||||||||
2497 | QByteArray flags; | - | ||||||||||||||||||
2498 | - | |||||||||||||||||||
2499 | if (patternOptions == QRegularExpression::NoPatternOption) {
| 0-1 | ||||||||||||||||||
2500 | flags = "NoPatternOption"; | - | ||||||||||||||||||
2501 | } else { executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||||||||
2502 | flags.reserve(200); // worst case... | - | ||||||||||||||||||
2503 | if (patternOptions & QRegularExpression::CaseInsensitiveOption)
| 0 | ||||||||||||||||||
2504 | flags.append("CaseInsensitiveOption|"); never executed: flags.append("CaseInsensitiveOption|"); | 0 | ||||||||||||||||||
2505 | if (patternOptions & QRegularExpression::DotMatchesEverythingOption)
| 0 | ||||||||||||||||||
2506 | flags.append("DotMatchesEverythingOption|"); never executed: flags.append("DotMatchesEverythingOption|"); | 0 | ||||||||||||||||||
2507 | if (patternOptions & QRegularExpression::MultilineOption)
| 0 | ||||||||||||||||||
2508 | flags.append("MultilineOption|"); never executed: flags.append("MultilineOption|"); | 0 | ||||||||||||||||||
2509 | if (patternOptions & QRegularExpression::ExtendedPatternSyntaxOption)
| 0 | ||||||||||||||||||
2510 | flags.append("ExtendedPatternSyntaxOption|"); never executed: flags.append("ExtendedPatternSyntaxOption|"); | 0 | ||||||||||||||||||
2511 | if (patternOptions & QRegularExpression::InvertedGreedinessOption)
| 0 | ||||||||||||||||||
2512 | flags.append("InvertedGreedinessOption|"); never executed: flags.append("InvertedGreedinessOption|"); | 0 | ||||||||||||||||||
2513 | if (patternOptions & QRegularExpression::DontCaptureOption)
| 0 | ||||||||||||||||||
2514 | flags.append("DontCaptureOption|"); never executed: flags.append("DontCaptureOption|"); | 0 | ||||||||||||||||||
2515 | if (patternOptions & QRegularExpression::UseUnicodePropertiesOption)
| 0 | ||||||||||||||||||
2516 | flags.append("UseUnicodePropertiesOption|"); never executed: flags.append("UseUnicodePropertiesOption|"); | 0 | ||||||||||||||||||
2517 | if (patternOptions & QRegularExpression::OptimizeOnFirstUsageOption)
| 0 | ||||||||||||||||||
2518 | flags.append("OptimizeOnFirstUsageOption|"); never executed: flags.append("OptimizeOnFirstUsageOption|"); | 0 | ||||||||||||||||||
2519 | if (patternOptions & QRegularExpression::DontAutomaticallyOptimizeOption)
| 0 | ||||||||||||||||||
2520 | flags.append("DontAutomaticallyOptimizeOption|"); never executed: flags.append("DontAutomaticallyOptimizeOption|"); | 0 | ||||||||||||||||||
2521 | flags.chop(1); | - | ||||||||||||||||||
2522 | } never executed: end of block | 0 | ||||||||||||||||||
2523 | - | |||||||||||||||||||
2524 | debug.nospace() << "QRegularExpression::PatternOptions(" << flags << ')'; | - | ||||||||||||||||||
2525 | - | |||||||||||||||||||
2526 | return debug; executed 1 time by 1 test: return debug; Executed by:
| 1 | ||||||||||||||||||
2527 | } | - | ||||||||||||||||||
2528 | /*! | - | ||||||||||||||||||
2529 | \relates QRegularExpressionMatch | - | ||||||||||||||||||
2530 | - | |||||||||||||||||||
2531 | Writes the match object \a match into the debug object \a debug for | - | ||||||||||||||||||
2532 | debugging purposes. | - | ||||||||||||||||||
2533 | - | |||||||||||||||||||
2534 | \sa {Debugging Techniques} | - | ||||||||||||||||||
2535 | */ | - | ||||||||||||||||||
2536 | QDebug operator<<(QDebug debug, const QRegularExpressionMatch &match) | - | ||||||||||||||||||
2537 | { | - | ||||||||||||||||||
2538 | QDebugStateSaver saver(debug); | - | ||||||||||||||||||
2539 | debug.nospace() << "QRegularExpressionMatch("; | - | ||||||||||||||||||
2540 | - | |||||||||||||||||||
2541 | if (!match.isValid()) {
| 0 | ||||||||||||||||||
2542 | debug << "Invalid)"; | - | ||||||||||||||||||
2543 | return debug; never executed: return debug; | 0 | ||||||||||||||||||
2544 | } | - | ||||||||||||||||||
2545 | - | |||||||||||||||||||
2546 | debug << "Valid"; | - | ||||||||||||||||||
2547 | - | |||||||||||||||||||
2548 | if (match.hasMatch()) {
| 0 | ||||||||||||||||||
2549 | debug << ", has match: "; | - | ||||||||||||||||||
2550 | for (int i = 0; i <= match.lastCapturedIndex(); ++i) {
| 0 | ||||||||||||||||||
2551 | debug << i | - | ||||||||||||||||||
2552 | << ":(" << match.capturedStart(i) << ", " << match.capturedEnd(i) | - | ||||||||||||||||||
2553 | << ", " << match.captured(i) << ')'; | - | ||||||||||||||||||
2554 | if (i < match.lastCapturedIndex())
| 0 | ||||||||||||||||||
2555 | debug << ", "; never executed: debug << ", "; | 0 | ||||||||||||||||||
2556 | } never executed: end of block | 0 | ||||||||||||||||||
2557 | } else if (match.hasPartialMatch()) { never executed: end of block
| 0 | ||||||||||||||||||
2558 | debug << ", has partial match: (" | - | ||||||||||||||||||
2559 | << match.capturedStart(0) << ", " | - | ||||||||||||||||||
2560 | << match.capturedEnd(0) << ", " | - | ||||||||||||||||||
2561 | << match.captured(0) << ')'; | - | ||||||||||||||||||
2562 | } else { never executed: end of block | 0 | ||||||||||||||||||
2563 | debug << ", no match"; | - | ||||||||||||||||||
2564 | } never executed: end of block | 0 | ||||||||||||||||||
2565 | - | |||||||||||||||||||
2566 | debug << ')'; | - | ||||||||||||||||||
2567 | - | |||||||||||||||||||
2568 | return debug; never executed: return debug; | 0 | ||||||||||||||||||
2569 | } | - | ||||||||||||||||||
2570 | #endif | - | ||||||||||||||||||
2571 | - | |||||||||||||||||||
2572 | // fool lupdate: make it extract those strings for translation, but don't put them | - | ||||||||||||||||||
2573 | // inside Qt -- they're already inside libpcre (cf. man 3 pcreapi, pcre_compile.c). | - | ||||||||||||||||||
2574 | #if 0 | - | ||||||||||||||||||
2575 | - | |||||||||||||||||||
2576 | /* PCRE is a library of functions to support regular expressions whose syntax | - | ||||||||||||||||||
2577 | and semantics are as close as possible to those of the Perl 5 language. | - | ||||||||||||||||||
2578 | - | |||||||||||||||||||
2579 | Written by Philip Hazel | - | ||||||||||||||||||
2580 | Copyright (c) 1997-2012 University of Cambridge | - | ||||||||||||||||||
2581 | - | |||||||||||||||||||
2582 | ----------------------------------------------------------------------------- | - | ||||||||||||||||||
2583 | Redistribution and use in source and binary forms, with or without | - | ||||||||||||||||||
2584 | modification, are permitted provided that the following conditions are met: | - | ||||||||||||||||||
2585 | - | |||||||||||||||||||
2586 | * Redistributions of source code must retain the above copyright notice, | - | ||||||||||||||||||
2587 | this list of conditions and the following disclaimer. | - | ||||||||||||||||||
2588 | - | |||||||||||||||||||
2589 | * Redistributions in binary form must reproduce the above copyright | - | ||||||||||||||||||
2590 | notice, this list of conditions and the following disclaimer in the | - | ||||||||||||||||||
2591 | documentation and/or other materials provided with the distribution. | - | ||||||||||||||||||
2592 | - | |||||||||||||||||||
2593 | * Neither the name of the University of Cambridge nor the names of its | - | ||||||||||||||||||
2594 | contributors may be used to endorse or promote products derived from | - | ||||||||||||||||||
2595 | this software without specific prior written permission. | - | ||||||||||||||||||
2596 | - | |||||||||||||||||||
2597 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | - | ||||||||||||||||||
2598 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | - | ||||||||||||||||||
2599 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | - | ||||||||||||||||||
2600 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | - | ||||||||||||||||||
2601 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | - | ||||||||||||||||||
2602 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | - | ||||||||||||||||||
2603 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | - | ||||||||||||||||||
2604 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | - | ||||||||||||||||||
2605 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | - | ||||||||||||||||||
2606 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | - | ||||||||||||||||||
2607 | POSSIBILITY OF SUCH DAMAGE. | - | ||||||||||||||||||
2608 | ----------------------------------------------------------------------------- | - | ||||||||||||||||||
2609 | */ | - | ||||||||||||||||||
2610 | - | |||||||||||||||||||
2611 | static const char *pcreCompileErrorCodes[] = | - | ||||||||||||||||||
2612 | { | - | ||||||||||||||||||
2613 | QT_TRANSLATE_NOOP("QRegularExpression", "no error"), | - | ||||||||||||||||||
2614 | QT_TRANSLATE_NOOP("QRegularExpression", "\\ at end of pattern"), | - | ||||||||||||||||||
2615 | QT_TRANSLATE_NOOP("QRegularExpression", "\\c at end of pattern"), | - | ||||||||||||||||||
2616 | QT_TRANSLATE_NOOP("QRegularExpression", "unrecognized character follows \\"), | - | ||||||||||||||||||
2617 | QT_TRANSLATE_NOOP("QRegularExpression", "numbers out of order in {} quantifier"), | - | ||||||||||||||||||
2618 | QT_TRANSLATE_NOOP("QRegularExpression", "number too big in {} quantifier"), | - | ||||||||||||||||||
2619 | QT_TRANSLATE_NOOP("QRegularExpression", "missing terminating ] for character class"), | - | ||||||||||||||||||
2620 | QT_TRANSLATE_NOOP("QRegularExpression", "invalid escape sequence in character class"), | - | ||||||||||||||||||
2621 | QT_TRANSLATE_NOOP("QRegularExpression", "range out of order in character class"), | - | ||||||||||||||||||
2622 | QT_TRANSLATE_NOOP("QRegularExpression", "nothing to repeat"), | - | ||||||||||||||||||
2623 | QT_TRANSLATE_NOOP("QRegularExpression", "internal error: unexpected repeat"), | - | ||||||||||||||||||
2624 | QT_TRANSLATE_NOOP("QRegularExpression", "unrecognized character after (? or (?-"), | - | ||||||||||||||||||
2625 | QT_TRANSLATE_NOOP("QRegularExpression", "POSIX named classes are supported only within a class"), | - | ||||||||||||||||||
2626 | QT_TRANSLATE_NOOP("QRegularExpression", "missing )"), | - | ||||||||||||||||||
2627 | QT_TRANSLATE_NOOP("QRegularExpression", "reference to non-existent subpattern"), | - | ||||||||||||||||||
2628 | QT_TRANSLATE_NOOP("QRegularExpression", "erroffset passed as NULL"), | - | ||||||||||||||||||
2629 | QT_TRANSLATE_NOOP("QRegularExpression", "unknown option bit(s) set"), | - | ||||||||||||||||||
2630 | QT_TRANSLATE_NOOP("QRegularExpression", "missing ) after comment"), | - | ||||||||||||||||||
2631 | QT_TRANSLATE_NOOP("QRegularExpression", "regular expression is too large"), | - | ||||||||||||||||||
2632 | QT_TRANSLATE_NOOP("QRegularExpression", "failed to get memory"), | - | ||||||||||||||||||
2633 | QT_TRANSLATE_NOOP("QRegularExpression", "unmatched parentheses"), | - | ||||||||||||||||||
2634 | QT_TRANSLATE_NOOP("QRegularExpression", "internal error: code overflow"), | - | ||||||||||||||||||
2635 | QT_TRANSLATE_NOOP("QRegularExpression", "unrecognized character after (?<"), | - | ||||||||||||||||||
2636 | QT_TRANSLATE_NOOP("QRegularExpression", "lookbehind assertion is not fixed length"), | - | ||||||||||||||||||
2637 | QT_TRANSLATE_NOOP("QRegularExpression", "malformed number or name after (?("), | - | ||||||||||||||||||
2638 | QT_TRANSLATE_NOOP("QRegularExpression", "conditional group contains more than two branches"), | - | ||||||||||||||||||
2639 | QT_TRANSLATE_NOOP("QRegularExpression", "assertion expected after (?("), | - | ||||||||||||||||||
2640 | QT_TRANSLATE_NOOP("QRegularExpression", "(?R or (?[+-]digits must be followed by )"), | - | ||||||||||||||||||
2641 | QT_TRANSLATE_NOOP("QRegularExpression", "unknown POSIX class name"), | - | ||||||||||||||||||
2642 | QT_TRANSLATE_NOOP("QRegularExpression", "POSIX collating elements are not supported"), | - | ||||||||||||||||||
2643 | QT_TRANSLATE_NOOP("QRegularExpression", "this version of PCRE is not compiled with PCRE_UTF8 support"), | - | ||||||||||||||||||
2644 | QT_TRANSLATE_NOOP("QRegularExpression", "character value in \\x{...} sequence is too large"), | - | ||||||||||||||||||
2645 | QT_TRANSLATE_NOOP("QRegularExpression", "invalid condition (?(0)"), | - | ||||||||||||||||||
2646 | QT_TRANSLATE_NOOP("QRegularExpression", "\\C not allowed in lookbehind assertion"), | - | ||||||||||||||||||
2647 | QT_TRANSLATE_NOOP("QRegularExpression", "PCRE does not support \\L, \\l, \\N{name}, \\U, or \\u"), | - | ||||||||||||||||||
2648 | QT_TRANSLATE_NOOP("QRegularExpression", "number after (?C is > 255"), | - | ||||||||||||||||||
2649 | QT_TRANSLATE_NOOP("QRegularExpression", "closing ) for (?C expected"), | - | ||||||||||||||||||
2650 | QT_TRANSLATE_NOOP("QRegularExpression", "recursive call could loop indefinitely"), | - | ||||||||||||||||||
2651 | QT_TRANSLATE_NOOP("QRegularExpression", "unrecognized character after (?P"), | - | ||||||||||||||||||
2652 | QT_TRANSLATE_NOOP("QRegularExpression", "syntax error in subpattern name (missing terminator)"), | - | ||||||||||||||||||
2653 | QT_TRANSLATE_NOOP("QRegularExpression", "two named subpatterns have the same name"), | - | ||||||||||||||||||
2654 | QT_TRANSLATE_NOOP("QRegularExpression", "invalid UTF-8 string"), | - | ||||||||||||||||||
2655 | QT_TRANSLATE_NOOP("QRegularExpression", "support for \\P, \\p, and \\X has not been compiled"), | - | ||||||||||||||||||
2656 | QT_TRANSLATE_NOOP("QRegularExpression", "malformed \\P or \\p sequence"), | - | ||||||||||||||||||
2657 | QT_TRANSLATE_NOOP("QRegularExpression", "unknown property name after \\P or \\p"), | - | ||||||||||||||||||
2658 | QT_TRANSLATE_NOOP("QRegularExpression", "subpattern name is too long (maximum 32 characters)"), | - | ||||||||||||||||||
2659 | QT_TRANSLATE_NOOP("QRegularExpression", "too many named subpatterns (maximum 10000)"), | - | ||||||||||||||||||
2660 | QT_TRANSLATE_NOOP("QRegularExpression", "octal value is greater than \\377 (not in UTF-8 mode)"), | - | ||||||||||||||||||
2661 | QT_TRANSLATE_NOOP("QRegularExpression", "internal error: overran compiling workspace"), | - | ||||||||||||||||||
2662 | QT_TRANSLATE_NOOP("QRegularExpression", "internal error: previously-checked referenced subpattern not found"), | - | ||||||||||||||||||
2663 | QT_TRANSLATE_NOOP("QRegularExpression", "DEFINE group contains more than one branch"), | - | ||||||||||||||||||
2664 | QT_TRANSLATE_NOOP("QRegularExpression", "repeating a DEFINE group is not allowed"), | - | ||||||||||||||||||
2665 | QT_TRANSLATE_NOOP("QRegularExpression", "inconsistent NEWLINE options"), | - | ||||||||||||||||||
2666 | QT_TRANSLATE_NOOP("QRegularExpression", "\\g is not followed by a braced, angle-bracketed, or quoted name/number or by a plain number"), | - | ||||||||||||||||||
2667 | QT_TRANSLATE_NOOP("QRegularExpression", "a numbered reference must not be zero"), | - | ||||||||||||||||||
2668 | QT_TRANSLATE_NOOP("QRegularExpression", "an argument is not allowed for (*ACCEPT), (*FAIL), or (*COMMIT)"), | - | ||||||||||||||||||
2669 | QT_TRANSLATE_NOOP("QRegularExpression", "(*VERB) not recognized"), | - | ||||||||||||||||||
2670 | QT_TRANSLATE_NOOP("QRegularExpression", "number is too big"), | - | ||||||||||||||||||
2671 | QT_TRANSLATE_NOOP("QRegularExpression", "subpattern name expected"), | - | ||||||||||||||||||
2672 | QT_TRANSLATE_NOOP("QRegularExpression", "digit expected after (?+"), | - | ||||||||||||||||||
2673 | QT_TRANSLATE_NOOP("QRegularExpression", "] is an invalid data character in JavaScript compatibility mode"), | - | ||||||||||||||||||
2674 | QT_TRANSLATE_NOOP("QRegularExpression", "different names for subpatterns of the same number are not allowed"), | - | ||||||||||||||||||
2675 | QT_TRANSLATE_NOOP("QRegularExpression", "(*MARK) must have an argument"), | - | ||||||||||||||||||
2676 | QT_TRANSLATE_NOOP("QRegularExpression", "this version of PCRE is not compiled with PCRE_UCP support"), | - | ||||||||||||||||||
2677 | QT_TRANSLATE_NOOP("QRegularExpression", "\\c must be followed by an ASCII character"), | - | ||||||||||||||||||
2678 | QT_TRANSLATE_NOOP("QRegularExpression", "\\k is not followed by a braced, angle-bracketed, or quoted name"), | - | ||||||||||||||||||
2679 | QT_TRANSLATE_NOOP("QRegularExpression", "internal error: unknown opcode in find_fixedlength()"), | - | ||||||||||||||||||
2680 | QT_TRANSLATE_NOOP("QRegularExpression", "\\N is not supported in a class"), | - | ||||||||||||||||||
2681 | QT_TRANSLATE_NOOP("QRegularExpression", "too many forward references"), | - | ||||||||||||||||||
2682 | QT_TRANSLATE_NOOP("QRegularExpression", "disallowed Unicode code point (>= 0xd800 && <= 0xdfff)"), | - | ||||||||||||||||||
2683 | QT_TRANSLATE_NOOP("QRegularExpression", "invalid UTF-16 string"), | - | ||||||||||||||||||
2684 | QT_TRANSLATE_NOOP("QRegularExpression", "name is too long in (*MARK), (*PRUNE), (*SKIP), or (*THEN)"), | - | ||||||||||||||||||
2685 | QT_TRANSLATE_NOOP("QRegularExpression", "character value in \\u.... sequence is too large"), | - | ||||||||||||||||||
2686 | QT_TRANSLATE_NOOP("QRegularExpression", "invalid UTF-32 string"), | - | ||||||||||||||||||
2687 | QT_TRANSLATE_NOOP("QRegularExpression", "setting UTF is disabled by the application"), | - | ||||||||||||||||||
2688 | QT_TRANSLATE_NOOP("QRegularExpression", "non-hex character in \\x{} (closing brace missing?)"), | - | ||||||||||||||||||
2689 | QT_TRANSLATE_NOOP("QRegularExpression", "non-octal character in \\o{} (closing brace missing?)"), | - | ||||||||||||||||||
2690 | QT_TRANSLATE_NOOP("QRegularExpression", "missing opening brace after \\o"), | - | ||||||||||||||||||
2691 | QT_TRANSLATE_NOOP("QRegularExpression", "parentheses are too deeply nested"), | - | ||||||||||||||||||
2692 | QT_TRANSLATE_NOOP("QRegularExpression", "invalid range in character class"), | - | ||||||||||||||||||
2693 | QT_TRANSLATE_NOOP("QRegularExpression", "group name must start with a non-digit"), | - | ||||||||||||||||||
2694 | QT_TRANSLATE_NOOP("QRegularExpression", "parentheses are too deeply nested (stack check)"), | - | ||||||||||||||||||
2695 | QT_TRANSLATE_NOOP("QRegularExpression", "digits missing in \\x{} or \\o{}") | - | ||||||||||||||||||
2696 | }; | - | ||||||||||||||||||
2697 | #endif // #if 0 | - | ||||||||||||||||||
2698 | - | |||||||||||||||||||
2699 | QT_END_NAMESPACE | - | ||||||||||||||||||
2700 | - | |||||||||||||||||||
2701 | #endif // QT_NO_REGULAREXPRESSION | - | ||||||||||||||||||
Source code | Switch to Preprocessed file |