diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/text/qlocale.cpp | 47 | ||||
-rw-r--r-- | src/corelib/text/qlocale.h | 4 |
2 files changed, 49 insertions, 2 deletions
diff --git a/src/corelib/text/qlocale.cpp b/src/corelib/text/qlocale.cpp index aabdb3b213..faa49ee4bc 100644 --- a/src/corelib/text/qlocale.cpp +++ b/src/corelib/text/qlocale.cpp @@ -175,7 +175,7 @@ QLocale::Country QLocalePrivate::codeToCountry(QStringView code) noexcept QLatin1String QLocalePrivate::languageToCode(QLocale::Language language) { - if (language == QLocale::AnyLanguage) + if (language == QLocale::AnyLanguage || language > QLocale::LastLanguage) return QLatin1String(); if (language == QLocale::C) return QLatin1String("C"); @@ -194,7 +194,7 @@ QLatin1String QLocalePrivate::scriptToCode(QLocale::Script script) QLatin1String QLocalePrivate::countryToCode(QLocale::Country country) { - if (country == QLocale::AnyCountry) + if (country == QLocale::AnyCountry || country > QLocale::LastCountry) return QLatin1String(); const unsigned char *c = country_code_list + 3 * country; @@ -1346,6 +1346,49 @@ QString QLocale::bcp47Name() const } /*! + Returns the two- or three-letter language code for \a language, as defined + in the ISO 639 standards. + + \note For \c{QLocale::C} the function returns \c{"C"}. + For \c QLocale::AnyLanguage an empty string is returned. + + \since 6.1 + \sa language(), name(), bcp47Name(), countryToCode(), scriptToCode() +*/ +QString QLocale::languageToCode(Language language) +{ + return QLocalePrivate::languageToCode(language); +} + +/*! + Returns the two-letter country code for \a country, as defined + in the ISO 3166 standard. + + \note For \c{QLocale::AnyCountry} an empty string is returned. + + \since 6.1 + \sa country(), name(), bcp47Name(), languageToCode(), scriptToCode() +*/ +QString QLocale::countryToCode(Country country) +{ + return QLocalePrivate::countryToCode(country); +} + +/*! + Returns the four-letter script code for \a script, as defined in the + ISO 15924 standard. + + \note For \c{QLocale::AnyScript} an empty string is returned. + + \since 6.1 + \sa script(), name(), bcp47Name(), languageToCode(), countryToCode() +*/ +QString QLocale::scriptToCode(Script script) +{ + return QLocalePrivate::scriptToCode(script); +} + +/*! Returns a QString containing the name of \a language. \sa countryToString(), scriptToString(), bcp47Name() diff --git a/src/corelib/text/qlocale.h b/src/corelib/text/qlocale.h index 2f9070bdd1..a05196946f 100644 --- a/src/corelib/text/qlocale.h +++ b/src/corelib/text/qlocale.h @@ -1067,6 +1067,10 @@ public: QStringList uiLanguages() const; + static QString languageToCode(Language language); + static QString countryToCode(Country country); + static QString scriptToCode(Script script); + static QString languageToString(Language language); static QString countryToString(Country country); static QString scriptToString(Script script); |