8#include <QtCore/qcoreapplication.h>
9#include <QtCore/qhashfunctions.h>
10#include <QtCore/qlist.h>
11#include <QtCore/qmutex.h>
12#include <QtCore/qstringlist.h>
13#include <QtCore/qdebug.h>
14#include <QtCore/qglobal.h>
15#include <QtCore/qatomic.h>
16#include <QtCore/qdatastream.h>
18#if defined(Q_OS_MACOS)
19#include <QtCore/private/qcore_mac_p.h>
22#define PCRE2_CODE_UNIT_WIDTH 16
672 options |= PCRE2_CASELESS;
674 options |= PCRE2_DOTALL;
676 options |= PCRE2_MULTILINE;
678 options |= PCRE2_EXTENDED;
680 options |= PCRE2_UNGREEDY;
682 options |= PCRE2_NO_AUTO_CAPTURE;
684 options |= PCRE2_UCP;
697 options |= PCRE2_ANCHORED;
699 options |= PCRE2_NO_UTF_CHECK;
804 qWarning(
"%s(): called on an invalid QRegularExpression object "
807 qWarning(
"%s(): called on an invalid QRegularExpression object", where);
831 usingCrLfNewlines(
false),
855 patternOptions(
other.patternOptions),
862 usingCrLfNewlines(
false),
894 options |= PCRE2_UTF;
896 PCRE2_SIZE patternErrorOffset;
926 unsigned int patternNewlineSetting;
927 if (pcre2_pattern_info_16(
compiledPattern, PCRE2_INFO_NEWLINE, &patternNewlineSetting) != 0) {
929 pcre2_config_16(PCRE2_CONFIG_NEWLINE, &patternNewlineSetting);
933 (patternNewlineSetting == PCRE2_NEWLINE_ANY) ||
934 (patternNewlineSetting == PCRE2_NEWLINE_ANYCRLF);
936 unsigned int hasJOptionChanged;
937 pcre2_pattern_info_16(
compiledPattern, PCRE2_INFO_JCHANGED, &hasJOptionChanged);
939 qWarning(
"QRegularExpressionPrivate::getPatternInfo(): the pattern '%ls'\n is using the (?J) option; duplicate capturing group names are not supported by Qt",
950struct PcreJitStackFree
952 void operator()(pcre2_jit_stack_16 *stack)
955 pcre2_jit_stack_free_16(stack);
958Q_CONSTINIT
static thread_local std::unique_ptr<pcre2_jit_stack_16, PcreJitStackFree> jitStacks;
966 return jitStacks.get();
975 if (!jitEnvironment.isEmpty()) {
977 int enableJit = jitEnvironment.toInt(&
ok);
978 return ok ? (enableJit != 0) :
true;
983#elif defined(Q_OS_MACOS)
984 return !qt_mac_runningUnderRosetta();
1008 pcre2_jit_compile_16(
compiledPattern, PCRE2_JIT_COMPLETE | PCRE2_JIT_PARTIAL_SOFT | PCRE2_JIT_PARTIAL_HARD);
1025 PCRE2_SPTR16 *namedCapturingTable;
1026 unsigned int namedCapturingTableEntryCount;
1027 unsigned int namedCapturingTableEntrySize;
1029 pcre2_pattern_info_16(
compiledPattern, PCRE2_INFO_NAMETABLE, &namedCapturingTable);
1030 pcre2_pattern_info_16(
compiledPattern, PCRE2_INFO_NAMECOUNT, &namedCapturingTableEntryCount);
1031 pcre2_pattern_info_16(
compiledPattern, PCRE2_INFO_NAMEENTRYSIZE, &namedCapturingTableEntrySize);
1033 for (
unsigned int i = 0;
i < namedCapturingTableEntryCount; ++
i) {
1034 const auto currentNamedCapturingTableRow =
1035 reinterpret_cast<const char16_t *
>(namedCapturingTable) + namedCapturingTableEntrySize *
i;
1037 if (
name == (currentNamedCapturingTableRow + 1)) {
1038 const int index = *currentNamedCapturingTableRow;
1056 pcre2_match_data_16 *matchData,
1057 pcre2_match_context_16 *matchContext)
1060 startOffset, options, matchData, matchContext);
1062 if (
result == PCRE2_ERROR_JIT_STACKLIMIT && !jitStacks) {
1065 jitStacks.reset(pcre2_jit_stack_create_16(32 * 1024, 512 * 1024, NULL));
1068 startOffset, options, matchData, matchContext);
1115 if (offset < 0 || offset > subjectLength)
1125 priv->isValid =
true;
1132 pcreOptions |= PCRE2_PARTIAL_SOFT;
1134 pcreOptions |= PCRE2_PARTIAL_HARD;
1137 pcreOptions |= PCRE2_NO_UTF_CHECK;
1139 bool previousMatchWasEmpty =
false;
1140 if (previous && previous->
hasMatch &&
1142 previousMatchWasEmpty =
true;
1145 pcre2_match_context_16 *matchContext = pcre2_match_context_create_16(
nullptr);
1146 pcre2_jit_stack_assign_16(matchContext, &
qtPcreCallback,
nullptr);
1147 pcre2_match_data_16 *matchData = pcre2_match_data_create_from_pattern_16(
compiledPattern,
nullptr);
1153 const char16_t dummySubject = 0;
1154 const char16_t *
const subjectUtf16 = [&]()
1156 const auto subjectUtf16 =
priv->subject.utf16();
1158 return subjectUtf16;
1160 return &dummySubject;
1165 if (!previousMatchWasEmpty) {
1167 reinterpret_cast<PCRE2_SPTR16
>(subjectUtf16), subjectLength,
1169 matchData, matchContext);
1172 reinterpret_cast<PCRE2_SPTR16
>(subjectUtf16), subjectLength,
1173 offset, pcreOptions | PCRE2_NOTEMPTY_ATSTART | PCRE2_ANCHORED,
1174 matchData, matchContext);
1176 if (
result == PCRE2_ERROR_NOMATCH) {
1180 &&
offset < subjectLength
1181 && subjectUtf16[
offset - 1] == u
'\r'
1182 && subjectUtf16[
offset] == u
'\n') {
1184 }
else if (
offset < subjectLength
1185 && QChar::isLowSurrogate(subjectUtf16[
offset])) {
1190 reinterpret_cast<PCRE2_SPTR16
>(subjectUtf16), subjectLength,
1192 matchData, matchContext);
1196#ifdef QREGULAREXPRESSION_DEBUG
1199 <<
priv->matchType <<
priv->matchOptions << previousMatchWasEmpty
1208 priv->isValid =
true;
1209 priv->hasMatch =
true;
1214 priv->hasPartialMatch = (
result == PCRE2_ERROR_PARTIAL);
1215 priv->isValid = (
result == PCRE2_ERROR_NOMATCH ||
result == PCRE2_ERROR_PARTIAL);
1217 if (
result == PCRE2_ERROR_PARTIAL) {
1220 priv->capturedCount = 1;
1221 priv->capturedOffsets.resize(2);
1224 priv->capturedCount = 0;
1225 priv->capturedOffsets.clear();
1230 if (
priv->capturedCount) {
1231 PCRE2_SIZE *ovector = pcre2_get_ovector_pointer_16(matchData);
1232 qsizetype *
const capturedOffsets =
priv->capturedOffsets.data();
1238 static_assert(
qsizetype(PCRE2_UNSET) ==
qsizetype(-1),
"Internal error: PCRE2 changed its API");
1240 for (
int i = 0;
i <
priv->capturedCount * 2; ++
i)
1254 if (
result == PCRE2_ERROR_PARTIAL) {
1255 unsigned int maximumLookBehind;
1256 pcre2_pattern_info_16(
compiledPattern, PCRE2_INFO_MAXLOOKBEHIND, &maximumLookBehind);
1257 capturedOffsets[0] -= maximumLookBehind;
1261 pcre2_match_data_free_16(matchData);
1262 pcre2_match_context_free_16(matchContext);
1269 const QString &subjectStorage,
1272 QRegularExpression::MatchOptions matchOptions)
1273 : regularExpression(re),
1274 subjectStorage(subjectStorage),
1276 matchType(matchType),
1277 matchOptions(matchOptions)
1311 QRegularExpression::MatchOptions matchOptions,
1314 regularExpression(re),
1315 matchType(matchType), matchOptions(matchOptions)
1496 PCRE2_SPTR16 *namedCapturingTable;
1497 unsigned int namedCapturingTableEntryCount;
1498 unsigned int namedCapturingTableEntrySize;
1500 pcre2_pattern_info_16(d->
compiledPattern, PCRE2_INFO_NAMETABLE, &namedCapturingTable);
1501 pcre2_pattern_info_16(d->
compiledPattern, PCRE2_INFO_NAMECOUNT, &namedCapturingTableEntryCount);
1502 pcre2_pattern_info_16(d->
compiledPattern, PCRE2_INFO_NAMEENTRYSIZE, &namedCapturingTableEntrySize);
1507 for (
unsigned int i = 0;
i < namedCapturingTableEntryCount; ++
i) {
1508 const auto currentNamedCapturingTableRow =
1509 reinterpret_cast<const char16_t *
>(namedCapturingTable) + namedCapturingTableEntrySize *
i;
1511 const int index = *currentNamedCapturingTableRow;
1542 int errorStringLength;
1545 errorStringLength = pcre2_get_error_message_16(d->
errorCode,
1548 }
while (errorStringLength < 0);
1551#ifdef QT_NO_TRANSLATION
1557#ifdef QT_NO_TRANSLATION
1558 return u
"no error"_s;
1590 MatchOptions matchOptions)
const
1602#if QT_DEPRECATED_SINCE(6, 8)
1612 MatchType matchType,
1613 MatchOptions matchOptions)
const
1638 MatchOptions matchOptions)
const
1664 MatchOptions matchOptions)
const
1675#if QT_DEPRECATED_SINCE(6, 8)
1685 MatchType matchType,
1686 MatchOptions matchOptions)
const
1713 MatchOptions matchOptions)
const
1749 return (lhs.d == rhs.d) ||
1750 (lhs.d->pattern == rhs.d->pattern && lhs.d->patternOptions == rhs.d->patternOptions);
1820 if (current == QChar::Null) {
1826 }
else if ((current < u
'a' || current > u
'z') &&
1827 (current < u
'A' || current > u
'Z') &&
1828 (current < u
'0' || current > u
'9') &&
1832 if (current.isHighSurrogate() &&
i < (
count - 1))
1935 rx.reserve(wclen + wclen / 16);
1939 struct GlobSettings {
1940 char16_t nativePathSeparator;
1945 const GlobSettings
settings = [options]() {
1949 return GlobSettings{ u
'\0', u
"[\\d\\D]*", u
"[\\d\\D]" };
1952 return GlobSettings{ u
'\\', u
"[^/\\\\]*", u
"[^/\\\\]" };
1954 return GlobSettings{ u
'/', u
"[^/]*", u
"[^/]" };
1961 switch (
c.unicode()) {
2002 if (wc[
i] == u
'!') {
2007 if (
i < wclen && wc[
i] == u
']')
2010 while (
i < wclen && wc[
i] != u
']') {
2015 if (wc[
i] == u
'/' || wc[
i] ==
settings.nativePathSeparator)
2050 WildcardConversionOptions options)
2341 if (
name.isEmpty()) {
2342 qWarning(
"QRegularExpressionMatch::captured: empty capturing group name passed");
2366 if (
name.isEmpty()) {
2367 qWarning(
"QRegularExpressionMatch::capturedView: empty capturing group name passed");
2451 if (
name.isEmpty()) {
2452 qWarning(
"QRegularExpressionMatch::capturedStart: empty capturing group name passed");
2477 if (
name.isEmpty()) {
2478 qWarning(
"QRegularExpressionMatch::capturedLength: empty capturing group name passed");
2502 if (
name.isEmpty()) {
2503 qWarning(
"QRegularExpressionMatch::capturedEnd: empty capturing group name passed");
2673 qWarning(
"QRegularExpressionMatchIterator::peekNext() called on an iterator already at end");
2687 qWarning(
"QRegularExpressionMatchIterator::next() called on an iterator already at end");
2743#ifndef QT_NO_DATASTREAM
2753 out << re.pattern() <<
quint32(re.patternOptions().toInt());
2770 re.setPatternOptions(QRegularExpression::PatternOptions::fromInt(patternOptions));
2775#ifndef QT_NO_DEBUG_STREAM
2787 debug.nospace() <<
"QRegularExpression(" << re.pattern() <<
", " << re.patternOptions() <<
')';
2805 flags =
"NoPatternOption";
2809 flags.append(
"CaseInsensitiveOption|");
2811 flags.append(
"DotMatchesEverythingOption|");
2813 flags.append(
"MultilineOption|");
2815 flags.append(
"ExtendedPatternSyntaxOption|");
2817 flags.append(
"InvertedGreedinessOption|");
2819 flags.append(
"DontCaptureOption|");
2821 flags.append(
"UseUnicodePropertiesOption|");
2825 debug.nospace() <<
"QRegularExpression::PatternOptions(" <<
flags <<
')';
2840 debug.nospace() <<
"QRegularExpressionMatch(";
2842 if (!
match.isValid()) {
2843 debug <<
"Invalid)";
2849 if (
match.hasMatch()) {
2850 debug <<
", has match: ";
2851 for (
int i = 0;
i <=
match.lastCapturedIndex(); ++
i) {
2853 <<
":(" <<
match.capturedStart(
i) <<
", " <<
match.capturedEnd(
i)
2854 <<
", " <<
match.captured(
i) <<
')';
2855 if (
i <
match.lastCapturedIndex())
2858 }
else if (
match.hasPartialMatch()) {
2859 debug <<
", has partial match: ("
2860 <<
match.capturedStart(0) <<
", "
2861 <<
match.capturedEnd(0) <<
", "
2862 <<
match.captured(0) <<
')';
2864 debug <<
", no match";
2913static const char *pcreCompileErrorCodes[] =
2919 QT_TRANSLATE_NOOP(
"QRegularExpression",
"numbers out of order in {} quantifier"),
2921 QT_TRANSLATE_NOOP(
"QRegularExpression",
"missing terminating ] for character class"),
2922 QT_TRANSLATE_NOOP(
"QRegularExpression",
"escape sequence is invalid in character class"),
2923 QT_TRANSLATE_NOOP(
"QRegularExpression",
"range out of order in character class"),
2924 QT_TRANSLATE_NOOP(
"QRegularExpression",
"quantifier does not follow a repeatable item"),
2926 QT_TRANSLATE_NOOP(
"QRegularExpression",
"unrecognized character after (? or (?-"),
2927 QT_TRANSLATE_NOOP(
"QRegularExpression",
"POSIX named classes are supported only within a class"),
2928 QT_TRANSLATE_NOOP(
"QRegularExpression",
"POSIX collating elements are not supported"),
2930 QT_TRANSLATE_NOOP(
"QRegularExpression",
"reference to non-existent subpattern"),
2932 QT_TRANSLATE_NOOP(
"QRegularExpression",
"unrecognised compile-time option bit(s)"),
2939 QT_TRANSLATE_NOOP(
"QRegularExpression",
"missing closing parenthesis for condition"),
2940 QT_TRANSLATE_NOOP(
"QRegularExpression",
"lookbehind assertion is not fixed length"),
2941 QT_TRANSLATE_NOOP(
"QRegularExpression",
"a relative value of zero is not allowed"),
2942 QT_TRANSLATE_NOOP(
"QRegularExpression",
"conditional subpattern contains more than two branches"),
2943 QT_TRANSLATE_NOOP(
"QRegularExpression",
"assertion expected after (?( or (?(?C)"),
2946 QT_TRANSLATE_NOOP(
"QRegularExpression",
"internal error in pcre2_study(): should not occur"),
2947 QT_TRANSLATE_NOOP(
"QRegularExpression",
"this version of PCRE2 does not have Unicode support"),
2948 QT_TRANSLATE_NOOP(
"QRegularExpression",
"parentheses are too deeply nested (stack check)"),
2949 QT_TRANSLATE_NOOP(
"QRegularExpression",
"character code point value in \\x{} or \\o{} is too large"),
2951 QT_TRANSLATE_NOOP(
"QRegularExpression",
"\\C is not allowed in a lookbehind assertion in UTF-" "16" " mode"),
2952 QT_TRANSLATE_NOOP(
"QRegularExpression",
"PCRE2 does not support \\F, \\L, \\l, \\N{name}, \\U, or \\u"),
2953 QT_TRANSLATE_NOOP(
"QRegularExpression",
"number after (?C is greater than 255"),
2954 QT_TRANSLATE_NOOP(
"QRegularExpression",
"closing parenthesis for (?C expected"),
2955 QT_TRANSLATE_NOOP(
"QRegularExpression",
"invalid escape sequence in (*VERB) name"),
2957 QT_TRANSLATE_NOOP(
"QRegularExpression",
"syntax error in subpattern name (missing terminator?)"),
2958 QT_TRANSLATE_NOOP(
"QRegularExpression",
"two named subpatterns have the same name (PCRE2_DUPNAMES not set)"),
2959 QT_TRANSLATE_NOOP(
"QRegularExpression",
"subpattern name must start with a non-digit"),
2960 QT_TRANSLATE_NOOP(
"QRegularExpression",
"this version of PCRE2 does not have support for \\P, \\p, or \\X"),
2962 QT_TRANSLATE_NOOP(
"QRegularExpression",
"unknown property name after \\P or \\p"),
2963 QT_TRANSLATE_NOOP(
"QRegularExpression",
"subpattern name is too long (maximum " "32" " code units)"),
2964 QT_TRANSLATE_NOOP(
"QRegularExpression",
"too many named subpatterns (maximum " "10000" ")"),
2966 QT_TRANSLATE_NOOP(
"QRegularExpression",
"octal value is greater than \\377 in 8-bit non-UTF-8 mode"),
2967 QT_TRANSLATE_NOOP(
"QRegularExpression",
"internal error: overran compiling workspace"),
2968 QT_TRANSLATE_NOOP(
"QRegularExpression",
"internal error: previously-checked referenced subpattern not found"),
2969 QT_TRANSLATE_NOOP(
"QRegularExpression",
"DEFINE subpattern contains more than one branch"),
2971 QT_TRANSLATE_NOOP(
"QRegularExpression",
"internal error: unknown newline setting"),
2972 QT_TRANSLATE_NOOP(
"QRegularExpression",
"\\g is not followed by a braced, angle-bracketed, or quoted name/number or by a plain number"),
2973 QT_TRANSLATE_NOOP(
"QRegularExpression",
"(?R (recursive pattern call) must be followed by a closing parenthesis"),
2978 QT_TRANSLATE_NOOP(
"QRegularExpression",
"internal error: parsed pattern overflow"),
2979 QT_TRANSLATE_NOOP(
"QRegularExpression",
"non-octal character in \\o{} (closing brace missing?)"),
2980 QT_TRANSLATE_NOOP(
"QRegularExpression",
"different names for subpatterns of the same number are not allowed"),
2982 QT_TRANSLATE_NOOP(
"QRegularExpression",
"non-hex character in \\x{} (closing brace missing?)"),
2983 QT_TRANSLATE_NOOP(
"QRegularExpression",
"\\c must be followed by a printable ASCII character"),
2984 QT_TRANSLATE_NOOP(
"QRegularExpression",
"\\c must be followed by a letter or one of [\\]^_?"),
2985 QT_TRANSLATE_NOOP(
"QRegularExpression",
"\\k is not followed by a braced, angle-bracketed, or quoted name"),
2986 QT_TRANSLATE_NOOP(
"QRegularExpression",
"internal error: unknown meta code in check_lookbehinds()"),
2989 QT_TRANSLATE_NOOP(
"QRegularExpression",
"disallowed Unicode code point (>= 0xd800 && <= 0xdfff)"),
2990 QT_TRANSLATE_NOOP(
"QRegularExpression",
"using UTF is disabled by the application"),
2991 QT_TRANSLATE_NOOP(
"QRegularExpression",
"using UCP is disabled by the application"),
2992 QT_TRANSLATE_NOOP(
"QRegularExpression",
"name is too long in (*MARK), (*PRUNE), (*SKIP), or (*THEN)"),
2993 QT_TRANSLATE_NOOP(
"QRegularExpression",
"character code point value in \\u.... sequence is too large"),
2994 QT_TRANSLATE_NOOP(
"QRegularExpression",
"digits missing in \\x{} or \\o{} or \\N{U+}"),
2995 QT_TRANSLATE_NOOP(
"QRegularExpression",
"syntax error or number too big in (?(VERSION condition"),
2996 QT_TRANSLATE_NOOP(
"QRegularExpression",
"internal error: unknown opcode in auto_possessify()"),
2997 QT_TRANSLATE_NOOP(
"QRegularExpression",
"missing terminating delimiter for callout with string argument"),
2998 QT_TRANSLATE_NOOP(
"QRegularExpression",
"unrecognized string delimiter follows (?C"),
2999 QT_TRANSLATE_NOOP(
"QRegularExpression",
"using \\C is disabled by the application"),
3000 QT_TRANSLATE_NOOP(
"QRegularExpression",
"(?| and/or (?J: or (?x: parentheses are too deeply nested"),
3001 QT_TRANSLATE_NOOP(
"QRegularExpression",
"using \\C is disabled in this PCRE2 library"),
3002 QT_TRANSLATE_NOOP(
"QRegularExpression",
"regular expression is too complicated"),
3004 QT_TRANSLATE_NOOP(
"QRegularExpression",
"pattern string is longer than the limit set by the application"),
3005 QT_TRANSLATE_NOOP(
"QRegularExpression",
"internal error: unknown code in parsed pattern"),
3006 QT_TRANSLATE_NOOP(
"QRegularExpression",
"internal error: bad code value in parsed_skip()"),
3007 QT_TRANSLATE_NOOP(
"QRegularExpression",
"PCRE2_EXTRA_ALLOW_SURROGATE_ESCAPES is not allowed in UTF-16 mode"),
3008 QT_TRANSLATE_NOOP(
"QRegularExpression",
"invalid option bits with PCRE2_LITERAL"),
3009 QT_TRANSLATE_NOOP(
"QRegularExpression",
"\\N{U+dddd} is supported only in Unicode (UTF) mode"),
3012 QT_TRANSLATE_NOOP(
"QRegularExpression",
"script runs require Unicode support, which this version of PCRE2 does not have"),
3013 QT_TRANSLATE_NOOP(
"QRegularExpression",
"too many capturing groups (maximum 65535)"),
3014 QT_TRANSLATE_NOOP(
"QRegularExpression",
"atomic assertion expected after (?( or (?(?C)"),
3023 QT_TRANSLATE_NOOP(
"QRegularExpression",
"UTF-8 error: byte 2 top bits not 0x80"),
3024 QT_TRANSLATE_NOOP(
"QRegularExpression",
"UTF-8 error: byte 3 top bits not 0x80"),
3025 QT_TRANSLATE_NOOP(
"QRegularExpression",
"UTF-8 error: byte 4 top bits not 0x80"),
3026 QT_TRANSLATE_NOOP(
"QRegularExpression",
"UTF-8 error: byte 5 top bits not 0x80"),
3027 QT_TRANSLATE_NOOP(
"QRegularExpression",
"UTF-8 error: byte 6 top bits not 0x80"),
3028 QT_TRANSLATE_NOOP(
"QRegularExpression",
"UTF-8 error: 5-byte character is not allowed (RFC 3629)"),
3029 QT_TRANSLATE_NOOP(
"QRegularExpression",
"UTF-8 error: 6-byte character is not allowed (RFC 3629)"),
3030 QT_TRANSLATE_NOOP(
"QRegularExpression",
"UTF-8 error: code points greater than 0x10ffff are not defined"),
3031 QT_TRANSLATE_NOOP(
"QRegularExpression",
"UTF-8 error: code points 0xd800-0xdfff are not defined"),
3032 QT_TRANSLATE_NOOP(
"QRegularExpression",
"UTF-8 error: overlong 2-byte sequence"),
3033 QT_TRANSLATE_NOOP(
"QRegularExpression",
"UTF-8 error: overlong 3-byte sequence"),
3034 QT_TRANSLATE_NOOP(
"QRegularExpression",
"UTF-8 error: overlong 4-byte sequence"),
3035 QT_TRANSLATE_NOOP(
"QRegularExpression",
"UTF-8 error: overlong 5-byte sequence"),
3036 QT_TRANSLATE_NOOP(
"QRegularExpression",
"UTF-8 error: overlong 6-byte sequence"),
3037 QT_TRANSLATE_NOOP(
"QRegularExpression",
"UTF-8 error: isolated byte with 0x80 bit set"),
3038 QT_TRANSLATE_NOOP(
"QRegularExpression",
"UTF-8 error: illegal byte (0xfe or 0xff)"),
3039 QT_TRANSLATE_NOOP(
"QRegularExpression",
"UTF-16 error: missing low surrogate at end"),
3041 QT_TRANSLATE_NOOP(
"QRegularExpression",
"UTF-16 error: isolated low surrogate"),
3042 QT_TRANSLATE_NOOP(
"QRegularExpression",
"UTF-32 error: code points 0xd800-0xdfff are not defined"),
3043 QT_TRANSLATE_NOOP(
"QRegularExpression",
"UTF-32 error: code points greater than 0x10ffff are not defined"),
3045 QT_TRANSLATE_NOOP(
"QRegularExpression",
"patterns do not all use the same character tables"),
3047 QT_TRANSLATE_NOOP(
"QRegularExpression",
"pattern compiled in wrong mode: 8/16/32-bit error"),
3053 QT_TRANSLATE_NOOP(
"QRegularExpression",
"invalid data in workspace for DFA restart"),
3055 QT_TRANSLATE_NOOP(
"QRegularExpression",
"backreference condition or recursion test is not supported for DFA matching"),
3056 QT_TRANSLATE_NOOP(
"QRegularExpression",
"function is not supported for DFA matching"),
3057 QT_TRANSLATE_NOOP(
"QRegularExpression",
"pattern contains an item that is not supported for DFA matching"),
3058 QT_TRANSLATE_NOOP(
"QRegularExpression",
"workspace size exceeded in DFA matching"),
3059 QT_TRANSLATE_NOOP(
"QRegularExpression",
"internal error - pattern overwritten?"),
3067 QT_TRANSLATE_NOOP(
"QRegularExpression",
"nested recursion at the same subject position"),
3071 QT_TRANSLATE_NOOP(
"QRegularExpression",
"offset limit set without PCRE2_USE_OFFSET_LIMIT"),
3072 QT_TRANSLATE_NOOP(
"QRegularExpression",
"bad escape sequence in replacement string"),
3073 QT_TRANSLATE_NOOP(
"QRegularExpression",
"expected closing curly bracket in replacement string"),
3074 QT_TRANSLATE_NOOP(
"QRegularExpression",
"bad substitution in replacement string"),
3075 QT_TRANSLATE_NOOP(
"QRegularExpression",
"match with end before start or start moved backwards is not supported"),
3076 QT_TRANSLATE_NOOP(
"QRegularExpression",
"too many replacements (more than INT_MAX)"),
3080 QT_TRANSLATE_NOOP(
"QRegularExpression",
"internal error - duplicate substitution match"),
3081 QT_TRANSLATE_NOOP(
"QRegularExpression",
"PCRE2_MATCH_INVALID_UTF is not supported for DFA matching"),
3082 QT_TRANSLATE_NOOP(
"QRegularExpression",
"INTERNAL ERROR: invalid substring offset")
void reserve(qsizetype size)
Attempts to allocate memory for at least size bytes.
static QString translate(const char *context, const char *key, const char *disambiguation=nullptr, int n=-1)
\threadsafe
\inmodule QtCore\reentrant
void detach()
If the shared data object's reference count is greater than 1, this function creates a deep copy of t...
T * data() const noexcept
Returns a pointer to the shared data object.
const T * constData() const noexcept
Returns a const pointer to the shared data object.
const_reference at(qsizetype i) const noexcept
\inmodule QtCore \reentrant
QRegularExpressionMatch next()
Returns the next match result and advances the iterator by one position.
QRegularExpressionMatchIterator & operator=(const QRegularExpressionMatchIterator &iterator)
Assigns the iterator iterator to this object, and returns a reference to the copy.
bool isValid() const
Returns true if the iterator object was obtained as a result from the QRegularExpression::globalMatch...
~QRegularExpressionMatchIterator()
Destroys the QRegularExpressionMatchIterator object.
QRegularExpressionMatchIterator()
QRegularExpression::MatchOptions matchOptions() const
Returns the match options that were used to get this QRegularExpressionMatchIterator object,...
QRegularExpressionMatch peekNext() const
Returns the next match result without moving the iterator.
bool hasNext() const
Returns true if there is at least one match result ahead of the iterator; otherwise it returns false.
QRegularExpression::MatchType matchType() const
Returns the match type that was used to get this QRegularExpressionMatchIterator object,...
QRegularExpression regularExpression() const
Returns the QRegularExpression object whose globalMatch() function returned this object.
\inmodule QtCore \reentrant
QRegularExpression::MatchOptions matchOptions() const
Returns the match options that were used to get this QRegularExpressionMatch object,...
QRegularExpressionMatch()
QStringView capturedView(int nth=0) const
qsizetype capturedEnd(int nth=0) const
Returns the offset inside the subject string immediately after the ending position of the substring c...
QRegularExpression::MatchType matchType() const
Returns the match type that was used to get this QRegularExpressionMatch object, that is,...
~QRegularExpressionMatch()
Destroys the match result.
bool hasCaptured(QAnyStringView name) const
bool hasPartialMatch() const
Returns true if the regular expression partially matched against the subject string,...
bool isValid() const
Returns true if the match object was obtained as a result from the QRegularExpression::match() functi...
bool hasMatch() const
Returns true if the regular expression matched against the subject string, or false otherwise.
QStringList capturedTexts() const
Returns a list of all strings captured by capturing groups, in the order the groups themselves appear...
qsizetype capturedStart(int nth=0) const
Returns the offset inside the subject string corresponding to the starting position of the substring ...
qsizetype capturedLength(int nth=0) const
Returns the length of the substring captured by the nth capturing group.
int lastCapturedIndex() const
Returns the index of the last capturing group that captured something, including the implicit capturi...
QRegularExpressionMatch & operator=(const QRegularExpressionMatch &match)
Assigns the match result match to this object, and returns a reference to the copy.
QString captured(int nth=0) const
Returns the substring captured by the nth capturing group.
QRegularExpression regularExpression() const
Returns the QRegularExpression object whose match() function returned this object.
QDebug operator<<(QDebug debug, const QRegularExpressionMatch &match)
Writes the match object match into the debug object debug for debugging purposes.
\inmodule QtCore \reentrant
~QRegularExpression()
Destroys the QRegularExpression object.
bool isValid() const
Returns true if the regular expression is a valid regular expression (that is, it contains no syntax ...
@ AnchorAtOffsetMatchOption
@ DontCheckSubjectStringMatchOption
PatternOptions patternOptions() const
Returns the pattern options for the regular expression.
friend class QRegularExpressionMatch
void setPatternOptions(PatternOptions options)
Sets the given options as the pattern options of the regular expression.
int captureCount() const
Returns the number of capturing groups inside the pattern string, or -1 if the regular expression is ...
QDataStream & operator<<(QDataStream &out, const QRegularExpression &re)
Writes the regular expression re to stream out.
QRegularExpression & operator=(const QRegularExpression &re) noexcept
Assigns the regular expression re to this object, and returns a reference to the copy.
qsizetype patternErrorOffset() const
Returns the offset, inside the pattern string, at which an error was found when checking the validity...
static QString escape(const QString &str)
This is an overloaded member function, provided for convenience. It differs from the above function o...
QDataStream & operator>>(QDataStream &in, QRegularExpression &re)
Reads a regular expression from stream in into re.
static QRegularExpression fromWildcard(QStringView pattern, Qt::CaseSensitivity cs=Qt::CaseInsensitive, WildcardConversionOptions options=DefaultWildcardConversion)
void setPattern(const QString &pattern)
Sets the pattern string of the regular expression to pattern.
QStringList namedCaptureGroups() const
@ ExtendedPatternSyntaxOption
@ InvertedGreedinessOption
@ UseUnicodePropertiesOption
@ DotMatchesEverythingOption
friend struct QRegularExpressionMatchPrivate
MatchType
The MatchType enum defines the type of the match that should be attempted against the subject string.
@ PartialPreferCompleteMatch
@ PartialPreferFirstMatch
friend class QRegularExpressionMatchIterator
QRegularExpressionMatch matchView(QStringView subjectView, qsizetype offset=0, MatchType matchType=NormalMatch, MatchOptions matchOptions=NoMatchOption) const
QString pattern() const
Returns the pattern string of the regular expression.
QRegularExpressionMatch match(const QString &subject, qsizetype offset=0, MatchType matchType=NormalMatch, MatchOptions matchOptions=NoMatchOption) const
Attempts to match the regular expression against the given subject string, starting at the position o...
QDebug operator<<(QDebug debug, QRegularExpression::PatternOptions patternOptions)
Writes the pattern options patternOptions into the debug object debug for debugging purposes.
QRegularExpressionMatchIterator globalMatchView(QStringView subjectView, qsizetype offset=0, MatchType matchType=NormalMatch, MatchOptions matchOptions=NoMatchOption) const
QString errorString() const
Returns a textual description of the error found when checking the validity of the regular expression...
QRegularExpressionMatchIterator globalMatch(const QString &subject, qsizetype offset=0, MatchType matchType=NormalMatch, MatchOptions matchOptions=NoMatchOption) const
Attempts to perform a global match of the regular expression against the given subject string,...
static QString anchoredPattern(const QString &expression)
static QString wildcardToRegularExpression(const QString &str, WildcardConversionOptions options=DefaultWildcardConversion)
@ NonPathWildcardConversion
@ UnanchoredWildcardConversion
QDebug operator<<(QDebug debug, const QRegularExpression &re)
Writes the regular expression re into the debug object debug for debugging purposes.
QRegularExpression()
Constructs a QRegularExpression object with an empty pattern and no pattern options.
QString toString() const
Returns a deep copy of this string view's data as a QString.
constexpr QStringView mid(qsizetype pos, qsizetype n=-1) const noexcept
Returns the substring of length length starting at position start in this object.
\macro QT_RESTRICTED_CAST_FROM_ASCII
qsizetype size() const noexcept
Returns the number of characters in this string.
const QChar at(qsizetype i) const
Returns the character at the given index position in the string.
QChar * data()
Returns a pointer to the data stored in the QString.
void resize(qsizetype size)
Sets the size of the string to size characters.
Combined button and popup list for selecting options.
#define Q_DECL_COLD_FUNCTION
QList< QString > QStringList
Constructs a string list that contains the given string, str.
size_t qHash(const QFileSystemWatcherPathKey &key, size_t seed=0)
constexpr QtPrivate::QHashMultiReturnType< T... > qHashMulti(size_t seed, const T &... args) noexcept(std::conjunction_v< QtPrivate::QNothrowHashable< T >... >)
GLenum GLuint GLenum GLsizei length
GLenum GLenum GLsizei count
GLenum GLuint GLintptr offset
static Q_CONSTINIT QBasicAtomicInteger< unsigned > seed
static pcre2_jit_stack_16 * qtPcreCallback(void *)
bool comparesEqual(const QRegularExpression &lhs, const QRegularExpression &rhs) noexcept
static int convertToPcreOptions(QRegularExpression::PatternOptions patternOptions)
Q_DECL_COLD_FUNCTION void qtWarnAboutInvalidRegularExpression(const QString &pattern, const char *where)
static bool isJitEnabled()
static int safe_pcre2_match_16(const pcre2_code_16 *code, PCRE2_SPTR16 subject, qsizetype length, qsizetype startOffset, int options, pcre2_match_data_16 *matchData, pcre2_match_context_16 *matchContext)
QtPrivate::QRegularExpressionMatchIteratorRangeBasedForIterator begin(const QRegularExpressionMatchIterator &iterator)
#define QT_DEFINE_QESDP_SPECIALIZATION_DTOR(Class)
#define qUtf16Printable(string)
Q_CORE_EXPORT QByteArray qgetenv(const char *varName)
static bool match(const uchar *found, uint foundLen, const char *target, uint targetLen)
#define QT_TRANSLATE_NOOP(scope, x)
QSettings settings("MySoft", "Star Runner")
[0]
QTextStream out(stdout)
[7]
QRegularExpressionMatch next
QRegularExpressionMatchIteratorPrivate(const QRegularExpression &re, QRegularExpression::MatchType matchType, QRegularExpression::MatchOptions matchOptions, const QRegularExpressionMatch &next)
const QRegularExpression regularExpression
const QRegularExpression::MatchOptions matchOptions
const QRegularExpression::MatchType matchType
QList< qsizetype > capturedOffsets
QRegularExpressionMatchPrivate(const QRegularExpression &re, const QString &subjectStorage, QStringView subject, QRegularExpression::MatchType matchType, QRegularExpression::MatchOptions matchOptions)
const QRegularExpression::MatchType matchType
const QRegularExpression::MatchOptions matchOptions
const QString subjectStorage
QRegularExpressionMatch nextMatch() const
const QRegularExpression regularExpression
const QStringView subject
int captureIndexForName(QAnyStringView name) const
void doMatch(QRegularExpressionMatchPrivate *priv, qsizetype offset, CheckSubjectStringOption checkSubjectStringOption=CheckSubjectString, const QRegularExpressionMatchPrivate *previous=nullptr) const
void cleanCompiledPattern()
QRegularExpressionPrivate()
pcre2_code_16 * compiledPattern
~QRegularExpressionPrivate()
QRegularExpression::PatternOptions patternOptions