*
* @param symbol Constant to indicate a number format symbol.
* @return the format symbol by the param 'symbol'
- * @internal
+ * @draft ICU 61
*/
- inline const UnicodeString &getConstSymbol(ENumberFormatSymbol symbol) const;
+ inline const UnicodeString& getConstSymbol(ENumberFormatSymbol symbol) const;
#ifndef U_HIDE_INTERNAL_API
+ /**
+ * Returns the const UnicodeString reference, like getConstSymbol,
+ * corresponding to the digit with the given value. This is equivalent
+ * to accessing the symbol from getConstSymbol with the corresponding
+ * key, such as kZeroDigitSymbol or kOneDigitSymbol.
+ *
+ * @internal This API is currently for ICU use only.
+ */
+ inline const UnicodeString& getConstDigitSymbol(int32_t digit);
+
/**
* Returns that pattern stored in currecy info. Internal API for use by NumberFormat API.
* @internal
return *strPtr;
}
+inline const UnicodeString& DecimalFormatSymbols::getConstDigitSymbol(int32_t digit) {
+ if (digit < 0 || digit > 9) {
+ digit = 0;
+ }
+ if (digit == 0) {
+ return fSymbols[kZeroDigitSymbol];
+ }
+ ENumberFormatSymbol key = static_cast<ENumberFormatSymbol>(kOneDigitSymbol + digit - 1);
+ return fSymbols[key];
+}
+
// -------------------------------------
inline void
void IntlTestDecimalFormatSymbols::testDigitSymbols() {
// This test does more in ICU4J than in ICU4C right now.
- // In ICU4C, it is basically just a test for codePointZero.
+ // In ICU4C, it is basically just a test for codePointZero and getConstDigitSymbol.
UChar defZero = u'0';
UChar32 osmanyaZero = U'\U000104A0';
static const UChar* osmanyaDigitStrings[] = {
if (defZero != symbols.getCodePointZero()) {
errln("ERROR: Code point zero be ASCII 0");
}
+ for (int32_t i=0; i<=9; i++) {
+ assertEquals(UnicodeString("i. ASCII Digit at index ") + Int64ToUnicodeString(i),
+ UnicodeString(u'0' + i),
+ symbols.getConstDigitSymbol(i));
+ }
for (int32_t i=0; i<=9; i++) {
DecimalFormatSymbols::ENumberFormatSymbol key =
i == 0
? DecimalFormatSymbols::kZeroDigitSymbol
: static_cast<DecimalFormatSymbols::ENumberFormatSymbol>
- (DecimalFormatSymbols::kOneDigitSymbol + i);
+ (DecimalFormatSymbols::kOneDigitSymbol + i - 1);
symbols.setSymbol(key, UnicodeString(osmanyaDigitStrings[i]), FALSE);
}
// NOTE: in ICU4J, the calculation of codePointZero is smarter;
if (-1 != symbols.getCodePointZero()) {
errln("ERROR: Code point zero be invalid");
}
+ for (int32_t i=0; i<=9; i++) {
+ assertEquals(UnicodeString("ii. Osmanya digit at index ") + Int64ToUnicodeString(i),
+ UnicodeString(osmanyaDigitStrings[i]),
+ symbols.getConstDigitSymbol(i));
+ }
// Check Osmanya codePointZero
symbols.setSymbol(
if (osmanyaZero != symbols.getCodePointZero()) {
errln("ERROR: Code point zero be Osmanya code point zero");
}
+ for (int32_t i=0; i<=9; i++) {
+ assertEquals(UnicodeString("iii. Osmanya digit at index ") + Int64ToUnicodeString(i),
+ UnicodeString(osmanyaDigitStrings[i]),
+ symbols.getConstDigitSymbol(i));
+ }
// Reset digits to Latin
symbols.setSymbol(
if (defZero != symbols.getCodePointZero()) {
errln("ERROR: Code point zero be ASCII 0");
}
+ for (int32_t i=0; i<=9; i++) {
+ assertEquals(UnicodeString("iv. ASCII Digit at index ") + Int64ToUnicodeString(i),
+ UnicodeString(u'0' + i),
+ symbols.getConstDigitSymbol(i));
+ }
}
void IntlTestDecimalFormatSymbols::testNumberingSystem() {