]> granicus.if.org Git - icu/commitdiff
ICU-13574 Adding getConstDigitSymbol to ICU4C, right now as @internal. Follow-up...
authorShane Carr <shane@unicode.org>
Thu, 8 Feb 2018 03:18:00 +0000 (03:18 +0000)
committerShane Carr <shane@unicode.org>
Thu, 8 Feb 2018 03:18:00 +0000 (03:18 +0000)
X-SVN-Rev: 40858

icu4c/source/i18n/unicode/dcfmtsym.h
icu4c/source/test/intltest/tsdcfmsy.cpp

index c6da623034cb616d9b19e2da02aabf0c04aafb72..ebcaa4cb94367b105ee662a76353c4676890adc1 100644 (file)
@@ -411,11 +411,21 @@ public:
      *
      * @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 UnicodeStringgetConstSymbol(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
@@ -500,6 +510,17 @@ DecimalFormatSymbols::getConstSymbol(ENumberFormatSymbol symbol) const {
     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
index 0cbd784ec873055427075d0938d12dafeb6febcb..a7462ae7533a69a6d005cffd39b0b8b9e34c0398 100644 (file)
@@ -252,7 +252,7 @@ void IntlTestDecimalFormatSymbols::testLastResortData() {
 
 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[] = {
@@ -266,13 +266,18 @@ void IntlTestDecimalFormatSymbols::testDigitSymbols() {
     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;
@@ -280,6 +285,11 @@ void IntlTestDecimalFormatSymbols::testDigitSymbols() {
     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(
@@ -288,6 +298,11 @@ void IntlTestDecimalFormatSymbols::testDigitSymbols() {
     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(
@@ -296,6 +311,11 @@ void IntlTestDecimalFormatSymbols::testDigitSymbols() {
     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() {