diff options
Diffstat (limited to 'thirdparty/icu4c/common/uscript.cpp')
-rw-r--r-- | thirdparty/icu4c/common/uscript.cpp | 35 |
1 files changed, 11 insertions, 24 deletions
diff --git a/thirdparty/icu4c/common/uscript.cpp b/thirdparty/icu4c/common/uscript.cpp index 3cc2b6675c..2e9012a982 100644 --- a/thirdparty/icu4c/common/uscript.cpp +++ b/thirdparty/icu4c/common/uscript.cpp @@ -18,7 +18,6 @@ #include "unicode/uchar.h" #include "unicode/uscript.h" #include "unicode/uloc.h" -#include "bytesinkutil.h" #include "charstr.h" #include "cmemory.h" #include "cstring.h" @@ -57,33 +56,25 @@ setOneCode(UScriptCode script, UScriptCode *scripts, int32_t capacity, UErrorCod static int32_t getCodesFromLocale(const char *locale, UScriptCode *scripts, int32_t capacity, UErrorCode *err) { - UErrorCode internalErrorCode = U_ZERO_ERROR; - char lang[8] = {0}; - char script[8] = {0}; - int32_t scriptLength; - if(U_FAILURE(*err)) { return 0; } + if (U_FAILURE(*err)) { return 0; } + icu::CharString lang; + icu::CharString script; + ulocimp_getSubtags(locale, &lang, &script, nullptr, nullptr, nullptr, *err); + if (U_FAILURE(*err)) { return 0; } // Multi-script languages, equivalent to the LocaleScript data // that we used to load from locale resource bundles. - /*length = */ uloc_getLanguage(locale, lang, UPRV_LENGTHOF(lang), &internalErrorCode); - if(U_FAILURE(internalErrorCode) || internalErrorCode == U_STRING_NOT_TERMINATED_WARNING) { - return 0; - } - if(0 == uprv_strcmp(lang, "ja")) { + if (lang == "ja") { return setCodes(JAPANESE, UPRV_LENGTHOF(JAPANESE), scripts, capacity, err); } - if(0 == uprv_strcmp(lang, "ko")) { + if (lang == "ko") { return setCodes(KOREAN, UPRV_LENGTHOF(KOREAN), scripts, capacity, err); } - scriptLength = uloc_getScript(locale, script, UPRV_LENGTHOF(script), &internalErrorCode); - if(U_FAILURE(internalErrorCode) || internalErrorCode == U_STRING_NOT_TERMINATED_WARNING) { - return 0; - } - if(0 == uprv_strcmp(lang, "zh") && 0 == uprv_strcmp(script, "Hant")) { + if (lang == "zh" && script == "Hant") { return setCodes(HAN_BOPO, UPRV_LENGTHOF(HAN_BOPO), scripts, capacity, err); } // Explicit script code. - if(scriptLength != 0) { - UScriptCode scriptCode = (UScriptCode)u_getPropertyValueEnum(UCHAR_SCRIPT, script); + if (!script.isEmpty()) { + UScriptCode scriptCode = (UScriptCode)u_getPropertyValueEnum(UCHAR_SCRIPT, script.data()); if(scriptCode != USCRIPT_INVALID_CODE) { if(scriptCode == USCRIPT_SIMPLIFIED_HAN || scriptCode == USCRIPT_TRADITIONAL_HAN) { scriptCode = USCRIPT_HAN; @@ -140,11 +131,7 @@ uscript_getCode(const char* nameOrAbbrOrLocale, if(U_FAILURE(*err) || length != 0) { return length; } - icu::CharString likely; - { - icu::CharStringByteSink sink(&likely); - ulocimp_addLikelySubtags(nameOrAbbrOrLocale, sink, &internalErrorCode); - } + icu::CharString likely = ulocimp_addLikelySubtags(nameOrAbbrOrLocale, internalErrorCode); if(U_SUCCESS(internalErrorCode) && internalErrorCode != U_STRING_NOT_TERMINATED_WARNING) { length = getCodesFromLocale(likely.data(), fillIn, capacity, err); if(U_FAILURE(*err) || length != 0) { |