Logo Search packages:      
Sourcecode: icu version File versions

U_STABLE const UChar* U_EXPORT2 ucurr_getPluralName ( const UChar *  currency,
const char *  locale,
UBool isChoiceFormat,
const char *  pluralCount,
int32_t *  len,
UErrorCode ec 
)

Returns the plural name for the given currency in the given locale. For example, the plural name for the USD currency object in the en_US locale is "US dollar" or "US dollars".

Parameters:
currency null-terminated 3-letter ISO 4217 code
locale locale in which to display currency
isChoiceFormat fill-in set to TRUE if the returned value is a ChoiceFormat pattern; otherwise it is a static string
pluralCount plural count
len fill-in parameter to receive length of result
ec error code
Returns:
pointer to display string of 'len' UChars. If the resource data contains no entry for 'currency', then 'currency' itself is returned. ICU 4.2

Definition at line 571 of file ucurr.cpp.

References NULL, U_FAILURE, U_ILLEGAL_ARGUMENT_ERROR, U_STRING_NOT_TERMINATED_WARNING, u_strlen(), U_SUCCESS, U_USING_DEFAULT_WARNING, U_USING_FALLBACK_WARNING, U_ZERO_ERROR, UCURR_LONG_NAME, and ULOC_FULLNAME_CAPACITY.

                                    {
    // Look up the Currencies resource for the given locale.  The
    // Currencies locale data looks like this:
    //|en {
    //|  CurrencyPlurals {
    //|    USD{
    //|      one{"US dollar"}
    //|      other{"US dollars"}
    //|    }
    //|  }
    //|}

    if (U_FAILURE(*ec)) {
        return 0;
    }

    // Use a separate UErrorCode here that does not propagate out of
    // this function.
    UErrorCode ec2 = U_ZERO_ERROR;

    char loc[ULOC_FULLNAME_CAPACITY];
    uloc_getName(locale, loc, sizeof(loc), &ec2);
    if (U_FAILURE(ec2) || ec2 == U_STRING_NOT_TERMINATED_WARNING) {
        *ec = U_ILLEGAL_ARGUMENT_ERROR;
        return 0;
    }

    char buf[ISO_COUNTRY_CODE_LENGTH+1];
    myUCharsToChars(buf, currency);

    const UChar* s = NULL;
    ec2 = U_ZERO_ERROR;
    UResourceBundle* rb = ures_open(NULL, loc, &ec2);

    rb = ures_getByKey(rb, CURRENCYPLURALS, rb, &ec2);

    // Fetch resource with multi-level resource inheritance fallback
    rb = ures_getByKeyWithFallback(rb, buf, rb, &ec2);

    s = ures_getStringByKeyWithFallback(rb, pluralCount, len, &ec2);
    if (U_FAILURE(ec2)) {
        //  fall back to "other"
        ec2 = U_ZERO_ERROR;
        s = ures_getStringByKeyWithFallback(rb, "other", len, &ec2);     
        if (U_FAILURE(ec2)) {
            ures_close(rb);
            // fall back to long name in Currencies
            return ucurr_getName(currency, locale, UCURR_LONG_NAME, 
                                 isChoiceFormat, len, ec);
        }
    }
    ures_close(rb);

    // If we've succeeded we're done.  Otherwise, try to fallback.
    // If that fails (because we are already at root) then exit.
    if (U_SUCCESS(ec2)) {
        if (ec2 == U_USING_DEFAULT_WARNING
            || (ec2 == U_USING_FALLBACK_WARNING && *ec != U_USING_DEFAULT_WARNING)) {
            *ec = ec2;
        }
        U_ASSERT(s != NULL);
        return s;
    }

    // If we fail to find a match, use the ISO 4217 code
    *len = u_strlen(currency); // Should == ISO_COUNTRY_CODE_LENGTH, but maybe not...?
    *ec = U_USING_DEFAULT_WARNING;
    return currency;
}


Generated by  Doxygen 1.6.0   Back to index