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:
parent
b18e037531
commit
f4a623e94b
@ -411,11 +411,21 @@ public:
|
|||||||
*
|
*
|
||||||
* @param symbol Constant to indicate a number format symbol.
|
* @param symbol Constant to indicate a number format symbol.
|
||||||
* @return the format symbol by the param '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
|
#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.
|
* Returns that pattern stored in currecy info. Internal API for use by NumberFormat API.
|
||||||
* @internal
|
* @internal
|
||||||
@ -500,6 +510,17 @@ DecimalFormatSymbols::getConstSymbol(ENumberFormatSymbol symbol) const {
|
|||||||
return *strPtr;
|
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
|
inline void
|
||||||
|
@ -252,7 +252,7 @@ void IntlTestDecimalFormatSymbols::testLastResortData() {
|
|||||||
|
|
||||||
void IntlTestDecimalFormatSymbols::testDigitSymbols() {
|
void IntlTestDecimalFormatSymbols::testDigitSymbols() {
|
||||||
// This test does more in ICU4J than in ICU4C right now.
|
// 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';
|
UChar defZero = u'0';
|
||||||
UChar32 osmanyaZero = U'\U000104A0';
|
UChar32 osmanyaZero = U'\U000104A0';
|
||||||
static const UChar* osmanyaDigitStrings[] = {
|
static const UChar* osmanyaDigitStrings[] = {
|
||||||
@ -266,13 +266,18 @@ void IntlTestDecimalFormatSymbols::testDigitSymbols() {
|
|||||||
if (defZero != symbols.getCodePointZero()) {
|
if (defZero != symbols.getCodePointZero()) {
|
||||||
errln("ERROR: Code point zero be ASCII 0");
|
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++) {
|
for (int32_t i=0; i<=9; i++) {
|
||||||
DecimalFormatSymbols::ENumberFormatSymbol key =
|
DecimalFormatSymbols::ENumberFormatSymbol key =
|
||||||
i == 0
|
i == 0
|
||||||
? DecimalFormatSymbols::kZeroDigitSymbol
|
? DecimalFormatSymbols::kZeroDigitSymbol
|
||||||
: static_cast<DecimalFormatSymbols::ENumberFormatSymbol>
|
: static_cast<DecimalFormatSymbols::ENumberFormatSymbol>
|
||||||
(DecimalFormatSymbols::kOneDigitSymbol + i);
|
(DecimalFormatSymbols::kOneDigitSymbol + i - 1);
|
||||||
symbols.setSymbol(key, UnicodeString(osmanyaDigitStrings[i]), FALSE);
|
symbols.setSymbol(key, UnicodeString(osmanyaDigitStrings[i]), FALSE);
|
||||||
}
|
}
|
||||||
// NOTE: in ICU4J, the calculation of codePointZero is smarter;
|
// NOTE: in ICU4J, the calculation of codePointZero is smarter;
|
||||||
@ -280,6 +285,11 @@ void IntlTestDecimalFormatSymbols::testDigitSymbols() {
|
|||||||
if (-1 != symbols.getCodePointZero()) {
|
if (-1 != symbols.getCodePointZero()) {
|
||||||
errln("ERROR: Code point zero be invalid");
|
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
|
// Check Osmanya codePointZero
|
||||||
symbols.setSymbol(
|
symbols.setSymbol(
|
||||||
@ -288,6 +298,11 @@ void IntlTestDecimalFormatSymbols::testDigitSymbols() {
|
|||||||
if (osmanyaZero != symbols.getCodePointZero()) {
|
if (osmanyaZero != symbols.getCodePointZero()) {
|
||||||
errln("ERROR: Code point zero be Osmanya code point zero");
|
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
|
// Reset digits to Latin
|
||||||
symbols.setSymbol(
|
symbols.setSymbol(
|
||||||
@ -296,6 +311,11 @@ void IntlTestDecimalFormatSymbols::testDigitSymbols() {
|
|||||||
if (defZero != symbols.getCodePointZero()) {
|
if (defZero != symbols.getCodePointZero()) {
|
||||||
errln("ERROR: Code point zero be ASCII 0");
|
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() {
|
void IntlTestDecimalFormatSymbols::testNumberingSystem() {
|
||||||
|
Loading…
Reference in New Issue
Block a user