intl/icu/source/i18n/dcfmtsym.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /*
michael@0 2 *******************************************************************************
michael@0 3 * Copyright (C) 1997-2013, International Business Machines Corporation and
michael@0 4 * others. All Rights Reserved.
michael@0 5 *******************************************************************************
michael@0 6 *
michael@0 7 * File DCFMTSYM.CPP
michael@0 8 *
michael@0 9 * Modification History:
michael@0 10 *
michael@0 11 * Date Name Description
michael@0 12 * 02/19/97 aliu Converted from java.
michael@0 13 * 03/18/97 clhuang Implemented with C++ APIs.
michael@0 14 * 03/27/97 helena Updated to pass the simple test after code review.
michael@0 15 * 08/26/97 aliu Added currency/intl currency symbol support.
michael@0 16 * 07/20/98 stephen Slightly modified initialization of monetarySeparator
michael@0 17 ********************************************************************************
michael@0 18 */
michael@0 19
michael@0 20 #include "unicode/utypes.h"
michael@0 21
michael@0 22 #if !UCONFIG_NO_FORMATTING
michael@0 23
michael@0 24 #include "unicode/dcfmtsym.h"
michael@0 25 #include "unicode/ures.h"
michael@0 26 #include "unicode/decimfmt.h"
michael@0 27 #include "unicode/ucurr.h"
michael@0 28 #include "unicode/choicfmt.h"
michael@0 29 #include "unicode/unistr.h"
michael@0 30 #include "unicode/numsys.h"
michael@0 31 #include "unicode/unum.h"
michael@0 32 #include "unicode/utf16.h"
michael@0 33 #include "ucurrimp.h"
michael@0 34 #include "cstring.h"
michael@0 35 #include "locbased.h"
michael@0 36 #include "uresimp.h"
michael@0 37 #include "ureslocs.h"
michael@0 38
michael@0 39 // *****************************************************************************
michael@0 40 // class DecimalFormatSymbols
michael@0 41 // *****************************************************************************
michael@0 42
michael@0 43 U_NAMESPACE_BEGIN
michael@0 44
michael@0 45 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(DecimalFormatSymbols)
michael@0 46
michael@0 47 static const char gNumberElements[] = "NumberElements";
michael@0 48 static const char gCurrencySpacingTag[] = "currencySpacing";
michael@0 49 static const char gBeforeCurrencyTag[] = "beforeCurrency";
michael@0 50 static const char gAfterCurrencyTag[] = "afterCurrency";
michael@0 51 static const char gCurrencyMatchTag[] = "currencyMatch";
michael@0 52 static const char gCurrencySudMatchTag[] = "surroundingMatch";
michael@0 53 static const char gCurrencyInsertBtnTag[] = "insertBetween";
michael@0 54
michael@0 55
michael@0 56 static const UChar INTL_CURRENCY_SYMBOL_STR[] = {0xa4, 0xa4, 0};
michael@0 57
michael@0 58 // -------------------------------------
michael@0 59 // Initializes this with the decimal format symbols in the default locale.
michael@0 60
michael@0 61 DecimalFormatSymbols::DecimalFormatSymbols(UErrorCode& status)
michael@0 62 : UObject(),
michael@0 63 locale()
michael@0 64 {
michael@0 65 initialize(locale, status, TRUE);
michael@0 66 }
michael@0 67
michael@0 68 // -------------------------------------
michael@0 69 // Initializes this with the decimal format symbols in the desired locale.
michael@0 70
michael@0 71 DecimalFormatSymbols::DecimalFormatSymbols(const Locale& loc, UErrorCode& status)
michael@0 72 : UObject(),
michael@0 73 locale(loc)
michael@0 74 {
michael@0 75 initialize(locale, status);
michael@0 76 }
michael@0 77
michael@0 78 DecimalFormatSymbols::DecimalFormatSymbols()
michael@0 79 : UObject(),
michael@0 80 locale(Locale::getRoot()),
michael@0 81 currPattern(NULL) {
michael@0 82 *validLocale = *actualLocale = 0;
michael@0 83 initialize();
michael@0 84 }
michael@0 85
michael@0 86 DecimalFormatSymbols*
michael@0 87 DecimalFormatSymbols::createWithLastResortData(UErrorCode& status) {
michael@0 88 if (U_FAILURE(status)) { return NULL; }
michael@0 89 DecimalFormatSymbols* sym = new DecimalFormatSymbols();
michael@0 90 if (sym == NULL) {
michael@0 91 status = U_MEMORY_ALLOCATION_ERROR;
michael@0 92 }
michael@0 93 return sym;
michael@0 94 }
michael@0 95
michael@0 96 // -------------------------------------
michael@0 97
michael@0 98 DecimalFormatSymbols::~DecimalFormatSymbols()
michael@0 99 {
michael@0 100 }
michael@0 101
michael@0 102 // -------------------------------------
michael@0 103 // copy constructor
michael@0 104
michael@0 105 DecimalFormatSymbols::DecimalFormatSymbols(const DecimalFormatSymbols &source)
michael@0 106 : UObject(source)
michael@0 107 {
michael@0 108 *this = source;
michael@0 109 }
michael@0 110
michael@0 111 // -------------------------------------
michael@0 112 // assignment operator
michael@0 113
michael@0 114 DecimalFormatSymbols&
michael@0 115 DecimalFormatSymbols::operator=(const DecimalFormatSymbols& rhs)
michael@0 116 {
michael@0 117 if (this != &rhs) {
michael@0 118 for(int32_t i = 0; i < (int32_t)kFormatSymbolCount; ++i) {
michael@0 119 // fastCopyFrom is safe, see docs on fSymbols
michael@0 120 fSymbols[(ENumberFormatSymbol)i].fastCopyFrom(rhs.fSymbols[(ENumberFormatSymbol)i]);
michael@0 121 }
michael@0 122 for(int32_t i = 0; i < (int32_t)UNUM_CURRENCY_SPACING_COUNT; ++i) {
michael@0 123 currencySpcBeforeSym[i].fastCopyFrom(rhs.currencySpcBeforeSym[i]);
michael@0 124 currencySpcAfterSym[i].fastCopyFrom(rhs.currencySpcAfterSym[i]);
michael@0 125 }
michael@0 126 locale = rhs.locale;
michael@0 127 uprv_strcpy(validLocale, rhs.validLocale);
michael@0 128 uprv_strcpy(actualLocale, rhs.actualLocale);
michael@0 129 }
michael@0 130 return *this;
michael@0 131 }
michael@0 132
michael@0 133 // -------------------------------------
michael@0 134
michael@0 135 UBool
michael@0 136 DecimalFormatSymbols::operator==(const DecimalFormatSymbols& that) const
michael@0 137 {
michael@0 138 if (this == &that) {
michael@0 139 return TRUE;
michael@0 140 }
michael@0 141 for(int32_t i = 0; i < (int32_t)kFormatSymbolCount; ++i) {
michael@0 142 if(fSymbols[(ENumberFormatSymbol)i] != that.fSymbols[(ENumberFormatSymbol)i]) {
michael@0 143 return FALSE;
michael@0 144 }
michael@0 145 }
michael@0 146 for(int32_t i = 0; i < (int32_t)UNUM_CURRENCY_SPACING_COUNT; ++i) {
michael@0 147 if(currencySpcBeforeSym[i] != that.currencySpcBeforeSym[i]) {
michael@0 148 return FALSE;
michael@0 149 }
michael@0 150 if(currencySpcAfterSym[i] != that.currencySpcAfterSym[i]) {
michael@0 151 return FALSE;
michael@0 152 }
michael@0 153 }
michael@0 154 return locale == that.locale &&
michael@0 155 uprv_strcmp(validLocale, that.validLocale) == 0 &&
michael@0 156 uprv_strcmp(actualLocale, that.actualLocale) == 0;
michael@0 157 }
michael@0 158
michael@0 159 // -------------------------------------
michael@0 160
michael@0 161 void
michael@0 162 DecimalFormatSymbols::initialize(const Locale& loc, UErrorCode& status, UBool useLastResortData)
michael@0 163 {
michael@0 164 static const char *gNumberElementKeys[kFormatSymbolCount] = {
michael@0 165 "decimal",
michael@0 166 "group",
michael@0 167 "list",
michael@0 168 "percentSign",
michael@0 169 NULL, /* Native zero digit is deprecated from CLDR - get it from the numbering system */
michael@0 170 NULL, /* Pattern digit character is deprecated from CLDR - use # by default always */
michael@0 171 "minusSign",
michael@0 172 "plusSign",
michael@0 173 NULL, /* currency symbol - We don't really try to load this directly from CLDR until we know the currency */
michael@0 174 NULL, /* intl currency symbol - We don't really try to load this directly from CLDR until we know the currency */
michael@0 175 "currencyDecimal",
michael@0 176 "exponential",
michael@0 177 "perMille",
michael@0 178 NULL, /* Escape padding character - not in CLDR */
michael@0 179 "infinity",
michael@0 180 "nan",
michael@0 181 NULL, /* Significant digit symbol - not in CLDR */
michael@0 182 "currencyGroup",
michael@0 183 NULL, /* one digit - get it from the numbering system */
michael@0 184 NULL, /* two digit - get it from the numbering system */
michael@0 185 NULL, /* three digit - get it from the numbering system */
michael@0 186 NULL, /* four digit - get it from the numbering system */
michael@0 187 NULL, /* five digit - get it from the numbering system */
michael@0 188 NULL, /* six digit - get it from the numbering system */
michael@0 189 NULL, /* seven digit - get it from the numbering system */
michael@0 190 NULL, /* eight digit - get it from the numbering system */
michael@0 191 NULL, /* nine digit - get it from the numbering system */
michael@0 192 };
michael@0 193
michael@0 194 static const char *gLatn = "latn";
michael@0 195 static const char *gSymbols = "symbols";
michael@0 196 const char *nsName;
michael@0 197 const UChar *sym = NULL;
michael@0 198 int32_t len = 0;
michael@0 199
michael@0 200 *validLocale = *actualLocale = 0;
michael@0 201 currPattern = NULL;
michael@0 202 if (U_FAILURE(status))
michael@0 203 return;
michael@0 204
michael@0 205 const char* locStr = loc.getName();
michael@0 206 LocalUResourceBundlePointer resource(ures_open(NULL, locStr, &status));
michael@0 207 LocalUResourceBundlePointer numberElementsRes(
michael@0 208 ures_getByKeyWithFallback(resource.getAlias(), gNumberElements, NULL, &status));
michael@0 209
michael@0 210 if (U_FAILURE(status)) {
michael@0 211 if ( useLastResortData ) {
michael@0 212 status = U_USING_DEFAULT_WARNING;
michael@0 213 initialize();
michael@0 214 }
michael@0 215 return;
michael@0 216 }
michael@0 217
michael@0 218 // First initialize all the symbols to the fallbacks for anything we can't find
michael@0 219 initialize();
michael@0 220
michael@0 221 //
michael@0 222 // Next get the numbering system for this locale and set zero digit
michael@0 223 // and the digit string based on the numbering system for the locale
michael@0 224 //
michael@0 225
michael@0 226 LocalPointer<NumberingSystem> ns(NumberingSystem::createInstance(loc, status));
michael@0 227 if (U_SUCCESS(status) && ns->getRadix() == 10 && !ns->isAlgorithmic()) {
michael@0 228 nsName = ns->getName();
michael@0 229 UnicodeString digitString(ns->getDescription());
michael@0 230 int32_t digitIndex = 0;
michael@0 231 UChar32 digit = digitString.char32At(0);
michael@0 232 fSymbols[kZeroDigitSymbol].setTo(digit);
michael@0 233 for (int32_t i = kOneDigitSymbol; i <= kNineDigitSymbol; ++i) {
michael@0 234 digitIndex += U16_LENGTH(digit);
michael@0 235 digit = digitString.char32At(digitIndex);
michael@0 236 fSymbols[i].setTo(digit);
michael@0 237 }
michael@0 238 } else {
michael@0 239 nsName = gLatn;
michael@0 240 }
michael@0 241
michael@0 242 UBool isLatn = !uprv_strcmp(nsName,gLatn);
michael@0 243
michael@0 244 UErrorCode nlStatus = U_ZERO_ERROR;
michael@0 245 LocalUResourceBundlePointer nonLatnSymbols;
michael@0 246 if ( !isLatn ) {
michael@0 247 nonLatnSymbols.adoptInstead(
michael@0 248 ures_getByKeyWithFallback(numberElementsRes.getAlias(), nsName, NULL, &nlStatus));
michael@0 249 ures_getByKeyWithFallback(nonLatnSymbols.getAlias(), gSymbols, nonLatnSymbols.getAlias(), &nlStatus);
michael@0 250 }
michael@0 251
michael@0 252 LocalUResourceBundlePointer latnSymbols(
michael@0 253 ures_getByKeyWithFallback(numberElementsRes.getAlias(), gLatn, NULL, &status));
michael@0 254 ures_getByKeyWithFallback(latnSymbols.getAlias(), gSymbols, latnSymbols.getAlias(), &status);
michael@0 255
michael@0 256 UBool kMonetaryDecimalSet = FALSE;
michael@0 257 UBool kMonetaryGroupingSet = FALSE;
michael@0 258 for(int32_t i = 0; i<kFormatSymbolCount; i++) {
michael@0 259 if ( gNumberElementKeys[i] != NULL ) {
michael@0 260 UErrorCode localStatus = U_ZERO_ERROR;
michael@0 261 if ( !isLatn ) {
michael@0 262 sym = ures_getStringByKeyWithFallback(nonLatnSymbols.getAlias(),
michael@0 263 gNumberElementKeys[i], &len, &localStatus);
michael@0 264 // If we can't find the symbol in the numbering system specific resources,
michael@0 265 // use the "latn" numbering system as the fallback.
michael@0 266 if ( U_FAILURE(localStatus) ) {
michael@0 267 localStatus = U_ZERO_ERROR;
michael@0 268 sym = ures_getStringByKeyWithFallback(latnSymbols.getAlias(),
michael@0 269 gNumberElementKeys[i], &len, &localStatus);
michael@0 270 }
michael@0 271 } else {
michael@0 272 sym = ures_getStringByKeyWithFallback(latnSymbols.getAlias(),
michael@0 273 gNumberElementKeys[i], &len, &localStatus);
michael@0 274 }
michael@0 275
michael@0 276 if ( U_SUCCESS(localStatus) ) {
michael@0 277 setSymbol((ENumberFormatSymbol)i, UnicodeString(TRUE, sym, len));
michael@0 278 if ( i == kMonetarySeparatorSymbol ) {
michael@0 279 kMonetaryDecimalSet = TRUE;
michael@0 280 } else if ( i == kMonetaryGroupingSeparatorSymbol ) {
michael@0 281 kMonetaryGroupingSet = TRUE;
michael@0 282 }
michael@0 283 }
michael@0 284 }
michael@0 285 }
michael@0 286
michael@0 287 // If monetary decimal or grouping were not explicitly set, then set them to be the
michael@0 288 // same as their non-monetary counterparts.
michael@0 289
michael@0 290 if ( !kMonetaryDecimalSet ) {
michael@0 291 setSymbol(kMonetarySeparatorSymbol,fSymbols[kDecimalSeparatorSymbol]);
michael@0 292 }
michael@0 293 if ( !kMonetaryGroupingSet ) {
michael@0 294 setSymbol(kMonetaryGroupingSeparatorSymbol,fSymbols[kGroupingSeparatorSymbol]);
michael@0 295 }
michael@0 296
michael@0 297 // Obtain currency data from the currency API. This is strictly
michael@0 298 // for backward compatibility; we don't use DecimalFormatSymbols
michael@0 299 // for currency data anymore.
michael@0 300 UErrorCode internalStatus = U_ZERO_ERROR; // don't propagate failures out
michael@0 301 UChar curriso[4];
michael@0 302 UnicodeString tempStr;
michael@0 303 ucurr_forLocale(locStr, curriso, 4, &internalStatus);
michael@0 304
michael@0 305 uprv_getStaticCurrencyName(curriso, locStr, tempStr, internalStatus);
michael@0 306 if (U_SUCCESS(internalStatus)) {
michael@0 307 fSymbols[kIntlCurrencySymbol].setTo(curriso, -1);
michael@0 308 fSymbols[kCurrencySymbol] = tempStr;
michael@0 309 }
michael@0 310 /* else use the default values. */
michael@0 311
michael@0 312 U_LOCALE_BASED(locBased, *this);
michael@0 313 locBased.setLocaleIDs(ures_getLocaleByType(numberElementsRes.getAlias(),
michael@0 314 ULOC_VALID_LOCALE, &status),
michael@0 315 ures_getLocaleByType(numberElementsRes.getAlias(),
michael@0 316 ULOC_ACTUAL_LOCALE, &status));
michael@0 317
michael@0 318 //load the currency data
michael@0 319 UChar ucc[4]={0}; //Currency Codes are always 3 chars long
michael@0 320 int32_t uccLen = 4;
michael@0 321 const char* locName = loc.getName();
michael@0 322 UErrorCode localStatus = U_ZERO_ERROR;
michael@0 323 uccLen = ucurr_forLocale(locName, ucc, uccLen, &localStatus);
michael@0 324
michael@0 325 if(U_SUCCESS(localStatus) && uccLen > 0) {
michael@0 326 char cc[4]={0};
michael@0 327 u_UCharsToChars(ucc, cc, uccLen);
michael@0 328 /* An explicit currency was requested */
michael@0 329 LocalUResourceBundlePointer currencyResource(ures_open(U_ICUDATA_CURR, locStr, &localStatus));
michael@0 330 LocalUResourceBundlePointer currency(
michael@0 331 ures_getByKeyWithFallback(currencyResource.getAlias(), "Currencies", NULL, &localStatus));
michael@0 332 ures_getByKeyWithFallback(currency.getAlias(), cc, currency.getAlias(), &localStatus);
michael@0 333 if(U_SUCCESS(localStatus) && ures_getSize(currency.getAlias())>2) { // the length is 3 if more data is present
michael@0 334 ures_getByIndex(currency.getAlias(), 2, currency.getAlias(), &localStatus);
michael@0 335 int32_t currPatternLen = 0;
michael@0 336 currPattern =
michael@0 337 ures_getStringByIndex(currency.getAlias(), (int32_t)0, &currPatternLen, &localStatus);
michael@0 338 UnicodeString decimalSep =
michael@0 339 ures_getUnicodeStringByIndex(currency.getAlias(), (int32_t)1, &localStatus);
michael@0 340 UnicodeString groupingSep =
michael@0 341 ures_getUnicodeStringByIndex(currency.getAlias(), (int32_t)2, &localStatus);
michael@0 342 if(U_SUCCESS(localStatus)){
michael@0 343 fSymbols[kMonetaryGroupingSeparatorSymbol] = groupingSep;
michael@0 344 fSymbols[kMonetarySeparatorSymbol] = decimalSep;
michael@0 345 //pattern.setTo(TRUE, currPattern, currPatternLen);
michael@0 346 status = localStatus;
michael@0 347 }
michael@0 348 }
michael@0 349 /* else An explicit currency was requested and is unknown or locale data is malformed. */
michael@0 350 /* ucurr_* API will get the correct value later on. */
michael@0 351 }
michael@0 352 // else ignore the error if no currency
michael@0 353
michael@0 354 // Currency Spacing.
michael@0 355 localStatus = U_ZERO_ERROR;
michael@0 356 LocalUResourceBundlePointer currencyResource(ures_open(U_ICUDATA_CURR, locStr, &localStatus));
michael@0 357 LocalUResourceBundlePointer currencySpcRes(
michael@0 358 ures_getByKeyWithFallback(currencyResource.getAlias(),
michael@0 359 gCurrencySpacingTag, NULL, &localStatus));
michael@0 360
michael@0 361 if (localStatus == U_USING_FALLBACK_WARNING || U_SUCCESS(localStatus)) {
michael@0 362 const char* keywords[UNUM_CURRENCY_SPACING_COUNT] = {
michael@0 363 gCurrencyMatchTag, gCurrencySudMatchTag, gCurrencyInsertBtnTag
michael@0 364 };
michael@0 365 localStatus = U_ZERO_ERROR;
michael@0 366 LocalUResourceBundlePointer dataRes(
michael@0 367 ures_getByKeyWithFallback(currencySpcRes.getAlias(),
michael@0 368 gBeforeCurrencyTag, NULL, &localStatus));
michael@0 369 if (localStatus == U_USING_FALLBACK_WARNING || U_SUCCESS(localStatus)) {
michael@0 370 localStatus = U_ZERO_ERROR;
michael@0 371 for (int32_t i = 0; i < UNUM_CURRENCY_SPACING_COUNT; i++) {
michael@0 372 currencySpcBeforeSym[i] =
michael@0 373 ures_getUnicodeStringByKey(dataRes.getAlias(), keywords[i], &localStatus);
michael@0 374 }
michael@0 375 }
michael@0 376 dataRes.adoptInstead(
michael@0 377 ures_getByKeyWithFallback(currencySpcRes.getAlias(),
michael@0 378 gAfterCurrencyTag, NULL, &localStatus));
michael@0 379 if (localStatus == U_USING_FALLBACK_WARNING || U_SUCCESS(localStatus)) {
michael@0 380 localStatus = U_ZERO_ERROR;
michael@0 381 for (int32_t i = 0; i < UNUM_CURRENCY_SPACING_COUNT; i++) {
michael@0 382 currencySpcAfterSym[i] =
michael@0 383 ures_getUnicodeStringByKey(dataRes.getAlias(), keywords[i], &localStatus);
michael@0 384 }
michael@0 385 }
michael@0 386 }
michael@0 387 }
michael@0 388
michael@0 389 void
michael@0 390 DecimalFormatSymbols::initialize() {
michael@0 391 /*
michael@0 392 * These strings used to be in static arrays, but the HP/UX aCC compiler
michael@0 393 * cannot initialize a static array with class constructors.
michael@0 394 * markus 2000may25
michael@0 395 */
michael@0 396 fSymbols[kDecimalSeparatorSymbol] = (UChar)0x2e; // '.' decimal separator
michael@0 397 fSymbols[kGroupingSeparatorSymbol].remove(); // group (thousands) separator
michael@0 398 fSymbols[kPatternSeparatorSymbol] = (UChar)0x3b; // ';' pattern separator
michael@0 399 fSymbols[kPercentSymbol] = (UChar)0x25; // '%' percent sign
michael@0 400 fSymbols[kZeroDigitSymbol] = (UChar)0x30; // '0' native 0 digit
michael@0 401 fSymbols[kOneDigitSymbol] = (UChar)0x31; // '1' native 1 digit
michael@0 402 fSymbols[kTwoDigitSymbol] = (UChar)0x32; // '2' native 2 digit
michael@0 403 fSymbols[kThreeDigitSymbol] = (UChar)0x33; // '3' native 3 digit
michael@0 404 fSymbols[kFourDigitSymbol] = (UChar)0x34; // '4' native 4 digit
michael@0 405 fSymbols[kFiveDigitSymbol] = (UChar)0x35; // '5' native 5 digit
michael@0 406 fSymbols[kSixDigitSymbol] = (UChar)0x36; // '6' native 6 digit
michael@0 407 fSymbols[kSevenDigitSymbol] = (UChar)0x37; // '7' native 7 digit
michael@0 408 fSymbols[kEightDigitSymbol] = (UChar)0x38; // '8' native 8 digit
michael@0 409 fSymbols[kNineDigitSymbol] = (UChar)0x39; // '9' native 9 digit
michael@0 410 fSymbols[kDigitSymbol] = (UChar)0x23; // '#' pattern digit
michael@0 411 fSymbols[kPlusSignSymbol] = (UChar)0x002b; // '+' plus sign
michael@0 412 fSymbols[kMinusSignSymbol] = (UChar)0x2d; // '-' minus sign
michael@0 413 fSymbols[kCurrencySymbol] = (UChar)0xa4; // 'OX' currency symbol
michael@0 414 fSymbols[kIntlCurrencySymbol].setTo(TRUE, INTL_CURRENCY_SYMBOL_STR, 2);
michael@0 415 fSymbols[kMonetarySeparatorSymbol] = (UChar)0x2e; // '.' monetary decimal separator
michael@0 416 fSymbols[kExponentialSymbol] = (UChar)0x45; // 'E' exponential
michael@0 417 fSymbols[kPerMillSymbol] = (UChar)0x2030; // '%o' per mill
michael@0 418 fSymbols[kPadEscapeSymbol] = (UChar)0x2a; // '*' pad escape symbol
michael@0 419 fSymbols[kInfinitySymbol] = (UChar)0x221e; // 'oo' infinite
michael@0 420 fSymbols[kNaNSymbol] = (UChar)0xfffd; // SUB NaN
michael@0 421 fSymbols[kSignificantDigitSymbol] = (UChar)0x0040; // '@' significant digit
michael@0 422 fSymbols[kMonetaryGroupingSeparatorSymbol].remove(); //
michael@0 423 }
michael@0 424
michael@0 425 Locale
michael@0 426 DecimalFormatSymbols::getLocale(ULocDataLocaleType type, UErrorCode& status) const {
michael@0 427 U_LOCALE_BASED(locBased, *this);
michael@0 428 return locBased.getLocale(type, status);
michael@0 429 }
michael@0 430
michael@0 431 const UnicodeString&
michael@0 432 DecimalFormatSymbols::getPatternForCurrencySpacing(UCurrencySpacing type,
michael@0 433 UBool beforeCurrency,
michael@0 434 UErrorCode& status) const {
michael@0 435 if (U_FAILURE(status)) {
michael@0 436 return fNoSymbol; // always empty.
michael@0 437 }
michael@0 438 if (beforeCurrency) {
michael@0 439 return currencySpcBeforeSym[(int32_t)type];
michael@0 440 } else {
michael@0 441 return currencySpcAfterSym[(int32_t)type];
michael@0 442 }
michael@0 443 }
michael@0 444
michael@0 445 void
michael@0 446 DecimalFormatSymbols::setPatternForCurrencySpacing(UCurrencySpacing type,
michael@0 447 UBool beforeCurrency,
michael@0 448 const UnicodeString& pattern) {
michael@0 449 if (beforeCurrency) {
michael@0 450 currencySpcBeforeSym[(int32_t)type] = pattern;
michael@0 451 } else {
michael@0 452 currencySpcAfterSym[(int32_t)type] = pattern;
michael@0 453 }
michael@0 454 }
michael@0 455 U_NAMESPACE_END
michael@0 456
michael@0 457 #endif /* #if !UCONFIG_NO_FORMATTING */
michael@0 458
michael@0 459 //eof

mercurial