| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/tools/qregularexpression.cpp |
| Switch to Source code | Preprocessed file |
| Line | Source | Count |
|---|---|---|
| 1 | - | |
| 2 | - | |
| 3 | - | |
| 4 | - | |
| 5 | - | |
| 6 | - | |
| 7 | __attribute__((visibility("default"))) unsigned int qt_qregularexpression_optimize_after_use_count = 10; | - |
| 8 | - | |
| 9 | - | |
| 10 | - | |
| 11 | - | |
| 12 | - | |
| 13 | - | |
| 14 | - | |
| 15 | static int convertToPcreOptions(QRegularExpression::PatternOptions patternOptions) | - |
| 16 | { | - |
| 17 | int options = 0; | - |
| 18 | - | |
| 19 | if (patternOptions & QRegularExpression::CaseInsensitiveOption) | - |
| 20 | options |= 0x00000001; | - |
| 21 | if (patternOptions & QRegularExpression::DotMatchesEverythingOption) | - |
| 22 | options |= 0x00000004; | - |
| 23 | if (patternOptions & QRegularExpression::MultilineOption) | - |
| 24 | options |= 0x00000002; | - |
| 25 | if (patternOptions & QRegularExpression::ExtendedPatternSyntaxOption) | - |
| 26 | options |= 0x00000008; | - |
| 27 | if (patternOptions & QRegularExpression::InvertedGreedinessOption) | - |
| 28 | options |= 0x00000200; | - |
| 29 | if (patternOptions & QRegularExpression::DontCaptureOption) | - |
| 30 | options |= 0x00001000; | - |
| 31 | if (patternOptions & QRegularExpression::UseUnicodePropertiesOption) | - |
| 32 | options |= 0x20000000; | - |
| 33 | - | |
| 34 | return options; | - |
| 35 | } | - |
| 36 | - | |
| 37 | - | |
| 38 | - | |
| 39 | - | |
| 40 | static int convertToPcreOptions(QRegularExpression::MatchOptions matchOptions) | - |
| 41 | { | - |
| 42 | int options = 0; | - |
| 43 | - | |
| 44 | if (matchOptions & QRegularExpression::AnchoredMatchOption) | - |
| 45 | options |= 0x00000010; | - |
| 46 | - | |
| 47 | return options; | - |
| 48 | } | - |
| 49 | - | |
| 50 | struct QRegularExpressionPrivate : QSharedData | - |
| 51 | { | - |
| 52 | QRegularExpressionPrivate(); | - |
| 53 | ~QRegularExpressionPrivate(); | - |
| 54 | QRegularExpressionPrivate(const QRegularExpressionPrivate &other); | - |
| 55 | - | |
| 56 | void cleanCompiledPattern(); | - |
| 57 | void compilePattern(); | - |
| 58 | void getPatternInfo(); | - |
| 59 | - | |
| 60 | enum OptimizePatternOption { | - |
| 61 | LazyOptimizeOption, | - |
| 62 | ImmediateOptimizeOption | - |
| 63 | }; | - |
| 64 | - | |
| 65 | void optimizePattern(OptimizePatternOption option); | - |
| 66 | - | |
| 67 | enum CheckSubjectStringOption { | - |
| 68 | CheckSubjectString, | - |
| 69 | DontCheckSubjectString | - |
| 70 | }; | - |
| 71 | - | |
| 72 | QRegularExpressionMatchPrivate *doMatch(const QString &subject, | - |
| 73 | int subjectStartPos, | - |
| 74 | int subjectLength, | - |
| 75 | int offset, | - |
| 76 | QRegularExpression::MatchType matchType, | - |
| 77 | QRegularExpression::MatchOptions matchOptions, | - |
| 78 | CheckSubjectStringOption checkSubjectStringOption = CheckSubjectString, | - |
| 79 | const QRegularExpressionMatchPrivate *previous = 0) const; | - |
| 80 | - | |
| 81 | int captureIndexForName(const QString &name) const; | - |
| 82 | - | |
| 83 | - | |
| 84 | QRegularExpression::PatternOptions patternOptions; | - |
| 85 | QString pattern; | - |
| 86 | - | |
| 87 | - | |
| 88 | - | |
| 89 | - | |
| 90 | - | |
| 91 | - | |
| 92 | - | |
| 93 | QMutex mutex; | - |
| 94 | - | |
| 95 | - | |
| 96 | - | |
| 97 | - | |
| 98 | pcre16 *compiledPattern; | - |
| 99 | QAtomicPointer<pcre16_extra> studyData; | - |
| 100 | const char *errorString; | - |
| 101 | int errorOffset; | - |
| 102 | int capturingCount; | - |
| 103 | unsigned int usedCount; | - |
| 104 | bool usingCrLfNewlines; | - |
| 105 | bool isDirty; | - |
| 106 | }; | - |
| 107 | - | |
| 108 | struct QRegularExpressionMatchPrivate : QSharedData | - |
| 109 | { | - |
| 110 | QRegularExpressionMatchPrivate(const QRegularExpression &re, | - |
| 111 | const QString &subject, | - |
| 112 | int subjectStart, | - |
| 113 | int subjectLength, | - |
| 114 | QRegularExpression::MatchType matchType, | - |
| 115 | QRegularExpression::MatchOptions matchOptions, | - |
| 116 | int capturingCount = 0); | - |
| 117 | - | |
| 118 | QRegularExpressionMatch nextMatch() const; | - |
| 119 | - | |
| 120 | const QRegularExpression regularExpression; | - |
| 121 | const QString subject; | - |
| 122 | - | |
| 123 | - | |
| 124 | QVector<int> capturedOffsets; | - |
| 125 | - | |
| 126 | const int subjectStart; | - |
| 127 | const int subjectLength; | - |
| 128 | - | |
| 129 | const QRegularExpression::MatchType matchType; | - |
| 130 | const QRegularExpression::MatchOptions matchOptions; | - |
| 131 | - | |
| 132 | int capturedCount; | - |
| 133 | - | |
| 134 | bool hasMatch; | - |
| 135 | bool hasPartialMatch; | - |
| 136 | bool isValid; | - |
| 137 | }; | - |
| 138 | - | |
| 139 | struct QRegularExpressionMatchIteratorPrivate : QSharedData | - |
| 140 | { | - |
| 141 | QRegularExpressionMatchIteratorPrivate(const QRegularExpression &re, | - |
| 142 | QRegularExpression::MatchType matchType, | - |
| 143 | QRegularExpression::MatchOptions matchOptions, | - |
| 144 | const QRegularExpressionMatch &next); | - |
| 145 | - | |
| 146 | bool hasNext() const; | - |
| 147 | QRegularExpressionMatch next; | - |
| 148 | const QRegularExpression regularExpression; | - |
| 149 | const QRegularExpression::MatchType matchType; | - |
| 150 | const QRegularExpression::MatchOptions matchOptions; | - |
| 151 | }; | - |
| 152 | - | |
| 153 | - | |
| 154 | - | |
| 155 | - | |
| 156 | QRegularExpression::QRegularExpression(QRegularExpressionPrivate &dd) | - |
| 157 | : d(&dd) | - |
| 158 | { | - |
| 159 | } | - |
| 160 | - | |
| 161 | - | |
| 162 | - | |
| 163 | - | |
| 164 | QRegularExpressionPrivate::QRegularExpressionPrivate() | - |
| 165 | : patternOptions(0), pattern(), | - |
| 166 | mutex(), | - |
| 167 | compiledPattern(0), studyData(0), | - |
| 168 | errorString(0), errorOffset(-1), | - |
| 169 | capturingCount(0), | - |
| 170 | usedCount(0), | - |
| 171 | usingCrLfNewlines(false), | - |
| 172 | isDirty(true) | - |
| 173 | { | - |
| 174 | } | - |
| 175 | - | |
| 176 | - | |
| 177 | - | |
| 178 | - | |
| 179 | QRegularExpressionPrivate::~QRegularExpressionPrivate() | - |
| 180 | { | - |
| 181 | cleanCompiledPattern(); | - |
| 182 | } | - |
| 183 | QRegularExpressionPrivate::QRegularExpressionPrivate(const QRegularExpressionPrivate &other) | - |
| 184 | : QSharedData(other), | - |
| 185 | patternOptions(other.patternOptions), pattern(other.pattern), | - |
| 186 | mutex(), | - |
| 187 | compiledPattern(0), studyData(0), | - |
| 188 | errorString(0), | - |
| 189 | errorOffset(-1), capturingCount(0), | - |
| 190 | usedCount(0), | - |
| 191 | usingCrLfNewlines(false), isDirty(true) | - |
| 192 | { | - |
| 193 | } | - |
| 194 | - | |
| 195 | - | |
| 196 | - | |
| 197 | - | |
| 198 | void QRegularExpressionPrivate::cleanCompiledPattern() | - |
| 199 | { | - |
| 200 | pcre16_free(compiledPattern); | - |
| 201 | pcre16_free_study(studyData.load()); | - |
| 202 | usedCount = 0; | - |
| 203 | compiledPattern = 0; | - |
| 204 | studyData.store(0); | - |
| 205 | usingCrLfNewlines = false; | - |
| 206 | errorOffset = -1; | - |
| 207 | capturingCount = 0; | - |
| 208 | } | - |
| 209 | - | |
| 210 | - | |
| 211 | - | |
| 212 | - | |
| 213 | void QRegularExpressionPrivate::compilePattern() | - |
| 214 | { | - |
| 215 | QMutexLocker lock(&mutex); | - |
| 216 | - | |
| 217 | if (!isDirty) | - |
| 218 | return; | - |
| 219 | - | |
| 220 | isDirty = false; | - |
| 221 | cleanCompiledPattern(); | - |
| 222 | - | |
| 223 | int options = convertToPcreOptions(patternOptions); | - |
| 224 | options |= 0x00000800; | - |
| 225 | - | |
| 226 | int errorCode; | - |
| 227 | compiledPattern = pcre16_compile2(pattern.utf16(), options, | - |
| 228 | &errorCode, &errorString, &errorOffset, 0); | - |
| 229 | - | |
| 230 | if (!compiledPattern) | - |
| 231 | return; | - |
| 232 | - | |
| 233 | ((!(errorCode == 0)) ? qt_assert("errorCode == 0",__FILE__,10091015) : qt_noop()); | - |
| 234 | ((!(studyData.load() == 0)) ? qt_assert("studyData.load() == 0",__FILE__,10101016) : qt_noop()); | - |
| 235 | errorOffset = -1; | - |
| 236 | - | |
| 237 | getPatternInfo(); | - |
| 238 | } | - |
| 239 | - | |
| 240 | - | |
| 241 | - | |
| 242 | - | |
| 243 | void QRegularExpressionPrivate::getPatternInfo() | - |
| 244 | { | - |
| 245 | ((!(compiledPattern)) ? qt_assert("compiledPattern",__FILE__,10211027) : qt_noop()); | - |
| 246 | ((!(studyData.load() == 0)) ? qt_assert("studyData.load() == 0",__FILE__,10221028) : qt_noop()); | - |
| 247 | - | |
| 248 | pcre16_fullinfo(compiledPattern, 0, 2, &capturingCount); | - |
| 249 | - | |
| 250 | - | |
| 251 | unsigned long int patternNewlineSetting; | - |
| 252 | pcre16_fullinfo(compiledPattern, 0, 0, &patternNewlineSetting); | - |
| 253 | patternNewlineSetting &= 0x00100000 | 0x00200000 | 0x00300000 | - |
| 254 | | 0x00400000 | 0x00500000; | - |
| 255 | if (patternNewlineSetting == 0) { | - |
| 256 | - | |
| 257 | int pcreNewlineSetting; | - |
| 258 | pcre16_config(1, &pcreNewlineSetting); | - |
| 259 | switch (pcreNewlineSetting) { | - |
| 260 | case 13: | - |
| 261 | patternNewlineSetting = 0x00100000; break; | - |
| 262 | case 10: | - |
| 263 | patternNewlineSetting = 0x00200000; break; | - |
| 264 | case 3338: | - |
| 265 | patternNewlineSetting = 0x00300000; break; | - |
| 266 | case -2: | - |
| 267 | patternNewlineSetting = 0x00500000; break; | - |
| 268 | case -1: | - |
| 269 | patternNewlineSetting = 0x00400000; break; | - |
| 270 | default: | - |
| 271 | QMessageLogger(__FILE__, 10471053, __PRETTY_FUNCTION__).warning("QRegularExpressionPrivate::compilePattern(): " | - |
| 272 | "PCRE_CONFIG_NEWLINE returned an unknown newline"); | - |
| 273 | break; | - |
| 274 | } | - |
| 275 | } | - |
| 276 | - | |
| 277 | usingCrLfNewlines = (patternNewlineSetting == 0x00300000) || | - |
| 278 | (patternNewlineSetting == 0x00400000) || | - |
| 279 | (patternNewlineSetting == 0x00500000); | - |
| 280 | - | |
| 281 | int hasJOptionChanged; | - |
| 282 | pcre16_fullinfo(compiledPattern, 0, 13, &hasJOptionChanged); | - |
| 283 | if (hasJOptionChanged) { | - |
| 284 | QMessageLogger(__FILE__, 10601066, __PRETTY_FUNCTION__).warning("QRegularExpressionPrivate::getPatternInfo(): the pattern '%s'\n" | - |
| 285 | " is using the (?J) option; duplicate capturing group names are not supported by Qt", | - |
| 286 | QString(pattern).toLocal8Bit().constData()); | - |
| 287 | } | - |
| 288 | } | - |
| 289 | - | |
| 290 | - | |
| 291 | - | |
| 292 | - | |
| 293 | - | |
| 294 | - | |
| 295 | class QPcreJitStackPointer | - |
| 296 | { | - |
| 297 | QPcreJitStackPointer(const QPcreJitStackPointer &) = delete; QPcreJitStackPointer &operator=(const QPcreJitStackPointer &) = delete; | - |
| 298 | - | |
| 299 | public: | - |
| 300 | - | |
| 301 | - | |
| 302 | - | |
| 303 | QPcreJitStackPointer() | - |
| 304 | { | - |
| 305 | - | |
| 306 | - | |
| 307 | stack = pcre16_jit_stack_alloc(32*1024, 512*1024); | - |
| 308 | } | - |
| 309 | - | |
| 310 | - | |
| 311 | - | |
| 312 | ~QPcreJitStackPointer() | - |
| 313 | { | - |
| 314 | if (stack) | - |
| 315 | pcre16_jit_stack_free(stack); | - |
| 316 | } | - |
| 317 | - | |
| 318 | pcre16_jit_stack *stack; | - |
| 319 | }; | - |
| 320 | - | |
| 321 | namespace { namespace Q_QGS_jitStacks { typedef QThreadStorage<QPcreJitStackPointer *> Type; QBasicAtomicInt guard = { QtGlobalStatic::Uninitialized }; __attribute__((visibility("hidden"))) inline Type *innerFunction() { struct HolderBase { ~HolderBase() noexcept { if (guard.load() == QtGlobalStatic::Initialized) guard.store(QtGlobalStatic::Destroyed); } }; static struct Holder : public HolderBase { Type value; Holder() noexcept(noexcept(Type ())) : value () { guard.store(QtGlobalStatic::Initialized); } } holder; return &holder.value; } } } static QGlobalStatic<QThreadStorage<QPcreJitStackPointer *>, Q_QGS_jitStacks::innerFunction, Q_QGS_jitStacks::guard> jitStacks; | - |
| 322 | - | |
| 323 | - | |
| 324 | - | |
| 325 | - | |
| 326 | static pcre16_jit_stack *qtPcreCallback(void *) | - |
| 327 | { | - |
| 328 | if (jitStacks()->hasLocalData()) | - |
| 329 | return jitStacks()->localData()->stack; | - |
| 330 | - | |
| 331 | return 0; | - |
| 332 | } | - |
| 333 | - | |
| 334 | - | |
| 335 | - | |
| 336 | - | |
| 337 | static bool isJitEnabled() | - |
| 338 | { | - |
| 339 | QByteArray jitEnvironment = qgetenv("QT_ENABLE_REGEXP_JIT"); | - |
| 340 | if (!jitEnvironment.isEmpty()) { | - |
| 341 | bool ok; | - |
| 342 | int enableJit = jitEnvironment.toInt(&ok); | - |
| 343 | return ok ? (enableJit != 0) : true; | - |
| 344 | } | - |
| 345 | - | |
| 346 | - | |
| 347 | return false; | - |
| 348 | - | |
| 349 | - | |
| 350 | - | |
| 351 | } | - |
| 352 | void QRegularExpressionPrivate::optimizePattern(OptimizePatternOption option) | - |
| 353 | { | - |
| 354 | ((!(compiledPattern)) ? qt_assert("compiledPattern",__FILE__,11531159) : qt_noop()); | - |
| 355 | - | |
| 356 | QMutexLocker lock(&mutex); | - |
| 357 | - | |
| 358 | if (studyData.load()) | - |
| 359 | return; | - |
| 360 | - | |
| 361 | if ((option == LazyOptimizeOption) && (++usedCount != qt_qregularexpression_optimize_after_use_count)) | - |
| 362 | return; | - |
| 363 | - | |
| 364 | static const bool enableJit = isJitEnabled(); | - |
| 365 | - | |
| 366 | int studyOptions = 0; | - |
| 367 | if (enableJit) | - |
| 368 | studyOptions |= (0x0001 | 0x0002 | 0x0004); | - |
| 369 | - | |
| 370 | const char *err; | - |
| 371 | pcre16_extra * const localStudyData = pcre16_study(compiledPattern, studyOptions, &err); | - |
| 372 | - | |
| 373 | if (localStudyData && localStudyData->flags & 0x0040) | - |
| 374 | pcre16_assign_jit_stack(localStudyData, qtPcreCallback, 0); | - |
| 375 | - | |
| 376 | if (!localStudyData && err) | - |
| 377 | QMessageLogger(__FILE__, 11761182, __PRETTY_FUNCTION__).warning("QRegularExpressionPrivate::optimizePattern(): pcre_study failed: %s", err); | - |
| 378 | - | |
| 379 | studyData.storeRelease(localStudyData); | - |
| 380 | } | - |
| 381 | - | |
| 382 | - | |
| 383 | - | |
| 384 | - | |
| 385 | - | |
| 386 | - | |
| 387 | - | |
| 388 | int QRegularExpressionPrivate::captureIndexForName(const QString &name) const | - |
| 389 | { | - |
| 390 | ((!(!name.isEmpty())) ? qt_assert("!name.isEmpty()",__FILE__,11891195) : qt_noop()); | - |
| 391 | - | |
| 392 | if (!compiledPattern) | - |
| 393 | return -1; | - |
| 394 | - | |
| 395 | int index = pcre16_get_stringnumber(compiledPattern, name.utf16()); | - |
| 396 | if (index >= 0) | - |
| 397 | return index; | - |
| 398 | - | |
| 399 | return -1; | - |
| 400 | } | - |
| 401 | static int pcre16SafeExec(const pcre16 *code, const pcre16_extra *extra, | - |
| 402 | const unsigned short *subject, int length, | - |
| 403 | int startOffset, int options, | - |
| 404 | int *ovector, int ovecsize) | - |
| 405 | { | - |
| 406 | int result = pcre16_exec(code, extra, subject, length, | - |
| 407 | startOffset, options, ovector, ovecsize); | - |
| 408 | - | |
| 409 | if (result == (-27) && !jitStacks()->hasLocalData()) { | - |
| 410 | QPcreJitStackPointer *p = new QPcreJitStackPointer; | - |
| 411 | jitStacks()->setLocalData(p); | - |
| 412 | - | |
| 413 | result = pcre16_exec(code, extra, subject, length, | - |
| 414 | startOffset, options, ovector, ovecsize); | - |
| 415 | } | - |
| 416 | - | |
| 417 | return result; | - |
| 418 | } | - |
| 419 | QRegularExpressionMatchPrivate *QRegularExpressionPrivate::doMatch(const QString &subject, | - |
| 420 | int subjectStart, | - |
| 421 | int subjectLength, | - |
| 422 | int offset, | - |
| 423 | QRegularExpression::MatchType matchType, | - |
| 424 | QRegularExpression::MatchOptions matchOptions, | - |
| 425 | CheckSubjectStringOption checkSubjectStringOption, | - |
| 426 | const QRegularExpressionMatchPrivate *previous) const | - |
| 427 | { | - |
| 428 | if (offset < 0) | - |
| 429 | offset += subjectLength; | - |
| 430 | - | |
| 431 | QRegularExpression re(*const_cast<QRegularExpressionPrivate *>(this)); | - |
| 432 | - | |
| 433 | if (offset < 0 || offset > subjectLength) | - |
| 434 | return new QRegularExpressionMatchPrivate(re, subject, subjectStart, subjectLength, matchType, matchOptions); | - |
| 435 | - | |
| 436 | if (!compiledPattern) { | - |
| 437 | QMessageLogger(__FILE__, 12741280, __PRETTY_FUNCTION__).warning("QRegularExpressionPrivate::doMatch(): called on an invalid QRegularExpression object"); | - |
| 438 | return new QRegularExpressionMatchPrivate(re, subject, subjectStart, subjectLength, matchType, matchOptions); | - |
| 439 | } | - |
| 440 | - | |
| 441 | - | |
| 442 | if (matchType == QRegularExpression::NoMatch) { | - |
| 443 | QRegularExpressionMatchPrivate *priv = new QRegularExpressionMatchPrivate(re, subject, | - |
| 444 | subjectStart, subjectLength, | - |
| 445 | matchType, matchOptions); | - |
| 446 | priv->isValid = true; | - |
| 447 | return priv; | - |
| 448 | } | - |
| 449 | - | |
| 450 | - | |
| 451 | QRegularExpressionMatchPrivate *priv = new QRegularExpressionMatchPrivate(re, subject, | - |
| 452 | subjectStart, subjectLength, | - |
| 453 | matchType, matchOptions, | - |
| 454 | capturingCount + 1); | - |
| 455 | - | |
| 456 | if (!(patternOptions & QRegularExpression::DontAutomaticallyOptimizeOption)) { | - |
| 457 | const OptimizePatternOption optimizePatternOption = | - |
| 458 | (patternOptions & QRegularExpression::OptimizeOnFirstUsageOption) | - |
| 459 | ? ImmediateOptimizeOption | - |
| 460 | : LazyOptimizeOption; | - |
| 461 | - | |
| 462 | - | |
| 463 | const_cast<QRegularExpressionPrivate *>(this)->optimizePattern(optimizePatternOption); | - |
| 464 | } | - |
| 465 | - | |
| 466 | - | |
| 467 | - | |
| 468 | - | |
| 469 | const pcre16_extra * const currentStudyData = studyData.loadAcquire(); | - |
| 470 | - | |
| 471 | int pcreOptions = convertToPcreOptions(matchOptions); | - |
| 472 | - | |
| 473 | if (matchType == QRegularExpression::PartialPreferCompleteMatch) | - |
| 474 | pcreOptions |= 0x00008000; | - |
| 475 | else if (matchType == QRegularExpression::PartialPreferFirstMatch) | - |
| 476 | pcreOptions |= 0x08000000; | - |
| 477 | - | |
| 478 | if (checkSubjectStringOption == DontCheckSubjectString | - |
| 479 | || matchOptions & QRegularExpression::DontCheckSubjectStringMatchOption) { | - |
| 480 | pcreOptions |= 0x00002000; | - |
| 481 | } | - |
| 482 | - | |
| 483 | bool previousMatchWasEmpty = false; | - |
| 484 | if (previous && previous->hasMatch && | - |
| 485 | (previous->capturedOffsets.at(0) == previous->capturedOffsets.at(1))) { | - |
| 486 | previousMatchWasEmpty = true; | - |
| 487 | } | - |
| 488 | - | |
| 489 | int * const captureOffsets = priv->capturedOffsets.data(); | - |
| 490 | const int captureOffsetsCount = priv->capturedOffsets.size(); | - |
| 491 | - | |
| 492 | const unsigned short * const subjectUtf16 = subject.utf16() + subjectStart; | - |
| 493 | - | |
| 494 | int result; | - |
| 495 | - | |
| 496 | if (!previousMatchWasEmpty) { | - |
| 497 | result = pcre16SafeExec(compiledPattern, currentStudyData, | - |
| 498 | subjectUtf16, subjectLength, | - |
| 499 | offset, pcreOptions, | - |
| 500 | captureOffsets, captureOffsetsCount); | - |
| 501 | } else { | - |
| 502 | result = pcre16SafeExec(compiledPattern, currentStudyData, | - |
| 503 | subjectUtf16, subjectLength, | - |
| 504 | offset, pcreOptions | 0x10000000 | 0x00000010, | - |
| 505 | captureOffsets, captureOffsetsCount); | - |
| 506 | - | |
| 507 | if (result == (-1)) { | - |
| 508 | ++offset; | - |
| 509 | - | |
| 510 | if (usingCrLfNewlines | - |
| 511 | && offset < subjectLength | - |
| 512 | && subjectUtf16[offset - 1] == QLatin1Char('\r') | - |
| 513 | && subjectUtf16[offset] == QLatin1Char('\n')) { | - |
| 514 | ++offset; | - |
| 515 | } else if (offset < subjectLength | - |
| 516 | && QChar::isLowSurrogate(subjectUtf16[offset])) { | - |
| 517 | ++offset; | - |
| 518 | } | - |
| 519 | - | |
| 520 | result = pcre16SafeExec(compiledPattern, currentStudyData, | - |
| 521 | subjectUtf16, subjectLength, | - |
| 522 | offset, pcreOptions, | - |
| 523 | captureOffsets, captureOffsetsCount); | - |
| 524 | } | - |
| 525 | } | - |
| 526 | ((!(result != 0)) ? qt_assert("result != 0",__FILE__,13731379) : qt_noop()); | - |
| 527 | - | |
| 528 | if (result > 0) { | - |
| 529 | - | |
| 530 | priv->isValid = true; | - |
| 531 | priv->hasMatch = true; | - |
| 532 | priv->capturedCount = result; | - |
| 533 | priv->capturedOffsets.resize(result * 2); | - |
| 534 | } else { | - |
| 535 | - | |
| 536 | priv->hasPartialMatch = (result == (-12)); | - |
| 537 | priv->isValid = (result == (-1) || result == (-12)); | - |
| 538 | - | |
| 539 | if (result == (-12)) { | - |
| 540 | - | |
| 541 | - | |
| 542 | priv->capturedCount = 1; | - |
| 543 | priv->capturedOffsets.resize(2); | - |
| 544 | } else { | - |
| 545 | - | |
| 546 | priv->capturedCount = 0; | - |
| 547 | priv->capturedOffsets.clear(); | - |
| 548 | } | - |
| 549 | } | - |
| 550 | - | |
| 551 | return priv; | - |
| 552 | } | - |
| 553 | - | |
| 554 | - | |
| 555 | - | |
| 556 | - | |
| 557 | QRegularExpressionMatchPrivate::QRegularExpressionMatchPrivate(const QRegularExpression &re, | - |
| 558 | const QString &subject, | - |
| 559 | int subjectStart, | - |
| 560 | int subjectLength, | - |
| 561 | QRegularExpression::MatchType matchType, | - |
| 562 | QRegularExpression::MatchOptions matchOptions, | - |
| 563 | int capturingCount) | - |
| 564 | : regularExpression(re), subject(subject), | - |
| 565 | subjectStart(subjectStart), subjectLength(subjectLength), | - |
| 566 | matchType(matchType), matchOptions(matchOptions), | - |
| 567 | capturedCount(0), | - |
| 568 | hasMatch(false), hasPartialMatch(false), isValid(false) | - |
| 569 | { | - |
| 570 | ((!(capturingCount >= 0)) ? qt_assert("capturingCount >= 0",__FILE__,14171423) : qt_noop()); | - |
| 571 | if (capturingCount > 0) { | - |
| 572 | const int captureOffsetsCount = capturingCount * 3; | - |
| 573 | capturedOffsets.resize(captureOffsetsCount); | - |
| 574 | } | - |
| 575 | } | - |
| 576 | - | |
| 577 | - | |
| 578 | - | |
| 579 | - | |
| 580 | - | |
| 581 | QRegularExpressionMatch QRegularExpressionMatchPrivate::nextMatch() const | - |
| 582 | { | - |
| 583 | ((!(isValid)) ? qt_assert("isValid",__FILE__,14301436) : qt_noop()); | - |
| 584 | ((!(hasMatch || hasPartialMatch)) ? qt_assert("hasMatch || hasPartialMatch",__FILE__,14311437) : qt_noop()); | - |
| 585 | - | |
| 586 | - | |
| 587 | - | |
| 588 | - | |
| 589 | - | |
| 590 | QRegularExpressionMatchPrivate *nextPrivate = regularExpression.d->doMatch(subject, | - |
| 591 | subjectStart, | - |
| 592 | subjectLength, | - |
| 593 | capturedOffsets.at(1), | - |
| 594 | matchType, | - |
| 595 | matchOptions, | - |
| 596 | QRegularExpressionPrivate::DontCheckSubjectString, | - |
| 597 | this); | - |
| 598 | return QRegularExpressionMatch(*nextPrivate); | - |
| 599 | } | - |
| 600 | - | |
| 601 | - | |
| 602 | - | |
| 603 | - | |
| 604 | QRegularExpressionMatchIteratorPrivate::QRegularExpressionMatchIteratorPrivate(const QRegularExpression &re, | - |
| 605 | QRegularExpression::MatchType matchType, | - |
| 606 | QRegularExpression::MatchOptions matchOptions, | - |
| 607 | const QRegularExpressionMatch &next) | - |
| 608 | : next(next), | - |
| 609 | regularExpression(re), | - |
| 610 | matchType(matchType), matchOptions(matchOptions) | - |
| 611 | { | - |
| 612 | } | - |
| 613 | - | |
| 614 | - | |
| 615 | - | |
| 616 | - | |
| 617 | bool QRegularExpressionMatchIteratorPrivate::hasNext() const | - |
| 618 | { | - |
| 619 | return next.isValid() && (next.hasMatch() || next.hasPartialMatch()); | - |
| 620 | } | - |
| 621 | QRegularExpression::QRegularExpression() | - |
| 622 | : d(new QRegularExpressionPrivate) | - |
| 623 | { | - |
| 624 | } | - |
| 625 | - | |
| 626 | - | |
| 627 | - | |
| 628 | - | |
| 629 | - | |
| 630 | - | |
| 631 | - | |
| 632 | QRegularExpression::QRegularExpression(const QString &pattern, PatternOptions options) | - |
| 633 | : d(new QRegularExpressionPrivate) | - |
| 634 | { | - |
| 635 | d->pattern = pattern; | - |
| 636 | d->patternOptions = options; | - |
| 637 | } | - |
| 638 | - | |
| 639 | - | |
| 640 | - | |
| 641 | - | |
| 642 | - | |
| 643 | - | |
| 644 | QRegularExpression::QRegularExpression(const QRegularExpression &re) | - |
| 645 | : d(re.d) | - |
| 646 | { | - |
| 647 | } | - |
| 648 | - | |
| 649 | - | |
| 650 | - | |
| 651 | - | |
| 652 | QRegularExpression::~QRegularExpression() | - |
| 653 | { | - |
| 654 | } | - |
| 655 | - | |
| 656 | - | |
| 657 | - | |
| 658 | - | |
| 659 | - | |
| 660 | QRegularExpression &QRegularExpression::operator=(const QRegularExpression &re) | - |
| 661 | { | - |
| 662 | d = re.d; | - |
| 663 | return *this; | - |
| 664 | } | - |
| 665 | QString QRegularExpression::pattern() const | - |
| 666 | { | - |
| 667 | return d->pattern; | - |
| 668 | } | - |
| 669 | - | |
| 670 | - | |
| 671 | - | |
| 672 | - | |
| 673 | - | |
| 674 | - | |
| 675 | - | |
| 676 | void QRegularExpression::setPattern(const QString &pattern) | - |
| 677 | { | - |
| 678 | d.detach(); | - |
| 679 | d->isDirty = true; | - |
| 680 | d->pattern = pattern; | - |
| 681 | } | - |
| 682 | - | |
| 683 | - | |
| 684 | - | |
| 685 | - | |
| 686 | - | |
| 687 | - | |
| 688 | QRegularExpression::PatternOptions QRegularExpression::patternOptions() const | - |
| 689 | { | - |
| 690 | return d->patternOptions; | - |
| 691 | } | - |
| 692 | - | |
| 693 | - | |
| 694 | - | |
| 695 | - | |
| 696 | - | |
| 697 | - | |
| 698 | - | |
| 699 | void QRegularExpression::setPatternOptions(PatternOptions options) | - |
| 700 | { | - |
| 701 | d.detach(); | - |
| 702 | d->isDirty = true; | - |
| 703 | d->patternOptions = options; | - |
| 704 | } | - |
| 705 | int QRegularExpression::captureCount() const | - |
| 706 | { | - |
| 707 | if (!isValid()) | - |
| 708 | return -1; | - |
| 709 | return d->capturingCount; | - |
| 710 | } | - |
| 711 | QStringList QRegularExpression::namedCaptureGroups() const | - |
| 712 | { | - |
| 713 | if (!isValid()) | - |
| 714 | return QStringList(); | - |
| 715 | - | |
| 716 | - | |
| 717 | - | |
| 718 | - | |
| 719 | - | |
| 720 | - | |
| 721 | ushort *namedCapturingTable; | - |
| 722 | int namedCapturingTableEntryCount; | - |
| 723 | int namedCapturingTableEntrySize; | - |
| 724 | - | |
| 725 | pcre16_fullinfo(d->compiledPattern, 0, 9, &namedCapturingTable); | - |
| 726 | pcre16_fullinfo(d->compiledPattern, 0, 8, &namedCapturingTableEntryCount); | - |
| 727 | pcre16_fullinfo(d->compiledPattern, 0, 7, &namedCapturingTableEntrySize); | - |
| 728 | - | |
| 729 | QStringList result; | - |
| 730 | - | |
| 731 | - | |
| 732 | result.reserve(d->capturingCount + 1); | - |
| 733 | for (int i = 0; i < d->capturingCount + 1; ++i) | - |
| 734 | result.append(QString()); | - |
| 735 | - | |
| 736 | for (int i = 0; i < namedCapturingTableEntryCount; ++i) { | - |
| 737 | const ushort * const currentNamedCapturingTableRow = namedCapturingTable + | - |
| 738 | namedCapturingTableEntrySize * i; | - |
| 739 | - | |
| 740 | const int index = *currentNamedCapturingTableRow; | - |
| 741 | result[index] = QString::fromUtf16(currentNamedCapturingTableRow + 1); | - |
| 742 | } | - |
| 743 | - | |
| 744 | return result; | - |
| 745 | } | - |
| 746 | bool QRegularExpression::isValid() const | - |
| 747 | { | - |
| 748 | d.data()->compilePattern(); | - |
| 749 | return d->compiledPattern; | - |
| 750 | } | - |
| 751 | - | |
| 752 | - | |
| 753 | - | |
| 754 | - | |
| 755 | - | |
| 756 | - | |
| 757 | - | |
| 758 | QString QRegularExpression::errorString() const | - |
| 759 | { | - |
| 760 | d.data()->compilePattern(); | - |
| 761 | if (d->errorString) | - |
| 762 | return QCoreApplication::translate("QRegularExpression", d->errorString); | - |
| 763 | return QCoreApplication::translate("QRegularExpression", "no error"); | - |
| 764 | } | - |
| 765 | int QRegularExpression::patternErrorOffset() const | - |
| 766 | { | - |
| 767 | d.data()->compilePattern(); | - |
| 768 | return d->errorOffset; | - |
| 769 | } | - |
| 770 | QRegularExpressionMatch QRegularExpression::match(const QString &subject, | - |
| 771 | int offset, | - |
| 772 | MatchType matchType, | - |
| 773 | MatchOptions matchOptions) const | - |
| 774 | { | - |
| 775 | d.data()->compilePattern(); | - |
| 776 | - | |
| 777 | QRegularExpressionMatchPrivate *priv = d->doMatch(subject, 0, subject.length(), offset, matchType, matchOptions); | - |
| 778 | return QRegularExpressionMatch(*priv); | - |
| 779 | } | - |
| 780 | QRegularExpressionMatch QRegularExpression::match(const QStringRef &subjectRef, | - |
| 781 | int offset, | - |
| 782 | MatchType matchType, | - |
| 783 | MatchOptions matchOptions) const | - |
| 784 | { | - |
| 785 | d.data()->compilePattern(); | - |
| 786 | - | |
| 787 | const QString subject = subjectRef.string() ? *subjectRef.string() : QString(); | - |
| 788 | - | |
| 789 | QRegularExpressionMatchPrivate *priv = d->doMatch(subject, subjectRef.position(), subjectRef.length(), offset, matchType, matchOptions); | - |
| 790 | return QRegularExpressionMatch(*priv); | - |
| 791 | } | - |
| 792 | QRegularExpressionMatchIterator QRegularExpression::globalMatch(const QString &subject, | - |
| 793 | int offset, | - |
| 794 | MatchType matchType, | - |
| 795 | MatchOptions matchOptions) const | - |
| 796 | { | - |
| 797 | QRegularExpressionMatchIteratorPrivate *priv = | - |
| 798 | new QRegularExpressionMatchIteratorPrivate(*this, | - |
| 799 | matchType, | - |
| 800 | matchOptions, | - |
| 801 | match(subject, offset, matchType, matchOptions)); | - |
| 802 | - | |
| 803 | return QRegularExpressionMatchIterator(*priv); | - |
| 804 | } | - |
| 805 | QRegularExpressionMatchIterator QRegularExpression::globalMatch(const QStringRef &subjectRef, | - |
| 806 | int offset, | - |
| 807 | MatchType matchType, | - |
| 808 | MatchOptions matchOptions) const | - |
| 809 | { | - |
| 810 | QRegularExpressionMatchIteratorPrivate *priv = | - |
| 811 | new QRegularExpressionMatchIteratorPrivate(*this, | - |
| 812 | matchType, | - |
| 813 | matchOptions, | - |
| 814 | match(subjectRef, offset, matchType, matchOptions)); | - |
| 815 | - | |
| 816 | return QRegularExpressionMatchIterator(*priv); | - |
| 817 | } | - |
| 818 | void QRegularExpression::optimize() const | - |
| 819 | { | - |
| 820 | if (!isValid()) | - |
| 821 | return; | - |
| 822 | - | |
| 823 | d->optimizePattern(QRegularExpressionPrivate::ImmediateOptimizeOption); | - |
| 824 | } | - |
| 825 | bool QRegularExpression::operator==(const QRegularExpression &re) const | - |
| 826 | { | - |
| 827 | return (d == re.d) || | - |
| 828 | (d->pattern == re.d->pattern && d->patternOptions == re.d->patternOptions); | - |
| 829 | } | - |
| 830 | uint qHash(const QRegularExpression &key, uint seed) noexcept | - |
| 831 | { | - |
| 832 | QtPrivate::QHashCombine hash; | - |
| 833 | seed = hash(seed, key.d->pattern); | - |
| 834 | seed = hash(seed, key.d->patternOptions); | - |
| 835 | return executed 1350 times by 3 tests: seed;return seed;Executed by:
executed 1350 times by 3 tests: return seed;Executed by:
| 1350 |
| 836 | } | - |
| 837 | QString QRegularExpression::escape(const QString &str) | - |
| 838 | { | - |
| 839 | QString result; | - |
| 840 | const int count = str.size(); | - |
| 841 | result.reserve(count * 2); | - |
| 842 | - | |
| 843 | - | |
| 844 | - | |
| 845 | for (int i = 0; i < count; ++i) { | - |
| 846 | const QChar current = str.at(i); | - |
| 847 | - | |
| 848 | if (current == QChar::Null) { | - |
| 849 | - | |
| 850 | - | |
| 851 | - | |
| 852 | result.append(QLatin1Char('\\')); | - |
| 853 | result.append(QLatin1Char('0')); | - |
| 854 | } else if ( (current < QLatin1Char('a') || current > QLatin1Char('z')) && | - |
| 855 | (current < QLatin1Char('A') || current > QLatin1Char('Z')) && | - |
| 856 | (current < QLatin1Char('0') || current > QLatin1Char('9')) && | - |
| 857 | current != QLatin1Char('_') ) | - |
| 858 | { | - |
| 859 | result.append(QLatin1Char('\\')); | - |
| 860 | result.append(current); | - |
| 861 | if (current.isHighSurrogate() && i < (count - 1)) | - |
| 862 | result.append(str.at(++i)); | - |
| 863 | } else { | - |
| 864 | result.append(current); | - |
| 865 | } | - |
| 866 | } | - |
| 867 | - | |
| 868 | result.squeeze(); | - |
| 869 | return result; | - |
| 870 | } | - |
| 871 | QRegularExpressionMatch::QRegularExpressionMatch() | - |
| 872 | : d(new QRegularExpressionMatchPrivate(QRegularExpression(), | - |
| 873 | QString(), | - |
| 874 | 0, | - |
| 875 | 0, | - |
| 876 | QRegularExpression::NoMatch, | - |
| 877 | QRegularExpression::NoMatchOption)) | - |
| 878 | { | - |
| 879 | d->isValid = true; | - |
| 880 | } | - |
| 881 | - | |
| 882 | - | |
| 883 | - | |
| 884 | - | |
| 885 | QRegularExpressionMatch::~QRegularExpressionMatch() | - |
| 886 | { | - |
| 887 | } | - |
| 888 | - | |
| 889 | - | |
| 890 | - | |
| 891 | - | |
| 892 | - | |
| 893 | - | |
| 894 | QRegularExpressionMatch::QRegularExpressionMatch(const QRegularExpressionMatch &match) | - |
| 895 | : d(match.d) | - |
| 896 | { | - |
| 897 | } | - |
| 898 | - | |
| 899 | - | |
| 900 | - | |
| 901 | - | |
| 902 | - | |
| 903 | QRegularExpressionMatch &QRegularExpressionMatch::operator=(const QRegularExpressionMatch &match) | - |
| 904 | { | - |
| 905 | d = match.d; | - |
| 906 | return *this; | - |
| 907 | } | - |
| 908 | QRegularExpressionMatch::QRegularExpressionMatch(QRegularExpressionMatchPrivate &dd) | - |
| 909 | : d(&dd) | - |
| 910 | { | - |
| 911 | } | - |
| 912 | - | |
| 913 | - | |
| 914 | - | |
| 915 | - | |
| 916 | - | |
| 917 | - | |
| 918 | - | |
| 919 | QRegularExpression QRegularExpressionMatch::regularExpression() const | - |
| 920 | { | - |
| 921 | return d->regularExpression; | - |
| 922 | } | - |
| 923 | QRegularExpression::MatchType QRegularExpressionMatch::matchType() const | - |
| 924 | { | - |
| 925 | return d->matchType; | - |
| 926 | } | - |
| 927 | QRegularExpression::MatchOptions QRegularExpressionMatch::matchOptions() const | - |
| 928 | { | - |
| 929 | return d->matchOptions; | - |
| 930 | } | - |
| 931 | int QRegularExpressionMatch::lastCapturedIndex() const | - |
| 932 | { | - |
| 933 | return d->capturedCount - 1; | - |
| 934 | } | - |
| 935 | QString QRegularExpressionMatch::captured(int nth) const | - |
| 936 | { | - |
| 937 | if (nth < 0 || nth > lastCapturedIndex()) | - |
| 938 | return QString(); | - |
| 939 | - | |
| 940 | int start = capturedStart(nth); | - |
| 941 | - | |
| 942 | if (start == -1) | - |
| 943 | return QString(); | - |
| 944 | - | |
| 945 | return d->subject.mid(start + d->subjectStart, capturedLength(nth)); | - |
| 946 | } | - |
| 947 | QStringRef QRegularExpressionMatch::capturedRef(int nth) const | - |
| 948 | { | - |
| 949 | if (nth < 0 || nth > lastCapturedIndex()) | - |
| 950 | return QStringRef(); | - |
| 951 | - | |
| 952 | int start = capturedStart(nth); | - |
| 953 | - | |
| 954 | if (start == -1) | - |
| 955 | return QStringRef(); | - |
| 956 | - | |
| 957 | return d->subject.midRef(start + d->subjectStart, capturedLength(nth)); | - |
| 958 | } | - |
| 959 | QString QRegularExpressionMatch::captured(const QString &name) const | - |
| 960 | { | - |
| 961 | if (name.isEmpty()) { | - |
| 962 | QMessageLogger(__FILE__, 20922098, __PRETTY_FUNCTION__).warning("QRegularExpressionMatch::captured: empty capturing group name passed"); | - |
| 963 | return QString(); | - |
| 964 | } | - |
| 965 | int nth = d->regularExpression.d->captureIndexForName(name); | - |
| 966 | if (nth == -1) | - |
| 967 | return QString(); | - |
| 968 | return captured(nth); | - |
| 969 | } | - |
| 970 | QStringRef QRegularExpressionMatch::capturedRef(const QString &name) const | - |
| 971 | { | - |
| 972 | if (name.isEmpty()) { | - |
| 973 | QMessageLogger(__FILE__, 21122118, __PRETTY_FUNCTION__).warning("QRegularExpressionMatch::capturedRef: empty capturing group name passed"); | - |
| 974 | return QStringRef(); | - |
| 975 | } | - |
| 976 | int nth = d->regularExpression.d->captureIndexForName(name); | - |
| 977 | if (nth == -1) | - |
| 978 | return QStringRef(); | - |
| 979 | return capturedRef(nth); | - |
| 980 | } | - |
| 981 | - | |
| 982 | - | |
| 983 | - | |
| 984 | - | |
| 985 | - | |
| 986 | QStringList QRegularExpressionMatch::capturedTexts() const | - |
| 987 | { | - |
| 988 | QStringList texts; | - |
| 989 | texts.reserve(d->capturedCount); | - |
| 990 | for (int i = 0; i < d->capturedCount; ++i) | - |
| 991 | texts << captured(i); | - |
| 992 | return texts; | - |
| 993 | } | - |
| 994 | int QRegularExpressionMatch::capturedStart(int nth) const | - |
| 995 | { | - |
| 996 | if (nth < 0 || nth > lastCapturedIndex()) | - |
| 997 | return -1; | - |
| 998 | - | |
| 999 | return d->capturedOffsets.at(nth * 2); | - |
| 1000 | } | - |
| 1001 | int QRegularExpressionMatch::capturedLength(int nth) const | - |
| 1002 | { | - |
| 1003 | - | |
| 1004 | return capturedEnd(nth) - capturedStart(nth); | - |
| 1005 | } | - |
| 1006 | int QRegularExpressionMatch::capturedEnd(int nth) const | - |
| 1007 | { | - |
| 1008 | if (nth < 0 || nth > lastCapturedIndex()) | - |
| 1009 | return -1; | - |
| 1010 | - | |
| 1011 | return d->capturedOffsets.at(nth * 2 + 1); | - |
| 1012 | } | - |
| 1013 | int QRegularExpressionMatch::capturedStart(const QString &name) const | - |
| 1014 | { | - |
| 1015 | if (name.isEmpty()) { | - |
| 1016 | QMessageLogger(__FILE__, 21902196, __PRETTY_FUNCTION__).warning("QRegularExpressionMatch::capturedStart: empty capturing group name passed"); | - |
| 1017 | return -1; | - |
| 1018 | } | - |
| 1019 | int nth = d->regularExpression.d->captureIndexForName(name); | - |
| 1020 | if (nth == -1) | - |
| 1021 | return -1; | - |
| 1022 | return capturedStart(nth); | - |
| 1023 | } | - |
| 1024 | int QRegularExpressionMatch::capturedLength(const QString &name) const | - |
| 1025 | { | - |
| 1026 | if (name.isEmpty()) { | - |
| 1027 | QMessageLogger(__FILE__, 22112217, __PRETTY_FUNCTION__).warning("QRegularExpressionMatch::capturedLength: empty capturing group name passed"); | - |
| 1028 | return 0; | - |
| 1029 | } | - |
| 1030 | int nth = d->regularExpression.d->captureIndexForName(name); | - |
| 1031 | if (nth == -1) | - |
| 1032 | return 0; | - |
| 1033 | return capturedLength(nth); | - |
| 1034 | } | - |
| 1035 | int QRegularExpressionMatch::capturedEnd(const QString &name) const | - |
| 1036 | { | - |
| 1037 | if (name.isEmpty()) { | - |
| 1038 | QMessageLogger(__FILE__, 22312237, __PRETTY_FUNCTION__).warning("QRegularExpressionMatch::capturedEnd: empty capturing group name passed"); | - |
| 1039 | return -1; | - |
| 1040 | } | - |
| 1041 | int nth = d->regularExpression.d->captureIndexForName(name); | - |
| 1042 | if (nth == -1) | - |
| 1043 | return -1; | - |
| 1044 | return capturedEnd(nth); | - |
| 1045 | } | - |
| 1046 | - | |
| 1047 | - | |
| 1048 | - | |
| 1049 | - | |
| 1050 | - | |
| 1051 | - | |
| 1052 | - | |
| 1053 | bool QRegularExpressionMatch::hasMatch() const | - |
| 1054 | { | - |
| 1055 | return d->hasMatch; | - |
| 1056 | } | - |
| 1057 | bool QRegularExpressionMatch::hasPartialMatch() const | - |
| 1058 | { | - |
| 1059 | return d->hasPartialMatch; | - |
| 1060 | } | - |
| 1061 | bool QRegularExpressionMatch::isValid() const | - |
| 1062 | { | - |
| 1063 | return d->isValid; | - |
| 1064 | } | - |
| 1065 | - | |
| 1066 | - | |
| 1067 | - | |
| 1068 | - | |
| 1069 | QRegularExpressionMatchIterator::QRegularExpressionMatchIterator(QRegularExpressionMatchIteratorPrivate &dd) | - |
| 1070 | : d(&dd) | - |
| 1071 | { | - |
| 1072 | } | - |
| 1073 | QRegularExpressionMatchIterator::QRegularExpressionMatchIterator() | - |
| 1074 | : d(new QRegularExpressionMatchIteratorPrivate(QRegularExpression(), | - |
| 1075 | QRegularExpression::NoMatch, | - |
| 1076 | QRegularExpression::NoMatchOption, | - |
| 1077 | QRegularExpressionMatch())) | - |
| 1078 | { | - |
| 1079 | } | - |
| 1080 | - | |
| 1081 | - | |
| 1082 | - | |
| 1083 | - | |
| 1084 | QRegularExpressionMatchIterator::~QRegularExpressionMatchIterator() | - |
| 1085 | { | - |
| 1086 | } | - |
| 1087 | - | |
| 1088 | - | |
| 1089 | - | |
| 1090 | - | |
| 1091 | - | |
| 1092 | - | |
| 1093 | - | |
| 1094 | QRegularExpressionMatchIterator::QRegularExpressionMatchIterator(const QRegularExpressionMatchIterator &iterator) | - |
| 1095 | : d(iterator.d) | - |
| 1096 | { | - |
| 1097 | } | - |
| 1098 | - | |
| 1099 | - | |
| 1100 | - | |
| 1101 | - | |
| 1102 | - | |
| 1103 | QRegularExpressionMatchIterator &QRegularExpressionMatchIterator::operator=(const QRegularExpressionMatchIterator &iterator) | - |
| 1104 | { | - |
| 1105 | d = iterator.d; | - |
| 1106 | return *this; | - |
| 1107 | } | - |
| 1108 | bool QRegularExpressionMatchIterator::isValid() const | - |
| 1109 | { | - |
| 1110 | return d->next.isValid(); | - |
| 1111 | } | - |
| 1112 | - | |
| 1113 | - | |
| 1114 | - | |
| 1115 | - | |
| 1116 | - | |
| 1117 | - | |
| 1118 | - | |
| 1119 | bool QRegularExpressionMatchIterator::hasNext() const | - |
| 1120 | { | - |
| 1121 | return d->hasNext(); | - |
| 1122 | } | - |
| 1123 | - | |
| 1124 | - | |
| 1125 | - | |
| 1126 | - | |
| 1127 | - | |
| 1128 | - | |
| 1129 | - | |
| 1130 | QRegularExpressionMatch QRegularExpressionMatchIterator::peekNext() const | - |
| 1131 | { | - |
| 1132 | if (!hasNext()) | - |
| 1133 | QMessageLogger(__FILE__, 23802386, __PRETTY_FUNCTION__).warning("QRegularExpressionMatchIterator::peekNext() called on an iterator already at end"); | - |
| 1134 | - | |
| 1135 | return d->next; | - |
| 1136 | } | - |
| 1137 | - | |
| 1138 | - | |
| 1139 | - | |
| 1140 | - | |
| 1141 | - | |
| 1142 | - | |
| 1143 | - | |
| 1144 | QRegularExpressionMatch QRegularExpressionMatchIterator::next() | - |
| 1145 | { | - |
| 1146 | if (!hasNext()) { | - |
| 1147 | QMessageLogger(__FILE__, 23942400, __PRETTY_FUNCTION__).warning("QRegularExpressionMatchIterator::next() called on an iterator already at end"); | - |
| 1148 | return d->next; | - |
| 1149 | } | - |
| 1150 | - | |
| 1151 | QRegularExpressionMatch current = d->next; | - |
| 1152 | d->next = d->next.d.constData()->nextMatch(); | - |
| 1153 | return current; | - |
| 1154 | } | - |
| 1155 | - | |
| 1156 | - | |
| 1157 | - | |
| 1158 | - | |
| 1159 | - | |
| 1160 | - | |
| 1161 | - | |
| 1162 | QRegularExpression QRegularExpressionMatchIterator::regularExpression() const | - |
| 1163 | { | - |
| 1164 | return d->regularExpression; | - |
| 1165 | } | - |
| 1166 | QRegularExpression::MatchType QRegularExpressionMatchIterator::matchType() const | - |
| 1167 | { | - |
| 1168 | return d->matchType; | - |
| 1169 | } | - |
| 1170 | QRegularExpression::MatchOptions QRegularExpressionMatchIterator::matchOptions() const | - |
| 1171 | { | - |
| 1172 | return d->matchOptions; | - |
| 1173 | } | - |
| 1174 | QDataStream &operator<<(QDataStream &out, const QRegularExpression &re) | - |
| 1175 | { | - |
| 1176 | out << re.pattern() << quint32(re.patternOptions()); | - |
| 1177 | return out; | - |
| 1178 | } | - |
| 1179 | QDataStream &operator>>(QDataStream &in, QRegularExpression &re) | - |
| 1180 | { | - |
| 1181 | QString pattern; | - |
| 1182 | quint32 patternOptions; | - |
| 1183 | in >> pattern >> patternOptions; | - |
| 1184 | re.setPattern(pattern); | - |
| 1185 | re.setPatternOptions(QRegularExpression::PatternOptions(patternOptions)); | - |
| 1186 | return in; | - |
| 1187 | } | - |
| 1188 | QDebug operator<<(QDebug debug, const QRegularExpression &re) | - |
| 1189 | { | - |
| 1190 | QDebugStateSaver saver(debug); | - |
| 1191 | debug.nospace() << "QRegularExpression(" << re.pattern() << ", " << re.patternOptions() << ')'; | - |
| 1192 | return debug; | - |
| 1193 | } | - |
| 1194 | QDebug operator<<(QDebug debug, QRegularExpression::PatternOptions patternOptions) | - |
| 1195 | { | - |
| 1196 | QDebugStateSaver saver(debug); | - |
| 1197 | QByteArray flags; | - |
| 1198 | - | |
| 1199 | if (patternOptions == QRegularExpression::NoPatternOption) { | - |
| 1200 | flags = "NoPatternOption"; | - |
| 1201 | } else { | - |
| 1202 | flags.reserve(200); | - |
| 1203 | if (patternOptions & QRegularExpression::CaseInsensitiveOption) | - |
| 1204 | flags.append("CaseInsensitiveOption|"); | - |
| 1205 | if (patternOptions & QRegularExpression::DotMatchesEverythingOption) | - |
| 1206 | flags.append("DotMatchesEverythingOption|"); | - |
| 1207 | if (patternOptions & QRegularExpression::MultilineOption) | - |
| 1208 | flags.append("MultilineOption|"); | - |
| 1209 | if (patternOptions & QRegularExpression::ExtendedPatternSyntaxOption) | - |
| 1210 | flags.append("ExtendedPatternSyntaxOption|"); | - |
| 1211 | if (patternOptions & QRegularExpression::InvertedGreedinessOption) | - |
| 1212 | flags.append("InvertedGreedinessOption|"); | - |
| 1213 | if (patternOptions & QRegularExpression::DontCaptureOption) | - |
| 1214 | flags.append("DontCaptureOption|"); | - |
| 1215 | if (patternOptions & QRegularExpression::UseUnicodePropertiesOption) | - |
| 1216 | flags.append("UseUnicodePropertiesOption|"); | - |
| 1217 | if (patternOptions & QRegularExpression::OptimizeOnFirstUsageOption) | - |
| 1218 | flags.append("OptimizeOnFirstUsageOption|"); | - |
| 1219 | if (patternOptions & QRegularExpression::DontAutomaticallyOptimizeOption) | - |
| 1220 | flags.append("DontAutomaticallyOptimizeOption|"); | - |
| 1221 | flags.chop(1); | - |
| 1222 | } | - |
| 1223 | - | |
| 1224 | debug.nospace() << "QRegularExpression::PatternOptions(" << flags << ')'; | - |
| 1225 | - | |
| 1226 | return debug; | - |
| 1227 | } | - |
| 1228 | QDebug operator<<(QDebug debug, const QRegularExpressionMatch &match) | - |
| 1229 | { | - |
| 1230 | QDebugStateSaver saver(debug); | - |
| 1231 | debug.nospace() << "QRegularExpressionMatch("; | - |
| 1232 | - | |
| 1233 | if (!match.isValid()) { | - |
| 1234 | debug << "Invalid)"; | - |
| 1235 | return debug; | - |
| 1236 | } | - |
| 1237 | - | |
| 1238 | debug << "Valid"; | - |
| 1239 | - | |
| 1240 | if (match.hasMatch()) { | - |
| 1241 | debug << ", has match: "; | - |
| 1242 | for (int i = 0; i <= match.lastCapturedIndex(); ++i) { | - |
| 1243 | debug << i | - |
| 1244 | << ":(" << match.capturedStart(i) << ", " << match.capturedEnd(i) | - |
| 1245 | << ", " << match.captured(i) << ')'; | - |
| 1246 | if (i < match.lastCapturedIndex()) | - |
| 1247 | debug << ", "; | - |
| 1248 | } | - |
| 1249 | } else if (match.hasPartialMatch()) { | - |
| 1250 | debug << ", has partial match: (" | - |
| 1251 | << match.capturedStart(0) << ", " | - |
| 1252 | << match.capturedEnd(0) << ", " | - |
| 1253 | << match.captured(0) << ')'; | - |
| 1254 | } else { | - |
| 1255 | debug << ", no match"; | - |
| 1256 | } | - |
| 1257 | - | |
| 1258 | debug << ')'; | - |
| 1259 | - | |
| 1260 | return debug; | - |
| 1261 | } | - |
| 1262 | - | |
| Switch to Source code | Preprocessed file |