summaryrefslogtreecommitdiffstats
path: root/src/corelib/text/qlocale_p.h
Commit message (Collapse)AuthorAgeFilesLines
* Pass QVariant to QSystemLocale::query() as rvalue referenceEdward Welbourne2024-04-091-1/+1
| | | | | | | | | | QVariant is rather big for passing by value; and no caller has any further use for the QVariant it's passing in. Pick-to: 6.7 6.5 Task-number: QTBUG-122619 Change-Id: I2751745e715aacfa8982ac97b4ae777fde5e88de Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QSystemLocale(): disable copy and moveEdward Welbourne2024-04-091-0/+1
| | | | | | | | | | | | | Axivion (SV546) points out (based on a clazy "rule of three" that might be rule of five by now) the lack of move and copy assignment and construction. We don't want those anyway, so tell the compiler not to create them. Pick-to: 6.7 6.5 Task-number: QTBUG-122619 Change-Id: Ie951a2c3d60d76ad3448310d3f9bbda22190015b Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Move QLocaleData::convertDoubleToFloat to qnumeric_p.hThiago Macieira2024-03-041-16/+7
| | | | | | | So others can use it too. Change-Id: I01ec3c774d9943adb903fffd17b86236d06a948c Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
* wasm: remove onLanguageChanged event handlerMorten Sørvig2024-01-171-3/+0
| | | | | | | | | | | | | | | QSystemLocale is setting the global window.onLanguageChanged property which may cause conflicts in cases where there are more than one Qt app instance on the same web page. In addition the QSystemLocale destructor never runs, which breaks also for repeated QLocale instantiations on the same page (for example for the QLocale auto- test) Pick-to: 6.7 Change-Id: I85af0587527b2922804fc866c83864f677700e6d Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* wasm: Add QLocale backendMorten Sørvig2023-10-311-0/+7
| | | | | | | | | | | | | | | | | | This is a simple backend based on navigator.languages, which gives us a prioritized list of languages in the form '["en-US", "zh-CN", "ja-JP"]'. Use this to implement QSystemLocale::query() for UILanguages and QSystemLocale::fallbackLocale(). Register an event handler for the native QWindow:languagechange event in the QSystemLocale constructor. This event handler stays active for the lifetime of the QSystemLocale object. Task-number: QTBUG-116613 Change-Id: Ibd176748377e891b63a3f1d57605af0c2a49edb3 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
* Fix digit grouping: m_grouping_top doesn't mean what I thought it didEdward Welbourne2023-08-081-1/+1
| | | | | | | | | | | | | | | | | I'd previously understood CLDR's minimumGroupingDigits to mean the most significant group must have that many digits. It turns out to mean only that the first grouping separator doesn't get added unless the more significant group has this many. Once we have one separator, more can be added that do isolate a single digit. In the process, I discover some of the prior arithmetic is incorrect; it is now fixed. Added some basic testing, amended some existing tests. In the process, fixed naming of some double validator tests. Pick-to: 6.6 6.5 Fixes: QTBUG-115740 Change-Id: Ia6ce011ba72e72428b015ca22b97d815ebf751b2 Reviewed-by: Ievgenii Meshcheriakov <ievgenii.meshcheriakov@qt.io>
* Use correct index for QLocale::system()'s staticEdward Welbourne2023-07-311-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Nothing prevents client code from calling QLocale::setDefault() before we ever instantiate QLocale::system() - aside from some quirks that mean setDefault(), currently, does instantiate QLocale::system() to force initialization of defaultLocalePrivate - so using defaultIndex() could set the system QLocalePrivate instance's index incorrectly. In any case, even if the index is initially set correctly, a subsequent change to the system locale would change the correct index; and nothing outside QLocale::system() has access to the instance that would then be remembering an out-of-date index. Actually tripping over that inconsistency took some deviousness, but was possible. The index is (currently) only used for month name lookups and those special-case, for the Roman-derived calendars, the system locale, to only use the index if the system locale offers no name for a month. Meanwhile, updateSystemPrivate() uses the fallback locale's index for its look-up of which CLDR data to copy into the fallback QLocaleData for the system locale. None the less, a non-Roman calendar's lookup will go via the index to get at the CLDR data for that calendar, thereby exposing the system locale's index to use; and, sure enough, a setDefault() could lead that to produce wrong answers. In QLocale::system() there's a cached QLocalePrivate, whose index we need to ensure stays in sync with the active system locale. So pass its &m_index to systemData(), which will now (when passed this) ensure it's up to date. Since we always have called systemData(), to ensure it is up to date, we can skip that update in the initialization of the cached private and use m_index = -1 to let systemData() know when it's in the initial call, thereby making the static cache constinit. Amended a test to what proved the issue was present. Change-Id: I8d7ab5830cf0bbb9265c2af2a1edc9396ddef79f Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* QLocaleData:: port bytearray/stringTo{U}LongLong to QSimpleParsedNumberAhmad Samir2023-07-221-7/+8
| | | | | | Change-Id: I97fe38d9b676cf92003a7323ebb5f56b9b79abad Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* QLocale: move QSimpleParsedNumber to qlocale_p.hAhmad Samir2023-07-221-0/+8
| | | | | | | | It was defined in qlocale_tools_p.h which already includes qlocale_p.h. Change-Id: I43464a27ec15266ce8632ca30dcd1c57d94b1f25 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QLocaleData: change validateChars() to return validation StateAhmad Samir2023-07-221-3/+15
| | | | | | | | | | | | | | | | | | | | Instead of returning just bool, return a result struct {State, CharBuff}, a State is useful as it can have an Intermediate state where the input isn't Acceptable yet, but not Invalid as such. The example from the linked bug is in tst_QIntValidator::validateFrench(), a string "1 ", which can be interpretted as a number with a group separator, but the input shouldn't end with a group separator (changing the unittest will be done as part of a separate commit). CharBuff (QVarLengthArray<char, 256>) replaces the QByteArray input parameter; a QVarLengthArray means no heap allocation in typical use-cases with input text < 256 characters to validate. This required minimum changes (QVLA doesn't have startsWith, replaced by comparing with buff[0]; and for converting to double, wrapped it in a QBAV). Task-number: QTBUG-111371 Change-Id: I4e0eb612d470ef03faf52031ddfe9c4bdb31e1e1 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* QLocaleData: move CharBuff typedef out of QLocaleDataAhmad Samir2023-03-211-2/+3
| | | | | | | It'll be used by another struct in a subsequent commit. Change-Id: Ia94c6ae3506f9ba6cba6b71a5839bff8b3a2ab1f Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Pack languageCodeList tighterMate Barany2023-03-151-2/+2
| | | | | | | | | | | | | | Pack some of the arrays that contain locale data more tightly. The AlphaCode struct is a char[4] but always holds only [a-z]{,3} which could be fit into 16 bits, halving the size of an AlphaCode struct. With the new constructor the initialization of the AlphaCode struct also changes - modify qlocalexml2cpp.py to reflect this change and regenerate the languageCodeList. Fixes: QTBUG-105050 Change-Id: I2b1e93ab7cc3f2d667bf67b45769b74a15211931 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Don't use unnamed namespace in qlocale_p.hEdward Welbourne2023-03-131-5/+6
| | | | | | | | | | Pointed out by CodeChecker. It's included by plenty of places, so duplicating that anonymous namespace potential code duplication. Use QtPrivate namespace instead. Change-Id: I9ccfd569089ea01a8be9ffd87889bca73b70dd9c Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* Support Cyrillic's equivalent of 'E' as exponent separatorEdward Welbourne2023-02-241-0/+3
| | | | | | | | | | | | Only Ukrainian is actually recorded in CLDR as using U+0415 as exponent separator; all other Cyrillic-using locales officially use plain ASCII 'E'. However, it seems reasonable, in all Cyrillic locales, to recognize both (given that they look very similar). Task-number: QTBUG-107801 Change-Id: I70a1e60a2d9fe7e254e01d32c5bad909ea4b8c76 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Ievgenii Meshcheriakov <ievgenii.meshcheriakov@qt.io>
* Fix parsing of numbers to cope with non-single-character tokensEdward Welbourne2023-02-241-47/+43
| | | | | | | | | | | | | | | | | | | | In some locales signs and the exponent are not single character tokens. Replace QLocaleData::numericToCLocale() with a tokenizer that will cope with this. At the same time, cache the locale data needed in support of that, so that we don't repeatedly recreate QString() objects just to compare them against input tokens. The caching class is inspired by Thiago's proposal for fixing the performance, which also inspires the optimization of the C locale in the tokenizer used here. Add some testing that round-tripping numbers via strings works for the locales with signs and exponents that use more than one character. Task-number: QTBUG-107801 Change-Id: I9fd8409a371ed62ed969d9ebc8b09584e752f7fb Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QLocale: modernize ascii_isspace() to C++17Thiago Macieira2023-02-201-7/+60
| | | | | | | | | | | | | | | | | | | | | | | And on 64-bit platforms, use a 64-bit integer, which removes a subtraction from the matching code. The loop in bytearrayToLongLong() looks like, on x86-64: movabsq $4294983168, %rsi .L1217: movzbl (%rdx), %ecx cmpl $64, %ecx ja .L1216 btq %rcx, %rsi jnc .L1216 incq %rdx cmpq %rbx, %rdx jne .L1217 Change-Id: I3d74c753055744deb8acfffd1723d8b51e151432 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Let QLocaleData::numberToCLocale() know the type of numberEdward Welbourne2023-01-191-1/+1
| | | | | | | | | | Passing a NumberMode lets it exclude floating-specific details for integer parsing. For now this is only partially exploited, but later work shall make more use of it. Fixes: QTBUG-81756 Change-Id: If11d3a5a122d0714f645e58a51ee0d0c47ebe61d Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QLocale: merge the code for some system locale queriesThiago Macieira2022-10-251-2/+0
| | | | | | | | | | QSystemLocale is now defined for QT_NO_SYSTEMLOCALE builds (bootstrap), but no implementation will be present. That's just to get the enum declarations. Pick-to: 6.4 Change-Id: I3c79b7e08fa346988dfefffd171fa00fde8ab080 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Eliminate QSystemLocaleSingleton and QSystemLocale(bool)Edward Welbourne2022-09-071-3/+0
| | | | | | | | | | | | | They are no longer needed. The global static will only ever be instantiated if and when the QSystemLocale stack is empty; it will then survive to the end of run-time, serving as a bottom-of-stack instance that will always be fallen back to after any other instances' lifetimes. It can thus be a local static of the only function that accesses it. Change-Id: I21a1623728b25b46da6e25db9bb973c507a39ca3 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* Perform uiLanguages() likely-adjusted processing purely on IDsEdward Welbourne2022-09-071-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The collection of translations available to us need not have anything to do with whether CLDR has matching data, so preserve the system UI language list's entries as they are, rather than forcing them through the QLocale constructor's exercise of likely sub-tag rules. Instead, simply parse the given locale tags to QLocaleId instances and use these in the likely-subtag processing to determine what other entries to add to the list in addition to those supplied by the operating system. Since going via QLocale did usually supply a territory, that was included in the BCP 47 name, it's now possible for the given entry to lack the language_territory name, so be sure to add that if missing. This incidentally reduces heap traffic and saves a fair deal of hidden likely-subtag processing in calls to the constructor and bcp47Name(). Expand testing of QLocale::uiLanguages(), both plain and system. In the process, cross-link the two closely-related tests, move a comment on one's _data() to the other's, where it really belongs, and add reporting of the actual lists on failure. Enable MySystemLocale to remember the requested locale's ID, before likely sub-tag processing, so that we can make query() report results for language, script and territory as requested, to ensure the fake system locale really does match what was requested. The new german-britain test failed without it, because there is no de-GB locale in CLDR. Task-number: QTBUG-99531 Change-Id: Ide041577772c442a4413e3b9a590e11140c48f49 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Simplify system locale managementEdward Welbourne2022-09-071-0/+1
| | | | | | | | | | | | Have QSystemLocale manage a stack, so that tests can install an over-ride for the actual system-specific one reliably and restore the system-specific one when finished. Leave the QSystemLocaleSingleton out of the stack, all the same. In the process, mark the QDoc comments for QSystemLocale all as \internal, since this is not public API. Change-Id: I8faed49780215e42f32be10cf936c32bb46105bf Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* QLocale: port to qsizetype [2/N]: remainder (qlocale_win.cpp partial)Marc Mutz2022-09-011-3/+3
| | | | | | | | | | | | | | | | | | Port ints to qsizetypes where they're not blatantly wrong. This includes indexed loops that don't require the additional range, because int these days is a code smell, so if we can save the next code reader a few moments of digging to convince herself that the int is ok even in 64-bit builds, then let's do it. The Windows implementation only has the most obvious occurrences ported, because I lack platform access. Created QTBUG-105100 to track the missing changes. OSX should be fine, provided sizeof(long) == 8 on 64-bit OSX. Pick-to: 6.4 6.3 Task-number: QTBUG-103531 Change-Id: I679183f28ed42e89e2879e29457e6a4e487fed0d Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* QLocale: port locale_data indexing to qsizetypeMarc Mutz2022-08-121-5/+5
| | | | | | | | | | | | | | | Not a bug, just porting to avoid the next reader having to wonder whether the ints and uints are 64-bit safe. As a drive-by, make a static variable constexpr and replace sizeof foo/sizeof *foo with q20::ssize(foo). Pick-to: 6.4 Task-number: QTBUG-103531 Change-Id: Iccc5a5896ab87981f4535820cea7f274e568f325 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Port qt_readEscapedFormatString() to qsizetypeMarc Mutz2022-08-121-1/+1
| | | | | | | | | More of the usual missing int -> qsizetype porting... Pick-to: 6.4 6.3 6.2 Task-number: QTBUG-103531 Change-Id: I53faff5fe306c1d207741bc93a1e5c15d3eefa4f Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Port qt_repeatCount() to qsizetypeMarc Mutz2022-07-201-1/+1
| | | | | | | | | | | | | | | | | While it's true that the typical user of the function won't expect more than half a dozen repeats, this function is fed with user-supplied input, so it could be asked to return in excess of INT_MAX matches. The truncation then means we're misreporting the number mod INT_MAX, which is as good as a random number and leads to false positive matches in users of the function. Just return the true result instead of a truncated one. Pick-to: 6.4 6.3 6.2 Task-number: QTBUG-103531 Change-Id: I5e3aa23dec873c6f9af255e90748fb38619d2f5d Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* QLocale: #include <QList>Thiago Macieira2022-07-201-7/+7
| | | | | | | | | | | It's required by that misguided QT_DECL_METATYPE_EXTERN_TAGGED that uses QList. I don't know why it is there in the first place, and will not investigate. qmetatype.h:1137:9: error: static_assert failed due to requirement 'is_complete<QList<Qt::DayOfWeek>, void>::value || std::is_void_v<QList<Qt::DayOfWeek>>' "Meta Types must be fully defined" Change-Id: I36b24183fbd041179f2ffffd17026e01888f5e9a Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Remove QStringView metatype declarationIvan Solovev2022-07-131-2/+0
| | | | | | | | | | | | | | It was required back in Qt 5 times, so that we could use qvariant_cast<> or QVariant.value() on it. Not required in Qt 6 anymore. As a drive-by: cleanup some unneeded includes in qstringview.cpp Task-number: QTBUG-102350 Pick-to: 6.4 Change-Id: Idbcdc5cfe62cf4a55b86e227106d7a997997e0ba Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QLocale: move some static_assert()s from _p.h into .cppMarc Mutz2022-07-061-14/+0
| | | | | | | | | | | | There's no point in having each TU that includes this header unit-test the ascii_isspace function anew. Amends 7f9398fd4d23469c77c6a53eac0819f92dfc3928. Pick-to: 6.4 Task-number: QTBUG-97601 Change-Id: I17addc3256f4afafb8ec6a86116654b0099efcda Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
* Use SPDX license identifiersLucie Gérard2022-05-161-39/+3
| | | | | | | | | | | | | Replace the current license disclaimer in files by a SPDX-License-Identifier. Files that have to be modified by hand are modified. License files are organized under LICENSES directory. Task-number: QTBUG-67283 Change-Id: Id880c92784c40f3bbde861c0d93f58151c18b9f1 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
* Rest of QtBase: sweep Q_DECLARE_METATYPE → QT_DECL_METATYPE_EXTERNMarc Mutz2022-04-071-4/+7
| | | | | | | | | | | | | | | | It's one of our best tools to improve compile times. In some places, we can't do the change, yet, because there's no .cpp file for the header file. Also mark Q_DECLARE_METATYPE macros that are in the wrong place. We shouldn't have Q_D_M markup for public classes in .cpp or _p.h files. Fixes: QTBUG-102206 Change-Id: Iec0a39e4745571b24d07dacc87593321967c10e3 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* QtCore: Replace remaining uses of QLatin1String with QLatin1StringViewSona Kurazyan2022-03-261-6/+6
| | | | | | | Task-number: QTBUG-98434 Change-Id: Ib7c5fc0aaca6ef33b93c7486e99502c555bf20bc Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* Core: Do not depend on transitive includesFabian Kosmale2022-03-171-0/+1
| | | | | Change-Id: I2c71188a4d27692a2d6ef1aa447b329627214b17 Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* Protect headers against min/max macrosMarc Mutz2022-02-221-1/+1
| | | | | | | | | | | | ... using the usual pattern, which, being idiomatic, doesn't need a comment explaining it. Pick-to: 6.3 Change-Id: Id6b12450495a18f89e1f83f2018b6218b03ff6a7 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QLocale: Extend support for language codesIevgenii Meshcheriakov2021-12-091-4/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | This commit extends functionality for QLocale::codeToLanguage() and QLocale::languageToCode() by adding an additional argument that allows selection of the ISO 639 code-set to consider for those operations. The following ISO 639 codes are supported: * Part 1 * Part 2 bibliographic * Part 2 terminological * Part 3 As a result of this change the codeToLanguage() overload without the additional argument now returns a Language value if it matches any know code. Previously a valid language was returned only if the function argument matched the first code defined for that language from the above list. [ChangeLog][QtCore][QLocale] Added overloads for codeToLanguage() and languageToCode() that support specifying which ISO 639 codes to consider. Fixes: QTBUG-98129 Change-Id: I4da8a89e2e68a673cf63a621359cded609873fa2 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Clean up exports from qlocale_p.hEdward Welbourne2021-11-101-2/+3
| | | | | | | | | | | | Explain why QSystemLocale needs to be an export. Unexport QLocaleId::fromName() now that qttools no longer uses it. QLocalePrivate was only Q_CORE_EXPORT for the sake of one use in tst_QLocale, that can now be replaced by a call to a public QLocale method. Change-Id: I1efe8ee03488acfc6e1c36661f6e956a86e191c3 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Teach QLocale::system() to use narrow formatIvan Solovev2021-09-151-1/+5
| | | | | | | | | | | | | | | | QLocale::system() was not making use of QLocaleFormat::Narrow, always treating it in the same way as QLocaleFormat::Short. This patch fixes the issue for day and month names. The implementation falls back to CLDR if system locale fails to provide some data. Pick-to: 6.2 Task-number: QTBUG-84877 Change-Id: Ia37e59dbf02d7a5e230f2767d294b9ab7de37f33 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* Fix QLocale::system() standalone day and month handlingIvan Solovev2021-09-061-1/+3
| | | | | | | | | | | | | | | Some backends were missing support for standalone days and months, also the standaloneDayName() implementation was always using the same codepath as dayName(). This patch fixes the issues. Support for narrow format will be added in the following patch. Task-number: QTBUG-84877 Pick-to: 6.2 Change-Id: I38ee06342cafab544e3c69097bd0e6ae68e85645 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Add a QLocale(QStringView) constructorEdward Welbourne2021-09-011-1/+1
| | | | | | | | | | | Only a few more internals just needed to change to take QStringView, to connect up the constructor with internals already long since converted. [ChangeLog][QtCore][QLocale] Added QLocale(QStringView) constructor. Change-Id: Iec31391e6168f333b4b6fc633c3d7d01872f83b3 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Mark QLocale's private functions [[nodiscard]]Edward Welbourne2021-09-011-80/+91
| | | | | | | | If only to make the exceptions stand out, so we can see which ones only exist for their side-effects. Change-Id: I90b649d4da09f57ab986f29c577993dd12e34721 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Rework QLocalePrivate::bytearrayToU?LongLong()Edward Welbourne2021-08-301-3/+3
| | | | | | | | | | | | Change it to take a QByteArrayView instead of a plain char *; all its callers do know the size and propagating it enables the implementation to call strntou?ll() rather than strtou?ll(), thereby escaping the need for '\0'-termination. Fixes: QTBUG-74286 Change-Id: Ie9394786e9fcf25c1d1be2421805f47c018d13bb Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QString::localeAwareCompare: adapt to QLocale::setDefault() being calledThiago Macieira2021-08-021-0/+2
| | | | | | | | | | | | | | | | | Because we're using a thread-specific global static, we need to recreate the QCollator type every time setDefault() is called. Since one is stored per-thread, we simply increment a generational counter and check that the next time that QString::localeAwareCompare is called in each thread. The issue was introduced on f6425da424b1a0d5927ee56fa657a9b31ca5afd1 (5.12) even though we were supposed to be using QCollator since commit 5279134935e858e6fa8565c936b17e88d7bded50 (5.3). Fixes: QTBUG-95050 Pick-to: 6.2 Change-Id: I7e0b82c2d2fe464082d8fffd1696a8c9f74e5b30 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Fix augmentation of UI language listEdward Welbourne2021-06-071-1/+0
| | | | | | | | | | | | | | | | | | | | Previously, the augmentation wasn't being applied to the system locale, due to a mistaken test claiming the locale's name didn't resemble the string from which it was constructed. The test dates from before various fixes to likely sub-tag processing that should make it redundant now. This makes QLocalePrivate::rawName() also redundant (and its conversion of QLatin1String to QByteArray relied on '\0' termination which wasn't actually present in the various codes). Expanded the test of systemLocale() to also test uiLanguages() turns a single entry into the list we expect; and add two new test-cases. (The test uses a mock system locale class, making this independent of the platform backend.) Fixes: QTBUG-92234 Pick-to: 6.1 5.15 Change-Id: I0cdf6eae152a42dc377f4ea3e62c282ff4be1764 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Add the "Territory" enumerated type for QLocaleJiDe Zhang2021-04-151-15/+15
| | | | | | | | | | | | | | | | | | | The use of "Country" is misleading as some entries in the enumeration are not countries (eg, HongKong), for all that most are. The Unicode Consortium's Common Locale Data Repository (CLDR, from which QLocale's data is taken) calls these territories, so introduce territory-based names and prepare to deprecate the country-based ones in due course. [ChangeLog][QtCore][QLocale] QLocale now has Territory as an alias for its Country enumeration, and associated territory-based names to match its country-named methods, to better match the usage in relevant standards. The country-based names shall in due course be deprecated in favor of the territory-based names. Fixes: QTBUG-91686 Change-Id: Ia1ae1ad7323867016186fb775c9600cd5113aa42 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Clarify what QSystemLocale::fallbackLocale() is used forTor Arne Vestbø2021-02-091-3/+3
| | | | | Change-Id: I8f073f996505ccb42020b32fd76520ecef54e628 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* QLocale: Allow direct conversion from language, country, and script codesKai Köhne2021-01-251-1/+0
| | | | | | | | | | | | | | | This complements patch a148c7b5d71d244, where languageToCode(), countryToCode() scriptToCode() methods were introduced, with matching codeToLanguage(), codeToCountry(), and codeToScript() methods. This allows us to remove the use of private Qt Core API in Qt Linguist. [ChangeLog][QtCore][QLocale] Added static codeToLanguage(), codeToCountry(), codeToScript() methods that convert ISO code strings to the respective enum values. Change-Id: If5c0843a718c006ade086a6f74ceb86ac6e0fce4 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* QLocale: Remove dead codeKai Köhne2021-01-061-2/+0
| | | | | | | The code using it got removed in qttools commit 01da5d9a Change-Id: I14d36ac939f2647139fcc42591a044a03e707553 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Replace discouraged Q_MOVABLE_TYPE by Q_RELOCATABLE_TYPEAndreas Buhr2020-11-301-1/+1
| | | | | | | | | | | | | | Q_MOVABLE_TYPE was conceived before C++ had move semantics. Now, with move semantics, its name is misleading. Q_RELOCATABLE_TYPE was introduced as a synonym to Q_MOVABLE_TYPE. Usage of Q_MOVABLE_TYPE is discouraged now. This patch replaces all usages of Q_MOVABLE_TYPE by Q_RELOCATABLE_TYPE in QtBase. As the two are synonymous, this patch should have no impact on users. Pick-to: 6.0 Change-Id: Ie653984363198c1aeb1f70f8e0fa189aae38eb5c Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
* Get rid of Q_COMPILER_CONSTEXPR checksAllan Sandfeld Jensen2020-11-171-2/+0
| | | | | | | Is required now. Change-Id: I62e95929d1649ea1390392230b619bd56d2a0349 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* String-view-ify qt_splitLocaleName() and simplify its callersEdward Welbourne2020-11-171-1/+2
| | | | | | | | | | | Two of its callers didn't even care about the fragments it was returning, one only cared about two of them. The parsing could be more straightforward and less verbose. Parsing into QStringView saves the need to allocate copies of the substrings parsed. Cleaned up around the code that called it. Change-Id: Ie65d2b1b3eb891c20bc82275d7a0da00c30d7b8d Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Export QLocaleId::fromName() so qttools can use itEdward Welbourne2020-11-171-1/+2
| | | | | | | | This shall replace QLocalePrivate::getLangAndCountry()'s use by qttools. Change-Id: Ib686a3769bd38c477d7fbad50cf494ee8a0b1c00 Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>