diff options
Diffstat (limited to 'src/corelib/text')
-rw-r--r-- | src/corelib/text/qregularexpression.cpp | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/src/corelib/text/qregularexpression.cpp b/src/corelib/text/qregularexpression.cpp index c52a80e676..a0b35f8142 100644 --- a/src/corelib/text/qregularexpression.cpp +++ b/src/corelib/text/qregularexpression.cpp @@ -1040,9 +1040,24 @@ int QRegularExpressionPrivate::captureIndexForName(QStringView name) const if (!compiledPattern) return -1; - int index = pcre2_substring_number_from_name_16(compiledPattern, reinterpret_cast<PCRE2_SPTR16>(name.utf16())); - if (index >= 0) - return index; + // See the other usages of pcre2_pattern_info_16 for more details about this + PCRE2_SPTR16 *namedCapturingTable; + unsigned int namedCapturingTableEntryCount; + unsigned int namedCapturingTableEntrySize; + + pcre2_pattern_info_16(compiledPattern, PCRE2_INFO_NAMETABLE, &namedCapturingTable); + pcre2_pattern_info_16(compiledPattern, PCRE2_INFO_NAMECOUNT, &namedCapturingTableEntryCount); + pcre2_pattern_info_16(compiledPattern, PCRE2_INFO_NAMEENTRYSIZE, &namedCapturingTableEntrySize); + + for (unsigned int i = 0; i < namedCapturingTableEntryCount; ++i) { + const auto currentNamedCapturingTableRow = + reinterpret_cast<const char16_t *>(namedCapturingTable) + namedCapturingTableEntrySize * i; + + if (name == (currentNamedCapturingTableRow + 1)) { + const int index = *currentNamedCapturingTableRow; + return index; + } + } return -1; } |