summaryrefslogtreecommitdiffstats
path: root/src/corelib/text
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/text')
-rw-r--r--src/corelib/text/qbytearray.cpp13
-rw-r--r--src/corelib/text/qchar.cpp2
-rw-r--r--src/corelib/text/qlocale.cpp47
-rw-r--r--src/corelib/text/qlocale_p.h3
-rw-r--r--src/corelib/text/qlocale_unix.cpp4
-rw-r--r--src/corelib/text/qregexp.cpp8
-rw-r--r--src/corelib/text/qregularexpression.cpp97
-rw-r--r--src/corelib/text/qstring.cpp29
-rw-r--r--src/corelib/text/qstring.h2
-rw-r--r--src/corelib/text/qstringalgorithms.h1
-rw-r--r--src/corelib/text/qstringview.cpp15
-rw-r--r--src/corelib/text/qstringview.h2
12 files changed, 172 insertions, 51 deletions
diff --git a/src/corelib/text/qbytearray.cpp b/src/corelib/text/qbytearray.cpp
index 3fa1868437..ac5f2afb57 100644
--- a/src/corelib/text/qbytearray.cpp
+++ b/src/corelib/text/qbytearray.cpp
@@ -4999,7 +4999,7 @@ QByteArray QByteArray::toPercentEncoding(const QByteArray &exclude, const QByteA
*/
/*!
- \fn QByteArray::FromBase64Result::operator QByteArray() const
+ \fn QByteArray &QByteArray::FromBase64Result::operator*() const
Returns the decoded byte array.
*/
@@ -5008,17 +5008,18 @@ QByteArray QByteArray::toPercentEncoding(const QByteArray &exclude, const QByteA
\fn bool operator==(const QByteArray::FromBase64Result &lhs, const QByteArray::FromBase64Result &rhs) noexcept
\relates QByteArray::FromBase64Result
- Compares \a lhs and \a rhs for equality. \a lhs and \a rhs are equal
- if and only if they contain the same decoding status and, if the
- status is QByteArray::Base64DecodingStatus::Ok, if and only if
- they contain the same decoded data.
+ Returns \c true if \a lhs and \a rhs are equal, otherwise returns \c false.
+
+ \a lhs and \a rhs are equal if and only if they contain the same decoding
+ status and, if the status is QByteArray::Base64DecodingStatus::Ok, if and
+ only if they contain the same decoded data.
*/
/*!
\fn bool operator!=(const QByteArray::FromBase64Result &lhs, const QByteArray::FromBase64Result &rhs) noexcept
\relates QByteArray::FromBase64Result
- Compares \a lhs and \a rhs for inequality.
+ Returns \c true if \a lhs and \a rhs are different, otherwise returns \c false.
*/
/*!
diff --git a/src/corelib/text/qchar.cpp b/src/corelib/text/qchar.cpp
index 847b4f0b08..61b61125b1 100644
--- a/src/corelib/text/qchar.cpp
+++ b/src/corelib/text/qchar.cpp
@@ -418,7 +418,7 @@ QT_BEGIN_NAMESPACE
\value Script_Sogdian Since Qt 5.15
\value Script_SoraSompeng
\value Script_Soyombo Since Qt 5.11
- \value Script_Sundaneseo
+ \value Script_Sundanese
\value Script_SylotiNagri
\value Script_Syriac
\value Script_Tagalog
diff --git a/src/corelib/text/qlocale.cpp b/src/corelib/text/qlocale.cpp
index 694d491273..c643c2a514 100644
--- a/src/corelib/text/qlocale.cpp
+++ b/src/corelib/text/qlocale.cpp
@@ -1969,7 +1969,8 @@ QString QLocale::toString(qlonglong i) const
{
int flags = d->m_numberOptions & OmitGroupSeparator
? 0
- : QLocaleData::ThousandsGroup;
+ : (d->m_data->m_country_id == Country::India)
+ ? QLocaleData::IndianNumberGrouping : QLocaleData::ThousandsGroup;
return d->m_data->longLongToString(i, -1, 10, -1, flags);
}
@@ -1984,7 +1985,8 @@ QString QLocale::toString(qulonglong i) const
{
int flags = d->m_numberOptions & OmitGroupSeparator
? 0
- : QLocaleData::ThousandsGroup;
+ : (d->m_data->m_country_id == Country::India)
+ ? QLocaleData::IndianNumberGrouping : QLocaleData::ThousandsGroup;
return d->m_data->unsLongLongToString(i, -1, 10, -1, flags);
}
@@ -3065,7 +3067,7 @@ QList<Qt::DayOfWeek> QLocale::weekdays() const
if (d->m_data == systemData()) {
QVariant res = systemLocale()->query(QSystemLocale::Weekdays, QVariant());
if (!res.isNull())
- return static_cast<QList<Qt::DayOfWeek> >(res.value<QList<Qt::DayOfWeek> >());
+ return static_cast<QList<Qt::DayOfWeek> >(qvariant_cast<QList<Qt::DayOfWeek> >(res));
}
#endif
QList<Qt::DayOfWeek> weekdays;
@@ -3626,10 +3628,19 @@ QT_WARNING_DISABLE_MSVC(4146)
QT_WARNING_POP
uint cnt_thousand_sep = 0;
- if (flags & ThousandsGroup && base == 10) {
- for (int i = num_str.length() - 3; i > 0; i -= 3) {
- num_str.insert(i, group);
- ++cnt_thousand_sep;
+ if (base == 10){
+ if (flags & ThousandsGroup) {
+ for (int i = num_str.length() - 3; i > 0; i -= 3) {
+ num_str.insert(i, group);
+ ++cnt_thousand_sep;
+ }
+ } else if (flags & IndianNumberGrouping) {
+ if (num_str.length() > 3)
+ num_str.insert(num_str.length() - 3 , group);
+ for (int i = num_str.length() - 6; i > 0; i -= 2) {
+ num_str.insert(i, group);
+ ++cnt_thousand_sep;
+ }
}
}
@@ -3713,10 +3724,19 @@ QString QLocaleData::unsLongLongToString(const QChar zero, const QChar group,
}
uint cnt_thousand_sep = 0;
- if (flags & ThousandsGroup && base == 10) {
- for (int i = num_str.length() - 3; i > 0; i -=3) {
- num_str.insert(i, group);
- ++cnt_thousand_sep;
+ if (base == 10) {
+ if (flags & ThousandsGroup) {
+ for (int i = num_str.length() - 3; i > 0; i -=3) {
+ num_str.insert(i, group);
+ ++cnt_thousand_sep;
+ }
+ } else if (flags & IndianNumberGrouping) {
+ if (num_str.length() > 3)
+ num_str.insert(num_str.length() - 3 , group);
+ for (int i = num_str.length() - 6; i > 0; i -= 2) {
+ num_str.insert(i, group);
+ ++cnt_thousand_sep;
+ }
}
}
@@ -3851,7 +3871,10 @@ bool QLocaleData::numberToCLocale(QStringView s, QLocale::NumberOptions number_o
// check distance from the last separator or from the beginning of the digits
// ### FIXME: Some locales allow other groupings!
// See https://en.wikipedia.org/wiki/Thousands_separator
- if (last_separator_idx != -1 && idx - last_separator_idx != 4)
+ if (m_country_id == QLocale::India) {
+ if (last_separator_idx != -1 && idx - last_separator_idx != 3)
+ return false;
+ } else if (last_separator_idx != -1 && idx - last_separator_idx != 4)
return false;
if (last_separator_idx == -1
&& (start_of_digits_idx == -1 || idx - start_of_digits_idx > 3)) {
diff --git a/src/corelib/text/qlocale_p.h b/src/corelib/text/qlocale_p.h
index edee3a89c7..bb24009523 100644
--- a/src/corelib/text/qlocale_p.h
+++ b/src/corelib/text/qlocale_p.h
@@ -213,7 +213,8 @@ public:
ShowBase = 0x80,
UppercaseBase = 0x100,
ZeroPadExponent = 0x200,
- ForcePoint = 0x400
+ ForcePoint = 0x400,
+ IndianNumberGrouping= 0x800
};
enum NumberMode { IntegerMode, DoubleStandardMode, DoubleScientificMode };
diff --git a/src/corelib/text/qlocale_unix.cpp b/src/corelib/text/qlocale_unix.cpp
index ff4274d932..5e1e47eae7 100644
--- a/src/corelib/text/qlocale_unix.cpp
+++ b/src/corelib/text/qlocale_unix.cpp
@@ -283,9 +283,9 @@ QVariant QSystemLocale::query(QueryType type, QVariant in) const
return d->uiLanguages.isEmpty() ? QVariant() : QVariant(d->uiLanguages);
}
case StringToStandardQuotation:
- return lc_messages.quoteString(in.value<QStringRef>());
+ return lc_messages.quoteString(qvariant_cast<QStringRef>(in));
case StringToAlternateQuotation:
- return lc_messages.quoteString(in.value<QStringRef>(), QLocale::AlternateQuotation);
+ return lc_messages.quoteString(qvariant_cast<QStringRef>(in), QLocale::AlternateQuotation);
case ListToSeparatedString:
return lc_messages.createSeparatedList(in.toStringList());
case LocaleChanged:
diff --git a/src/corelib/text/qregexp.cpp b/src/corelib/text/qregexp.cpp
index ac4d9bbc36..9301a7e573 100644
--- a/src/corelib/text/qregexp.cpp
+++ b/src/corelib/text/qregexp.cpp
@@ -2528,7 +2528,7 @@ void QRegExpEngine::Box::cat(const Box &b)
eng->addCatTransitions(rs, b.ls);
addAnchorsToEngine(b);
if (minl == 0) {
- lanchors.unite(b.lanchors);
+ lanchors.insert(b.lanchors);
if (skipanchors != 0) {
for (int i = 0; i < b.ls.size(); i++) {
int a = eng->anchorConcatenation(lanchors.value(b.ls.at(i), 0), skipanchors);
@@ -2538,7 +2538,7 @@ void QRegExpEngine::Box::cat(const Box &b)
mergeInto(&ls, b.ls);
}
if (b.minl == 0) {
- ranchors.unite(b.ranchors);
+ ranchors.insert(b.ranchors);
if (b.skipanchors != 0) {
for (int i = 0; i < rs.size(); i++) {
int a = eng->anchorConcatenation(ranchors.value(rs.at(i), 0), b.skipanchors);
@@ -2596,9 +2596,9 @@ void QRegExpEngine::Box::cat(const Box &b)
void QRegExpEngine::Box::orx(const Box &b)
{
mergeInto(&ls, b.ls);
- lanchors.unite(b.lanchors);
+ lanchors.insert(b.lanchors);
mergeInto(&rs, b.rs);
- ranchors.unite(b.ranchors);
+ ranchors.insert(b.ranchors);
if (b.minl == 0) {
if (minl == 0)
diff --git a/src/corelib/text/qregularexpression.cpp b/src/corelib/text/qregularexpression.cpp
index e05bef450b..068c960910 100644
--- a/src/corelib/text/qregularexpression.cpp
+++ b/src/corelib/text/qregularexpression.cpp
@@ -443,6 +443,38 @@ QT_BEGIN_NAMESPACE
Other differences are outlined below.
+ \section2 Different pattern syntax
+
+ Porting a regular expression from QRegExp to QRegularExpression may require
+ changes to the pattern itself.
+
+ In certain scenarios, QRegExp was too lenient and accepted patterns that
+ are simply invalid when using QRegularExpression. These are somehow easy
+ to detect, because the QRegularExpression objects built with these patterns
+ are not valid (cf. isValid()).
+
+ In other cases, a pattern ported from QRegExp to QRegularExpression may
+ silently change semantics. Therefore, it is necessary to review the
+ patterns used. The most notable cases of silent incompatibility are:
+
+ \list
+
+ \li Curly braces are needed in order to use a hexadecimal escape like
+ \c{\xHHHH} with more than 2 digits. A pattern like \c{\x2022} neeeds to
+ be ported to \c{\x{2022}}, or it will match a space (\c{0x20}) followed
+ by the string \c{"22"}. In general, it is highly recommended to always use
+ curly braces with the \c{\\x} escape, no matter the amount of digits
+ specified.
+
+ \li A 0-to-n quantification like \c{{,n}} needs to be ported to c{{0,n}} to
+ preserve semantics. Otherwise, a pattern such as \c{\d{,3}} would
+ actually match a digit followed by the exact string \c{"{,3}"}.
+
+ \li QRegExp by default does Unicode-aware matching, while
+ QRegularExpression requires a separate option; see below for more details.
+
+ \endlist
+
\section2 Porting from QRegExp::exactMatch()
QRegExp::exactMatch() in Qt 4 served two purposes: it exactly matched
@@ -2835,7 +2867,7 @@ static const char *pcreCompileErrorCodes[] =
QT_TRANSLATE_NOOP("QRegularExpression", "numbers out of order in {} quantifier"),
QT_TRANSLATE_NOOP("QRegularExpression", "number too big in {} quantifier"),
QT_TRANSLATE_NOOP("QRegularExpression", "missing terminating ] for character class"),
- QT_TRANSLATE_NOOP("QRegularExpression", "invalid escape sequence in character class"),
+ QT_TRANSLATE_NOOP("QRegularExpression", "escape sequence is invalid in character class"),
QT_TRANSLATE_NOOP("QRegularExpression", "range out of order in character class"),
QT_TRANSLATE_NOOP("QRegularExpression", "quantifier does not follow a repeatable item"),
QT_TRANSLATE_NOOP("QRegularExpression", "internal error: unexpected repeat"),
@@ -2852,46 +2884,46 @@ static const char *pcreCompileErrorCodes[] =
QT_TRANSLATE_NOOP("QRegularExpression", "failed to allocate heap memory"),
QT_TRANSLATE_NOOP("QRegularExpression", "unmatched closing parenthesis"),
QT_TRANSLATE_NOOP("QRegularExpression", "internal error: code overflow"),
- QT_TRANSLATE_NOOP("QRegularExpression", "letter or underscore expected after (?< or (?'"),
+ QT_TRANSLATE_NOOP("QRegularExpression", "missing closing parenthesis for condition"),
QT_TRANSLATE_NOOP("QRegularExpression", "lookbehind assertion is not fixed length"),
- QT_TRANSLATE_NOOP("QRegularExpression", "malformed number or name after (?("),
- QT_TRANSLATE_NOOP("QRegularExpression", "conditional group contains more than two branches"),
+ QT_TRANSLATE_NOOP("QRegularExpression", "a relative value of zero is not allowed"),
+ QT_TRANSLATE_NOOP("QRegularExpression", "conditional subpattern contains more than two branches"),
QT_TRANSLATE_NOOP("QRegularExpression", "assertion expected after (?( or (?(?C)"),
- QT_TRANSLATE_NOOP("QRegularExpression", "(?R or (?[+-]digits must be followed by )"),
+ QT_TRANSLATE_NOOP("QRegularExpression", "digit expected after (?+ or (?-"),
QT_TRANSLATE_NOOP("QRegularExpression", "unknown POSIX class name"),
QT_TRANSLATE_NOOP("QRegularExpression", "internal error in pcre2_study(): should not occur"),
QT_TRANSLATE_NOOP("QRegularExpression", "this version of PCRE2 does not have Unicode support"),
QT_TRANSLATE_NOOP("QRegularExpression", "parentheses are too deeply nested (stack check)"),
QT_TRANSLATE_NOOP("QRegularExpression", "character code point value in \\x{} or \\o{} is too large"),
- QT_TRANSLATE_NOOP("QRegularExpression", "invalid condition (?(0)"),
- QT_TRANSLATE_NOOP("QRegularExpression", "\\C is not allowed in a lookbehind assertion"),
- QT_TRANSLATE_NOOP("QRegularExpression", "PCRE does not support \\L, \\l, \\N{name}, \\U, or \\u"),
+ QT_TRANSLATE_NOOP("QRegularExpression", "lookbehind is too complicated"),
+ QT_TRANSLATE_NOOP("QRegularExpression", "\\C is not allowed in a lookbehind assertion in UTF-" "16" " mode"),
+ QT_TRANSLATE_NOOP("QRegularExpression", "PCRE2 does not support \\F, \\L, \\l, \\N{name}, \\U, or \\u"),
QT_TRANSLATE_NOOP("QRegularExpression", "number after (?C is greater than 255"),
QT_TRANSLATE_NOOP("QRegularExpression", "closing parenthesis for (?C expected"),
QT_TRANSLATE_NOOP("QRegularExpression", "invalid escape sequence in (*VERB) name"),
QT_TRANSLATE_NOOP("QRegularExpression", "unrecognized character after (?P"),
- QT_TRANSLATE_NOOP("QRegularExpression", "syntax error in subpattern name (missing terminator)"),
+ QT_TRANSLATE_NOOP("QRegularExpression", "syntax error in subpattern name (missing terminator?)"),
QT_TRANSLATE_NOOP("QRegularExpression", "two named subpatterns have the same name (PCRE2_DUPNAMES not set)"),
- QT_TRANSLATE_NOOP("QRegularExpression", "group name must start with a non-digit"),
+ QT_TRANSLATE_NOOP("QRegularExpression", "subpattern name must start with a non-digit"),
QT_TRANSLATE_NOOP("QRegularExpression", "this version of PCRE2 does not have support for \\P, \\p, or \\X"),
QT_TRANSLATE_NOOP("QRegularExpression", "malformed \\P or \\p sequence"),
QT_TRANSLATE_NOOP("QRegularExpression", "unknown property name after \\P or \\p"),
- QT_TRANSLATE_NOOP("QRegularExpression", "subpattern name is too long (maximum " "10000" " characters)"),
- QT_TRANSLATE_NOOP("QRegularExpression", "too many named subpatterns (maximum " "256" ")"),
+ QT_TRANSLATE_NOOP("QRegularExpression", "subpattern name is too long (maximum " "32" " code units)"),
+ QT_TRANSLATE_NOOP("QRegularExpression", "too many named subpatterns (maximum " "10000" ")"),
QT_TRANSLATE_NOOP("QRegularExpression", "invalid range in character class"),
QT_TRANSLATE_NOOP("QRegularExpression", "octal value is greater than \\377 in 8-bit non-UTF-8 mode"),
QT_TRANSLATE_NOOP("QRegularExpression", "internal error: overran compiling workspace"),
QT_TRANSLATE_NOOP("QRegularExpression", "internal error: previously-checked referenced subpattern not found"),
- QT_TRANSLATE_NOOP("QRegularExpression", "DEFINE group contains more than one branch"),
+ QT_TRANSLATE_NOOP("QRegularExpression", "DEFINE subpattern contains more than one branch"),
QT_TRANSLATE_NOOP("QRegularExpression", "missing opening brace after \\o"),
QT_TRANSLATE_NOOP("QRegularExpression", "internal error: unknown newline setting"),
QT_TRANSLATE_NOOP("QRegularExpression", "\\g is not followed by a braced, angle-bracketed, or quoted name/number or by a plain number"),
- QT_TRANSLATE_NOOP("QRegularExpression", "a numbered reference must not be zero"),
- QT_TRANSLATE_NOOP("QRegularExpression", "an argument is not allowed for (*ACCEPT), (*FAIL), or (*COMMIT)"),
+ QT_TRANSLATE_NOOP("QRegularExpression", "(?R (recursive pattern call) must be followed by a closing parenthesis"),
+ QT_TRANSLATE_NOOP("QRegularExpression", "obsolete error (should not occur)"),
QT_TRANSLATE_NOOP("QRegularExpression", "(*VERB) not recognized or malformed"),
- QT_TRANSLATE_NOOP("QRegularExpression", "number is too big"),
+ QT_TRANSLATE_NOOP("QRegularExpression", "subpattern number is too big"),
QT_TRANSLATE_NOOP("QRegularExpression", "subpattern name expected"),
- QT_TRANSLATE_NOOP("QRegularExpression", "digit expected after (?+"),
+ QT_TRANSLATE_NOOP("QRegularExpression", "internal error: parsed pattern overflow"),
QT_TRANSLATE_NOOP("QRegularExpression", "non-octal character in \\o{} (closing brace missing?)"),
QT_TRANSLATE_NOOP("QRegularExpression", "different names for subpatterns of the same number are not allowed"),
QT_TRANSLATE_NOOP("QRegularExpression", "(*MARK) must have an argument"),
@@ -2899,16 +2931,16 @@ static const char *pcreCompileErrorCodes[] =
QT_TRANSLATE_NOOP("QRegularExpression", "\\c must be followed by a printable ASCII character"),
QT_TRANSLATE_NOOP("QRegularExpression", "\\c must be followed by a letter or one of [\\]^_?"),
QT_TRANSLATE_NOOP("QRegularExpression", "\\k is not followed by a braced, angle-bracketed, or quoted name"),
- QT_TRANSLATE_NOOP("QRegularExpression", "internal error: unknown opcode in find_fixedlength()"),
+ QT_TRANSLATE_NOOP("QRegularExpression", "internal error: unknown meta code in check_lookbehinds()"),
QT_TRANSLATE_NOOP("QRegularExpression", "\\N is not supported in a class"),
- QT_TRANSLATE_NOOP("QRegularExpression", "SPARE ERROR"),
+ QT_TRANSLATE_NOOP("QRegularExpression", "callout string is too long"),
QT_TRANSLATE_NOOP("QRegularExpression", "disallowed Unicode code point (>= 0xd800 && <= 0xdfff)"),
QT_TRANSLATE_NOOP("QRegularExpression", "using UTF is disabled by the application"),
QT_TRANSLATE_NOOP("QRegularExpression", "using UCP is disabled by the application"),
QT_TRANSLATE_NOOP("QRegularExpression", "name is too long in (*MARK), (*PRUNE), (*SKIP), or (*THEN)"),
QT_TRANSLATE_NOOP("QRegularExpression", "character code point value in \\u.... sequence is too large"),
- QT_TRANSLATE_NOOP("QRegularExpression", "digits missing in \\x{} or \\o{}"),
- QT_TRANSLATE_NOOP("QRegularExpression", "syntax error in (?(VERSION condition"),
+ QT_TRANSLATE_NOOP("QRegularExpression", "digits missing in \\x{} or \\o{} or \\N{U+}"),
+ QT_TRANSLATE_NOOP("QRegularExpression", "syntax error or number too big in (?(VERSION condition"),
QT_TRANSLATE_NOOP("QRegularExpression", "internal error: unknown opcode in auto_possessify()"),
QT_TRANSLATE_NOOP("QRegularExpression", "missing terminating delimiter for callout with string argument"),
QT_TRANSLATE_NOOP("QRegularExpression", "unrecognized string delimiter follows (?C"),
@@ -2918,6 +2950,16 @@ static const char *pcreCompileErrorCodes[] =
QT_TRANSLATE_NOOP("QRegularExpression", "regular expression is too complicated"),
QT_TRANSLATE_NOOP("QRegularExpression", "lookbehind assertion is too long"),
QT_TRANSLATE_NOOP("QRegularExpression", "pattern string is longer than the limit set by the application"),
+ QT_TRANSLATE_NOOP("QRegularExpression", "internal error: unknown code in parsed pattern"),
+ QT_TRANSLATE_NOOP("QRegularExpression", "internal error: bad code value in parsed_skip()"),
+ QT_TRANSLATE_NOOP("QRegularExpression", "PCRE2_EXTRA_ALLOW_SURROGATE_ESCAPES is not allowed in UTF-16 mode"),
+ QT_TRANSLATE_NOOP("QRegularExpression", "invalid option bits with PCRE2_LITERAL"),
+ QT_TRANSLATE_NOOP("QRegularExpression", "\\N{U+dddd} is supported only in Unicode (UTF) mode"),
+ QT_TRANSLATE_NOOP("QRegularExpression", "invalid hyphen in option setting"),
+ QT_TRANSLATE_NOOP("QRegularExpression", "(*alpha_assertion) not recognized"),
+ QT_TRANSLATE_NOOP("QRegularExpression", "script runs require Unicode support, which this version of PCRE2 does not have"),
+ QT_TRANSLATE_NOOP("QRegularExpression", "too many capturing groups (maximum 65535)"),
+ QT_TRANSLATE_NOOP("QRegularExpression", "atomic assertion expected after (?( or (?(?C)"),
QT_TRANSLATE_NOOP("QRegularExpression", "no error"),
QT_TRANSLATE_NOOP("QRegularExpression", "no match"),
QT_TRANSLATE_NOOP("QRegularExpression", "partial match"),
@@ -2955,7 +2997,7 @@ static const char *pcreCompileErrorCodes[] =
QT_TRANSLATE_NOOP("QRegularExpression", "bad option value"),
QT_TRANSLATE_NOOP("QRegularExpression", "invalid replacement string"),
QT_TRANSLATE_NOOP("QRegularExpression", "bad offset into UTF string"),
- QT_TRANSLATE_NOOP("QRegularExpression", "callout error code"), /* Never returned by PCRE2 itself */
+ QT_TRANSLATE_NOOP("QRegularExpression", "callout error code"),
QT_TRANSLATE_NOOP("QRegularExpression", "invalid data in workspace for DFA restart"),
QT_TRANSLATE_NOOP("QRegularExpression", "too much recursion for DFA matching"),
QT_TRANSLATE_NOOP("QRegularExpression", "backreference condition or recursion test is not supported for DFA matching"),
@@ -2971,15 +3013,20 @@ static const char *pcreCompileErrorCodes[] =
QT_TRANSLATE_NOOP("QRegularExpression", "non-unique substring name"),
QT_TRANSLATE_NOOP("QRegularExpression", "NULL argument passed"),
QT_TRANSLATE_NOOP("QRegularExpression", "nested recursion at the same subject position"),
- QT_TRANSLATE_NOOP("QRegularExpression", "recursion limit exceeded"),
+ QT_TRANSLATE_NOOP("QRegularExpression", "matching depth limit exceeded"),
QT_TRANSLATE_NOOP("QRegularExpression", "requested value is not available"),
QT_TRANSLATE_NOOP("QRegularExpression", "requested value is not set"),
QT_TRANSLATE_NOOP("QRegularExpression", "offset limit set without PCRE2_USE_OFFSET_LIMIT"),
QT_TRANSLATE_NOOP("QRegularExpression", "bad escape sequence in replacement string"),
QT_TRANSLATE_NOOP("QRegularExpression", "expected closing curly bracket in replacement string"),
QT_TRANSLATE_NOOP("QRegularExpression", "bad substitution in replacement string"),
- QT_TRANSLATE_NOOP("QRegularExpression", "match with end before start is not supported"),
- QT_TRANSLATE_NOOP("QRegularExpression", "too many replacements (more than INT_MAX)")
+ QT_TRANSLATE_NOOP("QRegularExpression", "match with end before start or start moved backwards is not supported"),
+ QT_TRANSLATE_NOOP("QRegularExpression", "too many replacements (more than INT_MAX)"),
+ QT_TRANSLATE_NOOP("QRegularExpression", "bad serialized data"),
+ QT_TRANSLATE_NOOP("QRegularExpression", "heap limit exceeded"),
+ QT_TRANSLATE_NOOP("QRegularExpression", "invalid syntax"),
+ QT_TRANSLATE_NOOP("QRegularExpression", "internal error - duplicate substitution match"),
+ QT_TRANSLATE_NOOP("QRegularExpression", "PCRE2_MATCH_INVALID_UTF is not supported for DFA matching")
};
#endif // #if 0
diff --git a/src/corelib/text/qstring.cpp b/src/corelib/text/qstring.cpp
index 4234b3c402..51d383ea18 100644
--- a/src/corelib/text/qstring.cpp
+++ b/src/corelib/text/qstring.cpp
@@ -591,6 +591,20 @@ bool QtPrivate::isLatin1(QStringView s) noexcept
return true;
}
+bool QtPrivate::isValidUtf16(QStringView s) noexcept
+{
+ Q_CONSTEXPR uint InvalidCodePoint = UINT_MAX;
+
+ QStringIterator i(s);
+ while (i.hasNext()) {
+ uint c = i.next(InvalidCodePoint);
+ if (c == InvalidCodePoint)
+ return false;
+ }
+
+ return true;
+}
+
// conversion between Latin 1 and UTF-16
void qt_from_latin1(ushort *dst, const char *str, size_t size) noexcept
{
@@ -8924,6 +8938,21 @@ bool QString::isRightToLeft() const
return QtPrivate::isRightToLeft(QStringView(*this));
}
+/*!
+ \fn bool QString::isValidUtf16() const noexcept
+ \since 5.15
+
+ Returns \c true if the string contains valid UTF-16 encoded data,
+ or \c false otherwise.
+
+ Note that this function does not perform any special validation of the
+ data; it merely checks if it can be successfully decoded from UTF-16.
+ The data is assumed to be in host byte order; the presence of a BOM
+ is meaningless.
+
+ \sa QStringView::isValidUtf16()
+*/
+
/*! \fn QChar *QString::data()
Returns a pointer to the data stored in the QString. The pointer
diff --git a/src/corelib/text/qstring.h b/src/corelib/text/qstring.h
index 0350dabfc9..65d702ff1c 100644
--- a/src/corelib/text/qstring.h
+++ b/src/corelib/text/qstring.h
@@ -916,6 +916,8 @@ public:
bool isSimpleText() const;
bool isRightToLeft() const;
+ Q_REQUIRED_RESULT bool isValidUtf16() const noexcept
+ { return QStringView(*this).isValidUtf16(); }
QString(int size, Qt::Initialization);
explicit QString(DataPointer dd) : d(dd) {}
diff --git a/src/corelib/text/qstringalgorithms.h b/src/corelib/text/qstringalgorithms.h
index d54e376aa9..0b7774b4f3 100644
--- a/src/corelib/text/qstringalgorithms.h
+++ b/src/corelib/text/qstringalgorithms.h
@@ -99,6 +99,7 @@ Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool isAscii(QLatin1String
Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool isAscii(QStringView s) noexcept;
Q_REQUIRED_RESULT Q_DECL_CONSTEXPR inline bool isLatin1(QLatin1String s) noexcept;
Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool isLatin1(QStringView s) noexcept;
+Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool isValidUtf16(QStringView s) noexcept;
} // namespace QtPRivate
diff --git a/src/corelib/text/qstringview.cpp b/src/corelib/text/qstringview.cpp
index 75de827583..c4ddb06ea4 100644
--- a/src/corelib/text/qstringview.cpp
+++ b/src/corelib/text/qstringview.cpp
@@ -865,6 +865,21 @@ QT_BEGIN_NAMESPACE
*/
/*!
+ \fn bool QStringView::isValidUtf16() const
+ \since 5.15
+
+ Returns \c true if the string contains valid UTF-16 encoded data,
+ or \c false otherwise.
+
+ Note that this function does not perform any special validation of the
+ data; it merely checks if it can be successfully decoded from UTF-16.
+ The data is assumed to be in host byte order; the presence of a BOM
+ is meaningless.
+
+ \sa QString::isValidUtf16()
+*/
+
+/*!
\fn QStringView::toWCharArray(wchar_t *array) const
\since 5.14
diff --git a/src/corelib/text/qstringview.h b/src/corelib/text/qstringview.h
index 4ab4d2570f..06391ffef4 100644
--- a/src/corelib/text/qstringview.h
+++ b/src/corelib/text/qstringview.h
@@ -294,6 +294,8 @@ public:
Q_REQUIRED_RESULT bool isRightToLeft() const noexcept
{ return QtPrivate::isRightToLeft(*this); }
+ Q_REQUIRED_RESULT bool isValidUtf16() const noexcept
+ { return QtPrivate::isValidUtf16(*this); }
Q_REQUIRED_RESULT inline int toWCharArray(wchar_t *array) const; // defined in qstring.h