Пример #1
0
static jstring getCurrencyName(JNIEnv* env, jstring javaLanguageTag, jstring javaCurrencyCode, UCurrNameStyle nameStyle) {
  ScopedUtfChars languageTag(env, javaLanguageTag);
  if (languageTag.c_str() == NULL) {
    return NULL;
  }
  ScopedJavaUnicodeString currencyCode(env, javaCurrencyCode);
  if (!currencyCode.valid()) {
    return NULL;
  }
  UnicodeString icuCurrencyCode(currencyCode.unicodeString());
  UErrorCode status = U_ZERO_ERROR;
  UBool isChoiceFormat = false;
  int32_t charCount;
  const UChar* chars = ucurr_getName(icuCurrencyCode.getTerminatedBuffer(), languageTag.c_str(),
                                     nameStyle, &isChoiceFormat, &charCount, &status);
  if (status == U_USING_DEFAULT_WARNING) {
    if (nameStyle == UCURR_SYMBOL_NAME) {
      // ICU doesn't distinguish between falling back to the root locale and meeting a genuinely
      // unknown currency. The Currency class does.
      if (!ucurr_isAvailable(icuCurrencyCode.getTerminatedBuffer(), U_DATE_MIN, U_DATE_MAX, &status)) {
        return NULL;
      }
    }
    if (nameStyle == UCURR_LONG_NAME) {
      // ICU's default is English. We want the ISO 4217 currency code instead.
      chars = icuCurrencyCode.getBuffer();
      charCount = icuCurrencyCode.length();
    }
  }
  return (charCount == 0) ? NULL : env->NewString(chars, charCount);
}
Пример #2
0
static jint ICU_getCurrencyNumericCode(JNIEnv* env, jclass, jstring javaCurrencyCode) {
  ScopedJavaUnicodeString currencyCode(env, javaCurrencyCode);
  if (!currencyCode.valid()) {
    return 0;
  }
  UnicodeString icuCurrencyCode(currencyCode.unicodeString());
  return ucurr_getNumericCode(icuCurrencyCode.getTerminatedBuffer());
}
Пример #3
0
static jint ICU_getCurrencyFractionDigits(JNIEnv* env, jclass, jstring javaCurrencyCode) {
  ScopedJavaUnicodeString currencyCode(env, javaCurrencyCode);
  if (!currencyCode.valid()) {
    return 0;
  }
  UnicodeString icuCurrencyCode(currencyCode.unicodeString());
  UErrorCode status = U_ZERO_ERROR;
  return ucurr_getDefaultFractionDigits(icuCurrencyCode.getTerminatedBuffer(), &status);
}
Пример #4
0
static jint ICU_getCurrencyFractionDigitsNative(JNIEnv* env, jclass, jstring javaCurrencyCode) {
    UErrorCode status = U_ZERO_ERROR;
    UniquePtr<NumberFormat> fmt(NumberFormat::createCurrencyInstance(status));
    if (U_FAILURE(status)) {
        return -1;
    }
    ScopedJavaUnicodeString currencyCode(env, javaCurrencyCode);
    fmt->setCurrency(currencyCode.unicodeString().getBuffer(), status);
    if (U_FAILURE(status)) {
        return -1;
    }
    // for CurrencyFormats the minimum and maximum fraction digits are the same.
    return fmt->getMinimumFractionDigits();
}
Пример #5
0
static jstring ICU_getCurrencyDisplayName(JNIEnv* env, jclass, jstring javaLocaleName, jstring javaCurrencyCode) {
    ScopedUtfChars localeName(env, javaLocaleName);
    ScopedJavaUnicodeString currencyCode(env, javaCurrencyCode);
    UnicodeString icuCurrencyCode(currencyCode.unicodeString());
    UErrorCode status = U_ZERO_ERROR;
    UBool isChoiceFormat;
    int32_t charCount;
    const UChar* chars = ucurr_getName(icuCurrencyCode.getTerminatedBuffer(), localeName.c_str(),
            UCURR_LONG_NAME, &isChoiceFormat, &charCount, &status);
    if (status == U_USING_DEFAULT_WARNING) {
        // ICU's default is English. We want the ISO 4217 currency code instead.
        chars = icuCurrencyCode.getBuffer();
        charCount = icuCurrencyCode.length();
    }
    return (charCount == 0) ? NULL : env->NewString(chars, charCount);
}
Пример #6
0
QString KLocale::currencyCode() const
{
    return d->currencyCode();
}