static int32_t _getStringOrCopyKey(const char *path, const char *locale, const char *tableKey, const char* subTableKey, const char *itemKey, const char *substitute, UChar *dest, int32_t destCapacity, UErrorCode *pErrorCode) { const UChar *s = NULL; int32_t length = 0; if(itemKey==NULL) { /* top-level item: normal resource bundle access */ UResourceBundle *rb; rb=ures_open(path, locale, pErrorCode); if(U_SUCCESS(*pErrorCode)) { s=ures_getStringByKey(rb, tableKey, &length, pErrorCode); /* see comment about closing rb near "return item;" in _res_getTableStringWithFallback() */ ures_close(rb); } } else { /* Language code should not be a number. If it is, set the error code. */ if (!uprv_strncmp(tableKey, "Languages", 9) && uprv_strtol(itemKey, NULL, 10)) { *pErrorCode = U_MISSING_RESOURCE_ERROR; } else { /* second-level item, use special fallback */ s=uloc_getTableStringWithFallback(path, locale, tableKey, subTableKey, itemKey, &length, pErrorCode); } } if(U_SUCCESS(*pErrorCode)) { int32_t copyLength=uprv_min(length, destCapacity); if(copyLength>0 && s != NULL) { u_memcpy(dest, s, copyLength); } } else { /* no string from a resource bundle: convert the substitute */ length=(int32_t)uprv_strlen(substitute); u_charsToUChars(substitute, dest, uprv_min(length, destCapacity)); *pErrorCode=U_USING_DEFAULT_WARNING; } return u_terminateUChars(dest, destCapacity, length, pErrorCode); }
UnicodeString & ICUDataTable::get(const char* tableKey, const char* subTableKey, const char* itemKey, UnicodeString &result) const { UErrorCode status = U_ZERO_ERROR; int32_t len = 0; const UChar *s = uloc_getTableStringWithFallback(path, locale.getName(), tableKey, subTableKey, itemKey, &len, &status); if (U_SUCCESS(status) && len > 0) { return result.setTo(s, len); } return result.setTo(UnicodeString(itemKey, -1, US_INV)); }
static ULayoutType _uloc_getOrientationHelper(const char* localeId, const char* key, UErrorCode *status) { ULayoutType result = ULOC_LAYOUT_UNKNOWN; if (!U_FAILURE(*status)) { int32_t length = 0; char localeBuffer[ULOC_FULLNAME_CAPACITY]; uloc_canonicalize(localeId, localeBuffer, sizeof(localeBuffer), status); if (!U_FAILURE(*status)) { const UChar* const value = uloc_getTableStringWithFallback( NULL, localeBuffer, "layout", NULL, key, &length, status); if (!U_FAILURE(*status) && length != 0) { switch(value[0]) { case 0x0062: /* 'b' */ result = ULOC_LAYOUT_BTT; break; case 0x006C: /* 'l' */ result = ULOC_LAYOUT_LTR; break; case 0x0072: /* 'r' */ result = ULOC_LAYOUT_RTL; break; case 0x0074: /* 't' */ result = ULOC_LAYOUT_TTB; break; default: *status = U_INTERNAL_PROGRAM_ERROR; break; } } } } return result; }