?? qlocale.cpp
字號:
#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, 0);}/*! 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) d = defaultPrivate(); ::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();}/*! 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; 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 toLongLong(), toInt(), toDouble(), toString()*/qlonglong QLocale::toULongLong(const QString &s, bool *ok, int base) const{ QLocalePrivate::GroupSeparatorMode mode = ::numberOptions(v) & RejectGroupSeparator ? QLocalePrivate::FailOnGroupSeparators : QLocalePrivate::ParseGroupSeparators; return d()->stringToUnsLongLong(s, base, ok, mode);}/*! Returns the float represented by the localized string \a s, or 0.0 if the conversion failed. If \a ok is not 0, reports failure by setting *ok to false and success by setting *ok to true. This function ignores leading and trailing whitespace. \sa toDouble(), toInt(), toString()*/#define QT_MAX_FLOAT 3.4028234663852886e+38float QLocale::toFloat(const QString &s, bool *ok) const{ bool myOk; double d = toDouble(s, &myOk); if (!myOk || d > QT_MAX_FLOAT || d < -QT_MAX_FLOAT) { if (ok != 0) *ok = false; return 0.0; } if (ok != 0) *ok = true; return float(d);}/*! Returns the double represented by the localized string \a s, or 0.0 if the conversion failed. If \a ok is not 0, reports failure by setting *ok to false and success by setting *ok to true. Unlike QString::toDouble(), this function does not fall back to the "C" locale if the string cannot be interpreted in this locale. \code bool ok; double d; QLocale c(QLocale::C); d = c.toDouble( "1234.56", &ok ); // ok == true, d == 1234.56 d = c.toDouble( "1,234.56", &ok ); // ok == true, d == 1234.56 d = c.toDouble( "1234,56", &ok ); // ok == false QLocale german(QLocale::German); d = german.toDouble( "1234,56", &ok ); // ok == true, d == 1234.56 d = german.toDouble( "1.234,56", &ok ); // ok == true, d == 1234.56 d = german.toDouble( "1234.56", &ok ); // ok == false d = german.toDouble( "1.234", &ok ); // ok == true, d == 1234.0 \endcode Notice that the last conversion returns 1234.0, because '.' is the
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -