13#include "QtCore/private/qgregoriancalendar_p.h"
22#if QT_CONFIG(cpp_winrt)
23# include <QtCore/private/qt_winrtbase_p.h>
25# include <winrt/Windows.Foundation.h>
26# include <winrt/Windows.Foundation.Collections.h>
27# include <winrt/Windows.System.UserProfile.h>
38#ifndef QT_NO_SYSTEMLOCALE
40#ifndef MUI_LANGUAGE_NAME
41#define MUI_LANGUAGE_NAME 0x8
43#ifndef LOCALE_SSHORTESTDAYNAME1
44# define LOCALE_SSHORTESTDAYNAME1 0x0060
45# define LOCALE_SSHORTESTDAYNAME2 0x0061
46# define LOCALE_SSHORTESTDAYNAME3 0x0062
47# define LOCALE_SSHORTESTDAYNAME4 0x0063
48# define LOCALE_SSHORTESTDAYNAME5 0x0064
49# define LOCALE_SSHORTESTDAYNAME6 0x0065
50# define LOCALE_SSHORTESTDAYNAME7 0x0066
52#ifndef LOCALE_SNATIVELANGUAGENAME
53# define LOCALE_SNATIVELANGUAGENAME 0x00000004
55#ifndef LOCALE_SNATIVECOUNTRYNAME
56# define LOCALE_SNATIVECOUNTRYNAME 0x00000008
58#ifndef LOCALE_SSHORTTIME
59# define LOCALE_SSHORTTIME 0x00000079
94 enum SubstitutionType {
103 SubstitutionType substitutionType;
108 int getLocaleInfo_int(LCTYPE
type);
114 SubstitutionType substitution();
124 : substitutionType(SUnknown)
126 lcid = GetUserDefaultLCID();
129inline int QSystemLocalePrivate::getCurrencyFormat(DWORD
flags, LPCWSTR
value,
const CURRENCYFMTW *
format, LPWSTR
data,
int size)
134inline int QSystemLocalePrivate::getDateFormat(DWORD
flags,
const SYSTEMTIME *
date, LPCWSTR
format, LPWSTR
data,
int size)
139inline int QSystemLocalePrivate::getTimeFormat(DWORD
flags,
const SYSTEMTIME *
date, LPCWSTR
format, LPWSTR
data,
int size)
144inline int QSystemLocalePrivate::getLocaleInfo(LCTYPE
type, LPWSTR
data,
int size)
149QVariant QSystemLocalePrivate::getLocaleInfo(LCTYPE
type)
158 if (!getLocaleInfo(
type,
buf.data(),
buf.size())) {
159 const auto lastError = GetLastError();
160 if (
type == LOCALE_SPOSITIVESIGN && lastError == ERROR_SUCCESS)
162 if (lastError != ERROR_INSUFFICIENT_BUFFER)
164 int cnt = getLocaleInfo(
type, 0, 0);
168 if (!getLocaleInfo(
type,
buf.data(),
buf.size()))
171 if (
type == LOCALE_SPOSITIVESIGN && !
buf[0])
176int QSystemLocalePrivate::getLocaleInfo_int(LCTYPE
type)
179 int r = GetLocaleInfo(lcid,
type | LOCALE_RETURN_NUMBER,
180 reinterpret_cast<wchar_t *
>(&
value),
181 sizeof(
value) /
sizeof(
wchar_t));
182 return r ==
sizeof(
value) /
sizeof(
wchar_t) ?
value : 0;
185QSystemLocalePrivate::SubstitutionType QSystemLocalePrivate::substitution()
187 if (substitutionType == SUnknown) {
189 if (!getLocaleInfo(LOCALE_IDIGITSUBSTITUTION,
buf, 8)) {
190 substitutionType = QSystemLocalePrivate::SNever;
191 return substitutionType;
194 substitutionType = QSystemLocalePrivate::SNever;
195 else if (
buf[0] ==
'0')
196 substitutionType = QSystemLocalePrivate::SContext;
197 else if (
buf[0] ==
'2')
198 substitutionType = QSystemLocalePrivate::SAlways;
201 if (!getLocaleInfo(LOCALE_SNATIVEDIGITS,
digits, 11)) {
202 substitutionType = QSystemLocalePrivate::SNever;
203 return substitutionType;
206 substitutionType = QSystemLocalePrivate::SAlways;
208 substitutionType = QSystemLocalePrivate::SNever;
211 return substitutionType;
217 switch (zero.
size()) {
223 ushort *
const qch =
reinterpret_cast<ushort *
>(
string.data());
226 if (
ch >=
'0' &&
ch <=
'9')
234 for (
int i = 0;
i < 10;
i++) {
242 Q_ASSERT(!
"Expected zero digit to be a single UCS2 code-point or a surrogate pair");
246 return std::move(
string);
260 if (getLocaleInfo(LOCALE_SNATIVEDIGITS,
digits, 11)) {
271 return getLocaleInfo(LOCALE_SDECIMAL);
276 return getLocaleInfo(LOCALE_STHOUSAND);
281 return getLocaleInfo(LOCALE_SNEGATIVESIGN);
286 return getLocaleInfo(LOCALE_SPOSITIVESIGN);
293 return winToQtFormat(getLocaleInfo(LOCALE_SSHORTDATE).
toString());
295 return winToQtFormat(getLocaleInfo(LOCALE_SLONGDATE).
toString());
308 return winToQtFormat(getLocaleInfo(LOCALE_STIMEFORMAT).
toString());
322 if (day < 1 || day > 7)
325 static const LCTYPE short_day_map[]
326 = { LOCALE_SABBREVDAYNAME1, LOCALE_SABBREVDAYNAME2,
327 LOCALE_SABBREVDAYNAME3, LOCALE_SABBREVDAYNAME4, LOCALE_SABBREVDAYNAME5,
328 LOCALE_SABBREVDAYNAME6, LOCALE_SABBREVDAYNAME7 };
330 static const LCTYPE long_day_map[]
331 = { LOCALE_SDAYNAME1, LOCALE_SDAYNAME2,
332 LOCALE_SDAYNAME3, LOCALE_SDAYNAME4, LOCALE_SDAYNAME5,
333 LOCALE_SDAYNAME6, LOCALE_SDAYNAME7 };
335 static const LCTYPE narrow_day_map[]
344 return getLocaleInfo(long_day_map[day]);
346 return getLocaleInfo(narrow_day_map[day]);
347 return getLocaleInfo(short_day_map[day]);
352 static const LCTYPE short_month_map[]
353 = { LOCALE_SABBREVMONTHNAME1, LOCALE_SABBREVMONTHNAME2, LOCALE_SABBREVMONTHNAME3,
354 LOCALE_SABBREVMONTHNAME4, LOCALE_SABBREVMONTHNAME5, LOCALE_SABBREVMONTHNAME6,
355 LOCALE_SABBREVMONTHNAME7, LOCALE_SABBREVMONTHNAME8, LOCALE_SABBREVMONTHNAME9,
356 LOCALE_SABBREVMONTHNAME10, LOCALE_SABBREVMONTHNAME11, LOCALE_SABBREVMONTHNAME12 };
358 static const LCTYPE long_month_map[]
359 = { LOCALE_SMONTHNAME1, LOCALE_SMONTHNAME2, LOCALE_SMONTHNAME3,
360 LOCALE_SMONTHNAME4, LOCALE_SMONTHNAME5, LOCALE_SMONTHNAME6,
361 LOCALE_SMONTHNAME7, LOCALE_SMONTHNAME8, LOCALE_SMONTHNAME9,
362 LOCALE_SMONTHNAME10, LOCALE_SMONTHNAME11, LOCALE_SMONTHNAME12 };
364 if (month < 1 || month > 12)
368 return getLocaleInfo(
389 if (substitution() == SAlways)
390 text = substituteDigits(std::move(
text));
402QString QSystemLocalePrivate::yearFix(
int year,
int fakeYear,
QString &&formatted)
407 Q_ASSERT(fakeYear >= 1970 && fakeYear <= 2400);
408 const bool matchTwo = year >= 0 && year % 100 == fakeYear % 100;
412 if (formatted.contains(yearUsed))
413 return std::move(formatted).
replace(yearUsed,
sign + trueYear);
417 if (formatted.contains(tail)) {
419 return std::move(formatted);
420 return std::move(formatted).replace(tail.toString(),
sign + trueYear.last(2));
425 trueYear = substituteDigits(std::move(trueYear));
427 yearUsed = substituteDigits(std::move(yearUsed));
431 if (formatted.contains(yearUsed))
432 return std::move(formatted).
replace(yearUsed,
sign + trueYear);
436 if (formatted.contains(tail)) {
438 return std::move(formatted);
439 return std::move(formatted).replace(tail.toString(),
sign + trueYear.last(twoDigits));
442 qWarning(
"Failed to fix up year in formatted date-string using %d for %d", fakeYear, year);
443 return std::move(formatted);
452 const bool fixup = year < 1601;
457 Q_ASSERT(!fixup || st.wYear % 100 != st.wMonth);
458 Q_ASSERT(!fixup || st.wYear % 100 != st.wDay);
464 if (getDateFormat(
flags, &st, NULL,
buf, 255)) {
467 text = yearFix(year, st.wYear, std::move(
text));
468 if (substitution() == SAlways)
469 text = substituteDigits(std::move(
text));
481 st.wMilliseconds = 0;
488 auto formatStr =
reinterpret_cast<const wchar_t *
>(
format.isEmpty() ?
nullptr :
format.utf16());
491 if (getTimeFormat(
flags, &st, formatStr,
buf,
int(std::size(
buf)))) {
493 if (substitution() == SAlways)
494 text = substituteDigits(std::move(
text));
510 if (getLocaleInfo(LOCALE_IMEASURE,
output, 2)) {
520 return getLocaleInfo(LOCALE_SSORTLOCALE);
527 if (getLocaleInfo(LOCALE_S1159,
output, 15))
537 if (getLocaleInfo(LOCALE_S2359,
output, 15))
547 if (getLocaleInfo(LOCALE_IFIRSTDAYOFWEEK,
output, 4))
558 if (getLocaleInfo(LOCALE_SCURRENCY,
buf, 13))
562 if (getLocaleInfo(LOCALE_SINTLSYMBOL,
buf, 9))
567 if (!getLocaleInfo(LOCALE_SNATIVECURRNAME,
buf.data(),
buf.size())) {
568 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
571 if (!getLocaleInfo(LOCALE_SNATIVECURRNAME,
buf.data(),
buf.size()))
585 switch (
arg.value.typeId()) {
590 case QMetaType::UInt:
594 case QMetaType::Double:
598 case QMetaType::LongLong:
602 case QMetaType::ULongLong:
615 CURRENCYFMT *pformat = NULL;
616 if (!
arg.symbol.isEmpty()) {
617 format.NumDigits = getLocaleInfo_int(LOCALE_ICURRDIGITS);
618 format.LeadingZero = getLocaleInfo_int(LOCALE_ILZERO);
619 decimalSep = getLocaleInfo(LOCALE_SMONDECIMALSEP).toString();
620 format.lpDecimalSep = (
wchar_t *)decimalSep.
utf16();
621 thousandSep = getLocaleInfo(LOCALE_SMONTHOUSANDSEP).toString();
622 format.lpThousandSep = (
wchar_t *)thousandSep.
utf16();
623 format.NegativeOrder = getLocaleInfo_int(LOCALE_INEGCURR);
624 format.PositiveOrder = getLocaleInfo_int(LOCALE_ICURRENCY);
625 format.lpCurrencySymbol = (
wchar_t *)
arg.symbol.utf16();
633 QString groupingStr = getLocaleInfo(LOCALE_SMONGROUPING).toString();
635 if (
format.Grouping % 10 == 0)
642 int ret = getCurrencyFormat(0,
reinterpret_cast<const wchar_t *
>(
value.utf16()),
643 pformat,
out.data(),
out.size());
644 if (
ret == 0 && GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
645 ret = getCurrencyFormat(0,
reinterpret_cast<const wchar_t *
>(
value.utf16()),
646 pformat,
out.data(), 0);
648 getCurrencyFormat(0,
reinterpret_cast<const wchar_t *
>(
value.utf16()),
649 pformat,
out.data(),
out.size());
653 if (substitution() == SAlways)
661#if QT_CONFIG(cpp_winrt)
662 using namespace winrt;
663 using namespace Windows::System::UserProfile;
665 auto languages = GlobalizationPreferences::Languages();
666 for (
const auto &lang : languages)
675 unsigned long cnt = 0;
677# if !defined(QT_BOOTSTRAPPED)
678 unsigned long size =
buf.size();
681 if (GetLastError() == ERROR_INSUFFICIENT_BUFFER &&
691 for (; cnt > 0; --cnt) {
714 lcid = GetUserDefaultLCID();
715 substitutionType = SUnknown;
724 while (
i < sys_fmt.
size()) {
737 switch (
c.unicode()) {
742 else if (repeat == 3)
793 return d->decimalPoint();
795 return d->groupSeparator();
797 return d->negativeSign();
799 return d->positiveSign();
848 return d->zeroDigit();
860 return d->measurementSystem();
862 return d->collation();
868 return d->firstDayOfWeek();
874 return d->uiLanguages();
879 return d->nativeLanguageName();
881 return d->nativeTerritoryName();
895struct ByWindowsCode {
899 {
return int(lhs.windows_code) < rhs; }
1000 { 0x3001,
"ar_LB" },
1001 { 0x300a,
"es_EC" },
1002 { 0x3401,
"ar_KW" },
1003 { 0x340a,
"es_CL" },
1004 { 0x3801,
"ar_AE" },
1005 { 0x380a,
"es_UY" },
1006 { 0x3c01,
"ar_BH" },
1007 { 0x3c0a,
"es_PY" },
1008 { 0x4001,
"ar_QA" },
1009 { 0x400a,
"es_BO" },
1010 { 0x440a,
"es_SV" },
1011 { 0x480a,
"es_HN" },
1012 { 0x4c0a,
"es_NI" },
1033 return it->iso_name;
1042 return LOCALE_USER_DEFAULT;
1044 if (!strncmp(
name,
"nb", 2))
1046 if (!strncmp(
name,
"nn", 2))
1050 strncpy(
n,
name,
sizeof(
n));
1060 if (!strcmp(
n,
i.iso_name))
1061 return i.windows_code;
1063 return LOCALE_USER_DEFAULT;
1075 if (GetLocaleInfo(
id, LOCALE_ILANGUAGE,
out, 255))
1079 const QByteArray latin1 = std::move(lang_code).toLatin1();
1081 if (used >= latin1.
size() || (used > 0 && latin1[used] ==
'\0')) {
1096 if (GetLocaleInfo(
id, LOCALE_SISO639LANGNAME,
out, 255))
1107 if (GetLocaleInfo(
id, LOCALE_SISO3166CTRYNAME,
out, 255))
1116 if (
id == LOCALE_USER_DEFAULT) {
1123 if (used <= 0 ||
id == 0 || id < INT_MIN || id > INT_MAX)
1129 if (
id == LOCALE_USER_DEFAULT)
1130 id = GetUserDefaultLCID();
1134 resultusage += u
'_' + country;
1136 return std::move(resultusage).
toLatin1();
char * data()
\macro QT_NO_CAST_FROM_BYTEARRAY
qsizetype size() const noexcept
Returns the number of bytes in this byte array.
static constexpr char32_t surrogateToUcs4(char16_t high, char16_t low) noexcept
Converts a UTF16 surrogate pair with the given high and low values to it's UCS-4-encoded code point.
static constexpr char16_t highSurrogate(char32_t ucs4) noexcept
Returns the high surrogate part of a UCS-4-encoded code point.
constexpr char16_t unicode() const noexcept
Returns the numeric Unicode value of the QChar.
static constexpr char16_t lowSurrogate(char32_t ucs4) noexcept
Returns the low surrogate part of a UCS-4-encoded code point.
\inmodule QtCore\reentrant
QTime time() const
Returns the time part of the datetime.
QDate date() const
Returns the date part of the datetime.
\inmodule QtCore \reentrant
int month() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
int day() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
int year() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
static int yearSharingWeekDays(QDate date)
constexpr qsizetype size() const noexcept
Returns the size of this string view, in UTF-16 code units (that is, surrogate pairs count as two for...
constexpr QStringView last(qsizetype n) const noexcept
constexpr QChar at(qsizetype n) const noexcept
Returns the character at position n in this string view.
constexpr QStringView mid(qsizetype pos, qsizetype n=-1) const noexcept
Returns the substring of length length starting at position start in this object.
\macro QT_RESTRICTED_CAST_FROM_ASCII
QByteArray toLatin1() const &
int toInt(bool *ok=nullptr, int base=10) const
Returns the string converted to an int using base base, which is 10 by default and must be between 2 ...
QString & replace(qsizetype i, qsizetype len, QChar after)
static QString fromLatin1(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
const ushort * utf16() const
Returns the QString as a '\0\'-terminated array of unsigned shorts.
static QString fromStdString(const std::string &s)
static QString fromLocal8Bit(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
const QChar * constData() const
Returns a pointer to the data stored in the QString.
qsizetype size() const
Returns the number of characters in this string.
uint toUInt(bool *ok=nullptr, int base=10) const
Returns the string converted to an {unsigned int} using base base, which is 10 by default and must be...
const QChar at(qsizetype i) const
Returns the character at the given index position in the string.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
static QString fromWCharArray(const wchar_t *string, qsizetype size=-1)
QString & remove(qsizetype i, qsizetype len)
Removes n characters from the string, starting at the given position index, and returns a reference t...
void resize(qsizetype size)
Sets the size of the string to size characters.
@ StandaloneMonthNameLong
@ StandaloneDayNameNarrow
@ StandaloneMonthNameNarrow
@ StandaloneMonthNameShort
virtual QVariant query(QueryType type, QVariant in=QVariant()) const
virtual QLocale fallbackLocale() const
\inmodule QtCore \reentrant
int hour() const
Returns the hour part (0 to 23) of the time.
int minute() const
Returns the minute part (0 to 59) of the time.
int second() const
Returns the second part (0 to 59) of the time.
QString toString() const
Returns the variant as a QString if the variant has a userType() including, but not limited to:
QSet< QString >::iterator it
Combined button and popup list for selecting options.
constexpr bool is_sorted(ForwardIterator first, ForwardIterator last, BinaryPredicate p={})
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
#define Q_GLOBAL_STATIC(TYPE, NAME,...)
qsizetype qt_repeatCount(QStringView s)
bool qt_splitLocaleName(QStringView name, QStringView *lang, QStringView *script, QStringView *land)
QString qt_readEscapedFormatString(QStringView format, qsizetype *idx)
static QByteArray getWinLocaleName(LCID id=LOCALE_USER_DEFAULT)
static QString fourDigitYear(int year)
#define LOCALE_SSHORTESTDAYNAME2
#define LOCALE_SSHORTTIME
#define LOCALE_SSHORTESTDAYNAME4
#define LOCALE_SSHORTESTDAYNAME3
static QString winIso3116CtryName(LCID id=LOCALE_USER_DEFAULT)
#define LOCALE_SSHORTESTDAYNAME7
static constexpr WindowsToISOListElt windows_to_iso_list[]
#define LOCALE_SSHORTESTDAYNAME5
static QString winIso639LangName(LCID id=LOCALE_USER_DEFAULT)
#define LOCALE_SNATIVELANGUAGENAME
Q_CORE_EXPORT QLocale qt_localeFromLCID(LCID id)
#define LOCALE_SSHORTESTDAYNAME6
#define LOCALE_SNATIVECOUNTRYNAME
#define MUI_LANGUAGE_NAME
LCID qt_inIsoNametoLCID(const char *name)
static const char * winLangCodeToIsoName(int code)
#define LOCALE_SSHORTESTDAYNAME1
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat z
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLenum GLuint GLenum GLsizei const GLchar * buf
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLint GLsizei GLsizei GLenum format
#define QStringLiteral(str)
Q_CORE_EXPORT QByteArray qgetenv(const char *varName)
QT_BEGIN_NAMESPACE typedef uchar * output
QTextStream out(stdout)
[7]
\inmodule QtCore \reentrant
QString doubleToString(double d, int precision=-1, DoubleForm form=DFSignificantDigits, int width=-1, unsigned flags=NoFlags) const
static const QLocaleData * c()
QString longLongToString(qint64 l, int precision=-1, int base=10, int width=-1, unsigned flags=NoFlags) const
QString unsLongLongToString(quint64 l, int precision=-1, int base=10, int width=-1, unsigned flags=NoFlags) const
static Q_AUTOTEST_EXPORT QLocaleId fromName(QStringView name)
QVariant dateFormat(QLocale::FormatType)
QVariant toString(QDate, QLocale::FormatType)
QVariant dayName(int, QLocale::FormatType)
QVariant firstDayOfWeek()
QVariant monthName(int, QLocale::FormatType)
QVariant currencySymbol(QLocale::CurrencySymbolFormat)
QVariant nativeLanguageName()
QVariant standaloneMonthName(int, QLocale::FormatType)
QVariant nativeTerritoryName()
QVariant dateTimeFormat(QLocale::FormatType)
QVariant measurementSystem()
QVariant groupSeparator()
QVariant timeFormat(QLocale::FormatType)
QVariant toCurrencyString(const QSystemLocale::CurrencyToStringArgument &)