mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-07 22:44:49 +00:00
ICU-10601 Added UNUM_CURRENCY_ACCOUNTING to ICU4C NumberFormat.
X-SVN-Rev: 35198
This commit is contained in:
parent
e3e20601c0
commit
cfd57abf79
5 changed files with 52 additions and 7 deletions
|
@ -89,6 +89,9 @@ static const UChar gLastResortIsoCurrencyPat[] = {
|
|||
static const UChar gLastResortPluralCurrencyPat[] = {
|
||||
0x23, 0x30, 0x2E, 0x30, 0x30, 0xA0, 0xA4, 0xA4, 0xA4, 0 /* "#0.00\u00A0\u00A4\u00A4\u00A4*/
|
||||
};
|
||||
static const UChar gLastResortAccountingCurrencyPat[] = {
|
||||
0xA4, 0x23, 0x30, 0x2E, 0x30, 0x30, 0x3B, 0x28, 0xA4, 0x23, 0x30, 0x2E, 0x30, 0x30, 0x29, 0 /* "\u00A4#0.00;(\u00A4#0.00)" */
|
||||
};
|
||||
|
||||
static const UChar gSingleCurrencySign[] = {0xA4, 0};
|
||||
static const UChar gDoubleCurrencySign[] = {0xA4, 0xA4, 0};
|
||||
|
@ -114,7 +117,8 @@ static const UChar * const gLastResortNumberPatterns[UNUM_FORMAT_STYLE_COUNT] =
|
|||
NULL, // UNUM_NUMBERING_SYSTEM
|
||||
NULL, // UNUM_PATTERN_RULEBASED
|
||||
gLastResortIsoCurrencyPat, // UNUM_CURRENCY_ISO
|
||||
gLastResortPluralCurrencyPat // UNUM_CURRENCY_PLURAL
|
||||
gLastResortPluralCurrencyPat, // UNUM_CURRENCY_PLURAL
|
||||
gLastResortAccountingCurrencyPat // UNUM_CURRENCY_ACCOUNTING
|
||||
};
|
||||
|
||||
// Keys used for accessing resource bundles
|
||||
|
@ -138,7 +142,8 @@ static const char *gFormatKeys[UNUM_FORMAT_STYLE_COUNT] = {
|
|||
// except for replacing the single currency sign with
|
||||
// double currency sign or triple currency sign.
|
||||
"currencyFormat", // UNUM_CURRENCY_ISO
|
||||
"currencyFormat" // UNUM_CURRENCY_PLURAL
|
||||
"currencyFormat", // UNUM_CURRENCY_PLURAL
|
||||
"accountingFormat" // UNUM_CURRENCY_ACCOUNTING
|
||||
};
|
||||
|
||||
static icu::LRUCache *gNumberFormatCache = NULL;
|
||||
|
@ -1344,6 +1349,7 @@ NumberFormat::makeInstance(const Locale& desiredLocale,
|
|||
case UNUM_CURRENCY:
|
||||
case UNUM_CURRENCY_ISO: // do not support plural formatting here
|
||||
case UNUM_CURRENCY_PLURAL:
|
||||
case UNUM_CURRENCY_ACCOUNTING:
|
||||
f = new Win32NumberFormat(desiredLocale, curr, status);
|
||||
|
||||
if (U_SUCCESS(status)) {
|
||||
|
@ -1438,7 +1444,7 @@ NumberFormat::makeInstance(const Locale& desiredLocale,
|
|||
if (U_FAILURE(status)) {
|
||||
return NULL;
|
||||
}
|
||||
if(style==UNUM_CURRENCY || style == UNUM_CURRENCY_ISO){
|
||||
if(style==UNUM_CURRENCY || style == UNUM_CURRENCY_ISO || style == UNUM_CURRENCY_ACCOUNTING){
|
||||
const UChar* currPattern = symbolsToAdopt->getCurrencyPattern();
|
||||
if(currPattern!=NULL){
|
||||
pattern.setTo(currPattern, u_strlen(currPattern));
|
||||
|
|
|
@ -197,6 +197,12 @@ typedef enum UNumberFormatStyle {
|
|||
* @stable ICU 4.8
|
||||
*/
|
||||
UNUM_CURRENCY_PLURAL,
|
||||
/**
|
||||
* Currency format for accounting, e.g., "($3.00)" for
|
||||
* negative currency amount instead of "-$3.00" ({@link #UNUM_CURRENCY}).
|
||||
* @draft ICU 53
|
||||
*/
|
||||
UNUM_CURRENCY_ACCOUNTING,
|
||||
/**
|
||||
* One more than the highest number format style constant.
|
||||
* @stable ICU 4.8
|
||||
|
|
|
@ -54,6 +54,7 @@ unum_open( UNumberFormatStyle style,
|
|||
case UNUM_SCIENTIFIC:
|
||||
case UNUM_CURRENCY_ISO:
|
||||
case UNUM_CURRENCY_PLURAL:
|
||||
case UNUM_CURRENCY_ACCOUNTING:
|
||||
retVal = NumberFormat::createInstance(Locale(locale), style, *status);
|
||||
break;
|
||||
|
||||
|
|
|
@ -132,6 +132,7 @@ void NumberFormatTest::runIndexedTest( int32_t index, UBool exec, const char* &n
|
|||
TESTCASE_AUTO(Test10468ApplyPattern);
|
||||
TESTCASE_AUTO(TestRoundingScientific10542);
|
||||
TESTCASE_AUTO(TestZeroScientific10547);
|
||||
TESTCASE_AUTO(TestAccountingCurrency);
|
||||
TESTCASE_AUTO_END;
|
||||
}
|
||||
|
||||
|
@ -2549,12 +2550,12 @@ void NumberFormatTest::expect(NumberFormat& fmt, const Formattable& n,
|
|||
}
|
||||
|
||||
void NumberFormatTest::expect(NumberFormat* fmt, const Formattable& n,
|
||||
const UnicodeString& exp,
|
||||
const UnicodeString& exp, UBool rt,
|
||||
UErrorCode status) {
|
||||
if (fmt == NULL || U_FAILURE(status)) {
|
||||
dataerrln("FAIL: NumberFormat constructor");
|
||||
} else {
|
||||
expect(*fmt, n, exp);
|
||||
expect(*fmt, n, exp, rt);
|
||||
}
|
||||
delete fmt;
|
||||
}
|
||||
|
@ -7579,4 +7580,24 @@ void NumberFormatTest::verifyRounding(
|
|||
}
|
||||
}
|
||||
|
||||
void NumberFormatTest::TestAccountingCurrency() {
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
UNumberFormatStyle style = UNUM_CURRENCY_ACCOUNTING;
|
||||
|
||||
expect(NumberFormat::createInstance("en_US", style, status),
|
||||
(Formattable)1234.5, "$1,234.50", TRUE, status);
|
||||
expect(NumberFormat::createInstance("en_US", style, status),
|
||||
(Formattable)-1234.5, "($1,234.50)", TRUE, status);
|
||||
expect(NumberFormat::createInstance("en_US", style, status),
|
||||
(Formattable)0, "$0.00", TRUE, status);
|
||||
expect(NumberFormat::createInstance("en_US", style, status),
|
||||
(Formattable)-0.2, "($0.20)", TRUE, status);
|
||||
expect(NumberFormat::createInstance("ja_JP", style, status),
|
||||
(Formattable)10000, UnicodeString("\\uFFE510,000").unescape(), TRUE, status);
|
||||
expect(NumberFormat::createInstance("ja_JP", style, status),
|
||||
(Formattable)-1000.5, UnicodeString("(\\uFFE51,000)").unescape(), FALSE, status);
|
||||
expect(NumberFormat::createInstance("de_DE", style, status),
|
||||
(Formattable)-23456.7, UnicodeString("-23.456,70\\u00A0\\u20AC").unescape(), TRUE, status);
|
||||
}
|
||||
|
||||
#endif /* #if !UCONFIG_NO_FORMATTING */
|
||||
|
|
|
@ -179,6 +179,7 @@ class NumberFormatTest: public CalendarTimeZoneTest {
|
|||
void Test10468ApplyPattern();
|
||||
void TestRoundingScientific10542();
|
||||
void TestZeroScientific10547();
|
||||
void TestAccountingCurrency();
|
||||
|
||||
private:
|
||||
UBool testFormattableAsUFormattable(const char *file, int line, Formattable &f);
|
||||
|
@ -222,11 +223,21 @@ class NumberFormatTest: public CalendarTimeZoneTest {
|
|||
}
|
||||
|
||||
void expect(NumberFormat* fmt, const Formattable& n,
|
||||
const UnicodeString& exp, UErrorCode);
|
||||
const UnicodeString& exp, UBool rt, UErrorCode errorCode);
|
||||
|
||||
void expect(NumberFormat* fmt, const Formattable& n,
|
||||
const char *exp, UBool rt, UErrorCode errorCode) {
|
||||
expect(fmt, n, UnicodeString(exp, ""), rt, errorCode);
|
||||
}
|
||||
|
||||
void expect(NumberFormat* fmt, const Formattable& n,
|
||||
const UnicodeString& exp, UErrorCode errorCode) {
|
||||
expect(fmt, n, exp, TRUE, errorCode);
|
||||
}
|
||||
|
||||
void expect(NumberFormat* fmt, const Formattable& n,
|
||||
const char *exp, UErrorCode errorCode) {
|
||||
expect(fmt, n, UnicodeString(exp, ""), errorCode);
|
||||
expect(fmt, n, UnicodeString(exp, ""), TRUE, errorCode);
|
||||
}
|
||||
|
||||
void expectCurrency(NumberFormat& nf, const Locale& locale,
|
||||
|
|
Loading…
Add table
Reference in a new issue