diff options
Diffstat (limited to 'thirdparty/icu4c/common/uresbund.cpp')
-rw-r--r-- | thirdparty/icu4c/common/uresbund.cpp | 258 |
1 files changed, 125 insertions, 133 deletions
diff --git a/thirdparty/icu4c/common/uresbund.cpp b/thirdparty/icu4c/common/uresbund.cpp index 5aa1c5fa2f..ea4327b314 100644 --- a/thirdparty/icu4c/common/uresbund.cpp +++ b/thirdparty/icu4c/common/uresbund.cpp @@ -94,8 +94,16 @@ static UBool chopLocale(char *name) { static UBool hasVariant(const char* localeID) { UErrorCode err = U_ZERO_ERROR; - int32_t variantLength = uloc_getVariant(localeID, nullptr, 0, &err); - return variantLength != 0; + CheckedArrayByteSink sink(nullptr, 0); + ulocimp_getSubtags( + localeID, + nullptr, + nullptr, + nullptr, + &sink, + nullptr, + err); + return sink.NumberOfBytesAppended() != 0; } // This file contains the tables for doing locale fallback, which are generated @@ -209,17 +217,11 @@ static bool getParentLocaleID(char *name, const char *origName, UResOpenType ope } UErrorCode err = U_ZERO_ERROR; - const char* tempNamePtr = name; - CharString language = ulocimp_getLanguage(tempNamePtr, &tempNamePtr, err); - if (*tempNamePtr == '_') { - ++tempNamePtr; - } - CharString script = ulocimp_getScript(tempNamePtr, &tempNamePtr, err); - if (*tempNamePtr == '_') { - ++tempNamePtr; - } - CharString region = ulocimp_getCountry(tempNamePtr, &tempNamePtr, err); - CharString workingLocale; + CharString language; + CharString script; + CharString region; + ulocimp_getSubtags(name, &language, &script, ®ion, nullptr, nullptr, err); + if (U_FAILURE(err)) { // hopefully this never happens... return chopLocale(name); @@ -238,13 +240,15 @@ static bool getParentLocaleID(char *name, const char *origName, UResOpenType ope } } + CharString workingLocale; + // if it's not in the parent locale table, figure out the fallback script algorithmically // (see CLDR-15265 for an explanation of the algorithm) if (!script.isEmpty() && !region.isEmpty()) { // if "name" has both script and region, is the script the default script? // - if so, remove it and keep the region // - if not, remove the region and keep the script - if (getDefaultScript(language, region) == script.toStringPiece()) { + if (getDefaultScript(language, region) == script) { workingLocale.append(language, err).append("_", err).append(region, err); } else { workingLocale.append(language, err).append("_", err).append(script, err); @@ -254,12 +258,9 @@ static bool getParentLocaleID(char *name, const char *origName, UResOpenType ope // - if yes, replace the region with the script from the original locale ID // - if no, replace the region with the default script for that language and region UErrorCode err = U_ZERO_ERROR; - tempNamePtr = origName; - CharString origNameLanguage = ulocimp_getLanguage(tempNamePtr, &tempNamePtr, err); - if (*tempNamePtr == '_') { - ++tempNamePtr; - } - CharString origNameScript = ulocimp_getScript(origName, nullptr, err); + CharString origNameLanguage; + CharString origNameScript; + ulocimp_getSubtags(origName, &origNameLanguage, &origNameScript, nullptr, nullptr, nullptr, err); if (!origNameScript.isEmpty()) { workingLocale.append(language, err).append("_", err).append(origNameScript, err); } else { @@ -272,7 +273,7 @@ static bool getParentLocaleID(char *name, const char *origName, UResOpenType ope // - if not, return false to continue up the chain // (we don't do this for other open types for the same reason we don't look things up in the parent // locale table for other open types-- see the reference to UTS #35 above) - if (openType != URES_OPEN_LOCALE_DEFAULT_ROOT || getDefaultScript(language, CharString()) == script.toStringPiece()) { + if (openType != URES_OPEN_LOCALE_DEFAULT_ROOT || getDefaultScript(language, CharString()) == script) { workingLocale.append(language, err); } else { return false; @@ -1708,7 +1709,7 @@ U_CAPI int32_t U_EXPORT2 ures_getSize(const UResourceBundle *resB) { static const char16_t* ures_getStringWithAlias(const UResourceBundle *resB, Resource r, int32_t sIndex, int32_t *len, UErrorCode *status) { if(RES_GET_TYPE(r) == URES_ALIAS) { - const char16_t* result = 0; + const char16_t* result = nullptr; UResourceBundle *tempRes = ures_getByIndex(resB, sIndex, nullptr, status); result = ures_getString(tempRes, len, status); ures_close(tempRes); @@ -2573,7 +2574,7 @@ U_CAPI const char16_t* U_EXPORT2 ures_getStringByKey(const UResourceBundle *resB return res_getString({resB, key}, &dataEntry->fData, res, len); case URES_ALIAS: { - const char16_t* result = 0; + const char16_t* result = nullptr; UResourceBundle *tempRes = ures_getByKey(resB, inKey, nullptr, status); result = ures_getString(tempRes, len, status); ures_close(tempRes); @@ -2595,7 +2596,7 @@ U_CAPI const char16_t* U_EXPORT2 ures_getStringByKey(const UResourceBundle *resB return res_getString({resB, key}, &resB->getResData(), res, len); case URES_ALIAS: { - const char16_t* result = 0; + const char16_t* result = nullptr; UResourceBundle *tempRes = ures_getByKey(resB, inKey, nullptr, status); result = ures_getString(tempRes, len, status); ures_close(tempRes); @@ -2717,11 +2718,7 @@ ures_openWithType(UResourceBundle *r, const char* path, const char* localeID, UResourceDataEntry *entry; if(openType != URES_OPEN_DIRECT) { /* first "canonicalize" the locale ID */ - CharString canonLocaleID; - { - CharStringByteSink sink(&canonLocaleID); - ulocimp_getBaseName(localeID, sink, status); - } + CharString canonLocaleID = ulocimp_getBaseName(localeID, *status); if(U_FAILURE(*status)) { *status = U_ILLEGAL_ARGUMENT_ERROR; return nullptr; @@ -2952,7 +2949,7 @@ ures_loc_nextLocale(UEnumeration* en, UResourceBundle *k = nullptr; const char *result = nullptr; int32_t len = 0; - if(ures_hasNext(res) && (k = ures_getNextResource(res, &ctx->curr, status)) != 0) { + if (ures_hasNext(res) && (k = ures_getNextResource(res, &ctx->curr, status)) != nullptr) { result = ures_getKey(k); len = (int32_t)uprv_strlen(result); } @@ -3040,25 +3037,25 @@ static UBool isLocaleInList(UEnumeration *locEnum, const char *locToSearch, UErr static void getParentForFunctionalEquivalent(const char* localeID, UResourceBundle* res, UResourceBundle* bund1, - char* parent, - int32_t parentCapacity) { + CharString& parent) { // Get parent. // First check for a parent from %%Parent resource (Note that in resource trees // such as collation, data may have different parents than in parentLocales). UErrorCode subStatus = U_ZERO_ERROR; - parent[0] = '\0'; - if (res != NULL) { + parent.clear(); + if (res != nullptr) { ures_getByKey(res, "%%Parent", bund1, &subStatus); if (U_SUCCESS(subStatus)) { - int32_t parentLen = parentCapacity; - ures_getUTF8String(bund1, parent, &parentLen, true, &subStatus); + int32_t length16; + const char16_t* s16 = ures_getString(bund1, &length16, &subStatus); + parent.appendInvariantChars(s16, length16, subStatus); } } // If none there, use normal truncation parent - if (U_FAILURE(subStatus) || parent[0] == 0) { + if (U_FAILURE(subStatus) || parent.isEmpty()) { subStatus = U_ZERO_ERROR; - uloc_getParent(localeID, parent, parentCapacity, &subStatus); + parent = ulocimp_getParent(localeID, subStatus); } } @@ -3067,29 +3064,21 @@ ures_getFunctionalEquivalent(char *result, int32_t resultCapacity, const char *path, const char *resName, const char *keyword, const char *locid, UBool *isAvailable, UBool omitDefault, UErrorCode *status) { - char defVal[1024] = ""; /* default value for given locale */ - char defLoc[1024] = ""; /* default value for given locale */ - CharString base; /* base locale */ - char found[1024] = ""; - char parent[1024] = ""; - char full[1024] = ""; + CharString defVal; /* default value for given locale */ + CharString defLoc; /* default value for given locale */ + CharString found; + CharString parent; + CharString full; UResourceBundle bund1, bund2; UResourceBundle *res = nullptr; UErrorCode subStatus = U_ZERO_ERROR; int32_t length = 0; if(U_FAILURE(*status)) return 0; - CharString kwVal; - { - CharStringByteSink sink(&kwVal); - ulocimp_getKeywordValue(locid, keyword, sink, &subStatus); - } + CharString kwVal = ulocimp_getKeywordValue(locid, keyword, subStatus); if(kwVal == DEFAULT_TAG) { kwVal.clear(); } - { - CharStringByteSink sink(&base); - ulocimp_getBaseName(locid, sink, &subStatus); - } + CharString base = ulocimp_getBaseName(locid, subStatus); #if defined(URES_TREE_DEBUG) fprintf(stderr, "getFunctionalEquivalent: \"%s\" [%s=%s] in %s - %s\n", locid, keyword, kwVal.data(), base.data(), u_errorName(subStatus)); @@ -3097,14 +3086,14 @@ ures_getFunctionalEquivalent(char *result, int32_t resultCapacity, ures_initStackObject(&bund1); ures_initStackObject(&bund2); - base.extract(parent, UPRV_LENGTHOF(parent), subStatus); - base.extract(found, UPRV_LENGTHOF(found), subStatus); + parent.copyFrom(base, subStatus); + found.copyFrom(base, subStatus); if(isAvailable) { UEnumeration *locEnum = ures_openAvailableLocales(path, &subStatus); *isAvailable = true; if (U_SUCCESS(subStatus)) { - *isAvailable = isLocaleInList(locEnum, parent, &subStatus); + *isAvailable = isLocaleInList(locEnum, parent.data(), &subStatus); } uenum_close(locEnum); } @@ -3116,7 +3105,7 @@ ures_getFunctionalEquivalent(char *result, int32_t resultCapacity, do { subStatus = U_ZERO_ERROR; - res = ures_open(path, parent, &subStatus); + res = ures_open(path, parent.data(), &subStatus); if(((subStatus == U_USING_FALLBACK_WARNING) || (subStatus == U_USING_DEFAULT_WARNING)) && isAvailable) { @@ -3125,7 +3114,7 @@ ures_getFunctionalEquivalent(char *result, int32_t resultCapacity, isAvailable = nullptr; /* only want to set this the first time around */ #if defined(URES_TREE_DEBUG) - fprintf(stderr, "%s;%s -> %s [%s]\n", path?path:"ICUDATA", parent, u_errorName(subStatus), ures_getLocale(res, &subStatus)); + fprintf(stderr, "%s;%s -> %s [%s]\n", path?path:"ICUDATA", parent.data(), u_errorName(subStatus), ures_getLocale(res, &subStatus)); #endif if(U_FAILURE(subStatus)) { *status = subStatus; @@ -3137,21 +3126,21 @@ ures_getFunctionalEquivalent(char *result, int32_t resultCapacity, /* look for default item */ #if defined(URES_TREE_DEBUG) fprintf(stderr, "%s;%s : loaded default -> %s\n", - path?path:"ICUDATA", parent, u_errorName(subStatus)); + path?path:"ICUDATA", parent.data(), u_errorName(subStatus)); #endif defUstr = ures_getStringByKey(&bund1, DEFAULT_TAG, &defLen, &subStatus); if(U_SUCCESS(subStatus) && defLen) { - u_UCharsToChars(defUstr, defVal, u_strlen(defUstr)); + defVal.clear().appendInvariantChars(defUstr, defLen, subStatus); #if defined(URES_TREE_DEBUG) fprintf(stderr, "%s;%s -> default %s=%s, %s\n", - path?path:"ICUDATA", parent, keyword, defVal, u_errorName(subStatus)); + path?path:"ICUDATA", parent.data(), keyword, defVal.data(), u_errorName(subStatus)); #endif - uprv_strcpy(defLoc, parent); + defLoc.copyFrom(parent, subStatus); if(kwVal.isEmpty()) { - kwVal.append(defVal, defLen, subStatus); + kwVal.append(defVal, subStatus); #if defined(URES_TREE_DEBUG) fprintf(stderr, "%s;%s -> kwVal = %s\n", - path?path:"ICUDATA", parent, keyword, kwVal.data()); + path?path:"ICUDATA", parent.data(), keyword, kwVal.data()); #endif } } @@ -3161,23 +3150,23 @@ ures_getFunctionalEquivalent(char *result, int32_t resultCapacity, subStatus = U_ZERO_ERROR; if (res != nullptr) { - uprv_strcpy(found, ures_getLocaleByType(res, ULOC_VALID_LOCALE, &subStatus)); + found.clear().append(ures_getLocaleByType(res, ULOC_VALID_LOCALE, &subStatus), subStatus); } - if (uprv_strcmp(found, parent) != 0) { - uprv_strcpy(parent, found); + if (found != parent) { + parent.copyFrom(found, subStatus); } else { - getParentForFunctionalEquivalent(found,res,&bund1,parent,sizeof(parent)); + getParentForFunctionalEquivalent(found.data(),res,&bund1,parent); } ures_close(res); - } while(!defVal[0] && *found && uprv_strcmp(found, "root") != 0 && U_SUCCESS(*status)); + } while(defVal.isEmpty() && !found.isEmpty() && found != "root" && U_SUCCESS(*status)); /* Now, see if we can find the kwVal collator.. start the search over.. */ - base.extract(parent, UPRV_LENGTHOF(parent), subStatus); - base.extract(found, UPRV_LENGTHOF(found), subStatus); + parent.copyFrom(base, subStatus); + found.copyFrom(base, subStatus); do { - res = ures_open(path, parent, &subStatus); + res = ures_open(path, parent.data(), &subStatus); if((subStatus == U_USING_FALLBACK_WARNING) && isAvailable) { *isAvailable = false; } @@ -3185,7 +3174,7 @@ ures_getFunctionalEquivalent(char *result, int32_t resultCapacity, #if defined(URES_TREE_DEBUG) fprintf(stderr, "%s;%s -> %s (looking for %s)\n", - path?path:"ICUDATA", parent, u_errorName(subStatus), kwVal.data()); + path?path:"ICUDATA", parent.data(), u_errorName(subStatus), kwVal.data()); #endif if(U_FAILURE(subStatus)) { *status = subStatus; @@ -3202,86 +3191,85 @@ ures_getFunctionalEquivalent(char *result, int32_t resultCapacity, if(subStatus == U_ZERO_ERROR) { #if defined(URES_TREE_DEBUG) fprintf(stderr, "%s;%s -> full0 %s=%s, %s\n", - path?path:"ICUDATA", parent, keyword, kwVal.data(), u_errorName(subStatus)); + path?path:"ICUDATA", parent.data(), keyword, kwVal.data(), u_errorName(subStatus)); #endif - uprv_strcpy(full, parent); - if(*full == 0) { - uprv_strcpy(full, "root"); + if (parent.isEmpty()) { + full.clear().append("root", subStatus); + } else { + full.copyFrom(parent, subStatus); } /* now, recalculate default kw if need be */ - if(uprv_strlen(defLoc) > uprv_strlen(full)) { + if(defLoc.length() > full.length()) { const char16_t *defUstr; int32_t defLen; /* look for default item */ #if defined(URES_TREE_DEBUG) fprintf(stderr, "%s;%s -> recalculating Default0\n", - path?path:"ICUDATA", full); + path?path:"ICUDATA", full.data()); #endif defUstr = ures_getStringByKey(&bund1, DEFAULT_TAG, &defLen, &subStatus); if(U_SUCCESS(subStatus) && defLen) { - u_UCharsToChars(defUstr, defVal, u_strlen(defUstr)); + defVal.clear().appendInvariantChars(defUstr, defLen, subStatus); #if defined(URES_TREE_DEBUG) fprintf(stderr, "%s;%s -> default0 %s=%s, %s\n", - path?path:"ICUDATA", full, keyword, defVal, u_errorName(subStatus)); + path?path:"ICUDATA", full.data(), keyword, defVal.data(), u_errorName(subStatus)); #endif - uprv_strcpy(defLoc, full); + defLoc.copyFrom(full, subStatus); } } /* end of recalculate default KW */ #if defined(URES_TREE_DEBUG) else { - fprintf(stderr, "No trim0, %s <= %s\n", defLoc, full); + fprintf(stderr, "No trim0, %s <= %s\n", defLoc.data(), full.data()); } #endif } else { #if defined(URES_TREE_DEBUG) fprintf(stderr, "err=%s in %s looking for %s\n", - u_errorName(subStatus), parent, kwVal.data()); + u_errorName(subStatus), parent.data(), kwVal.data()); #endif } } } + subStatus = U_ZERO_ERROR; UBool haveFound = false; // At least for collations which may be aliased, we need to use the VALID locale // as the parent instead of just truncating, as long as the VALID locale is not // root and has a different language than the parent. Use of the VALID locale // here is similar to the procedure used at the end of the previous do-while loop // for all resource types. - if (res != NULL && uprv_strcmp(resName, "collations") == 0) { - subStatus = U_ZERO_ERROR; + if (res != nullptr && uprv_strcmp(resName, "collations") == 0) { const char *validLoc = ures_getLocaleByType(res, ULOC_VALID_LOCALE, &subStatus); - if (U_SUCCESS(subStatus) && validLoc != NULL && validLoc[0] != 0 && uprv_strcmp(validLoc, "root") != 0) { - char validLang[ULOC_LANG_CAPACITY]; - char parentLang[ULOC_LANG_CAPACITY]; - uloc_getLanguage(validLoc, validLang, ULOC_LANG_CAPACITY, &subStatus); - uloc_getLanguage(parent, parentLang, ULOC_LANG_CAPACITY, &subStatus); - if (U_SUCCESS(subStatus) && uprv_strcmp(validLang, parentLang) != 0) { + if (U_SUCCESS(subStatus) && validLoc != nullptr && validLoc[0] != 0 && uprv_strcmp(validLoc, "root") != 0) { + CharString validLang = ulocimp_getLanguage(validLoc, subStatus); + CharString parentLang = ulocimp_getLanguage(parent.data(), subStatus); + if (U_SUCCESS(subStatus) && validLang != parentLang) { // validLoc is not root and has a different language than parent, use it instead - uprv_strcpy(found, validLoc); + found.clear().append(validLoc, subStatus); haveFound = true; } } subStatus = U_ZERO_ERROR; } if (!haveFound) { - uprv_strcpy(found, parent); + found.copyFrom(parent, subStatus); } - getParentForFunctionalEquivalent(found,res,&bund1,parent,1023); + getParentForFunctionalEquivalent(found.data(),res,&bund1,parent); ures_close(res); subStatus = U_ZERO_ERROR; - } while(!full[0] && *found && U_SUCCESS(*status)); + } while(full.isEmpty() && !found.isEmpty() && U_SUCCESS(*status)); - if((full[0]==0) && kwVal != defVal) { + if(full.isEmpty() && kwVal != defVal) { #if defined(URES_TREE_DEBUG) - fprintf(stderr, "Failed to locate kw %s - try default %s\n", kwVal.data(), defVal); + fprintf(stderr, "Failed to locate kw %s - try default %s\n", kwVal.data(), defVal.data()); #endif kwVal.clear().append(defVal, subStatus); - base.extract(parent, UPRV_LENGTHOF(parent), subStatus); - base.extract(found, UPRV_LENGTHOF(found), subStatus); + parent.copyFrom(base, subStatus); + found.copyFrom(base, subStatus); do { /* search for 'default' named item */ - res = ures_open(path, parent, &subStatus); + res = ures_open(path, parent.data(), &subStatus); if((subStatus == U_USING_FALLBACK_WARNING) && isAvailable) { *isAvailable = false; } @@ -3289,7 +3277,7 @@ ures_getFunctionalEquivalent(char *result, int32_t resultCapacity, #if defined(URES_TREE_DEBUG) fprintf(stderr, "%s;%s -> %s (looking for default %s)\n", - path?path:"ICUDATA", parent, u_errorName(subStatus), kwVal.data()); + path?path:"ICUDATA", parent.data(), u_errorName(subStatus), kwVal.data()); #endif if(U_FAILURE(subStatus)) { *status = subStatus; @@ -3300,59 +3288,61 @@ ures_getFunctionalEquivalent(char *result, int32_t resultCapacity, if(subStatus == U_ZERO_ERROR) { #if defined(URES_TREE_DEBUG) fprintf(stderr, "%s;%s -> full1 %s=%s, %s\n", path?path:"ICUDATA", - parent, keyword, kwVal.data(), u_errorName(subStatus)); + parent.data(), keyword, kwVal.data(), u_errorName(subStatus)); #endif - uprv_strcpy(full, parent); - if(*full == 0) { - uprv_strcpy(full, "root"); + if (parent.isEmpty()) { + full.clear().append("root", subStatus); + } else { + full.copyFrom(parent, subStatus); } /* now, recalculate default kw if need be */ - if(uprv_strlen(defLoc) > uprv_strlen(full)) { + if(defLoc.length() > full.length()) { const char16_t *defUstr; int32_t defLen; /* look for default item */ #if defined(URES_TREE_DEBUG) fprintf(stderr, "%s;%s -> recalculating Default1\n", - path?path:"ICUDATA", full); + path?path:"ICUDATA", full.data()); #endif defUstr = ures_getStringByKey(&bund1, DEFAULT_TAG, &defLen, &subStatus); if(U_SUCCESS(subStatus) && defLen) { - u_UCharsToChars(defUstr, defVal, u_strlen(defUstr)); + defVal.clear().appendInvariantChars(defUstr, defLen, subStatus); #if defined(URES_TREE_DEBUG) fprintf(stderr, "%s;%s -> default %s=%s, %s\n", - path?path:"ICUDATA", full, keyword, defVal, u_errorName(subStatus)); + path?path:"ICUDATA", full.data(), keyword, defVal.data(), u_errorName(subStatus)); #endif - uprv_strcpy(defLoc, full); + defLoc.copyFrom(full, subStatus); } } /* end of recalculate default KW */ #if defined(URES_TREE_DEBUG) else { - fprintf(stderr, "No trim1, %s <= %s\n", defLoc, full); + fprintf(stderr, "No trim1, %s <= %s\n", defLoc.data(), full.data()); } #endif } } } - uprv_strcpy(found, parent); - getParentForFunctionalEquivalent(found,res,&bund1,parent,1023); + subStatus = U_ZERO_ERROR; + found.copyFrom(parent, subStatus); + getParentForFunctionalEquivalent(found.data(),res,&bund1,parent); ures_close(res); subStatus = U_ZERO_ERROR; - } while(!full[0] && *found && U_SUCCESS(*status)); + } while(full.isEmpty() && !found.isEmpty() && U_SUCCESS(*status)); } if(U_SUCCESS(*status)) { - if(!full[0]) { + if(full.isEmpty()) { #if defined(URES_TREE_DEBUG) fprintf(stderr, "Still could not load keyword %s=%s\n", keyword, kwVal.data()); #endif *status = U_MISSING_RESOURCE_ERROR; } else if(omitDefault) { #if defined(URES_TREE_DEBUG) - fprintf(stderr,"Trim? full=%s, defLoc=%s, found=%s\n", full, defLoc, found); + fprintf(stderr,"Trim? full=%s, defLoc=%s, found=%s\n", full.data(), defLoc.data(), found.data()); #endif - if(uprv_strlen(defLoc) <= uprv_strlen(full)) { + if(defLoc.length() <= full.length()) { /* found the keyword in a *child* of where the default tag was present. */ if(kwVal == defVal) { /* if the requested kw is default, */ /* and the default is in or in an ancestor of the current locale */ @@ -3363,17 +3353,19 @@ ures_getFunctionalEquivalent(char *result, int32_t resultCapacity, } } } - uprv_strcpy(found, full); + found.copyFrom(full, subStatus); if(!kwVal.isEmpty()) { - uprv_strcat(found, "@"); - uprv_strcat(found, keyword); - uprv_strcat(found, "="); - uprv_strcat(found, kwVal.data()); + found + .append("@", subStatus) + .append(keyword, subStatus) + .append("=", subStatus) + .append(kwVal, subStatus); } else if(!omitDefault) { - uprv_strcat(found, "@"); - uprv_strcat(found, keyword); - uprv_strcat(found, "="); - uprv_strcat(found, defVal); + found + .append("@", subStatus) + .append(keyword, subStatus) + .append("=", subStatus) + .append(defVal, subStatus); } } /* we found the default locale - no need to repeat it.*/ @@ -3381,12 +3373,12 @@ ures_getFunctionalEquivalent(char *result, int32_t resultCapacity, ures_close(&bund1); ures_close(&bund2); - length = (int32_t)uprv_strlen(found); + length = found.length(); if(U_SUCCESS(*status)) { int32_t copyLength = uprv_min(length, resultCapacity); if(copyLength>0) { - uprv_strncpy(result, found, copyLength); + found.extract(result, copyLength, subStatus); } if(length == 0) { *status = U_MISSING_RESOURCE_ERROR; @@ -3429,8 +3421,8 @@ ures_getKeywordValues(const char *path, const char *keyword, UErrorCode *status) valuesBuf[0]=0; valuesBuf[1]=0; - - while((locale = uenum_next(locs, &locLen, status)) != 0) { + + while ((locale = uenum_next(locs, &locLen, status)) != nullptr) { UResourceBundle *bund = nullptr; UResourceBundle *subPtr = nullptr; UErrorCode subStatus = U_ZERO_ERROR; /* don't fail if a bundle is unopenable */ @@ -3454,8 +3446,8 @@ ures_getKeywordValues(const char *path, const char *keyword, UErrorCode *status) bund = nullptr; continue; } - - while((subPtr = ures_getNextResource(&item,&subItem,&subStatus)) != 0 + + while ((subPtr = ures_getNextResource(&item, &subItem, &subStatus)) != nullptr && U_SUCCESS(subStatus)) { const char *k; int32_t i; |