summaryrefslogtreecommitdiffstats
path: root/src/corelib/text/qlocale_win.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Guard WinRT API code for clang-clPeter Varga2021-10-121-4/+4
| | | | | | | | | | | | | | It is unsupported with clang-cl and breaks the build. This is a fixup for: 51e8d3592a Let QLocale::uiLanguages() use WinRT API when possible Task-number: QTBUG-94341 Pick-to: 6.2 Change-Id: Icf32339e81d67d4c119b7fb8d8d834c744b9ead0 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Let QLocale::uiLanguages() use WinRT API when possibleIvan Solovev2021-10-011-1/+26
| | | | | | | | | | | | | | | | | | This patch introduces support for the WinRT UI languages API. We are using the Win32 API to get the list of preferred languages when the system locale is used. However, this API returns an incomplete list. As Qt 6 supports Windows 10 and above, we can make use of the WinRT API, if it's supported by the compiler. This API returns the full list, as reported by the Windows system itself. Note however, that this API can't be used with Clang and MinGW, so we still have to fall back to Win32 API for these compilers. We also do it if WinRT API returns an empty list of languages for some reason. Fixes: QTBUG-94341 Pick-to: 6.2 Change-Id: I1d23c68d2ec298ae7835d0d18718876ff041aede Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Teach QLocale::system() to use narrow formatIvan Solovev2021-09-151-0/+7
| | | | | | | | | | | | | | | | 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-0/+4
| | | | | | | | | | | | | | | 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>
* qlocale_win: Fix non-standalone month namesEdward Welbourne2021-09-011-3/+30
| | | | | | | | | | | | | | | | | | | | We have previously been using the standalong (nominative) month names both when asked for that and when asked for the plain (genitive) month name, probably because there was no LCTYPE value for the latter. However, MS's docs for the standalone values do contain a comment telling us how to get the genitive names. Rename the old monthName() to standaloneMonthName() and add a monthName() that calls GetDateFormat() suitably, as described by the MS doc. Pick-to: 6.2 5.15 Fixes: QTBUG-92018 Fixes: QTBUG-86279 Change-Id: I27f63198c3a15b792683f476d2019078b0860f99 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Convert various callers of strtou?ll() to call strntou?ll()Edward Welbourne2021-08-301-3/+3
| | | | | | | | Where size is known or can readily be determined. Change-Id: I442e7ebb3757fdbf7d021a15e19aeba533b590a5 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* qlocale_win: Simplify and explain month-name format lookupEdward Welbourne2021-08-271-5/+4
| | | | | | | | | | | | Retain the given month number and simply subtract one from it in the one place it's used (once the two array dereferencs are unified). That makes it clear that the off-by-one numbering is just down to our arrays, not some weired quirk of the MS API. Simplify a condition by inverting it: compare to LongFormat instead of ||-ing comparisons to the other two members of the enum. Change-Id: Ia03486b7869255ecdb1372de62d5c745d35d0a0a Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* qlocale_win: return null QVariant on failed look-upsEdward Welbourne2021-08-111-4/+4
| | | | | | | | | | | Various functions were still returning a null QString wrapped as a QVariant; the caller distinguishes these cases, so should get a null QVariant so it knows the backend failed to answer the query and can attempt whatever fall-back it may have at its disposal. Pick-to: 6.2 Change-Id: I0983b9f3b1026f17c3f13ab92b713bee90be466c Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* qlocale_win: Rename a misnamed local variableEdward Welbourne2021-08-101-6/+6
| | | | | | | | | | Although the function is called get{Dat,Tim}eFormat(), the content it's filling the buffer with isn't a format, it's a formatted date or time. So name the variable we transcribe the buffer into text instead of misleadingly calling it format. Change-Id: Ia3a51184963109a50dbc41e205bd8c83d83c04d7 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Initialize SYSTEMTIME to {} instead of memset()ingAndreas Buhr2021-05-261-4/+2
| | | | | Change-Id: I7ee02a6bcf5961adce26b635f12722e12c4865d3 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Add the "Territory" enumerated type for QLocaleJiDe Zhang2021-04-151-6/+6
| | | | | | | | | | | | | | | | | | | 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>
* Use Core library for qmake instead of the Bootstrap libraryAlexey Edelev2021-02-251-2/+2
| | | | | | | | | | | | | | | | | | | Move the qmake-specific logic of the QLibraryInfo class to qmake internals. 'qconfig.cpp.in' now stores information about the library info entries to keep them consistent between qmake and the Core library. qmake requires specific features enabled in the Core library, so building qmake will be skipped if the features are not enabled. All flags directly related to the qmake have been removed from Core lib. Remove all bootstrap related sections from qmake CMakeLists.txt Task-number: QTBUG-89369 Change-Id: I26de157d3bfd4a5526699296e9d46e1c180b89ae Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Kai Koehne <kai.koehne@qt.io>
* 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>
* String-view-ify qt_splitLocaleName() and simplify its callersEdward Welbourne2020-11-171-8/+6
| | | | | | | | | | | 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>
* MinGW: Fix compile error in qlocale_win.cppFriedemann Kleint2020-11-101-3/+3
| | | | | | | | | | | | | Cast enumerations to ushort, fixing: src/corelib/text/qlocale_win.cpp: In member function 'virtual QVariant QSystemLocale::query(QSystemLocale::QueryType, QVariant) const': src/corelib/text/qlocale_win.cpp:765:34: error: enumeral and non-enumeral type in conditional expression [-Werror=extra] As a drive-by, fix deprecation warning about QVariant::type(). Amends 098f43fdd2d46e15c87073aae44c5f2bd0cd8c98. Change-Id: I2adc9833c6d6d9e9d2500f0b92b25cb5d38b583b Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QLocale: use uint lessEdward Welbourne2020-11-081-2/+2
| | | | | | | | | | Various uses of uint were simply redundant, now that Language, Script and Country are ushort-based. Others should in any case have been quint16 or char32_t. Change-Id: Id0d0dc2558e1724907907cde56059f70972e824a Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Use QLocaleId in place of language, script, country triplesEdward Welbourne2020-11-081-8/+4
| | | | | | | | | | | | Pass a single argument in place of three; and (prepare to) replace QLocalePrivate::getLangAndCountry(), taking three out parameters, with QLocaleId::fromName(). Removal of getLangAndCountry() must wait for removal of linguist's use of it in qttools, which has to wait for this change to land in qtbase. In the process, change findLocaleIndex()'s return to int. Change-Id: I9f5c44c41f2dd1598c53ed5ccb0abddc6b17d21f Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Deprecate QVariant::TypeLars Knoll2020-10-231-5/+5
| | | | | | | | | It's been obsolete for a long time already. Make sure the compiler now warns about it and remove all remaining uses in qtbase. Change-Id: I0ff80311184dba52d2ba5f4e2fabe0d47fdc59d7 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Fix handling of Suzhou numbering systemEdward Welbourne2020-07-171-7/+9
| | | | | | | | | | | | | | | | 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>
* QSystemLocalePrivate::substituteDigits(): change to move semanticsEdward Welbourne2020-07-151-6/+6
| | | | | | | | | | Rather than passing an in-out reference parameter and ignoring the return (of that parameter) use an actual rvalue ref parameter and move the value through the function, to make it easier for compilers to see how to optimize it. Change-Id: Ie239400345da012d8fb8a731394f1687b8b62430 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Simplify qlocale_win's getLocaleInfo() and its _int variantEdward Welbourne2020-07-151-32/+28
| | | | | | | | | | | | One of the former's overloads was a template; it and its _int variant took an optional maxlen; no caller passed maxlen, only three callers didn't over-ride the template's <QString> default return value to <QVariant>; so eliminate maxlen and have it simply return QVariant, using .toString() on it where needed. Change-Id: Icf3ff32f167ee96cfbb6412613ecd7f0886a2fe9 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Simplify qlocale_win's currency formattingEdward Welbourne2020-07-141-11/+5
| | | | | | | | | | | | Use QLocaleData::c()'s instance method, rather than QLocaleData's static method, to format integers. This avoids the need to duplicate various arguments as literals, that the C locale provides as default. It also future-proofs against changes to the static methods. Change-Id: I5bba407cfc29e3f33d1e9fa878ddf35fff3b113c Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* Remove winrtOliver Wolff2020-06-061-121/+0
| | | | | | | | | Macros and the await helper function from qfunctions_winrt(_p).h are needed in other Qt modules which use UWP APIs on desktop windows. Task-number: QTBUG-84434 Change-Id: Ice09c11436ad151c17bdccd2c7defadd08c13925 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* Rework country setting to match how we return the script settingEdward Welbourne2020-04-211-3/+1
| | | | | Change-Id: I753673ef79b4ad208fa6e0c6a4eb8139cd2ee253 Reviewed-by: Orgad Shaneh <orgads@gmail.com>
* Revert "Revert "QLocale: Actually get the language script for the system ↵Edward Welbourne2020-04-211-2/+3
| | | | | | | | | | | | | | | locale"" This reverts commit 449390c3a5f3a91e3895cbba0a583386e93366b7. QLocale::system() should behave consistently. If UI widgets are consulting the system locale where they should be consulting their configured UI locale, that is a bug in the UI widget and should not be "fixed" by breaking QLocale. Change-Id: Ib31cf7882a28b26f9a018fba3adabba94a8c43bf Pick-to: 5.15 Fixes: QTBUG-49031 Reviewed-by: Orgad Shaneh <orgads@gmail.com>
* Allow surrogate pairs for various "single character" locale dataEdward Welbourne2020-02-171-11/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* Fall back to "+" if MS returns empty string for positive signEdward Welbourne2020-02-031-1/+11
| | | | | | | | | | | MS's documentation says empty means "+" here, so implement that fallback (which shall over-ride whatever the CLDR has given us for the fallbackUiLanguage's positive sign). Task-number: QTBUG-81530 Change-Id: Ic3f10dd061d0c46d1433f29b8065988da94c38e6 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* qlocale_win.cpp: distinguish empty QString from null QVariantEdward Welbourne2020-02-031-26/+29
| | | | | | | | | | | | | | | | | An empty string, when packaged as a QVariant, is non-null (as a QVariant); and QSystemLocale::query()'s callers care about the difference. Some callers of the internal getLocaleInfo(LCTYPE type, int maxlen) need an actual QString return, while others are what query() returns, so need to return a QVariant; where the former want an empty string, the latter need a null QVariant. So make that getLocaleInfo() into a template, so callers can chose QString or QVariant as return type, only affecting the failure returns. Change-Id: I7b9a698badedc0e0d8aef8c6e85c22931c33297a Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Fix flawed logic in QSystemLocalePrivate::getLocaleInfo()Edward Welbourne2020-01-301-3/+3
| | | | | | | | | | | If the first call to GetLocaleInfo() returned non-zero, then GetLastError()'s return has nothing to do with GetLocaleInfo(), since it didn't fail. The check for ERROR_INSUFFICIENT_BUFFER as last error needs to happen in the branch where GetLocaleInfo() failed, returning zero. Change-Id: Idb6eaad1515a003133c787998aff0c265ef98251 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
* Fix MS-Win system locale code to return QString for numeric tokensEdward Welbourne2020-01-161-35/+62
| | | | | | | | | | | | | | | | | QSystemLocale::query() is specified to return a QString (wrapped in a QVariant) for the various tokens used in formatting numbers (zero digit, signs, separators) but the MS-Win back-end was returning QChar (wrapped as QVariant) instead, using the first UCS-2 code-point of the string (even if this was the first of a surrogate pair). The same error shall be perpetrated by its caller, but we can at least DTRT in the back-end, ready for the coming fix (in Qt 6) to its caller. In the process, eliminate some local variables that shadowed a member variable and adapt number-conversion to cope with surrogate-pair digits. Optimised the latter for the case where zero is "0". Change-Id: Idfb416c301add4c961dde613b3dc28b2e31fd0af Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Pass QDate, QTime as value classes, rather than by const referenceEdward Welbourne2019-08-301-4/+4
| | | | | | | | | This can, of course, only be done in private APIs - but comment on public APIs to do the same at Qt 6. Change-Id: I3c79951572be3c37b0b0c5b1b05bced051a40964 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Paul Wicking <paul.wicking@qt.io>
* Move text-related code out of corelib/tools/ to corelib/text/Edward Welbourne2019-07-101-0/+1143
This includes byte array, string, char, unicode, locale, collation and regular expressions. Change-Id: I8b125fa52c8c513eb57a0f1298b91910e5a0d786 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>