From 6e3b4ddd9256801dc7d0c245808e81dc669b1f2f Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Sat, 23 Nov 2019 15:05:35 +0100 Subject: QRegularExpression: adjust the error codes matching PCRE2 10.34 Change-Id: I78ecda1bdc784b8d7a69a4927dbe3b0f08c1d907 Reviewed-by: Thiago Macieira Reviewed-by: Oswald Buddenhagen --- src/corelib/text/qregularexpression.cpp | 65 ++++++++++++++++++++------------- 1 file changed, 40 insertions(+), 25 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/text/qregularexpression.cpp b/src/corelib/text/qregularexpression.cpp index a02d471134..8627cbba4f 100644 --- a/src/corelib/text/qregularexpression.cpp +++ b/src/corelib/text/qregularexpression.cpp @@ -2867,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"), @@ -2884,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"), @@ -2931,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"), @@ -2950,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"), @@ -2987,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"), @@ -3003,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 -- cgit v1.2.3 From 27d139128013c969a939779536485c1a80be977e Mon Sep 17 00:00:00 2001 From: Tuomas Heimonen Date: Fri, 29 Nov 2019 09:27:35 +0200 Subject: QLocale: Support Indian number formatting When QLocale::Country is set to QLocale::India numbers are written so that after first three from the right and then after every second will be comma. E.g. 10000000 is written as 1,00,00,000 Task-number: QTBUG-24301 Change-Id: Ic06241c127b0af1824104f94f7e2ce6e2058a070 Reviewed-by: Venugopal Shivashankar Reviewed-by: Teemu Holappa --- src/corelib/text/qlocale.cpp | 45 +++++++++++++++++++++++++++++++++----------- src/corelib/text/qlocale_p.h | 3 ++- 2 files changed, 36 insertions(+), 12 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/text/qlocale.cpp b/src/corelib/text/qlocale.cpp index 75a5bc802e..425cb87d31 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); } @@ -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 }; -- cgit v1.2.3