summaryrefslogtreecommitdiffstats
path: root/src/corelib/text/qlocale_tools.cpp
Commit message (Collapse)AuthorAgeFilesLines
* QLocale: add a Q_CHECK_PTRGiuseppe D'Angelo2021-01-201-0/+1
| | | | | | | | | Avoid complaints from static analyzers that the pointer returned by malloc might be null. Change-Id: I3ec3ba03d0b5283dd569200a3040a5fe5990f763 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Mark two impossible code-paths with Q_UNREACHABLEEdward Welbourne2020-11-271-1/+2
| | | | | | Change-Id: I8c04f512b078d4c13d759854b65f4d39b7b80e75 Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io> Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
* Performance improvement for integer->QString conversionAndreas Buhr2020-10-311-4/+43
| | | | | | | | | | | | | The compiler can generate better code when the base is known in integer to string conversion. This patch creates separate branches for known bases and leaves generic code as a fallback. Saved about 12ns per conversion of 12345678 in one measurement. Task-number: QTBUG-87330 Change-Id: I44c9bb467cf211f7e617ed55104476062296bba6 Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* Revert changes in strto(u)ll.c to avoid integer overflowsRobert Loehning2020-10-261-0/+4
| | | | | | | | Found in oss-fuzz issue 26045. Pick-to: 5.12 5.15 Change-Id: Id9eac1b4f67ad9bbe2d92dd69cd03338a6ced74e Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Use char32_t for QLocaleData::zeroUcs() and friendsEdward Welbourne2020-08-281-6/+6
| | | | | | | | | | Also catch some stray ushort that should be char16_t by now, use unicode character values for some constants and rename a UCS2 variable to not claim it's UCS4. Change-Id: I374b791947f5c965eaa22ad5b16060b475081c9d Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QLocale: update qt_asciiToDouble to use qsizetypeThiago Macieira2020-07-311-10/+10
| | | | | | | | No need to change the output variable from int to qsizetype. That would complicate the use of libdouble-conversion, which uses ints. Change-Id: Iea47e0f8fc8b40378df7fffd1624bfdba1189d81 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* QLocale: fix conversion of "\0" to doubleThiago Macieira2020-07-281-1/+1
| | | | | | | | That is not a valid conversion. An empty string is a valid conversion; a string containing a null should fail. Change-Id: Iea47e0f8fc8b40378df7fffd1624c088f3bd1b14 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* QByteArray::toDouble: fix buffer overflow reads on fromRawData()Thiago Macieira2020-07-281-6/+25
| | | | | | | | | | | | | If Qt was not compiled with libdouble-conversion, sscanf() requires null-termination, which fromRawData() does not require. This could be fixed by making QByteArray pass a reallocated copy if it is operating on raw data, but fixing qt_asciiToDouble() means we catch all cases and we optimize for the common case of not-horribly-long strings. Fixes: QTBUG-85580 Pick-to: 5.15 5.12 Change-Id: Iea47e0f8fc8b40378df7fffd16246f6163b01442 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Fix handling of Suzhou numbering systemEdward Welbourne2020-07-171-2/+2
| | | | | | | | | | | | | | | | This only arises when the system locale tells us to use its zero as our zero digit, since no CLDR locale uses it by default. Adapt an MS-specific QLocale::system() test to use Suzhou numbering, so as to test this. While updating the locale-restoration code to also restore the digits being set in that test, add restore code for the long time format, where previously only the short time format was restored. Add a comment to make it less likely one of those shall be missed in future. Fixes: QTBUG-85409 Change-Id: I343324bb563ee0e455dfe77d4825bf8c3082ca30 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Support digit-grouping correctlyEdward Welbourne2020-07-141-3/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Read three more values from CLDR and add a byte to the bit-fields at the end of QLocaleData, indicating the three group sizes. This adds three new parameters to various low-level formatting functions. At the same time, rename ThousandsGroup to GroupDigits, more faithfully expressing what this (internal) option means. This replaces commit 27d139128013c969a939779536485c1a80be977e with a fuller implementation that handles digit-grouping in any of the ways that CLDR supports. The formerly "Indian" formatting now also applies to at least some locales for Bangladesh, Bhutan and Sri Lanka. Fixed Costa Rica currency formatting test that wrongly put a separator after the first digit; the locale (in common with several Spanish locales) requires at least two digits before the first separator. [ChangeLog][QtCore][Important Behavior Changes] Some locales require more than one digit before the first grouping separator; others use group sizes other than three. The latter was partially supported (only for India) at 5.15 but is now systematically supported; the former is now also supported. Task-number: QTBUG-24301 Fixes: QTBUG-81050 Change-Id: I4ea4e331f3254d1f34801cddf51f3c65d3815573 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QLocalePrivate: rearrange number format statics and toolsEdward Welbourne2020-07-141-85/+0
| | | | | | | | | | | | Instead of passing lots of instance data around among public static methods and functions in qlocale_tools, do the work in instance methods that can access the relevant attributes of the locale when they need them. Incidentally reduces clutter in the global namespace. Add a signPrefix() to handle a repeated computation. Keep new internal methods private. Change-Id: I9556a960acac9fb645872337c61f509fb902984e Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Fix floating-point 'g'-format's choice between 'e' and 'f' formsEdward Welbourne2020-07-141-0/+2
| | | | | | | | | | | | | | During review of a refactor (coming shortly), Thiago wondered what the magic numbers were. On closer examination, I concluded that they were wrong and wrote some tests to prove it. This commit adds those tests; replaces the misguided old code with something that passes them; and documents the reasons for the various parts of its decisions. In the process, tidy up QLocaleData::doubleToString() somewhat and rename some of its variables to conform to Qt coding style. Change-Id: Ibee43659b1bdb0707639cdb444cfe941c31d409f Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Use numeric_limits instead of hand-coded equivalentsEdward Welbourne2020-07-131-6/+7
| | | | | | | | | | | | | | As a comment noted, the reason for QLocaleData rolling its own values describing the ranges of digits and exponents in a double were all about std::numeric_limits's constants not being constexpr - which they have now been since C++11, so we can do away with our own. One of the constants was used in two places in the same way; so abstract that use out into an inline function in qlocale_tools, to save duplication and give somewhere to document it. Change-Id: I7e3740ece9b499c0ec434de18d70abe69e1fe079 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Port Q_STATIC_ASSERT(_X) to static_assertGiuseppe D'Angelo2020-06-191-1/+1
| | | | | | | | | | | | | | | | | There is no reason for keep using our macro now that we have C++17. The macro itself is left in for the moment being, as well as its detection logic, because it's needed for C code (not everything supports C11 yet). A few more cleanups will arrive in the next few patches. Note that this is a mere search/replace; some places were using double braces to work around the presence of commas in a macro, no attempt has been done to fix those. tst_qglobal had just some minor changes to keep testing the macro. Change-Id: I1c1c397d9f3e63db3338842bf350c9069ea57639 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Allow surrogate pairs for various "single character" locale dataEdward Welbourne2020-02-171-51/+69
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Extract the character in its proper unicode form and encode it in a new single_character_data table of locale data. Record each entry as the range within that table that encodes it. Also added an assertion in the generator script to check that the digits CLDR gives us are a contiguous sequence in increasing order, as has been assumed by the C++ code for some time. Lots of number-formatting code now has to take account of how wide the digits are. This leaves nowhere for updateSystemPrivate() to record values read from sys_locale->query(), so we must always consult that function when accessing these members of the systemData() object. Various internal users of these single-character fields need the system-or-CLDR value rather than the raw CLDR value, so move QLocalePrivate's methods to supply them down to QLocaleData and ensure they check for system values, where appropriate first. This allows us to finally support the Chakma language and script, for whose number system UTF-16 needs surrogate pairs. Costs 10.8 kB in added data, much of it due to adding two new locales that need surrogates to represent digits. [ChangeLog][QtCore][QLocale] Various QLocale methods that returned single QChar values now return QString values to accommodate those locales which need a surrogate pair to represent the (single character) return value. Fixes: QTBUG-69324 Fixes: QTBUG-81053 Change-Id: I481722d6f5ee266164f09031679a851dfa6e7839 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Tidy nullptr usageAllan Sandfeld Jensen2019-12-061-1/+1
| | | | | | | | | | | Move away from using 0 as pointer literal. Done using clang-tidy. This is not complete as run-clang-tidy can't handle all of qtbase in one go. Change-Id: I1076a21f32aac0dab078af6f175f7508145eece0 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Use quiet NaNs instead of signaling onesEdward Welbourne2019-09-041-2/+2
| | | | | | | | | | | | | | | I see no good reason why the NaN returned when reading "nan" as a double should be a signaling one; a quiet one should be just fine. [ChangeLog][QtCore][QLocale] The NaN obtained when reading "nan" as a floating-point value is now quiet rather than signaling. [ChangeLog][QtCore][QTextStream] The NaN obtained when reading "nan" as a floating-point value is now quiet rather than signaling. Change-Id: Ife477a30bfb813c611b13a33c38ea82f9e8a93eb Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Move text-related code out of corelib/tools/ to corelib/text/Edward Welbourne2019-07-101-0/+578
This includes byte array, string, char, unicode, locale, collation and regular expressions. Change-Id: I8b125fa52c8c513eb57a0f1298b91910e5a0d786 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>