aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/icu/common/uresbund.cpp
diff options
context:
space:
mode:
authorromankoshelev <romankoshelev@yandex-team.com>2023-08-14 19:51:50 +0300
committerromankoshelev <romankoshelev@yandex-team.com>2023-08-15 01:24:11 +0300
commitcfcd865e05c0d0525ea27d1e153a043b32a85138 (patch)
tree68d3b3b25271e8a4998505897a269ff7ce119b76 /contrib/libs/icu/common/uresbund.cpp
parentccb790c507bd5e8ffe2ef9886ce5ee0a7ce22a15 (diff)
downloadydb-cfcd865e05c0d0525ea27d1e153a043b32a85138.tar.gz
Update ICU to 73.2
Diffstat (limited to 'contrib/libs/icu/common/uresbund.cpp')
-rw-r--r--contrib/libs/icu/common/uresbund.cpp953
1 files changed, 563 insertions, 390 deletions
diff --git a/contrib/libs/icu/common/uresbund.cpp b/contrib/libs/icu/common/uresbund.cpp
index a9c6459418..d02bba8921 100644
--- a/contrib/libs/icu/common/uresbund.cpp
+++ b/contrib/libs/icu/common/uresbund.cpp
@@ -48,8 +48,8 @@ Static cache for already opened resource bundles - mostly for keeping fallback i
TODO: This cache should probably be removed when the deprecated code is
completely removed.
*/
-static UHashtable *cache = NULL;
-static icu::UInitOnce gCacheInitOnce = U_INITONCE_INITIALIZER;
+static UHashtable *cache = nullptr;
+static icu::UInitOnce gCacheInitOnce {};
static UMutex resbMutex;
@@ -83,12 +83,209 @@ static UBool U_CALLCONV compareEntries(const UHashTok p1, const UHashTok p2) {
static UBool chopLocale(char *name) {
char *i = uprv_strrchr(name, '_');
- if(i != NULL) {
+ if(i != nullptr) {
*i = '\0';
- return TRUE;
+ return true;
}
- return FALSE;
+ return false;
+}
+
+static UBool hasVariant(const char* localeID) {
+ UErrorCode err = U_ZERO_ERROR;
+ int32_t variantLength = uloc_getVariant(localeID, nullptr, 0, &err);
+ return variantLength != 0;
+}
+
+// This file contains the tables for doing locale fallback, which are generated
+// by the CLDR-to-ICU process directly from the CLDR data. This file should only
+// ever be included from here.
+#define INCLUDED_FROM_URESBUND_CPP
+#include "localefallback_data.h"
+
+static const char* performFallbackLookup(const char* key,
+ const char* keyStrs,
+ const char* valueStrs,
+ const int32_t* lookupTable,
+ int32_t lookupTableLength) {
+ const int32_t* bottom = lookupTable;
+ const int32_t* top = lookupTable + lookupTableLength;
+
+ while (bottom < top) {
+ // Effectively, divide by 2 and round down to an even index
+ const int32_t* middle = bottom + (((top - bottom) / 4) * 2);
+ const char* entryKey = &(keyStrs[*middle]);
+ int32_t strcmpResult = uprv_strcmp(key, entryKey);
+ if (strcmpResult == 0) {
+ return &(valueStrs[middle[1]]);
+ } else if (strcmpResult < 0) {
+ top = middle;
+ } else {
+ bottom = middle + 2;
+ }
+ }
+ return nullptr;
+}
+
+static CharString getDefaultScript(const CharString& language, const CharString& region) {
+ const char* defaultScript = nullptr;
+ UErrorCode err = U_ZERO_ERROR;
+
+ // the default script will be "Latn" if we don't find the locale ID in the tables
+ CharString result("Latn", err);
+
+ // if we were passed both language and region, make them into a locale ID and look that up in the default
+ // script table
+ if (!region.isEmpty()) {
+ CharString localeID;
+ localeID.append(language, err).append("_", err).append(region, err);
+ if (U_FAILURE(err)) {
+ return result;
+ }
+ defaultScript = performFallbackLookup(localeID.data(), dsLocaleIDChars, scriptCodeChars, defaultScriptTable, UPRV_LENGTHOF(defaultScriptTable));
+ }
+
+ // if we didn't find anything, look up just the language in the default script table
+ if (defaultScript == nullptr) {
+ defaultScript = performFallbackLookup(language.data(), dsLocaleIDChars, scriptCodeChars, defaultScriptTable, UPRV_LENGTHOF(defaultScriptTable));
+ }
+
+ // if either lookup above succeeded, copy the result from "defaultScript" into "result"; otherwise, return "Latn"
+ if (defaultScript != nullptr) {
+ result.clear();
+ result.append(defaultScript, err);
+ }
+ return result;
+}
+
+enum UResOpenType {
+ /**
+ * Open a resource bundle for the locale;
+ * if there is not even a base language bundle, then fall back to the default locale;
+ * if there is no bundle for that either, then load the root bundle.
+ *
+ * This is the default bundle loading behavior.
+ */
+ URES_OPEN_LOCALE_DEFAULT_ROOT,
+ // TODO: ICU ticket #11271 "consistent default locale across locale trees"
+ // Add an option to look at the main locale tree for whether to
+ // fall back to root directly (if the locale has main data) or
+ // fall back to the default locale first (if the locale does not even have main data).
+ /**
+ * Open a resource bundle for the locale;
+ * if there is not even a base language bundle, then load the root bundle;
+ * never fall back to the default locale.
+ *
+ * This is used for algorithms that have good pan-Unicode default behavior,
+ * such as case mappings, collation, and segmentation (BreakIterator).
+ */
+ URES_OPEN_LOCALE_ROOT,
+ /**
+ * Open a resource bundle for the exact bundle name as requested;
+ * no fallbacks, do not load parent bundles.
+ *
+ * This is used for supplemental (non-locale) data.
+ */
+ URES_OPEN_DIRECT
+};
+typedef enum UResOpenType UResOpenType;
+
+/**
+ * Internal function, determines the search path for resource bundle files.
+ * Currently, this function is used only by findFirstExisting() to help search for resource bundle files when a bundle for the specified
+ * locale doesn't exist. The code that supports inheritance of resources between existing resource bundle files continues to
+ * use chopLocale() below.
+ * @param name In-out parameter: On input, the locale ID to get a parent locale ID for (this is a locale's base name, without keywords); on output, the
+ * requested parent locale ID.
+ * @param origName The original locale ID the caller of findFirstExisting() requested. This is the same as `name` on the first call to this function,
+ * but as findFirstExisting() ascends the resource bundle's parent tree, this parameter will continue to be the original locale ID requested.
+ */
+static bool getParentLocaleID(char *name, const char *origName, UResOpenType openType) {
+ // early out if the locale ID has a variant code or ends with _
+ size_t nameLen = uprv_strlen(name);
+ if (!nameLen || name[nameLen - 1] == '_' || hasVariant(name)) {
+ return chopLocale(name);
+ }
+
+ 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;
+ if (U_FAILURE(err)) {
+ // hopefully this never happens...
+ return chopLocale(name);
+ }
+
+ // if the open type is URES_OPEN_LOCALE_DEFAULT_ROOT, first look the locale ID up in the parent locale table;
+ // if that table specifies a parent for it, return that (we don't do this for the other open types-- if we're not
+ // falling back through the system default locale, we also want to do straight truncation fallback instead
+ // of looking things up in the parent locale table-- see https://www.unicode.org/reports/tr35/tr35.html#Parent_Locales:
+ // "Collation data, however, is an exception...")
+ if (openType == URES_OPEN_LOCALE_DEFAULT_ROOT) {
+ const char* parentID = performFallbackLookup(name, parentLocaleChars, parentLocaleChars, parentLocaleTable, UPRV_LENGTHOF(parentLocaleTable));
+ if (parentID != nullptr) {
+ uprv_strcpy(name, parentID);
+ return true;
+ }
+ }
+
+ // 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()) {
+ workingLocale.append(language, err).append("_", err).append(region, err);
+ } else {
+ workingLocale.append(language, err).append("_", err).append(script, err);
+ }
+ } else if (!region.isEmpty()) {
+ // if "name" has region but not script, did the original locale ID specify a script?
+ // - 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);
+ if (!origNameScript.isEmpty()) {
+ workingLocale.append(language, err).append("_", err).append(origNameScript, err);
+ } else {
+ workingLocale.append(language, err).append("_", err).append(getDefaultScript(language, region), err);
+ }
+ } else if (!script.isEmpty()) {
+ // if "name" has script but not region (and our open type if URES_OPEN_LOCALE_DEFAULT_ROOT), is the script
+ // the default script for the language?
+ // - if so, remove it from the locale ID
+ // - 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()) {
+ workingLocale.append(language, err);
+ } else {
+ return false;
+ }
+ } else {
+ // if "name" just contains a language code, return false so the calling code falls back to "root"
+ return false;
+ }
+ if (U_SUCCESS(err) && !workingLocale.isEmpty()) {
+ uprv_strcpy(name, workingLocale.data());
+ return true;
+ } else {
+ return false;
+ }
}
/**
@@ -106,7 +303,7 @@ static UBool mayHaveParent(char *name) {
static void entryIncrease(UResourceDataEntry *entry) {
Mutex lock(&resbMutex);
entry->fCountExisting++;
- while(entry->fParent != NULL) {
+ while(entry->fParent != nullptr) {
entry = entry->fParent;
entry->fCountExisting++;
}
@@ -162,18 +359,18 @@ static void
free_entry(UResourceDataEntry *entry) {
UResourceDataEntry *alias;
res_unload(&(entry->fData));
- if(entry->fName != NULL && entry->fName != entry->fNameBuffer) {
+ if(entry->fName != nullptr && entry->fName != entry->fNameBuffer) {
uprv_free(entry->fName);
}
- if(entry->fPath != NULL) {
+ if(entry->fPath != nullptr) {
uprv_free(entry->fPath);
}
- if(entry->fPool != NULL) {
+ if(entry->fPool != nullptr) {
--entry->fPool->fCountExisting;
}
alias = entry->fAlias;
- if(alias != NULL) {
- while(alias->fAlias != NULL) {
+ if(alias != nullptr) {
+ while(alias->fAlias != nullptr) {
alias = alias->fAlias;
}
--alias->fCountExisting;
@@ -194,15 +391,15 @@ static int32_t ures_flushCache()
* return 0
*/
Mutex lock(&resbMutex);
- if (cache == NULL) {
+ if (cache == nullptr) {
return 0;
}
do {
- deletedMore = FALSE;
+ deletedMore = false;
/*creates an enumeration to iterate through every element in the table */
pos = UHASH_FIRST;
- while ((e = uhash_nextElement(cache, &pos)) != NULL)
+ while ((e = uhash_nextElement(cache, &pos)) != nullptr)
{
resB = (UResourceDataEntry *) e->value.pointer;
/* Deletes only if reference counter == 0
@@ -216,7 +413,7 @@ static int32_t ures_flushCache()
if (resB->fCountExisting == 0) {
rbDeletedNum++;
- deletedMore = TRUE;
+ deletedMore = true;
uhash_removeElement(cache, e);
free_entry(resB);
}
@@ -233,26 +430,26 @@ static int32_t ures_flushCache()
#ifdef URES_DEBUG
#include <stdio.h>
-U_CAPI UBool U_EXPORT2 ures_dumpCacheContents(void) {
- UBool cacheNotEmpty = FALSE;
+U_CAPI UBool U_EXPORT2 ures_dumpCacheContents() {
+ UBool cacheNotEmpty = false;
int32_t pos = UHASH_FIRST;
const UHashElement *e;
UResourceDataEntry *resB;
Mutex lock(&resbMutex);
- if (cache == NULL) {
- fprintf(stderr,"%s:%d: RB Cache is NULL.\n", __FILE__, __LINE__);
- return FALSE;
+ if (cache == nullptr) {
+ fprintf(stderr,"%s:%d: RB Cache is nullptr.\n", __FILE__, __LINE__);
+ return false;
}
- while ((e = uhash_nextElement(cache, &pos)) != NULL) {
- cacheNotEmpty=TRUE;
+ while ((e = uhash_nextElement(cache, &pos)) != nullptr) {
+ cacheNotEmpty=true;
resB = (UResourceDataEntry *) e->value.pointer;
fprintf(stderr,"%s:%d: RB Cache: Entry @0x%p, refcount %d, name %s:%s. Pool 0x%p, alias 0x%p, parent 0x%p\n",
__FILE__, __LINE__,
(void*)resB, resB->fCountExisting,
- resB->fName?resB->fName:"NULL",
- resB->fPath?resB->fPath:"NULL",
+ resB->fName?resB->fName:"nullptr",
+ resB->fPath?resB->fPath:"nullptr",
(void*)resB->fPool,
(void*)resB->fAlias,
(void*)resB->fParent);
@@ -264,21 +461,21 @@ U_CAPI UBool U_EXPORT2 ures_dumpCacheContents(void) {
#endif
-static UBool U_CALLCONV ures_cleanup(void)
+static UBool U_CALLCONV ures_cleanup()
{
- if (cache != NULL) {
+ if (cache != nullptr) {
ures_flushCache();
uhash_close(cache);
- cache = NULL;
+ cache = nullptr;
}
gCacheInitOnce.reset();
- return TRUE;
+ return true;
}
/** INTERNAL: Initializes the cache for resources */
static void U_CALLCONV createCache(UErrorCode &status) {
- U_ASSERT(cache == NULL);
- cache = uhash_open(hashEntry, compareEntries, NULL, &status);
+ U_ASSERT(cache == nullptr);
+ cache = uhash_open(hashEntry, compareEntries, nullptr, &status);
ucln_common_registerCleanup(UCLN_COMMON_URES, ures_cleanup);
}
@@ -290,7 +487,7 @@ static void initCache(UErrorCode *status) {
static void setEntryName(UResourceDataEntry *res, const char *name, UErrorCode *status) {
int32_t len = (int32_t)uprv_strlen(name);
- if(res->fName != NULL && res->fName != res->fNameBuffer) {
+ if(res->fName != nullptr && res->fName != res->fNameBuffer) {
uprv_free(res->fName);
}
if (len < (int32_t)sizeof(res->fNameBuffer)) {
@@ -299,7 +496,7 @@ static void setEntryName(UResourceDataEntry *res, const char *name, UErrorCode *
else {
res->fName = (char *)uprv_malloc(len+1);
}
- if(res->fName == NULL) {
+ if(res->fName == nullptr) {
*status = U_MEMORY_ALLOCATION_ERROR;
} else {
uprv_strcpy(res->fName, name);
@@ -314,21 +511,21 @@ getPoolEntry(const char *path, UErrorCode *status);
* CAUTION: resbMutex must be locked when calling this function.
*/
static UResourceDataEntry *init_entry(const char *localeID, const char *path, UErrorCode *status) {
- UResourceDataEntry *r = NULL;
+ UResourceDataEntry *r = nullptr;
UResourceDataEntry find;
/*int32_t hashValue;*/
const char *name;
char aliasName[100] = { 0 };
int32_t aliasLen = 0;
- /*UBool isAlias = FALSE;*/
+ /*UBool isAlias = false;*/
/*UHashTok hashkey; */
if(U_FAILURE(*status)) {
- return NULL;
+ return nullptr;
}
/* here we try to deduce the right locale name */
- if(localeID == NULL) { /* if localeID is NULL, we're trying to open default locale */
+ if(localeID == nullptr) { /* if localeID is nullptr, we're trying to open default locale */
name = uloc_getDefault();
} else if(*localeID == 0) { /* if localeID is "" then we try to open root locale */
name = kRootLocaleName;
@@ -345,12 +542,12 @@ static UResourceDataEntry *init_entry(const char *localeID, const char *path, UE
/* check to see if we already have this entry */
r = (UResourceDataEntry *)uhash_get(cache, &find);
- if(r == NULL) {
+ if(r == nullptr) {
/* if the entry is not yet in the hash table, we'll try to construct a new one */
r = (UResourceDataEntry *) uprv_malloc(sizeof(UResourceDataEntry));
- if(r == NULL) {
+ if(r == nullptr) {
*status = U_MEMORY_ALLOCATION_ERROR;
- return NULL;
+ return nullptr;
}
uprv_memset(r, 0, sizeof(UResourceDataEntry));
@@ -359,15 +556,15 @@ static UResourceDataEntry *init_entry(const char *localeID, const char *path, UE
setEntryName(r, name, status);
if (U_FAILURE(*status)) {
uprv_free(r);
- return NULL;
+ return nullptr;
}
- if(path != NULL) {
+ if(path != nullptr) {
r->fPath = (char *)uprv_strdup(path);
- if(r->fPath == NULL) {
+ if(r->fPath == nullptr) {
*status = U_MEMORY_ALLOCATION_ERROR;
uprv_free(r);
- return NULL;
+ return nullptr;
}
}
@@ -378,7 +575,7 @@ static UResourceDataEntry *init_entry(const char *localeID, const char *path, UE
/* if we failed to load due to an out-of-memory error, exit early. */
if (*status == U_MEMORY_ALLOCATION_ERROR) {
uprv_free(r);
- return NULL;
+ return nullptr;
}
/* we have no such entry in dll, so it will always use fallback */
*status = U_USING_FALLBACK_WARNING;
@@ -405,8 +602,8 @@ static UResourceDataEntry *init_entry(const char *localeID, const char *path, UE
aliasres = res_getResource(&(r->fData), "%%ALIAS");
if (aliasres != RES_BOGUS) {
// No tracing: called during initial data loading
- const UChar *alias = res_getStringNoTrace(&(r->fData), aliasres, &aliasLen);
- if(alias != NULL && aliasLen > 0) { /* if there is actual alias - unload and load new data */
+ const char16_t *alias = res_getStringNoTrace(&(r->fData), aliasres, &aliasLen);
+ if(alias != nullptr && aliasLen > 0) { /* if there is actual alias - unload and load new data */
u_UCharsToChars(alias, aliasName, aliasLen+1);
r->fAlias = init_entry(aliasName, path, status);
}
@@ -415,15 +612,15 @@ static UResourceDataEntry *init_entry(const char *localeID, const char *path, UE
}
{
- UResourceDataEntry *oldR = NULL;
- if((oldR = (UResourceDataEntry *)uhash_get(cache, r)) == NULL) { /* if the data is not cached */
+ UResourceDataEntry *oldR = nullptr;
+ if((oldR = (UResourceDataEntry *)uhash_get(cache, r)) == nullptr) { /* if the data is not cached */
/* just insert it in the cache */
UErrorCode cacheStatus = U_ZERO_ERROR;
uhash_put(cache, (void *)r, r, &cacheStatus);
if (U_FAILURE(cacheStatus)) {
*status = cacheStatus;
free_entry(r);
- r = NULL;
+ r = nullptr;
}
} else {
/* somebody have already inserted it while we were working, discard newly opened data */
@@ -434,9 +631,9 @@ static UResourceDataEntry *init_entry(const char *localeID, const char *path, UE
}
}
- if(r != NULL) {
+ if(r != nullptr) {
/* return the real bundle */
- while(r->fAlias != NULL) {
+ while(r->fAlias != nullptr) {
r = r->fAlias;
}
r->fCountExisting++; /* we increase its reference count */
@@ -453,7 +650,7 @@ static UResourceDataEntry *
getPoolEntry(const char *path, UErrorCode *status) {
UResourceDataEntry *poolBundle = init_entry(kPoolBundleName, path, status);
if( U_SUCCESS(*status) &&
- (poolBundle == NULL || poolBundle->fBogus != U_ZERO_ERROR || !poolBundle->fData.isPoolBundle)
+ (poolBundle == nullptr || poolBundle->fBogus != U_ZERO_ERROR || !poolBundle->fData.isPoolBundle)
) {
*status = U_INVALID_FORMAT_ERROR;
}
@@ -463,17 +660,19 @@ getPoolEntry(const char *path, UErrorCode *status) {
/* INTERNAL: */
/* CAUTION: resbMutex must be locked when calling this function! */
static UResourceDataEntry *
-findFirstExisting(const char* path, char* name, const char* defaultLocale,
- UBool *isRoot, UBool *hasChopped, UBool *isDefault, UErrorCode* status) {
- UResourceDataEntry *r = NULL;
- UBool hasRealData = FALSE;
- *hasChopped = TRUE; /* we're starting with a fresh name */
-
- while(*hasChopped && !hasRealData) {
+findFirstExisting(const char* path, char* name, const char* defaultLocale, UResOpenType openType,
+ UBool *isRoot, UBool *foundParent, UBool *isDefault, UErrorCode* status) {
+ UResourceDataEntry *r = nullptr;
+ UBool hasRealData = false;
+ *foundParent = true; /* we're starting with a fresh name */
+ char origName[ULOC_FULLNAME_CAPACITY];
+
+ uprv_strcpy(origName, name);
+ while(*foundParent && !hasRealData) {
r = init_entry(name, path, status);
/* Null pointer test */
if (U_FAILURE(*status)) {
- return NULL;
+ return nullptr;
}
*isDefault = (UBool)(uprv_strncmp(name, defaultLocale, uprv_strlen(name)) == 0);
hasRealData = (UBool)(r->fBogus == U_ZERO_ERROR);
@@ -485,7 +684,7 @@ findFirstExisting(const char* path, char* name, const char* defaultLocale,
/* are not updated yet. */
r->fCountExisting--;
/*entryCloseInt(r);*/
- r = NULL;
+ r = nullptr;
*status = U_USING_FALLBACK_WARNING;
} else {
uprv_strcpy(name, r->fName); /* this is needed for supporting aliases */
@@ -494,8 +693,14 @@ findFirstExisting(const char* path, char* name, const char* defaultLocale,
*isRoot = (UBool)(uprv_strcmp(name, kRootLocaleName) == 0);
/*Fallback data stuff*/
- *hasChopped = chopLocale(name);
- if (*hasChopped && *name == '\0') {
+ if (!hasRealData) {
+ *foundParent = getParentLocaleID(name, origName, openType);
+ } else {
+ // we've already found a real resource file; what we return to the caller is the parent
+ // locale ID for inheritance, which should come from chopLocale(), not getParentLocaleID()
+ *foundParent = chopLocale(name);
+ }
+ if (*foundParent && *name == '\0') {
uprv_strcpy(name, "und");
}
}
@@ -513,13 +718,13 @@ static void ures_setIsStackObject( UResourceBundle* resB, UBool state) {
}
static UBool ures_isStackObject(const UResourceBundle* resB) {
- return((resB->fMagic1 == MAGIC1 && resB->fMagic2 == MAGIC2)?FALSE:TRUE);
+ return((resB->fMagic1 == MAGIC1 && resB->fMagic2 == MAGIC2)?false:true);
}
U_CFUNC void ures_initStackObject(UResourceBundle* resB) {
uprv_memset(resB, 0, sizeof(UResourceBundle));
- ures_setIsStackObject(resB, TRUE);
+ ures_setIsStackObject(resB, true);
}
U_NAMESPACE_BEGIN
@@ -538,19 +743,19 @@ static UBool // returns U_SUCCESS(*status)
loadParentsExceptRoot(UResourceDataEntry *&t1,
char name[], int32_t nameCapacity,
UBool usingUSRData, char usrDataPath[], UErrorCode *status) {
- if (U_FAILURE(*status)) { return FALSE; }
- UBool checkParent = TRUE;
- while (checkParent && t1->fParent == NULL && !t1->fData.noFallback &&
+ if (U_FAILURE(*status)) { return false; }
+ UBool checkParent = true;
+ while (checkParent && t1->fParent == nullptr && !t1->fData.noFallback &&
res_getResource(&t1->fData,"%%ParentIsRoot") == RES_BOGUS) {
Resource parentRes = res_getResource(&t1->fData, "%%Parent");
if (parentRes != RES_BOGUS) { // An explicit parent was found.
int32_t parentLocaleLen = 0;
// No tracing: called during initial data loading
- const UChar *parentLocaleName = res_getStringNoTrace(&(t1->fData), parentRes, &parentLocaleLen);
- if(parentLocaleName != NULL && 0 < parentLocaleLen && parentLocaleLen < nameCapacity) {
+ const char16_t *parentLocaleName = res_getStringNoTrace(&(t1->fData), parentRes, &parentLocaleLen);
+ if(parentLocaleName != nullptr && 0 < parentLocaleLen && parentLocaleLen < nameCapacity) {
u_UCharsToChars(parentLocaleName, name, parentLocaleLen + 1);
if (uprv_strcmp(name, kRootLocaleName) == 0) {
- return TRUE;
+ return true;
}
}
}
@@ -559,16 +764,16 @@ loadParentsExceptRoot(UResourceDataEntry *&t1,
UResourceDataEntry *t2 = init_entry(name, t1->fPath, &parentStatus);
if (U_FAILURE(parentStatus)) {
*status = parentStatus;
- return FALSE;
+ return false;
}
- UResourceDataEntry *u2 = NULL;
+ UResourceDataEntry *u2 = nullptr;
UErrorCode usrStatus = U_ZERO_ERROR;
if (usingUSRData) { // This code inserts user override data into the inheritance chain.
u2 = init_entry(name, usrDataPath, &usrStatus);
// If we failed due to out-of-memory, report that to the caller and exit early.
if (usrStatus == U_MEMORY_ALLOCATION_ERROR) {
*status = usrStatus;
- return FALSE;
+ return false;
}
}
@@ -585,66 +790,34 @@ loadParentsExceptRoot(UResourceDataEntry *&t1,
t1 = t2;
checkParent = chopLocale(name) || mayHaveParent(name);
}
- return TRUE;
+ return true;
}
static UBool // returns U_SUCCESS(*status)
insertRootBundle(UResourceDataEntry *&t1, UErrorCode *status) {
- if (U_FAILURE(*status)) { return FALSE; }
+ if (U_FAILURE(*status)) { return false; }
UErrorCode parentStatus = U_ZERO_ERROR;
UResourceDataEntry *t2 = init_entry(kRootLocaleName, t1->fPath, &parentStatus);
if (U_FAILURE(parentStatus)) {
*status = parentStatus;
- return FALSE;
+ return false;
}
t1->fParent = t2;
t1 = t2;
- return TRUE;
+ return true;
}
-enum UResOpenType {
- /**
- * Open a resource bundle for the locale;
- * if there is not even a base language bundle, then fall back to the default locale;
- * if there is no bundle for that either, then load the root bundle.
- *
- * This is the default bundle loading behavior.
- */
- URES_OPEN_LOCALE_DEFAULT_ROOT,
- // TODO: ICU ticket #11271 "consistent default locale across locale trees"
- // Add an option to look at the main locale tree for whether to
- // fall back to root directly (if the locale has main data) or
- // fall back to the default locale first (if the locale does not even have main data).
- /**
- * Open a resource bundle for the locale;
- * if there is not even a base language bundle, then load the root bundle;
- * never fall back to the default locale.
- *
- * This is used for algorithms that have good pan-Unicode default behavior,
- * such as case mappings, collation, and segmentation (BreakIterator).
- */
- URES_OPEN_LOCALE_ROOT,
- /**
- * Open a resource bundle for the exact bundle name as requested;
- * no fallbacks, do not load parent bundles.
- *
- * This is used for supplemental (non-locale) data.
- */
- URES_OPEN_DIRECT
-};
-typedef enum UResOpenType UResOpenType;
-
static UResourceDataEntry *entryOpen(const char* path, const char* localeID,
UResOpenType openType, UErrorCode* status) {
U_ASSERT(openType != URES_OPEN_DIRECT);
UErrorCode intStatus = U_ZERO_ERROR;
- UResourceDataEntry *r = NULL;
- UResourceDataEntry *t1 = NULL;
- UBool isDefault = FALSE;
- UBool isRoot = FALSE;
- UBool hasRealData = FALSE;
- UBool hasChopped = TRUE;
- UBool usingUSRData = U_USE_USRDATA && ( path == NULL || uprv_strncmp(path,U_ICUDATA_NAME,8) == 0);
+ UResourceDataEntry *r = nullptr;
+ UResourceDataEntry *t1 = nullptr;
+ UBool isDefault = false;
+ UBool isRoot = false;
+ UBool hasRealData = false;
+ UBool hasChopped = true;
+ UBool usingUSRData = U_USE_USRDATA && ( path == nullptr || uprv_strncmp(path,U_ICUDATA_NAME,8) == 0);
char name[ULOC_FULLNAME_CAPACITY];
char usrDataPath[96];
@@ -652,14 +825,14 @@ static UResourceDataEntry *entryOpen(const char* path, const char* localeID,
initCache(status);
if(U_FAILURE(*status)) {
- return NULL;
+ return nullptr;
}
uprv_strncpy(name, localeID, sizeof(name) - 1);
name[sizeof(name) - 1] = 0;
if ( usingUSRData ) {
- if ( path == NULL ) {
+ if ( path == nullptr ) {
uprv_strcpy(usrDataPath, U_USRDATA_NAME);
} else {
uprv_strncpy(usrDataPath, path, sizeof(usrDataPath) - 1);
@@ -676,7 +849,7 @@ static UResourceDataEntry *entryOpen(const char* path, const char* localeID,
Mutex lock(&resbMutex); // Lock resbMutex until the end of this function.
/* We're going to skip all the locales that do not have any data */
- r = findFirstExisting(path, name, defaultLocale, &isRoot, &hasChopped, &isDefault, &intStatus);
+ r = findFirstExisting(path, name, defaultLocale, openType, &isRoot, &hasChopped, &isDefault, &intStatus);
// If we failed due to out-of-memory, report the failure and exit early.
if (intStatus == U_MEMORY_ALLOCATION_ERROR) {
@@ -684,9 +857,9 @@ static UResourceDataEntry *entryOpen(const char* path, const char* localeID,
goto finish;
}
- if(r != NULL) { /* if there is one real locale, we can look for parents. */
+ if(r != nullptr) { /* if there is one real locale, we can look for parents. */
t1 = r;
- hasRealData = TRUE;
+ hasRealData = true;
if ( usingUSRData ) { /* This code inserts user override data into the inheritance chain */
UErrorCode usrStatus = U_ZERO_ERROR;
UResourceDataEntry *u1 = init_entry(t1->fName, usrDataPath, &usrStatus);
@@ -695,7 +868,7 @@ static UResourceDataEntry *entryOpen(const char* path, const char* localeID,
*status = intStatus;
goto finish;
}
- if ( u1 != NULL ) {
+ if ( u1 != nullptr ) {
if(u1->fBogus == U_ZERO_ERROR) {
u1->fParent = t1;
r = u1;
@@ -714,20 +887,20 @@ static UResourceDataEntry *entryOpen(const char* path, const char* localeID,
/* we could have reached this point without having any real data */
/* if that is the case, we need to chain in the default locale */
- if(r==NULL && openType == URES_OPEN_LOCALE_DEFAULT_ROOT && !isDefault && !isRoot) {
+ if(r==nullptr && openType == URES_OPEN_LOCALE_DEFAULT_ROOT && !isDefault && !isRoot) {
/* insert default locale */
uprv_strcpy(name, defaultLocale);
- r = findFirstExisting(path, name, defaultLocale, &isRoot, &hasChopped, &isDefault, &intStatus);
+ r = findFirstExisting(path, name, defaultLocale, openType, &isRoot, &hasChopped, &isDefault, &intStatus);
// If we failed due to out-of-memory, report the failure and exit early.
if (intStatus == U_MEMORY_ALLOCATION_ERROR) {
*status = intStatus;
goto finish;
}
intStatus = U_USING_DEFAULT_WARNING;
- if(r != NULL) { /* the default locale exists */
+ if(r != nullptr) { /* the default locale exists */
t1 = r;
- hasRealData = TRUE;
- isDefault = TRUE;
+ hasRealData = true;
+ isDefault = true;
// TODO: Why not if (usingUSRData) { ... } like in the non-default-locale code path?
if ((hasChopped || mayHaveParent(name)) && !isRoot) {
if (!loadParentsExceptRoot(t1, name, UPRV_LENGTHOF(name), usingUSRData, usrDataPath, status)) {
@@ -737,26 +910,26 @@ static UResourceDataEntry *entryOpen(const char* path, const char* localeID,
}
}
- /* we could still have r == NULL at this point - maybe even default locale is not */
+ /* we could still have r == nullptr at this point - maybe even default locale is not */
/* present */
- if(r == NULL) {
+ if(r == nullptr) {
uprv_strcpy(name, kRootLocaleName);
- r = findFirstExisting(path, name, defaultLocale, &isRoot, &hasChopped, &isDefault, &intStatus);
+ r = findFirstExisting(path, name, defaultLocale, openType, &isRoot, &hasChopped, &isDefault, &intStatus);
// If we failed due to out-of-memory, report the failure and exit early.
if (intStatus == U_MEMORY_ALLOCATION_ERROR) {
*status = intStatus;
goto finish;
}
- if(r != NULL) {
+ if(r != nullptr) {
t1 = r;
intStatus = U_USING_DEFAULT_WARNING;
- hasRealData = TRUE;
+ hasRealData = true;
} else { /* we don't even have the root locale */
*status = U_MISSING_RESOURCE_ERROR;
goto finish;
}
} else if(!isRoot && uprv_strcmp(t1->fName, kRootLocaleName) != 0 &&
- t1->fParent == NULL && !r->fData.noFallback) {
+ t1->fParent == nullptr && !r->fData.noFallback) {
if (!insertRootBundle(t1, status)) {
goto finish;
}
@@ -766,7 +939,7 @@ static UResourceDataEntry *entryOpen(const char* path, const char* localeID,
}
// TODO: Does this ever loop?
- while(r != NULL && !isRoot && t1->fParent != NULL) {
+ while(r != nullptr && !isRoot && t1->fParent != nullptr) {
t1->fParent->fCountExisting++;
t1 = t1->fParent;
}
@@ -778,7 +951,7 @@ finish:
}
return r;
} else {
- return NULL;
+ return nullptr;
}
}
@@ -792,12 +965,12 @@ static UResourceDataEntry *
entryOpenDirect(const char* path, const char* localeID, UErrorCode* status) {
initCache(status);
if(U_FAILURE(*status)) {
- return NULL;
+ return nullptr;
}
// Note: We need to query the default locale *before* locking resbMutex.
- // If the localeID is NULL, then we want to use the default locale.
- if (localeID == NULL) {
+ // If the localeID is nullptr, then we want to use the default locale.
+ if (localeID == nullptr) {
localeID = uloc_getDefault();
} else if (*localeID == 0) {
// If the localeID is "", then we want to use the root locale.
@@ -811,34 +984,34 @@ entryOpenDirect(const char* path, const char* localeID, UErrorCode* status) {
if(U_SUCCESS(*status)) {
if(r->fBogus != U_ZERO_ERROR) {
r->fCountExisting--;
- r = NULL;
+ r = nullptr;
}
} else {
- r = NULL;
+ r = nullptr;
}
// Some code depends on the ures_openDirect() bundle to have a parent bundle chain,
// unless it is marked with "nofallback".
UResourceDataEntry *t1 = r;
- if(r != NULL && uprv_strcmp(localeID, kRootLocaleName) != 0 && // not root
- r->fParent == NULL && !r->fData.noFallback &&
+ if(r != nullptr && uprv_strcmp(localeID, kRootLocaleName) != 0 && // not root
+ r->fParent == nullptr && !r->fData.noFallback &&
uprv_strlen(localeID) < ULOC_FULLNAME_CAPACITY) {
char name[ULOC_FULLNAME_CAPACITY];
uprv_strcpy(name, localeID);
if(!chopLocale(name) || uprv_strcmp(name, kRootLocaleName) == 0 ||
- loadParentsExceptRoot(t1, name, UPRV_LENGTHOF(name), FALSE, NULL, status)) {
- if(uprv_strcmp(t1->fName, kRootLocaleName) != 0 && t1->fParent == NULL) {
+ loadParentsExceptRoot(t1, name, UPRV_LENGTHOF(name), false, nullptr, status)) {
+ if(uprv_strcmp(t1->fName, kRootLocaleName) != 0 && t1->fParent == nullptr) {
insertRootBundle(t1, status);
}
}
if(U_FAILURE(*status)) {
- r = NULL;
+ r = nullptr;
}
}
- if(r != NULL) {
+ if(r != nullptr) {
// TODO: Does this ever loop?
- while(t1->fParent != NULL) {
+ while(t1->fParent != nullptr) {
t1->fParent->fCountExisting++;
t1 = t1->fParent;
}
@@ -854,7 +1027,7 @@ entryOpenDirect(const char* path, const char* localeID, UErrorCode* status) {
static void entryCloseInt(UResourceDataEntry *resB) {
UResourceDataEntry *p = resB;
- while(resB != NULL) {
+ while(resB != nullptr) {
p = resB->fParent;
resB->fCountExisting--;
@@ -866,10 +1039,10 @@ static void entryCloseInt(UResourceDataEntry *resB) {
if(resB->fBogus == U_ZERO_ERROR) {
res_unload(&(resB->fData));
}
- if(resB->fName != NULL) {
+ if(resB->fName != nullptr) {
uprv_free(resB->fName);
}
- if(resB->fPath != NULL) {
+ if(resB->fPath != nullptr) {
uprv_free(resB->fPath);
}
uprv_free(resB);
@@ -891,7 +1064,7 @@ static void entryClose(UResourceDataEntry *resB) {
/*
U_CFUNC void ures_setResPath(UResourceBundle *resB, const char* toAdd) {
- if(resB->fResPath == NULL) {
+ if(resB->fResPath == nullptr) {
resB->fResPath = resB->fResBuf;
*(resB->fResPath) = 0;
}
@@ -908,7 +1081,7 @@ U_CFUNC void ures_setResPath(UResourceBundle *resB, const char* toAdd) {
*/
static void ures_appendResPath(UResourceBundle *resB, const char* toAdd, int32_t lenToAdd, UErrorCode *status) {
int32_t resPathLenOrig = resB->fResPathLen;
- if(resB->fResPath == NULL) {
+ if(resB->fResPath == nullptr) {
resB->fResPath = resB->fResBuf;
*(resB->fResPath) = 0;
resB->fResPathLen = 0;
@@ -918,7 +1091,7 @@ static void ures_appendResPath(UResourceBundle *resB, const char* toAdd, int32_t
if(resB->fResPath == resB->fResBuf) {
resB->fResPath = (char *)uprv_malloc((resB->fResPathLen+1)*sizeof(char));
/* Check that memory was allocated correctly. */
- if (resB->fResPath == NULL) {
+ if (resB->fResPath == nullptr) {
*status = U_MEMORY_ALLOCATION_ERROR;
return;
}
@@ -926,7 +1099,7 @@ static void ures_appendResPath(UResourceBundle *resB, const char* toAdd, int32_t
} else {
char *temp = (char *)uprv_realloc(resB->fResPath, (resB->fResPathLen+1)*sizeof(char));
/* Check that memory was reallocated correctly. */
- if (temp == NULL) {
+ if (temp == nullptr) {
*status = U_MEMORY_ALLOCATION_ERROR;
return;
}
@@ -940,23 +1113,23 @@ static void ures_freeResPath(UResourceBundle *resB) {
if (resB->fResPath && resB->fResPath != resB->fResBuf) {
uprv_free(resB->fResPath);
}
- resB->fResPath = NULL;
+ resB->fResPath = nullptr;
resB->fResPathLen = 0;
}
static void
ures_closeBundle(UResourceBundle* resB, UBool freeBundleObj)
{
- if(resB != NULL) {
- if(resB->fData != NULL) {
+ if(resB != nullptr) {
+ if(resB->fData != nullptr) {
entryClose(resB->fData);
}
- if(resB->fVersion != NULL) {
+ if(resB->fVersion != nullptr) {
uprv_free(resB->fVersion);
}
ures_freeResPath(resB);
- if(ures_isStackObject(resB) == FALSE && freeBundleObj) {
+ if(ures_isStackObject(resB) == false && freeBundleObj) {
uprv_free(resB);
}
#if 0 /*U_DEBUG*/
@@ -971,7 +1144,7 @@ ures_closeBundle(UResourceBundle* resB, UBool freeBundleObj)
U_CAPI void U_EXPORT2
ures_close(UResourceBundle* resB)
{
- ures_closeBundle(resB, TRUE);
+ ures_closeBundle(resB, true);
}
namespace {
@@ -994,7 +1167,7 @@ UResourceBundle *getAliasTargetAsResourceBundle(
if (U_FAILURE(*status)) { return resB; }
U_ASSERT(RES_GET_TYPE(r) == URES_ALIAS);
int32_t len = 0;
- const UChar *alias = res_getAlias(&resData, r, &len);
+ const char16_t *alias = res_getAlias(&resData, r, &len);
if(len <= 0) {
// bad alias
*status = U_ILLEGAL_ARGUMENT_ERROR;
@@ -1214,12 +1387,12 @@ UResourceBundle *init_resb_result(
int32_t recursionDepth,
UResourceBundle *resB, UErrorCode *status) {
// TODO: When an error occurs: Should we return nullptr vs. resB?
- if(status == NULL || U_FAILURE(*status)) {
+ if(status == nullptr || U_FAILURE(*status)) {
return resB;
}
if (validLocaleDataEntry == nullptr) {
*status = U_ILLEGAL_ARGUMENT_ERROR;
- return NULL;
+ return nullptr;
}
if(RES_GET_TYPE(r) == URES_ALIAS) {
// This is an alias, need to exchange with real data.
@@ -1231,20 +1404,20 @@ UResourceBundle *init_resb_result(
dataEntry->fData, r, key, idx,
validLocaleDataEntry, containerResPath, recursionDepth, resB, status);
}
- if(resB == NULL) {
+ if(resB == nullptr) {
resB = (UResourceBundle *)uprv_malloc(sizeof(UResourceBundle));
- if (resB == NULL) {
+ if (resB == nullptr) {
*status = U_MEMORY_ALLOCATION_ERROR;
- return NULL;
+ return nullptr;
}
- ures_setIsStackObject(resB, FALSE);
- resB->fResPath = NULL;
+ ures_setIsStackObject(resB, false);
+ resB->fResPath = nullptr;
resB->fResPathLen = 0;
} else {
- if(resB->fData != NULL) {
+ if(resB->fData != nullptr) {
entryClose(resB->fData);
}
- if(resB->fVersion != NULL) {
+ if(resB->fVersion != nullptr) {
uprv_free(resB->fVersion);
}
/*
@@ -1254,7 +1427,7 @@ UResourceBundle *init_resb_result(
treated the same
*/
/*
- if(ures_isStackObject(resB) != FALSE) {
+ if(ures_isStackObject(resB) != false) {
ures_initStackObject(resB);
}
*/
@@ -1264,8 +1437,8 @@ UResourceBundle *init_resb_result(
}
resB->fData = dataEntry;
entryIncrease(resB->fData);
- resB->fHasFallback = FALSE;
- resB->fIsTopLevel = FALSE;
+ resB->fHasFallback = false;
+ resB->fIsTopLevel = false;
resB->fIndex = -1;
resB->fKey = key;
resB->fValidLocaleDataEntry = validLocaleDataEntry;
@@ -1273,7 +1446,7 @@ UResourceBundle *init_resb_result(
ures_appendResPath(
resB, containerResPath, static_cast<int32_t>(uprv_strlen(containerResPath)), status);
}
- if(key != NULL) {
+ if(key != nullptr) {
ures_appendResPath(resB, key, (int32_t)uprv_strlen(key), status);
if(resB->fResPath[resB->fResPathLen-1] != RES_PATH_SEPARATOR) {
ures_appendResPath(resB, RES_PATH_SEPARATOR_S, 1, status);
@@ -1292,7 +1465,7 @@ UResourceBundle *init_resb_result(
uprv_memset(resB->fResBuf + usedLen, 0, sizeof(resB->fResBuf) - usedLen);
}
- resB->fVersion = NULL;
+ resB->fVersion = nullptr;
resB->fRes = r;
resB->fSize = res_countArrayItems(&resB->getResData(), resB->fRes);
ResourceTracer(resB).trace("get");
@@ -1316,27 +1489,27 @@ UResourceBundle *ures_copyResb(UResourceBundle *r, const UResourceBundle *origin
if(U_FAILURE(*status) || r == original) {
return r;
}
- if(original != NULL) {
- if(r == NULL) {
- isStackObject = FALSE;
+ if(original != nullptr) {
+ if(r == nullptr) {
+ isStackObject = false;
r = (UResourceBundle *)uprv_malloc(sizeof(UResourceBundle));
- /* test for NULL */
- if (r == NULL) {
+ /* test for nullptr */
+ if (r == nullptr) {
*status = U_MEMORY_ALLOCATION_ERROR;
- return NULL;
+ return nullptr;
}
} else {
isStackObject = ures_isStackObject(r);
- ures_closeBundle(r, FALSE);
+ ures_closeBundle(r, false);
}
uprv_memcpy(r, original, sizeof(UResourceBundle));
- r->fResPath = NULL;
+ r->fResPath = nullptr;
r->fResPathLen = 0;
if(original->fResPath) {
ures_appendResPath(r, original->fResPath, original->fResPathLen, status);
}
ures_setIsStackObject(r, isStackObject);
- if(r->fData != NULL) {
+ if(r->fData != nullptr) {
entryIncrease(r->fData);
}
}
@@ -1347,45 +1520,45 @@ UResourceBundle *ures_copyResb(UResourceBundle *r, const UResourceBundle *origin
* Functions to retrieve data from resource bundles.
*/
-U_CAPI const UChar* U_EXPORT2 ures_getString(const UResourceBundle* resB, int32_t* len, UErrorCode* status) {
- const UChar *s;
- if (status==NULL || U_FAILURE(*status)) {
- return NULL;
+U_CAPI const char16_t* U_EXPORT2 ures_getString(const UResourceBundle* resB, int32_t* len, UErrorCode* status) {
+ const char16_t *s;
+ if (status==nullptr || U_FAILURE(*status)) {
+ return nullptr;
}
- if(resB == NULL) {
+ if(resB == nullptr) {
*status = U_ILLEGAL_ARGUMENT_ERROR;
- return NULL;
+ return nullptr;
}
s = res_getString({resB}, &resB->getResData(), resB->fRes, len);
- if (s == NULL) {
+ if (s == nullptr) {
*status = U_RESOURCE_TYPE_MISMATCH;
}
return s;
}
static const char *
-ures_toUTF8String(const UChar *s16, int32_t length16,
+ures_toUTF8String(const char16_t *s16, int32_t length16,
char *dest, int32_t *pLength,
UBool forceCopy,
UErrorCode *status) {
int32_t capacity;
if (U_FAILURE(*status)) {
- return NULL;
+ return nullptr;
}
- if (pLength != NULL) {
+ if (pLength != nullptr) {
capacity = *pLength;
} else {
capacity = 0;
}
- if (capacity < 0 || (capacity > 0 && dest == NULL)) {
+ if (capacity < 0 || (capacity > 0 && dest == nullptr)) {
*status = U_ILLEGAL_ARGUMENT_ERROR;
- return NULL;
+ return nullptr;
}
if (length16 == 0) {
/* empty string, return as read-only pointer */
- if (pLength != NULL) {
+ if (pLength != nullptr) {
*pLength = 0;
}
if (forceCopy) {
@@ -1398,18 +1571,18 @@ ures_toUTF8String(const UChar *s16, int32_t length16,
/* We need to transform the string to the destination buffer. */
if (capacity < length16) {
/* No chance for the string to fit. Pure preflighting. */
- return u_strToUTF8(NULL, 0, pLength, s16, length16, status);
+ return u_strToUTF8(nullptr, 0, pLength, s16, length16, status);
}
if (!forceCopy && (length16 <= 0x2aaaaaaa)) {
/*
- * We know the string will fit into dest because each UChar turns
+ * We know the string will fit into dest because each char16_t turns
* into at most three UTF-8 bytes. Fill the latter part of dest
* so that callers do not expect to use dest as a string pointer,
* hopefully leading to more robust code for when resource bundles
* may store UTF-8 natively.
* (In which case dest would not be used at all.)
*
- * We do not do this if forceCopy=TRUE because then the caller
+ * We do not do this if forceCopy=true because then the caller
* expects the string to start exactly at dest.
*
* The test above for <= 0x2aaaaaaa prevents overflows.
@@ -1431,22 +1604,22 @@ ures_getUTF8String(const UResourceBundle *resB,
UBool forceCopy,
UErrorCode *status) {
int32_t length16;
- const UChar *s16 = ures_getString(resB, &length16, status);
+ const char16_t *s16 = ures_getString(resB, &length16, status);
return ures_toUTF8String(s16, length16, dest, pLength, forceCopy, status);
}
U_CAPI const uint8_t* U_EXPORT2 ures_getBinary(const UResourceBundle* resB, int32_t* len,
UErrorCode* status) {
const uint8_t *p;
- if (status==NULL || U_FAILURE(*status)) {
- return NULL;
+ if (status==nullptr || U_FAILURE(*status)) {
+ return nullptr;
}
- if(resB == NULL) {
+ if(resB == nullptr) {
*status = U_ILLEGAL_ARGUMENT_ERROR;
- return NULL;
+ return nullptr;
}
p = res_getBinary({resB}, &resB->getResData(), resB->fRes, len);
- if (p == NULL) {
+ if (p == nullptr) {
*status = U_RESOURCE_TYPE_MISMATCH;
}
return p;
@@ -1455,15 +1628,15 @@ U_CAPI const uint8_t* U_EXPORT2 ures_getBinary(const UResourceBundle* resB, int3
U_CAPI const int32_t* U_EXPORT2 ures_getIntVector(const UResourceBundle* resB, int32_t* len,
UErrorCode* status) {
const int32_t *p;
- if (status==NULL || U_FAILURE(*status)) {
- return NULL;
+ if (status==nullptr || U_FAILURE(*status)) {
+ return nullptr;
}
- if(resB == NULL) {
+ if(resB == nullptr) {
*status = U_ILLEGAL_ARGUMENT_ERROR;
- return NULL;
+ return nullptr;
}
p = res_getIntVector({resB}, &resB->getResData(), resB->fRes, len);
- if (p == NULL) {
+ if (p == nullptr) {
*status = U_RESOURCE_TYPE_MISMATCH;
}
return p;
@@ -1472,10 +1645,10 @@ U_CAPI const int32_t* U_EXPORT2 ures_getIntVector(const UResourceBundle* resB, i
/* this function returns a signed integer */
/* it performs sign extension */
U_CAPI int32_t U_EXPORT2 ures_getInt(const UResourceBundle* resB, UErrorCode *status) {
- if (status==NULL || U_FAILURE(*status)) {
+ if (status==nullptr || U_FAILURE(*status)) {
return 0xffffffff;
}
- if(resB == NULL) {
+ if(resB == nullptr) {
*status = U_ILLEGAL_ARGUMENT_ERROR;
return 0xffffffff;
}
@@ -1487,10 +1660,10 @@ U_CAPI int32_t U_EXPORT2 ures_getInt(const UResourceBundle* resB, UErrorCode *st
}
U_CAPI uint32_t U_EXPORT2 ures_getUInt(const UResourceBundle* resB, UErrorCode *status) {
- if (status==NULL || U_FAILURE(*status)) {
+ if (status==nullptr || U_FAILURE(*status)) {
return 0xffffffff;
}
- if(resB == NULL) {
+ if(resB == nullptr) {
*status = U_ILLEGAL_ARGUMENT_ERROR;
return 0xffffffff;
}
@@ -1502,7 +1675,7 @@ U_CAPI uint32_t U_EXPORT2 ures_getUInt(const UResourceBundle* resB, UErrorCode *
}
U_CAPI UResType U_EXPORT2 ures_getType(const UResourceBundle *resB) {
- if(resB == NULL) {
+ if(resB == nullptr) {
return URES_NONE;
}
return res_getPublicType(resB->fRes);
@@ -1518,24 +1691,24 @@ U_CAPI const char * U_EXPORT2 ures_getKey(const UResourceBundle *resB) {
// However, I believe we have some data (e.g., in res_index) where the key
// strings are the data. Tracing the enclosing table should suffice.
//
- if(resB == NULL) {
- return NULL;
+ if(resB == nullptr) {
+ return nullptr;
}
return(resB->fKey);
}
U_CAPI int32_t U_EXPORT2 ures_getSize(const UResourceBundle *resB) {
- if(resB == NULL) {
+ if(resB == nullptr) {
return 0;
}
return resB->fSize;
}
-static const UChar* ures_getStringWithAlias(const UResourceBundle *resB, Resource r, int32_t sIndex, int32_t *len, UErrorCode *status) {
+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 UChar* result = 0;
- UResourceBundle *tempRes = ures_getByIndex(resB, sIndex, NULL, status);
+ const char16_t* result = 0;
+ UResourceBundle *tempRes = ures_getByIndex(resB, sIndex, nullptr, status);
result = ures_getString(tempRes, len, status);
ures_close(tempRes);
return result;
@@ -1545,28 +1718,28 @@ static const UChar* ures_getStringWithAlias(const UResourceBundle *resB, Resourc
}
U_CAPI void U_EXPORT2 ures_resetIterator(UResourceBundle *resB){
- if(resB == NULL) {
+ if(resB == nullptr) {
return;
}
resB->fIndex = -1;
}
U_CAPI UBool U_EXPORT2 ures_hasNext(const UResourceBundle *resB) {
- if(resB == NULL) {
- return FALSE;
+ if(resB == nullptr) {
+ return false;
}
return (UBool)(resB->fIndex < resB->fSize-1);
}
-U_CAPI const UChar* U_EXPORT2 ures_getNextString(UResourceBundle *resB, int32_t* len, const char ** key, UErrorCode *status) {
+U_CAPI const char16_t* U_EXPORT2 ures_getNextString(UResourceBundle *resB, int32_t* len, const char ** key, UErrorCode *status) {
Resource r = RES_BOGUS;
- if (status==NULL || U_FAILURE(*status)) {
- return NULL;
+ if (status==nullptr || U_FAILURE(*status)) {
+ return nullptr;
}
- if(resB == NULL) {
+ if(resB == nullptr) {
*status = U_ILLEGAL_ARGUMENT_ERROR;
- return NULL;
+ return nullptr;
}
if(resB->fIndex == resB->fSize-1) {
@@ -1600,30 +1773,30 @@ U_CAPI const UChar* U_EXPORT2 ures_getNextString(UResourceBundle *resB, int32_t*
*status = U_RESOURCE_TYPE_MISMATCH;
U_FALLTHROUGH;
default:
- return NULL;
+ return nullptr;
}
}
- return NULL;
+ return nullptr;
}
U_CAPI UResourceBundle* U_EXPORT2 ures_getNextResource(UResourceBundle *resB, UResourceBundle *fillIn, UErrorCode *status) {
- const char *key = NULL;
+ const char *key = nullptr;
Resource r = RES_BOGUS;
- if (status==NULL || U_FAILURE(*status)) {
- /*return NULL;*/
+ if (status==nullptr || U_FAILURE(*status)) {
+ /*return nullptr;*/
return fillIn;
}
- if(resB == NULL) {
+ if(resB == nullptr) {
*status = U_ILLEGAL_ARGUMENT_ERROR;
- /*return NULL;*/
+ /*return nullptr;*/
return fillIn;
}
if(resB->fIndex == resB->fSize-1) {
*status = U_INDEX_OUTOFBOUNDS_ERROR;
- /*return NULL;*/
+ /*return nullptr;*/
} else {
resB->fIndex++;
switch(RES_GET_TYPE(resB->fRes)) {
@@ -1649,25 +1822,25 @@ U_CAPI UResourceBundle* U_EXPORT2 ures_getNextResource(UResourceBundle *resB, UR
}
return init_resb_result(resB->fData, r, key, resB->fIndex, resB, fillIn, status);
default:
- /*return NULL;*/
+ /*return nullptr;*/
return fillIn;
}
}
- /*return NULL;*/
+ /*return nullptr;*/
return fillIn;
}
U_CAPI UResourceBundle* U_EXPORT2 ures_getByIndex(const UResourceBundle *resB, int32_t indexR, UResourceBundle *fillIn, UErrorCode *status) {
- const char* key = NULL;
+ const char* key = nullptr;
Resource r = RES_BOGUS;
- if (status==NULL || U_FAILURE(*status)) {
- /*return NULL;*/
+ if (status==nullptr || U_FAILURE(*status)) {
+ /*return nullptr;*/
return fillIn;
}
- if(resB == NULL) {
+ if(resB == nullptr) {
*status = U_ILLEGAL_ARGUMENT_ERROR;
- /*return NULL;*/
+ /*return nullptr;*/
return fillIn;
}
@@ -1695,26 +1868,26 @@ U_CAPI UResourceBundle* U_EXPORT2 ures_getByIndex(const UResourceBundle *resB, i
}
return init_resb_result(resB->fData, r, key, indexR, resB, fillIn, status);
default:
- /*return NULL;*/
+ /*return nullptr;*/
return fillIn;
}
} else {
*status = U_MISSING_RESOURCE_ERROR;
}
- /*return NULL;*/
+ /*return nullptr;*/
return fillIn;
}
-U_CAPI const UChar* U_EXPORT2 ures_getStringByIndex(const UResourceBundle *resB, int32_t indexS, int32_t* len, UErrorCode *status) {
- const char* key = NULL;
+U_CAPI const char16_t* U_EXPORT2 ures_getStringByIndex(const UResourceBundle *resB, int32_t indexS, int32_t* len, UErrorCode *status) {
+ const char* key = nullptr;
Resource r = RES_BOGUS;
- if (status==NULL || U_FAILURE(*status)) {
- return NULL;
+ if (status==nullptr || U_FAILURE(*status)) {
+ return nullptr;
}
- if(resB == NULL) {
+ if(resB == nullptr) {
*status = U_ILLEGAL_ARGUMENT_ERROR;
- return NULL;
+ return nullptr;
}
if(indexS >= 0 && resB->fSize > indexS) {
@@ -1752,7 +1925,7 @@ U_CAPI const UChar* U_EXPORT2 ures_getStringByIndex(const UResourceBundle *resB,
} else {
*status = U_MISSING_RESOURCE_ERROR;
}
- return NULL;
+ return nullptr;
}
U_CAPI const char * U_EXPORT2
@@ -1762,7 +1935,7 @@ ures_getUTF8StringByIndex(const UResourceBundle *resB,
UBool forceCopy,
UErrorCode *status) {
int32_t length16;
- const UChar *s16 = ures_getStringByIndex(resB, idx, &length16, status);
+ const char16_t *s16 = ures_getStringByIndex(resB, idx, &length16, status);
return ures_toUTF8String(s16, length16, dest, pLength, forceCopy, status);
}
@@ -1773,21 +1946,21 @@ ures_getUTF8StringByIndex(const UResourceBundle *resB,
U_CAPI UResourceBundle* U_EXPORT2
ures_findResource(const char* path, UResourceBundle *fillIn, UErrorCode *status)
{
- UResourceBundle *first = NULL;
+ UResourceBundle *first = nullptr;
UResourceBundle *result = fillIn;
- char *packageName = NULL;
- char *pathToResource = NULL, *save = NULL;
- char *locale = NULL, *localeEnd = NULL;
+ char *packageName = nullptr;
+ char *pathToResource = nullptr, *save = nullptr;
+ char *locale = nullptr, *localeEnd = nullptr;
int32_t length;
- if(status == NULL || U_FAILURE(*status)) {
+ if(status == nullptr || U_FAILURE(*status)) {
return result;
}
length = (int32_t)(uprv_strlen(path)+1);
save = pathToResource = (char *)uprv_malloc(length*sizeof(char));
- /* test for NULL */
- if(pathToResource == NULL) {
+ /* test for nullptr */
+ if(pathToResource == nullptr) {
*status = U_MEMORY_ALLOCATION_ERROR;
return result;
}
@@ -1798,7 +1971,7 @@ ures_findResource(const char* path, UResourceBundle *fillIn, UErrorCode *status)
pathToResource++;
packageName = pathToResource;
pathToResource = uprv_strchr(pathToResource, RES_PATH_SEPARATOR);
- if(pathToResource == NULL) {
+ if(pathToResource == nullptr) {
*status = U_ILLEGAL_ARGUMENT_ERROR;
} else {
*pathToResource = 0;
@@ -1807,7 +1980,7 @@ ures_findResource(const char* path, UResourceBundle *fillIn, UErrorCode *status)
}
localeEnd = uprv_strchr(locale, RES_PATH_SEPARATOR);
- if(localeEnd != NULL) {
+ if(localeEnd != nullptr) {
*localeEnd = 0;
}
@@ -1832,7 +2005,7 @@ ures_findSubResource(const UResourceBundle *resB, char* path, UResourceBundle *f
UResourceBundle *result = fillIn;
const char *key;
- if(status == NULL || U_FAILURE(*status)) {
+ if(status == nullptr || U_FAILURE(*status)) {
return result;
}
@@ -1852,28 +2025,28 @@ ures_findSubResource(const UResourceBundle *resB, char* path, UResourceBundle *f
return result;
}
-U_CAPI const UChar* U_EXPORT2
+U_CAPI const char16_t* U_EXPORT2
ures_getStringByKeyWithFallback(const UResourceBundle *resB,
const char* inKey,
int32_t* len,
UErrorCode *status) {
UResourceBundle stack;
- const UChar* retVal = NULL;
+ const char16_t* retVal = nullptr;
ures_initStackObject(&stack);
ures_getByKeyWithFallback(resB, inKey, &stack, status);
int32_t length;
retVal = ures_getString(&stack, &length, status);
ures_close(&stack);
if (U_FAILURE(*status)) {
- return NULL;
+ return nullptr;
}
if (length == 3 && retVal[0] == EMPTY_SET && retVal[1] == EMPTY_SET && retVal[2] == EMPTY_SET ) {
- retVal = NULL;
+ retVal = nullptr;
length = 0;
*status = U_MISSING_RESOURCE_ERROR;
}
- if (len != NULL) {
+ if (len != nullptr) {
*len = length;
}
return retVal;
@@ -1892,7 +2065,7 @@ static Resource getTableItemByKeyPath(const ResourceData *pResData, Resource tab
UResType type = (UResType)RES_GET_TYPE(resource); /* the current resource type */
while (*pathPart && resource != RES_BOGUS && URES_IS_CONTAINER(type)) {
char *nextPathPart = uprv_strchr(pathPart, RES_PATH_SEPARATOR);
- if (nextPathPart != NULL) {
+ if (nextPathPart != nullptr) {
*nextPathPart = 0; /* Terminating null for this part of path. */
nextPathPart++;
} else {
@@ -1989,12 +2162,12 @@ ures_getByKeyWithFallback(const UResourceBundle *resB,
UResourceBundle *fillIn,
UErrorCode *status) {
Resource res = RES_BOGUS, rootRes = RES_BOGUS;
- UResourceBundle *helper = NULL;
+ UResourceBundle *helper = nullptr;
- if (status==NULL || U_FAILURE(*status)) {
+ if (status==nullptr || U_FAILURE(*status)) {
return fillIn;
}
- if(resB == NULL) {
+ if(resB == nullptr) {
*status = U_ILLEGAL_ARGUMENT_ERROR;
return fillIn;
}
@@ -2009,14 +2182,14 @@ ures_getByKeyWithFallback(const UResourceBundle *resB,
if(res == RES_BOGUS) {
UResourceDataEntry *dataEntry = resB->fData;
CharString path;
- char *myPath = NULL;
+ char *myPath = nullptr;
const char* resPath = resB->fResPath;
int32_t len = resB->fResPathLen;
- while(res == RES_BOGUS && (dataEntry->fParent != NULL || !didRootOnce)) { /* Otherwise, we'll look in parents */
- if (dataEntry->fParent != NULL) {
+ while(res == RES_BOGUS && (dataEntry->fParent != nullptr || !didRootOnce)) { /* Otherwise, we'll look in parents */
+ if (dataEntry->fParent != nullptr) {
dataEntry = dataEntry->fParent;
} else {
- // We can't just stop when we get to a bundle whose fParent is NULL. That'll work most of the time,
+ // We can't just stop when we get to a bundle whose fParent is nullptr. That'll work most of the time,
// but if the bundle that the caller passed to us was "root" (which happens in getAllItemsWithFallback(),
// this function will drop right out without doing anything if "root" doesn't contain the exact key path
// specified. In that case, we need one extra time through this loop to make sure we follow any
@@ -2037,7 +2210,7 @@ ures_getByKeyWithFallback(const UResourceBundle *resB,
res = res_findResource(&(dataEntry->fData), rootRes, &myPath, &key);
if (RES_GET_TYPE(res) == URES_ALIAS && *myPath) {
/* We hit an alias, but we didn't finish following the path. */
- helper = init_resb_result(dataEntry, res, NULL, -1, resB, helper, status);
+ helper = init_resb_result(dataEntry, res, nullptr, -1, resB, helper, status);
/*helper = init_resb_result(dataEntry, res, inKey, -1, resB, helper, status);*/
if(helper) {
dataEntry = helper->fData;
@@ -2116,7 +2289,7 @@ void getAllItemsWithFallback(
value.setData(bundle->getResData());
value.setValidLocaleDataEntry(bundle->fValidLocaleDataEntry);
UResourceDataEntry *parentEntry = bundle->fData->fParent;
- UBool hasParent = parentEntry != NULL && U_SUCCESS(parentEntry->fBogus);
+ UBool hasParent = parentEntry != nullptr && U_SUCCESS(parentEntry->fBogus);
value.setResource(bundle->fRes, ResourceTracer(bundle));
sink.put(bundle->fKey, value, !hasParent, errorCode);
if (hasParent) {
@@ -2133,7 +2306,7 @@ void getAllItemsWithFallback(
parentRef.fData = parentEntry;
parentRef.fValidLocaleDataEntry = bundle->fValidLocaleDataEntry;
parentRef.fHasFallback = !parentRef.getResData().noFallback;
- parentRef.fIsTopLevel = TRUE;
+ parentRef.fIsTopLevel = true;
parentRef.fRes = parentRef.getResData().rootRes;
parentRef.fSize = res_countArrayItems(&parentRef.getResData(), parentRef.fRes);
parentRef.fIndex = -1;
@@ -2143,7 +2316,7 @@ void getAllItemsWithFallback(
StackUResourceBundle containerBundle;
const UResourceBundle *rb;
UErrorCode pathErrorCode = U_ZERO_ERROR; // Ignore if parents up to root do not have this path.
- if (bundle->fResPath == NULL || *bundle->fResPath == 0) {
+ if (bundle->fResPath == nullptr || *bundle->fResPath == 0) {
rb = parentBundle.getAlias();
} else {
rb = ures_getByKeyWithFallback(parentBundle.getAlias(), bundle->fResPath,
@@ -2259,13 +2432,13 @@ ures_getAllItemsWithFallback(const UResourceBundle *bundle, const char *path,
U_CAPI UResourceBundle* U_EXPORT2 ures_getByKey(const UResourceBundle *resB, const char* inKey, UResourceBundle *fillIn, UErrorCode *status) {
Resource res = RES_BOGUS;
- UResourceDataEntry *dataEntry = NULL;
+ UResourceDataEntry *dataEntry = nullptr;
const char *key = inKey;
- if (status==NULL || U_FAILURE(*status)) {
+ if (status==nullptr || U_FAILURE(*status)) {
return fillIn;
}
- if(resB == NULL) {
+ if(resB == nullptr) {
*status = U_ILLEGAL_ARGUMENT_ERROR;
return fillIn;
}
@@ -2276,7 +2449,7 @@ U_CAPI UResourceBundle* U_EXPORT2 ures_getByKey(const UResourceBundle *resB, con
res = res_getTableItemByKey(&resB->getResData(), resB->fRes, &t, &key);
if(res == RES_BOGUS) {
key = inKey;
- if(resB->fHasFallback == TRUE) {
+ if(resB->fHasFallback) {
dataEntry = getFallbackData(resB, &key, &res, status);
if(U_SUCCESS(*status)) {
/* check if resB->fResPath gives the right name here */
@@ -2294,7 +2467,7 @@ U_CAPI UResourceBundle* U_EXPORT2 ures_getByKey(const UResourceBundle *resB, con
#if 0
/* this is a kind of TODO item. If we have an array with an index table, we could do this. */
/* not currently */
- else if(RES_GET_TYPE(resB->fRes) == URES_ARRAY && resB->fHasFallback == TRUE) {
+ else if(RES_GET_TYPE(resB->fRes) == URES_ARRAY && resB->fHasFallback == true) {
/* here should go a first attempt to locate the key using index table */
dataEntry = getFallbackData(resB, &key, &res, status);
if(U_SUCCESS(*status)) {
@@ -2310,17 +2483,17 @@ U_CAPI UResourceBundle* U_EXPORT2 ures_getByKey(const UResourceBundle *resB, con
return fillIn;
}
-U_CAPI const UChar* U_EXPORT2 ures_getStringByKey(const UResourceBundle *resB, const char* inKey, int32_t* len, UErrorCode *status) {
+U_CAPI const char16_t* U_EXPORT2 ures_getStringByKey(const UResourceBundle *resB, const char* inKey, int32_t* len, UErrorCode *status) {
Resource res = RES_BOGUS;
- UResourceDataEntry *dataEntry = NULL;
+ UResourceDataEntry *dataEntry = nullptr;
const char* key = inKey;
- if (status==NULL || U_FAILURE(*status)) {
- return NULL;
+ if (status==nullptr || U_FAILURE(*status)) {
+ return nullptr;
}
- if(resB == NULL) {
+ if(resB == nullptr) {
*status = U_ILLEGAL_ARGUMENT_ERROR;
- return NULL;
+ return nullptr;
}
int32_t type = RES_GET_TYPE(resB->fRes);
@@ -2331,7 +2504,7 @@ U_CAPI const UChar* U_EXPORT2 ures_getStringByKey(const UResourceBundle *resB, c
if(res == RES_BOGUS) {
key = inKey;
- if(resB->fHasFallback == TRUE) {
+ if(resB->fHasFallback) {
dataEntry = getFallbackData(resB, &key, &res, status);
if(U_SUCCESS(*status)) {
switch (RES_GET_TYPE(res)) {
@@ -2340,8 +2513,8 @@ U_CAPI const UChar* U_EXPORT2 ures_getStringByKey(const UResourceBundle *resB, c
return res_getString({resB, key}, &dataEntry->fData, res, len);
case URES_ALIAS:
{
- const UChar* result = 0;
- UResourceBundle *tempRes = ures_getByKey(resB, inKey, NULL, status);
+ const char16_t* result = 0;
+ UResourceBundle *tempRes = ures_getByKey(resB, inKey, nullptr, status);
result = ures_getString(tempRes, len, status);
ures_close(tempRes);
return result;
@@ -2362,8 +2535,8 @@ U_CAPI const UChar* U_EXPORT2 ures_getStringByKey(const UResourceBundle *resB, c
return res_getString({resB, key}, &resB->getResData(), res, len);
case URES_ALIAS:
{
- const UChar* result = 0;
- UResourceBundle *tempRes = ures_getByKey(resB, inKey, NULL, status);
+ const char16_t* result = 0;
+ UResourceBundle *tempRes = ures_getByKey(resB, inKey, nullptr, status);
result = ures_getString(tempRes, len, status);
ures_close(tempRes);
return result;
@@ -2376,7 +2549,7 @@ U_CAPI const UChar* U_EXPORT2 ures_getStringByKey(const UResourceBundle *resB, c
#if 0
/* this is a kind of TODO item. If we have an array with an index table, we could do this. */
/* not currently */
- else if(RES_GET_TYPE(resB->fRes) == URES_ARRAY && resB->fHasFallback == TRUE) {
+ else if(RES_GET_TYPE(resB->fRes) == URES_ARRAY && resB->fHasFallback == true) {
/* here should go a first attempt to locate the key using index table */
dataEntry = getFallbackData(resB, &key, &res, status);
if(U_SUCCESS(*status)) {
@@ -2390,7 +2563,7 @@ U_CAPI const UChar* U_EXPORT2 ures_getStringByKey(const UResourceBundle *resB, c
else {
*status = U_RESOURCE_TYPE_MISMATCH;
}
- return NULL;
+ return nullptr;
}
U_CAPI const char * U_EXPORT2
@@ -2400,7 +2573,7 @@ ures_getUTF8StringByKey(const UResourceBundle *resB,
UBool forceCopy,
UErrorCode *status) {
int32_t length16;
- const UChar *s16 = ures_getStringByKey(resB, key, &length16, status);
+ const char16_t *s16 = ures_getStringByKey(resB, key, &length16, status);
return ures_toUTF8String(s16, length16, dest, pLength, forceCopy, status);
}
@@ -2413,12 +2586,12 @@ ures_getUTF8StringByKey(const UResourceBundle *resB,
U_CAPI const char* U_EXPORT2
ures_getLocaleInternal(const UResourceBundle* resourceBundle, UErrorCode* status)
{
- if (status==NULL || U_FAILURE(*status)) {
- return NULL;
+ if (status==nullptr || U_FAILURE(*status)) {
+ return nullptr;
}
if (!resourceBundle) {
*status = U_ILLEGAL_ARGUMENT_ERROR;
- return NULL;
+ return nullptr;
} else {
return resourceBundle->fData->fName;
}
@@ -2436,12 +2609,12 @@ U_CAPI const char* U_EXPORT2
ures_getLocaleByType(const UResourceBundle* resourceBundle,
ULocDataLocaleType type,
UErrorCode* status) {
- if (status==NULL || U_FAILURE(*status)) {
- return NULL;
+ if (status==nullptr || U_FAILURE(*status)) {
+ return nullptr;
}
if (!resourceBundle) {
*status = U_ILLEGAL_ARGUMENT_ERROR;
- return NULL;
+ return nullptr;
} else {
switch(type) {
case ULOC_ACTUAL_LOCALE:
@@ -2451,14 +2624,14 @@ ures_getLocaleByType(const UResourceBundle* resourceBundle,
case ULOC_REQUESTED_LOCALE:
default:
*status = U_ILLEGAL_ARGUMENT_ERROR;
- return NULL;
+ return nullptr;
}
}
}
U_CFUNC const char* ures_getName(const UResourceBundle* resB) {
- if(resB == NULL) {
- return NULL;
+ if(resB == nullptr) {
+ return nullptr;
}
return resB->fData->fName;
@@ -2466,8 +2639,8 @@ U_CFUNC const char* ures_getName(const UResourceBundle* resB) {
#ifdef URES_DEBUG
U_CFUNC const char* ures_getPath(const UResourceBundle* resB) {
- if(resB == NULL) {
- return NULL;
+ if(resB == nullptr) {
+ return nullptr;
}
return resB->fData->fPath;
@@ -2478,7 +2651,7 @@ static UResourceBundle*
ures_openWithType(UResourceBundle *r, const char* path, const char* localeID,
UResOpenType openType, UErrorCode* status) {
if(U_FAILURE(*status)) {
- return NULL;
+ return nullptr;
}
UResourceDataEntry *entry;
@@ -2488,39 +2661,39 @@ ures_openWithType(UResourceBundle *r, const char* path, const char* localeID,
uloc_getBaseName(localeID, canonLocaleID, UPRV_LENGTHOF(canonLocaleID), status);
if(U_FAILURE(*status) || *status == U_STRING_NOT_TERMINATED_WARNING) {
*status = U_ILLEGAL_ARGUMENT_ERROR;
- return NULL;
+ return nullptr;
}
entry = entryOpen(path, canonLocaleID, openType, status);
} else {
entry = entryOpenDirect(path, localeID, status);
}
if(U_FAILURE(*status)) {
- return NULL;
+ return nullptr;
}
- if(entry == NULL) {
+ if(entry == nullptr) {
*status = U_MISSING_RESOURCE_ERROR;
- return NULL;
+ return nullptr;
}
UBool isStackObject;
- if(r == NULL) {
+ if(r == nullptr) {
r = (UResourceBundle *)uprv_malloc(sizeof(UResourceBundle));
- if(r == NULL) {
+ if(r == nullptr) {
entryClose(entry);
*status = U_MEMORY_ALLOCATION_ERROR;
- return NULL;
+ return nullptr;
}
- isStackObject = FALSE;
+ isStackObject = false;
} else { // fill-in
isStackObject = ures_isStackObject(r);
- ures_closeBundle(r, FALSE);
+ ures_closeBundle(r, false);
}
uprv_memset(r, 0, sizeof(UResourceBundle));
ures_setIsStackObject(r, isStackObject);
r->fValidLocaleDataEntry = r->fData = entry;
r->fHasFallback = openType != URES_OPEN_DIRECT && !r->getResData().noFallback;
- r->fIsTopLevel = TRUE;
+ r->fIsTopLevel = true;
r->fRes = r->getResData().rootRes;
r->fSize = res_countArrayItems(&r->getResData(), r->fRes);
r->fIndex = -1;
@@ -2532,12 +2705,12 @@ ures_openWithType(UResourceBundle *r, const char* path, const char* localeID,
U_CAPI UResourceBundle* U_EXPORT2
ures_open(const char* path, const char* localeID, UErrorCode* status) {
- return ures_openWithType(NULL, path, localeID, URES_OPEN_LOCALE_DEFAULT_ROOT, status);
+ return ures_openWithType(nullptr, path, localeID, URES_OPEN_LOCALE_DEFAULT_ROOT, status);
}
U_CAPI UResourceBundle* U_EXPORT2
ures_openNoDefault(const char* path, const char* localeID, UErrorCode* status) {
- return ures_openWithType(NULL, path, localeID, URES_OPEN_LOCALE_ROOT, status);
+ return ures_openWithType(nullptr, path, localeID, URES_OPEN_LOCALE_ROOT, status);
}
/**
@@ -2546,7 +2719,7 @@ ures_openNoDefault(const char* path, const char* localeID, UErrorCode* status) {
*/
U_CAPI UResourceBundle* U_EXPORT2
ures_openDirect(const char* path, const char* localeID, UErrorCode* status) {
- return ures_openWithType(NULL, path, localeID, URES_OPEN_DIRECT, status);
+ return ures_openWithType(nullptr, path, localeID, URES_OPEN_DIRECT, status);
}
/**
@@ -2559,7 +2732,7 @@ ures_openDirect(const char* path, const char* localeID, UErrorCode* status) {
U_CAPI void U_EXPORT2
ures_openFillIn(UResourceBundle *r, const char* path,
const char* localeID, UErrorCode* status) {
- if(U_SUCCESS(*status) && r == NULL) {
+ if(U_SUCCESS(*status) && r == nullptr) {
*status = U_ILLEGAL_ARGUMENT_ERROR;
return;
}
@@ -2571,7 +2744,7 @@ ures_openFillIn(UResourceBundle *r, const char* path,
*/
U_CAPI void U_EXPORT2
ures_openDirectFillIn(UResourceBundle *r, const char* path, const char* localeID, UErrorCode* status) {
- if(U_SUCCESS(*status) && r == NULL) {
+ if(U_SUCCESS(*status) && r == nullptr) {
*status = U_ILLEGAL_ARGUMENT_ERROR;
return;
}
@@ -2589,16 +2762,16 @@ ures_countArrayItems(const UResourceBundle* resourceBundle,
{
UResourceBundle resData;
ures_initStackObject(&resData);
- if (status==NULL || U_FAILURE(*status)) {
+ if (status==nullptr || U_FAILURE(*status)) {
return 0;
}
- if(resourceBundle == NULL) {
+ if(resourceBundle == nullptr) {
*status = U_ILLEGAL_ARGUMENT_ERROR;
return 0;
}
ures_getByKey(resourceBundle, resourceKey, &resData, status);
- if(resData.getResData().data != NULL) {
+ if(resData.getResData().data != nullptr) {
int32_t result = res_countArrayItems(&resData.getResData(), resData.fRes);
ures_close(&resData);
return result;
@@ -2622,9 +2795,9 @@ ures_countArrayItems(const UResourceBundle* resourceBundle,
U_CAPI const char* U_EXPORT2
ures_getVersionNumberInternal(const UResourceBundle *resourceBundle)
{
- if (!resourceBundle) return NULL;
+ if (!resourceBundle) return nullptr;
- if(resourceBundle->fVersion == NULL) {
+ if(resourceBundle->fVersion == nullptr) {
/* If the version ID has not been built yet, then do so. Retrieve */
/* the minor version from the file. */
@@ -2632,7 +2805,7 @@ ures_getVersionNumberInternal(const UResourceBundle *resourceBundle)
int32_t minor_len = 0;
int32_t len;
- const UChar* minor_version = ures_getStringByKey(resourceBundle, kVersionTag, &minor_len, &status);
+ const char16_t* minor_version = ures_getStringByKey(resourceBundle, kVersionTag, &minor_len, &status);
/* Determine the length of of the final version string. This is */
/* the length of the major part + the length of the separator */
@@ -2647,8 +2820,8 @@ ures_getVersionNumberInternal(const UResourceBundle *resourceBundle)
((UResourceBundle *)resourceBundle)->fVersion = (char *)uprv_malloc(1 + len);
/* Check for null pointer. */
- if (((UResourceBundle *)resourceBundle)->fVersion == NULL) {
- return NULL;
+ if (((UResourceBundle *)resourceBundle)->fVersion == nullptr) {
+ return nullptr;
}
if(minor_len > 0) {
@@ -2713,8 +2886,8 @@ ures_loc_nextLocale(UEnumeration* en,
UErrorCode* status) {
ULocalesContext *ctx = (ULocalesContext *)en->context;
UResourceBundle *res = &(ctx->installed);
- UResourceBundle *k = NULL;
- const char *result = NULL;
+ UResourceBundle *k = nullptr;
+ const char *result = nullptr;
int32_t len = 0;
if(ures_hasNext(res) && (k = ures_getNextResource(res, &ctx->curr, status)) != 0) {
result = ures_getKey(k);
@@ -2736,8 +2909,8 @@ ures_loc_resetLocales(UEnumeration* en,
U_CDECL_END
static const UEnumeration gLocalesEnum = {
- NULL,
- NULL,
+ nullptr,
+ nullptr,
ures_loc_closeLocales,
ures_loc_countLocales,
uenum_unextDefault,
@@ -2749,12 +2922,12 @@ static const UEnumeration gLocalesEnum = {
U_CAPI UEnumeration* U_EXPORT2
ures_openAvailableLocales(const char *path, UErrorCode *status)
{
- UResourceBundle *idx = NULL;
- UEnumeration *en = NULL;
- ULocalesContext *myContext = NULL;
+ UResourceBundle *idx = nullptr;
+ UEnumeration *en = nullptr;
+ ULocalesContext *myContext = nullptr;
if(U_FAILURE(*status)) {
- return NULL;
+ return nullptr;
}
myContext = static_cast<ULocalesContext *>(uprv_malloc(sizeof(ULocalesContext)));
en = (UEnumeration *)uprv_malloc(sizeof(UEnumeration));
@@ -2762,7 +2935,7 @@ ures_openAvailableLocales(const char *path, UErrorCode *status)
*status = U_MEMORY_ALLOCATION_ERROR;
uprv_free(en);
uprv_free(myContext);
- return NULL;
+ return nullptr;
}
uprv_memcpy(en, &gLocalesEnum, sizeof(UEnumeration));
@@ -2783,7 +2956,7 @@ ures_openAvailableLocales(const char *path, UErrorCode *status)
ures_close(&myContext->installed);
uprv_free(myContext);
uprv_free(en);
- en = NULL;
+ en = nullptr;
}
ures_close(idx);
@@ -2793,12 +2966,12 @@ ures_openAvailableLocales(const char *path, UErrorCode *status)
static UBool isLocaleInList(UEnumeration *locEnum, const char *locToSearch, UErrorCode *status) {
const char *loc;
- while ((loc = uenum_next(locEnum, NULL, status)) != NULL) {
+ while ((loc = uenum_next(locEnum, nullptr, status)) != nullptr) {
if (uprv_strcmp(loc, locToSearch) == 0) {
- return TRUE;
+ return true;
}
}
- return FALSE;
+ return false;
}
U_CAPI int32_t U_EXPORT2
@@ -2814,7 +2987,7 @@ ures_getFunctionalEquivalent(char *result, int32_t resultCapacity,
char parent[1024] = "";
char full[1024] = "";
UResourceBundle bund1, bund2;
- UResourceBundle *res = NULL;
+ UResourceBundle *res = nullptr;
UErrorCode subStatus = U_ZERO_ERROR;
int32_t length = 0;
if(U_FAILURE(*status)) return 0;
@@ -2836,7 +3009,7 @@ ures_getFunctionalEquivalent(char *result, int32_t resultCapacity,
if(isAvailable) {
UEnumeration *locEnum = ures_openAvailableLocales(path, &subStatus);
- *isAvailable = TRUE;
+ *isAvailable = true;
if (U_SUCCESS(subStatus)) {
*isAvailable = isLocaleInList(locEnum, parent, &subStatus);
}
@@ -2854,9 +3027,9 @@ ures_getFunctionalEquivalent(char *result, int32_t resultCapacity,
if(((subStatus == U_USING_FALLBACK_WARNING) ||
(subStatus == U_USING_DEFAULT_WARNING)) && isAvailable)
{
- *isAvailable = FALSE;
+ *isAvailable = false;
}
- isAvailable = NULL; /* only want to set this the first time around */
+ 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));
@@ -2866,7 +3039,7 @@ ures_getFunctionalEquivalent(char *result, int32_t resultCapacity,
} else if(subStatus == U_ZERO_ERROR) {
ures_getByKey(res,resName,&bund1, &subStatus);
if(subStatus == U_ZERO_ERROR) {
- const UChar *defUstr;
+ const char16_t *defUstr;
int32_t defLen;
/* look for default item */
#if defined(URES_TREE_DEBUG)
@@ -2894,7 +3067,7 @@ ures_getFunctionalEquivalent(char *result, int32_t resultCapacity,
subStatus = U_ZERO_ERROR;
- if (res != NULL) {
+ if (res != nullptr) {
uprv_strcpy(found, ures_getLocaleByType(res, ULOC_VALID_LOCALE, &subStatus));
}
@@ -2910,9 +3083,9 @@ ures_getFunctionalEquivalent(char *result, int32_t resultCapacity,
subStatus = U_ZERO_ERROR;
res = ures_open(path, parent, &subStatus);
if((subStatus == U_USING_FALLBACK_WARNING) && isAvailable) {
- *isAvailable = FALSE;
+ *isAvailable = false;
}
- isAvailable = NULL; /* only want to set this the first time around */
+ isAvailable = nullptr; /* only want to set this the first time around */
#if defined(URES_TREE_DEBUG)
fprintf(stderr, "%s;%s -> %s (looking for %s)\n",
@@ -2941,7 +3114,7 @@ ures_getFunctionalEquivalent(char *result, int32_t resultCapacity,
}
/* now, recalculate default kw if need be */
if(uprv_strlen(defLoc) > uprv_strlen(full)) {
- const UChar *defUstr;
+ const char16_t *defUstr;
int32_t defLen;
/* look for default item */
#if defined(URES_TREE_DEBUG)
@@ -2991,9 +3164,9 @@ ures_getFunctionalEquivalent(char *result, int32_t resultCapacity,
subStatus = U_ZERO_ERROR;
res = ures_open(path, parent, &subStatus);
if((subStatus == U_USING_FALLBACK_WARNING) && isAvailable) {
- *isAvailable = FALSE;
+ *isAvailable = false;
}
- isAvailable = NULL; /* only want to set this the first time around */
+ isAvailable = nullptr; /* only want to set this the first time around */
#if defined(URES_TREE_DEBUG)
fprintf(stderr, "%s;%s -> %s (looking for default %s)\n",
@@ -3017,7 +3190,7 @@ ures_getFunctionalEquivalent(char *result, int32_t resultCapacity,
/* now, recalculate default kw if need be */
if(uprv_strlen(defLoc) > uprv_strlen(full)) {
- const UChar *defUstr;
+ const char16_t *defUstr;
int32_t defLen;
/* look for default item */
#if defined(URES_TREE_DEBUG)
@@ -3120,7 +3293,7 @@ ures_getKeywordValues(const char *path, const char *keyword, UErrorCode *status)
const char *locale;
int32_t locLen;
- UEnumeration *locs = NULL;
+ UEnumeration *locs = nullptr;
UResourceBundle item;
UResourceBundle subItem;
@@ -3132,15 +3305,15 @@ ures_getKeywordValues(const char *path, const char *keyword, UErrorCode *status)
if(U_FAILURE(*status)) {
ures_close(&item);
ures_close(&subItem);
- return NULL;
+ return nullptr;
}
valuesBuf[0]=0;
valuesBuf[1]=0;
while((locale = uenum_next(locs, &locLen, status)) != 0) {
- UResourceBundle *bund = NULL;
- UResourceBundle *subPtr = NULL;
+ UResourceBundle *bund = nullptr;
+ UResourceBundle *subPtr = nullptr;
UErrorCode subStatus = U_ZERO_ERROR; /* don't fail if a bundle is unopenable */
bund = ures_open(path, locale, &subStatus);
@@ -3159,7 +3332,7 @@ ures_getKeywordValues(const char *path, const char *keyword, UErrorCode *status)
path?path:"<ICUDATA>", keyword, locale, u_errorName(subStatus));
#endif
ures_close(bund);
- bund = NULL;
+ bund = nullptr;
continue;
}
@@ -3172,18 +3345,18 @@ ures_getKeywordValues(const char *path, const char *keyword, UErrorCode *status)
#if defined(URES_TREE_DEBUG)
/* fprintf(stderr, "%s | %s | %s | %s\n", path?path:"<ICUDATA>", keyword, locale, k); */
#endif
- if(k == NULL || *k == 0 ||
+ if(k == nullptr || *k == 0 ||
uprv_strcmp(k, DEFAULT_TAG) == 0 || uprv_strncmp(k, "private-", 8) == 0) {
// empty or "default" or unlisted type
continue;
}
for(i=0; i<valuesCount; i++) {
if(!uprv_strcmp(valuesList[i],k)) {
- k = NULL; /* found duplicate */
+ k = nullptr; /* found duplicate */
break;
}
}
- if(k != NULL) {
+ if(k != nullptr) {
int32_t kLen = (int32_t)uprv_strlen(k);
if((valuesCount >= (VALUES_LIST_SIZE-1)) || /* no more space in list .. */
((valuesIndex+kLen+1+1) >= VALUES_BUF_SIZE)) { /* no more space in buffer (string + 2 nulls) */
@@ -3217,50 +3390,50 @@ ures_getKeywordValues(const char *path, const char *keyword, UErrorCode *status)
/* This code isn't needed, and given the documentation warnings the implementation is suspect */
U_CAPI UBool U_EXPORT2
ures_equal(const UResourceBundle* res1, const UResourceBundle* res2){
- if(res1==NULL || res2==NULL){
+ if(res1==nullptr || res2==nullptr){
return res1==res2; /* pointer comparison */
}
- if(res1->fKey==NULL|| res2->fKey==NULL){
+ if(res1->fKey==nullptr|| res2->fKey==nullptr){
return (res1->fKey==res2->fKey);
}else{
if(uprv_strcmp(res1->fKey, res2->fKey)!=0){
- return FALSE;
+ return false;
}
}
if(uprv_strcmp(res1->fData->fName, res2->fData->fName)!=0){
- return FALSE;
+ return false;
}
- if(res1->fData->fPath == NULL|| res2->fData->fPath==NULL){
+ if(res1->fData->fPath == nullptr|| res2->fData->fPath==nullptr){
return (res1->fData->fPath == res2->fData->fPath);
}else{
if(uprv_strcmp(res1->fData->fPath, res2->fData->fPath)!=0){
- return FALSE;
+ return false;
}
}
if(uprv_strcmp(res1->fData->fParent->fName, res2->fData->fParent->fName)!=0){
- return FALSE;
+ return false;
}
if(uprv_strcmp(res1->fData->fParent->fPath, res2->fData->fParent->fPath)!=0){
- return FALSE;
+ return false;
}
if(uprv_strncmp(res1->fResPath, res2->fResPath, res1->fResPathLen)!=0){
- return FALSE;
+ return false;
}
if(res1->fRes != res2->fRes){
- return FALSE;
+ return false;
}
- return TRUE;
+ return true;
}
U_CAPI UResourceBundle* U_EXPORT2
ures_clone(const UResourceBundle* res, UErrorCode* status){
- UResourceBundle* bundle = NULL;
- UResourceBundle* ret = NULL;
- if(U_FAILURE(*status) || res == NULL){
- return NULL;
+ UResourceBundle* bundle = nullptr;
+ UResourceBundle* ret = nullptr;
+ if(U_FAILURE(*status) || res == nullptr){
+ return nullptr;
}
bundle = ures_open(res->fData->fPath, res->fData->fName, status);
- if(res->fResPath!=NULL){
- ret = ures_findSubResource(bundle, res->fResPath, NULL, status);
+ if(res->fResPath!=nullptr){
+ ret = ures_findSubResource(bundle, res->fResPath, nullptr, status);
ures_close(bundle);
}else{
ret = bundle;
@@ -3269,8 +3442,8 @@ ures_clone(const UResourceBundle* res, UErrorCode* status){
}
U_CAPI const UResourceBundle* U_EXPORT2
ures_getParentBundle(const UResourceBundle* res){
- if(res==NULL){
- return NULL;
+ if(res==nullptr){
+ return nullptr;
}
return res->fParentRes;
}
@@ -3278,7 +3451,7 @@ ures_getParentBundle(const UResourceBundle* res){
U_CAPI void U_EXPORT2
ures_getVersionByKey(const UResourceBundle* res, const char *key, UVersionInfo ver, UErrorCode *status) {
- const UChar *str;
+ const char16_t *str;
int32_t len;
str = ures_getStringByKey(res, key, &len, status);
if(U_SUCCESS(*status)) {