static jstring ICU_getCurrencySymbol(JNIEnv* env, jclass, jstring locale, jstring currencyCode) { // We can't use ucurr_getName because it doesn't distinguish between using data root from // the root locale and parroting back the input because it's never heard of the currency code. ScopedUtfChars localeName(env, locale); UErrorCode status = U_ZERO_ERROR; ScopedResourceBundle currLoc(ures_open(U_ICUDATA_CURR, localeName.c_str(), &status)); if (U_FAILURE(status)) { return NULL; } ScopedResourceBundle currencies(ures_getByKey(currLoc.get(), "Currencies", NULL, &status)); if (U_FAILURE(status)) { return NULL; } ScopedUtfChars currency(env, currencyCode); ScopedResourceBundle currencyElems(ures_getByKey(currencies.get(), currency.c_str(), NULL, &status)); if (U_FAILURE(status)) { return NULL; } int32_t charCount; const jchar* chars = ures_getStringByIndex(currencyElems.get(), 0, &charCount, &status); if (U_FAILURE(status)) { return NULL; } return (charCount == 0) ? NULL : env->NewString(chars, charCount); }
static jstring getCurrencySymbolNative(JNIEnv* env, jclass clazz, jstring locale, jstring currencyCode) { // LOGI("ENTER getCurrencySymbolNative"); const char* locName = env->GetStringUTFChars(locale, NULL); UErrorCode status = U_ZERO_ERROR; ScopedResourceBundle root(ures_open(NULL, locName, &status)); env->ReleaseStringUTFChars(locale, locName); if (U_FAILURE(status)) { return NULL; } ScopedResourceBundle currencies(ures_getByKey(root.get(), "Currencies", NULL, &status)); if (U_FAILURE(status)) { return NULL; } const char* currName = env->GetStringUTFChars(currencyCode, NULL); ScopedResourceBundle currencyElems(ures_getByKey(currencies.get(), currName, NULL, &status)); env->ReleaseStringUTFChars(currencyCode, currName); if (U_FAILURE(status)) { return NULL; } int currSymbL; const jchar* currSymbU = ures_getStringByIndex(currencyElems.get(), 0, &currSymbL, &status); if (U_FAILURE(status)) { return NULL; } return (currSymbL == 0) ? NULL : env->NewString(currSymbU, currSymbL); }
static jstring ICU_getCurrencySymbolNative(JNIEnv* env, jclass, jstring locale, jstring currencyCode) { ScopedUtfChars localeName(env, locale); UErrorCode status = U_ZERO_ERROR; ScopedResourceBundle currLoc(ures_open(U_ICUDATA_CURR, localeName.c_str(), &status)); if (U_FAILURE(status)) { return NULL; } ScopedResourceBundle currencies(ures_getByKey(currLoc.get(), "Currencies", NULL, &status)); if (U_FAILURE(status)) { return NULL; } ScopedUtfChars currency(env, currencyCode); ScopedResourceBundle currencyElems(ures_getByKey(currencies.get(), currency.c_str(), NULL, &status)); if (U_FAILURE(status)) { return NULL; } int currSymbL; const jchar* currSymbU = ures_getStringByIndex(currencyElems.get(), 0, &currSymbL, &status); if (U_FAILURE(status)) { return NULL; } return (currSymbL == 0) ? NULL : env->NewString(currSymbU, currSymbL); }