📄 qlocale.cpp
字号:
\sa country()*//*! \enum QLocale::FormatType This enum describes the types of format that can be used when converting QDate and QTime objects to strings. \value LongFormat \value ShortFormat*//*! \enum QLocale::NumberOption This enum defines a set of options for number-to-string and string-to-number conversions. They can be retrieved with numberOptions() and set with setNumberOptions(). \value OmitGroupSeparator If this option is set, the number-to-string functions will not insert group separators in their return values. The default is to insert group seperators. \value RejectGroupSeparator If this option is set, the string-to-number functions will fail if they encounter group separators in their input. The default is to accept numbers containing correctly placed group separators. \sa setNumberOptions() numberOptions()*//*! \fn bool QLocale::operator==(const QLocale &other) const Returns true if the QLocale object is the same as the \a other locale specified; otherwise returns false.*//*! \fn bool QLocale::operator!=(const QLocale &other) const Returns true if the QLocale object is not the same as the \a other locale specified; otherwise returns false.*/static const int locale_data_size = sizeof(locale_data)/sizeof(QLocalePrivate) - 1;static const QLocalePrivate *dataPointer(void *v){ quint16 index = reinterpret_cast<quintptr>(v) & 0xFFFF;#ifndef QT_NO_SYSTEMLOCALE Q_ASSERT(index <= locale_data_size); if (index == locale_data_size) return system_lp;#else Q_ASSERT(index < locale_data_size);#endif return &locale_data[index];}static int numberOptions(void *v){ quint16 opt = (reinterpret_cast<quintptr>(v) >> 16) & 0xFFFF; return opt;}static void setDataPointer(void **v, const QLocalePrivate *p){ quint32 i = reinterpret_cast<quintptr>(*v);#ifndef QT_NO_SYSTEMLOCALE Q_ASSERT(p >= locale_data && p - locale_data < locale_data_size || p != 0 && p == system_lp); quint16 index = p == system_lp ? locale_data_size : p - locale_data;#else Q_ASSERT(p >= locale_data && p - locale_data < locale_data_size); quint16 index = p - locale_data;#endif i &= 0xFFFF0000; i |= index & 0xFFFF; *v = reinterpret_cast<void*>(i);}static void setNumberOptions(void **v, int _opts){ quint32 i = reinterpret_cast<quintptr>(*v); quint32 opts = quint32(_opts) << 16; i &= 0xFFFF; i |= opts & 0xFFFF0000; *v = reinterpret_cast<void*>(i);}/*! Constructs a QLocale object with the specified \a name, which has the format "language[_country][.codeset][@modifier]" or "C", where: \list \i language is a lowercase, two-letter, ISO 639 language code, \i territory is an uppercase, two-letter, ISO 3166 country code, \i and codeset and modifier are ignored. \endlist If the string violates the locale format, or language is not a valid ISO 369 code, the "C" locale is used instead. If country is not present, or is not a valid ISO 3166 code, the most appropriate country is chosen for the specified language. The language and country codes are converted to their respective \c Language and \c Country enums. After this conversion is performed the constructor behaves exactly like QLocale(Country, Language). This constructor is much slower than QLocale(Country, Language). \sa name()*/QLocale::QLocale(const QString &name){ ::setDataPointer(&v, findLocale(name)); ::setNumberOptions(&v, 0);}/*! Constructs a QLocale object initialized with the default locale. If no default locale was set using setDefaultLocale(), this locale will be the same as the one returned by system(). \sa setDefault()*/QLocale::QLocale(){ ::setDataPointer(&v, defaultPrivate()); ::setNumberOptions(&v, default_number_options);}/*! Constructs a QLocale object with the specified \a language and \a country. \list \i If the language/country pair is found in the database, it is used. \i If the language is found but the country is not, or if the country is \c AnyCountry, the language is used with the most appropriate available country (for example, Germany for German), \i If neither the language nor the country are found, QLocale defaults to the default locale (see setDefault()). \endlist The language and country that are actually used can be queried using language() and country(). \sa setDefault() language() country()*/QLocale::QLocale(Language language, Country country){ const QLocalePrivate *d = findLocale(language, country); // If not found, should default to system if (d->languageId() == QLocale::C && language != QLocale::C) { ::setDataPointer(&v, defaultPrivate()); ::setNumberOptions(&v, default_number_options); } else { ::setDataPointer(&v, d); ::setNumberOptions(&v, 0); }}/*! Constructs a QLocale object as a copy of \a other.*/QLocale::QLocale(const QLocale &other){ v = other.v;}const QLocalePrivate *QLocale::d() const{ return ::dataPointer(v);}/*! Assigns \a other to this QLocale object and returns a reference to this QLocale object.*/QLocale &QLocale::operator=(const QLocale &other){ v = other.v; return *this;}/*! \since 4.2 Sets the \a options related to number conversions for this QLocale instance.*/void QLocale::setNumberOptions(NumberOptions options){ ::setNumberOptions(&v, options);}/*! \since 4.2 Returns the options related to number conversions for this QLocale instance. By default, no options are set for the standard locales.*/QLocale::NumberOptions QLocale::numberOptions() const{ return static_cast<NumberOption>(::numberOptions(v));}/*! \nonreentrant Sets the global default locale to \a locale. These values are used when a QLocale object is constructed with no arguments. If this function is not called, the system's locale is used. \warning In a multithreaded application, the default locale should be set at application startup, before any non-GUI threads are created. \sa system() c()*/void QLocale::setDefault(const QLocale &locale){ default_lp = locale.d(); default_number_options = locale.numberOptions();}/*! Returns the language of this locale. \sa country(), languageToString(), name()*/QLocale::Language QLocale::language() const{ return Language(d()->languageId());}/*! Returns the country of this locale. \sa language(), countryToString(), name()*/QLocale::Country QLocale::country() const{ return Country(d()->countryId());}/*! Returns the language and country of this locale as a string of the form "language_country", where language is a lowercase, two-letter ISO 639 language code, and country is an uppercase, two-letter ISO 3166 country code. \sa language(), country()*/QString QLocale::name() const{ Language l = language(); QString result = languageToCode(l); if (l == C) return result; Country c = country(); if (c == AnyCountry) return result; result.append(QLatin1Char('_')); result.append(countryToCode(c)); return result;}/*! Returns a QString containing the name of \a language. \sa countryToString(), name()*/QString QLocale::languageToString(Language language){ if (uint(language) > uint(QLocale::LastLanguage)) return QLatin1String("Unknown"); return QLatin1String(language_name_list + language_name_index[language]);}/*! Returns a QString containing the name of \a country. \sa country(), name()*/QString QLocale::countryToString(Country country){ if (uint(country) > uint(QLocale::LastCountry)) return QLatin1String("Unknown"); return QLatin1String(country_name_list + country_name_index[country]);}/*! Returns the short int represented by the localized string \a s, using base \a base. If \a base is 0 the base is determined automatically using the following rules: If the string begins with "0x", it is assumed to be hexadecimal; if it begins with "0", it is assumed to be octal; otherwise it is assumed to be decimal. If the conversion fails the function returns 0. If \a ok is not 0, failure is reported by setting *ok to false, and success by setting *ok to true. This function ignores leading and trailing whitespace. \sa toUShort(), toString()*/short QLocale::toShort(const QString &s, bool *ok, int base) const{ qlonglong i = toLongLong(s, ok, base); if (i < SHRT_MIN || i > SHRT_MAX) { if (ok != 0) *ok = false; return 0; } return short(i);}/*! Returns the unsigned short int represented by the localized string \a s, using base \a base. If \a base is 0 the base is determined automatically using the following rules: If the string begins with "0x", it is assumed to be hexadecimal; if it begins with "0", it is assumed to be octal; otherwise it is assumed to be decimal. If the conversion fails the function returns 0. If \a ok is not 0, failure is reported by setting *ok to false, and success by setting *ok to true. This function ignores leading and trailing whitespace. \sa toShort(), toString()*/ushort QLocale::toUShort(const QString &s, bool *ok, int base) const{ qulonglong i = toULongLong(s, ok, base); if (i > USHRT_MAX) { if (ok != 0) *ok = false; return 0; } return ushort(i);}/*! Returns the int represented by the localized string \a s, using base \a base. If \a base is 0 the base is determined automatically using the following rules: If the string begins with "0x", it is assumed to be hexadecimal; if it begins with "0", it is assumed to be octal; otherwise it is assumed to be decimal. If the conversion fails the function returns 0. If \a ok is not 0, failure is reported by setting *ok to false, and success by setting *ok to true. This function ignores leading and trailing whitespace. \sa toUInt(), toString()*/int QLocale::toInt(const QString &s, bool *ok, int base) const{ qlonglong i = toLongLong(s, ok, base); if (i < INT_MIN || i > INT_MAX) { if (ok != 0) *ok = false; return 0; } return int(i);}/*! Returns the unsigned int represented by the localized string \a s, using base \a base. If \a base is 0 the base is determined automatically using the following rules: If the string begins with "0x", it is assumed to be hexadecimal; if it begins with "0", it is assumed to be octal; otherwise it is assumed to be decimal. If the conversion fails the function returns 0. If \a ok is not 0, failure is reported by setting *ok to false, and success by setting *ok to true. This function ignores leading and trailing whitespace. \sa toInt(), toString()*/uint QLocale::toUInt(const QString &s, bool *ok, int base) const{ qulonglong i = toULongLong(s, ok, base); if (i > UINT_MAX) { if (ok != 0) *ok = false; return 0; } return uint(i);}/*! Returns the long long int represented by the localized string \a s, using base \a base. If \a base is 0 the base is determined automatically using the following rules: If the string begins with "0x", it is assumed to be hexadecimal; if it begins with "0", it is assumed to be octal; otherwise it is assumed to be decimal. If the conversion fails the function returns 0. If \a ok is not 0, failure is reported by setting *ok to false, and success by setting *ok to true. This function ignores leading and trailing whitespace. \sa toInt(), toULongLong(), toDouble(), toString()*/qlonglong QLocale::toLongLong(const QString &s, bool *ok, int base) const{ QLocalePrivate::GroupSeparatorMode mode = ::numberOptions(v) & RejectGroupSeparator ? QLocalePrivate::FailOnGroupSeparators : QLocalePrivate::ParseGroupSeparators; return d()->stringToLongLong(s, base, ok, mode);}/*! Returns the unsigned long long int represented by the localized string \a s, using base \a base. If \a base is 0 the base is determined automatically using the following rules: If the string begins with "0x", it is assumed to be hexadecimal; if it begins with "0", it is assumed to be octal; o
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -