"%%tamil-thousands:",
"0: =%tamil=;",
"1000: <<\u0BF2[>>];",
+ "%zDefault:",
+ "0: =#,##0=;",
}
OrdinalRules{
"%digits-ordinal:",
NULL, // UNUM_SPELLOUT
NULL, // UNUM_ORDINAL
NULL, // UNUM_DURATION
- NULL, // UNUM_NUMBERING_SYSTEM
+ gLastResortDecimalPat, // UNUM_NUMBERING_SYSTEM
NULL, // UNUM_PATTERN_RULEBASED
gLastResortIsoCurrencyPat, // UNUM_CURRENCY_ISO
gLastResortPluralCurrencyPat, // UNUM_CURRENCY_PLURAL
status = U_ILLEGAL_ARGUMENT_ERROR;
return NULL;
}
+
+ // For the purposes of general number formatting, UNUM_NUMBERING_SYSTEM should behave the same
+ // was as UNUM_DECIMAL. In both cases, you get either a DecimalFormat or a RuleBasedNumberFormat
+ // depending on the locale's numbering system (either the default one for the locale or a specific
+ // one specified by using the "@numbers=" or "-u-nu-" parameter in the locale ID.
+ if (style == UNUM_NUMBERING_SYSTEM) {
+ style = UNUM_DECIMAL;
+ }
// Some styles are not supported. This is a result of merging
// the @draft ICU 4.2 NumberFormat::EStyles into the long-existing UNumberFormatStyle.
* @stable ICU 2.2
*/
enum URBNFRuleSetTag {
+ /**
+ * Requests predefined ruleset for spelling out numeric values in words.
+ * @stable ICU 2.2
+ */
URBNF_SPELLOUT,
+ /**
+ * Requests predefined ruleset for the ordinal form of a number.
+ * @stable ICU 2.2
+ */
URBNF_ORDINAL,
+ /**
+ * Requests predefined ruleset for formatting a value as a duration in hours, minutes, and seconds.
+ * @stable ICU 2.2
+ */
URBNF_DURATION,
+ /**
+ * Requests predefined ruleset for various non-place-value numbering systems.
+ * WARNING: The same resource contains rule sets for a variety of different numbering systems.
+ * You need to call setDefaultRuleSet() on the formatter to choose the actual numbering system.
+ * @stable ICU 2.2
+ */
URBNF_NUMBERING_SYSTEM,
#ifndef U_HIDE_DEPRECATED_API
/**
* URBNF_DURATION, which formats a duration in seconds as hours, minutes, and seconds always rounding down,
* and URBNF_NUMBERING_SYSTEM, which is used to invoke rules for alternate numbering
* systems such as the Hebrew numbering system, or for Roman Numerals, etc.
+ * NOTE: If you use URBNF_NUMBERING_SYSTEM, you must also call setDefaultRuleSet() to
+ * specify the exact numbering system you want to use. If you want the default numbering system
+ * for the locale, call NumberFormat::createInstance() instead of creating a RuleBasedNumberFormat directly.
* @param locale The locale for the formatter.
* @param status The status indicating whether the constructor succeeded.
* @stable ICU 2.0
case UNUM_CURRENCY_ACCOUNTING:
case UNUM_CASH_CURRENCY:
case UNUM_CURRENCY_STANDARD:
+ case UNUM_NUMBERING_SYSTEM:
retVal = NumberFormat::createInstance(Locale(locale), style, *status);
break;
case UNUM_DURATION:
retVal = new RuleBasedNumberFormat(URBNF_DURATION, Locale(locale), *status);
break;
-
- case UNUM_NUMBERING_SYSTEM:
- retVal = new RuleBasedNumberFormat(URBNF_NUMBERING_SYSTEM, Locale(locale), *status);
- break;
#endif
case UNUM_DECIMAL_COMPACT_SHORT:
static void TestSciNotationMaxFracCap(void);
static void TestMinIntMinFracZero(void);
static void Test21479_ExactCurrency(void);
+static void Test22088_Ethiopic(void);
#define TESTCASE(x) addTest(root, &x, "tsformat/cnumtst/" #x)
TESTCASE(TestSciNotationMaxFracCap);
TESTCASE(TestMinIntMinFracZero);
TESTCASE(Test21479_ExactCurrency);
+ TESTCASE(Test22088_Ethiopic);
}
/* test Parse int 64 */
unum_close(nf);
}
+static void Test22088_Ethiopic(void) {
+ UErrorCode err = U_ZERO_ERROR;
+ UNumberFormat* nf1 = unum_open(UNUM_DEFAULT, NULL, 0, "am_ET@numbers=ethi", NULL, &err);
+ UNumberFormat* nf2 = unum_open(UNUM_NUMBERING_SYSTEM, NULL, 0, "am_ET@numbers=ethi", NULL, &err);
+ UNumberFormat* nf3 = unum_open(UNUM_NUMBERING_SYSTEM, NULL, 0, "en_US", NULL, &err);
+
+ if (assertSuccess("Creation of number formatters failed", &err)) {
+ UChar result[200];
+
+ unum_formatDouble(nf1, 123, result, 200, NULL, &err);
+ assertSuccess("Formatting of number failed", &err);
+ assertUEquals("Wrong result with UNUM_DEFAULT", u"፻፳፫", result);
+
+ unum_formatDouble(nf2, 123, result, 200, NULL, &err);
+ assertSuccess("Formatting of number failed", &err);
+ assertUEquals("Wrong result with UNUM_NUMBERING_SYSTEM", u"፻፳፫", result);
+
+ unum_formatDouble(nf3, 123, result, 200, NULL, &err);
+ assertSuccess("Formatting of number failed", &err);
+ assertUEquals("Wrong result with UNUM_NUMBERING_SYSTEM and English", u"123", result);
+ }
+ unum_close(nf1);
+ unum_close(nf2);
+ unum_close(nf3);
+}
+
#endif /* #if !UCONFIG_NO_FORMATTING */
TESTCASE(26, TestParseFailure);
TESTCASE(27, TestMinMaxIntegerDigitsIgnored);
TESTCASE(28, TestNorwegianSpellout);
+ TESTCASE(29, TestNumberingSystem);
#else
TESTCASE(0, TestRBNFDisabled);
#endif
}
}
+void
+IntlTestRBNF::TestNumberingSystem() {
+ IcuTestErrorCode err(*this, "TestNumberingSystem");
+ RuleBasedNumberFormat rbnf(URBNF_NUMBERING_SYSTEM, Locale::getUS(), err);
+
+ if (!err.errIfFailureAndReset("Failed to create RBNF with URBNF_NUMBERING_SYSTEM")) {
+ UnicodeString result;
+ assertEquals("Wrong result with default rule set", u"123", rbnf.format(123, result, err));
+
+ result.remove();
+ rbnf.setDefaultRuleSet(u"%ethiopic", err);
+ assertEquals("Wrong result with Ethiopic rule set", u"፻፳፫", rbnf.format(123, result, err));
+ }
+}
+
/* U_HAVE_RBNF */
#else
void TestCompactDecimalFormatStyle();
void TestParseFailure();
void TestMinMaxIntegerDigitsIgnored();
+ void TestNumberingSystem();
protected:
virtual void doTest(RuleBasedNumberFormat* formatter, const char* const testData[][2], UBool testParsing);
TESTCASE_AUTO(Test21232_ParseTimeout);
TESTCASE_AUTO(Test10997_FormatCurrency);
TESTCASE_AUTO(Test21556_CurrencyAsDecimal);
+ TESTCASE_AUTO(Test22088_Ethiopic);
TESTCASE_AUTO_END;
}
}
}
+void NumberFormatTest::Test22088_Ethiopic() {
+ IcuTestErrorCode err(*this, "Test22088_Ethiopic");
+ LocalPointer<NumberFormat> nf1(NumberFormat::createInstance(Locale("am_ET@numbers=ethi"), UNUM_DEFAULT, err));
+ LocalPointer<NumberFormat> nf2(NumberFormat::createInstance(Locale("am_ET@numbers=ethi"), UNUM_NUMBERING_SYSTEM, err));
+ LocalPointer<NumberFormat> nf3(NumberFormat::createInstance(Locale::getUS(), UNUM_NUMBERING_SYSTEM, err));
+
+ if (!err.errIfFailureAndReset("Creation of number formatters failed")) {
+ UnicodeString result;
+ assertEquals("Wrong result with UNUM_DEFAULT", u"፻፳፫", nf1->format(123, result));
+ result.remove();
+ assertEquals("Wrong result with UNUM_NUMBERING_SYSTEM", u"፻፳፫", nf2->format(123, result));
+ result.remove();
+ assertEquals("Wrong result with UNUM_NUMBERING_SYSTEM and English", u"123", nf3->format(123, result));
+ }
+}
+
#endif /* #if !UCONFIG_NO_FORMATTING */
void Test21232_ParseTimeout();
void Test10997_FormatCurrency();
void Test21556_CurrencyAsDecimal();
+ void Test22088_Ethiopic();
private:
UBool testFormattableAsUFormattable(const char *file, int line, Formattable &f);
version https://git-lfs.github.com/spec/v1
-oid sha256:f3112f5cdf386100bc201a1fabc3a15a190d662d100712619a83ca211639d0fb
-size 13891395
+oid sha256:7280fe2b5614523890959916529e198ee81e51dcdbc02d61882c0257f3346e8d
+size 13891411
assertEquals("infinity", rbnf.format(Double.POSITIVE_INFINITY));
assertEquals("not a number", rbnf.format(Double.NaN));
}
+
+ @Test
+ public void TestNumberingSystem() {
+ RuleBasedNumberFormat rbnf = new RuleBasedNumberFormat(ULocale.US, RuleBasedNumberFormat.NUMBERING_SYSTEM);
+
+ assertEquals("Wrong result with default rule set", "123", rbnf.format(123));
+
+ rbnf.setDefaultRuleSet("%ethiopic");
+ assertEquals("Wrong result with Ethiopic rule set", "፻፳፫", rbnf.format(123));
+ }
}