49 #include "private/qsystemlibrary_p.h" 65 #ifndef QT_NO_SYSTEMLOCALE 67 #ifndef MUI_LANGUAGE_NAME 68 #define MUI_LANGUAGE_NAME 0x8 70 #ifndef LOCALE_SSHORTESTDAYNAME1 71 # define LOCALE_SSHORTESTDAYNAME1 0x0060 72 # define LOCALE_SSHORTESTDAYNAME2 0x0061 73 # define LOCALE_SSHORTESTDAYNAME3 0x0062 74 # define LOCALE_SSHORTESTDAYNAME4 0x0063 75 # define LOCALE_SSHORTESTDAYNAME5 0x0064 76 # define LOCALE_SSHORTESTDAYNAME6 0x0065 77 # define LOCALE_SSHORTESTDAYNAME7 0x0066 79 #ifndef LOCALE_SNATIVELANGUAGENAME 80 # define LOCALE_SNATIVELANGUAGENAME 0x00000004 82 #ifndef LOCALE_SNATIVECOUNTRYNAME 83 # define LOCALE_SNATIVECOUNTRYNAME 0x00000008 146 lcid = GetUserDefaultLCID();
154 if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
155 int cnt = GetLocaleInfo(
lcid, type, 0, 0);
169 int v = str.
toInt(&ok);
183 if (!GetLocaleInfo(
lcid, LOCALE_IDIGITSUBSTITUTION, buf, 8)) {
189 else if (buf[0] ==
'0')
191 else if (buf[0] ==
'2')
195 if (!GetLocaleInfo(
lcid, LOCALE_SNATIVEDIGITS, digits, 11)) {
199 const wchar_t zero = digits[0];
200 if (buf[0] == zero + 2)
213 for (
ushort *
end = qch +
string.size(); qch !=
end; ++qch) {
214 if (*qch >=
'0' && *qch <=
'9')
215 *qch = zero + (*qch -
'0');
280 static const LCTYPE short_day_map[]
281 = { LOCALE_SABBREVDAYNAME1, LOCALE_SABBREVDAYNAME2,
282 LOCALE_SABBREVDAYNAME3, LOCALE_SABBREVDAYNAME4, LOCALE_SABBREVDAYNAME5,
283 LOCALE_SABBREVDAYNAME6, LOCALE_SABBREVDAYNAME7 };
285 static const LCTYPE long_day_map[]
286 = { LOCALE_SDAYNAME1, LOCALE_SDAYNAME2,
287 LOCALE_SDAYNAME3, LOCALE_SDAYNAME4, LOCALE_SDAYNAME5,
288 LOCALE_SDAYNAME6, LOCALE_SDAYNAME7 };
290 static const LCTYPE narrow_day_map[]
307 static const LCTYPE short_month_map[]
308 = { LOCALE_SABBREVMONTHNAME1, LOCALE_SABBREVMONTHNAME2, LOCALE_SABBREVMONTHNAME3,
309 LOCALE_SABBREVMONTHNAME4, LOCALE_SABBREVMONTHNAME5, LOCALE_SABBREVMONTHNAME6,
310 LOCALE_SABBREVMONTHNAME7, LOCALE_SABBREVMONTHNAME8, LOCALE_SABBREVMONTHNAME9,
311 LOCALE_SABBREVMONTHNAME10, LOCALE_SABBREVMONTHNAME11, LOCALE_SABBREVMONTHNAME12 };
313 static const LCTYPE long_month_map[]
314 = { LOCALE_SMONTHNAME1, LOCALE_SMONTHNAME2, LOCALE_SMONTHNAME3,
315 LOCALE_SMONTHNAME4, LOCALE_SMONTHNAME5, LOCALE_SMONTHNAME6,
316 LOCALE_SMONTHNAME7, LOCALE_SMONTHNAME8, LOCALE_SMONTHNAME9,
317 LOCALE_SMONTHNAME10, LOCALE_SMONTHNAME11, LOCALE_SMONTHNAME12 };
320 if (month < 0 || month > 11)
324 ? short_month_map[month] : long_month_map[month];
331 memset(&st, 0,
sizeof(SYSTEMTIME));
332 st.wYear = date.
year();
333 st.wMonth = date.
month();
334 st.wDay = date.
day();
338 if (GetDateFormat(
lcid, flags, &st, NULL, buf, 255)) {
350 memset(&st, 0,
sizeof(SYSTEMTIME));
351 st.wHour = time.
hour();
352 st.wMinute = time.
minute();
353 st.wSecond = time.
second();
354 st.wMilliseconds = 0;
359 if (GetTimeFormat(
lcid, flags, &st, NULL, buf, 255)) {
377 if (GetLocaleInfo(
lcid, LOCALE_IMEASURE, output, 2)) {
391 if (GetLocaleInfo(
lcid, LOCALE_S1159, output, 15)) {
402 if (GetLocaleInfo(
lcid, LOCALE_S2359, output, 15)) {
413 if (GetLocaleInfo(
lcid, LOCALE_IFIRSTDAYOFWEEK, output, 4))
424 if (GetLocaleInfo(
lcid, LOCALE_SCURRENCY, buf, 13))
428 if (GetLocaleInfo(
lcid, LOCALE_SINTLSYMBOL, buf, 9))
433 if (!GetLocaleInfo(
lcid, LOCALE_SNATIVECURRNAME, buf.
data(), buf.
size())) {
434 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
437 if (!GetLocaleInfo(
lcid, LOCALE_SNATIVECURRNAME, buf.
data(), buf.
size()))
482 CURRENCYFMT *pformat = NULL;
487 format.lpDecimalSep = (
wchar_t *)decimalSep.
utf16();
489 format.lpThousandSep = (
wchar_t *)thousandSep.
utf16();
492 format.lpCurrencySymbol = (
wchar_t *)arg.
symbol.
utf16();
502 if (format.Grouping % 10 == 0)
503 format.Grouping /= 10;
505 format.Grouping *= 10;
509 int ret = ::GetCurrencyFormat(
lcid, 0, reinterpret_cast<const wchar_t *>(value.
utf16()),
511 if (ret == 0 && GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
512 ret = ::GetCurrencyFormat(
lcid, 0, reinterpret_cast<const wchar_t *>(value.
utf16()),
513 pformat, out.
data(), 0);
515 ::GetCurrencyFormat(
lcid, 0, reinterpret_cast<const wchar_t *>(value.
utf16()),
528 typedef BOOL (WINAPI *GetUserPreferredUILanguagesFunc) (
530 PULONG pulNumLanguages,
531 PWSTR pwszLanguagesBuffer,
532 PULONG pcchLanguagesBuffer);
533 static GetUserPreferredUILanguagesFunc GetUserPreferredUILanguages_ptr = 0;
534 if (!GetUserPreferredUILanguages_ptr) {
537 GetUserPreferredUILanguages_ptr = (GetUserPreferredUILanguagesFunc)lib.
resolve(
"GetUserPreferredUILanguages");
539 if (GetUserPreferredUILanguages_ptr) {
540 unsigned long cnt = 0;
542 unsigned long size = buf.
size();
545 if (GetLastError() == ERROR_INSUFFICIENT_BUFFER &&
555 for (; cnt > 0; --cnt) {
587 lcid = GetUserDefaultLCID();
597 while (i < sys_fmt.
size()) {
615 else if (repeat == 3)
675 case DateFormatShort:
679 case TimeFormatShort:
681 case DateTimeFormatLong:
683 case DateTimeFormatShort:
690 case StandaloneMonthNameLong:
693 case StandaloneMonthNameShort:
695 case DateToStringShort:
697 case DateToStringLong:
699 case TimeToStringShort:
701 case TimeToStringLong:
703 case DateTimeToStringShort:
705 case DateTimeToStringLong:
716 if (
type == LanguageId)
719 return fallbackLocale().country();
724 case MeasurementSystem:
734 case CurrencyToString:
741 case NativeLanguageName:
743 case NativeCountryName:
750 #endif // QT_NO_SYSTEMLOCALE 879 return windows_to_iso_list[0].
iso_name;
884 while (end - begin > 1) {
909 if (GetLocaleInfo(
id, LOCALE_ILANGUAGE, out, 255))
916 int i =
qstrtoull(latin1_lang_code, &endptr, 16, &ok);
917 if (ok && *endptr ==
'\0') {
932 if (GetLocaleInfo(
id, LOCALE_SISO639LANGNAME , out, 255))
943 if (GetLocaleInfo(
id, LOCALE_SISO3166CTRYNAME, out, 255))
952 if (
id == LOCALE_USER_DEFAULT) {
956 if ( result ==
"C" || (!result.
isEmpty()
961 if ( !ok ||
id == 0 || id < INT_MIN || id >
INT_MAX )
968 #if defined(Q_OS_WINCE) 971 if (
id == LOCALE_USER_DEFAULT)
972 id = GetUserDefaultLCID();
The QVariant class acts like a union for the most common Qt data types.
static QString fromWCharArray(const wchar_t *, int size=-1)
Returns a copy of the string, where the encoding of string depends on the size of wchar...
QVariant measurementSystem()
const T * constData() const
Q_CORE_EXPORT QByteArray qgetenv(const char *varName)
static QString fromLocal8Bit(const char *, int size=-1)
Returns a QString initialized with the first size characters of the 8-bit string str.
#define QT_END_NAMESPACE
This macro expands to.
char * data()
Returns a pointer to the data stored in the byte array.
#define LOCALE_SNATIVECOUNTRYNAME
int getLocaleInfo_int(LCTYPE type, int maxlen=0)
const QChar at(int i) const
Returns the character at the given index position in the string.
static QString winIso639LangName(LCID id=LOCALE_USER_DEFAULT)
static const char * winLangCodeToIsoName(int code)
int toInt(bool *ok=0, int base=10) const
Returns the string converted to an int using base base, which is 10 by default and must be between 2 ...
ushort unicode() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool isNull() const
Returns true if the character is the Unicode character 0x0000 ('\0'); otherwise returns false...
The QByteArray class provides an array of bytes.
int month() const
Returns the number corresponding to the month of this date, using the following convention: ...
static WinVersion windowsVersion()
Returns the version of the Windows operating system on which the application is run (Windows only)...
int day() const
Returns the day of the month (1 to 31) of this date.
The QDate class provides date functions.
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
bool qt_splitLocaleName(const QString &name, QString &lang, QString &script, QString &cntry)
QVariant nativeLanguageName()
The QString class provides a Unicode character string.
QVariant currencySymbol(QLocale::CurrencySymbolFormat)
bool load(bool onlySystemDirectory=true)
The QChar class provides a 16-bit Unicode character.
static const WindowsToISOListElt windows_to_iso_list[]
static QString doubleToString(const QChar zero, const QChar plus, const QChar minus, const QChar exponent, const QChar group, const QChar decimal, double d, int precision, DoubleForm form, int width, unsigned flags)
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
static void getLangAndCountry(const QString &name, QLocale::Language &lang, QLocale::Script &script, QLocale::Country &cntry)
static QString unsLongLongToString(const QChar zero, const QChar group, const QChar plus, quint64 l, int precision, int base, int width, unsigned flags)
void append(const T &t)
Inserts value at the end of the list.
#define MUI_LANGUAGE_NAME
int qt_repeatCount(const QString &s, int i)
The QTime class provides clock time functions.
static QString longLongToString(const QChar zero, const QChar group, const QChar plus, const QChar minus, qint64 l, int precision, int base, int width, unsigned flags)
#define QT_BEGIN_NAMESPACE
This macro expands to.
qlonglong toLongLong(bool *ok=0) const
Returns the variant as a long long int if the variant has type() LongLong , Bool , ByteArray , Char , Double , Int , String , UInt , or ULongLong ; otherwise returns 0.
#define LOCALE_SSHORTESTDAYNAME7
QString qt_readEscapedFormatString(const QString &format, int *idx)
#define LOCALE_SNATIVELANGUAGENAME
int size() const
Returns the number of characters in this string.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
#define LOCALE_SSHORTESTDAYNAME5
#define Q_GLOBAL_STATIC(TYPE, NAME)
Declares a global static variable with the given type and name.
The QStringList class provides a list of strings.
qulonglong toULongLong(bool *ok=0) const
Returns the variant as as an unsigned long long int if the variant has type() ULongLong ...
int second() const
Returns the second part (0 to 59) of the time.
static const char * data(const QByteArray &arr)
QChar getLocaleInfo_qchar(LCTYPE type)
QVariant dateTimeFormat(QLocale::FormatType)
QVariant dateFormat(QLocale::FormatType)
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
static int cmp(const ushort *s1, const ushort *s2, size_t len)
QString getLocaleInfo(LCTYPE type, int maxlen=0)
int minute() const
Returns the minute part (0 to 59) of the time.
QVariant timeFormat(QLocale::FormatType)
CurrencySymbolFormat
Specifies the format of the currency symbol.
Q_CORE_EXPORT int QT_FASTCALL script(uint ucs4)
#define LOCALE_SSHORTESTDAYNAME1
QVariant toCurrencyString(const QSystemLocale::CurrencyToStringArgument &)
static const int windows_to_iso_count
QDate date() const
Returns the date part of the datetime.
#define LOCALE_SSHORTESTDAYNAME4
#define LOCALE_SSHORTESTDAYNAME2
SubstitutionType substitutionType
#define LOCALE_SSHORTESTDAYNAME3
void * resolve(const char *symbol)
The QDateTime class provides date and time functions.
static QString winIso3116CtryName(LCID id=LOCALE_USER_DEFAULT)
#define LOCALE_SSHORTESTDAYNAME6
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Type type() const
Returns the storage type of the value stored in the variant.
QVariant toString(const QDate &, QLocale::FormatType)
Q_CORE_EXPORT QLocale qt_localeFromLCID(LCID id)
#define st(var, type, card)
QVariant nativeCountryName()
uint toUInt(bool *ok=0) const
Returns the variant as an unsigned int if the variant has type() UInt , Bool , ByteArray ...
QVariant firstDayOfWeek()
uint toUInt(bool *ok=0, int base=10) const
Returns the string converted to an unsigned int using base base, which is 10 by default and must be b...
QVariant dayName(int, QLocale::FormatType)
virtual QVariant query(QueryType type, QVariant in) const
double toDouble(bool *ok=0) const
Returns the variant as a double if the variant has type() Double , QMetaType::Float ...
virtual QLocale fallbackLocale() const
static QString winToQtFormat(const QString &sys_fmt)
QString & substituteDigits(QString &string)
int year() const
Returns the year of this date.
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
QTime time() const
Returns the time part of the datetime.
QString & remove(int i, int len)
Removes n characters from the string, starting at the given position index, and returns a reference t...
SubstitutionType substitution()
static const KeyPair *const end
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
QVariant monthName(int, QLocale::FormatType)
void reserve(int size)
Reserve space for alloc elements.
static QByteArray getWinLocaleName(LCID id=LOCALE_USER_DEFAULT)
int hour() const
Returns the hour part (0 to 23) of the time.
const ushort * utf16() const
Returns the QString as a '\0\'-terminated array of unsigned shorts.