ICU-13574 Adding getConstDigitSymbol to ICU4C, right now as @internal. Follow-up for promoting to @draft in ICU-13580

X-SVN-Rev: 40858
This commit is contained in:
Shane Carr 2018-02-08 03:18:00 +00:00
parent b18e037531
commit f4a623e94b
2 changed files with 45 additions and 4 deletions

View 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 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
@ -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

View 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() {