Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/intl/icu/source/i18n/dcfmtsym.cpp
Line
Count
Source (jump to first uncovered line)
1
// © 2016 and later: Unicode, Inc. and others.
2
// License & terms of use: http://www.unicode.org/copyright.html
3
/*
4
*******************************************************************************
5
* Copyright (C) 1997-2016, International Business Machines Corporation and
6
* others. All Rights Reserved.
7
*******************************************************************************
8
*
9
* File DCFMTSYM.CPP
10
*
11
* Modification History:
12
*
13
*   Date        Name        Description
14
*   02/19/97    aliu        Converted from java.
15
*   03/18/97    clhuang     Implemented with C++ APIs.
16
*   03/27/97    helena      Updated to pass the simple test after code review.
17
*   08/26/97    aliu        Added currency/intl currency symbol support.
18
*   07/20/98    stephen     Slightly modified initialization of monetarySeparator
19
********************************************************************************
20
*/
21
22
#include "unicode/utypes.h"
23
24
#if !UCONFIG_NO_FORMATTING
25
26
#include "unicode/dcfmtsym.h"
27
#include "unicode/ures.h"
28
#include "unicode/decimfmt.h"
29
#include "unicode/ucurr.h"
30
#include "unicode/choicfmt.h"
31
#include "unicode/unistr.h"
32
#include "unicode/numsys.h"
33
#include "unicode/unum.h"
34
#include "unicode/utf16.h"
35
#include "ucurrimp.h"
36
#include "cstring.h"
37
#include "locbased.h"
38
#include "uresimp.h"
39
#include "ureslocs.h"
40
#include "charstr.h"
41
#include "uassert.h"
42
43
// *****************************************************************************
44
// class DecimalFormatSymbols
45
// *****************************************************************************
46
47
U_NAMESPACE_BEGIN
48
49
UOBJECT_DEFINE_RTTI_IMPLEMENTATION(DecimalFormatSymbols)
50
51
static const char gNumberElements[] = "NumberElements";
52
static const char gCurrencySpacingTag[] = "currencySpacing";
53
static const char gBeforeCurrencyTag[] = "beforeCurrency";
54
static const char gAfterCurrencyTag[] = "afterCurrency";
55
static const char gCurrencyMatchTag[] = "currencyMatch";
56
static const char gCurrencySudMatchTag[] = "surroundingMatch";
57
static const char gCurrencyInsertBtnTag[] = "insertBetween";
58
static const char gLatn[] =  "latn";
59
static const char gSymbols[] = "symbols";
60
static const char gNumberElementsLatnSymbols[] = "NumberElements/latn/symbols";
61
62
static const UChar INTL_CURRENCY_SYMBOL_STR[] = {0xa4, 0xa4, 0};
63
64
// List of field names to be loaded from the data files.
65
// These are parallel with the enum ENumberFormatSymbol in unicode/dcfmtsym.h.
66
static const char *gNumberElementKeys[DecimalFormatSymbols::kFormatSymbolCount] = {
67
    "decimal",
68
    "group",
69
    NULL, /* #11897: the <list> symbol is NOT the pattern separator symbol */
70
    "percentSign",
71
    NULL, /* Native zero digit is deprecated from CLDR - get it from the numbering system */
72
    NULL, /* Pattern digit character is deprecated from CLDR - use # by default always */
73
    "minusSign",
74
    "plusSign",
75
    NULL, /* currency symbol - Wait until we know the currency before loading from CLDR */
76
    NULL, /* intl currency symbol - Wait until we know the currency before loading from CLDR */
77
    "currencyDecimal",
78
    "exponential",
79
    "perMille",
80
    NULL, /* Escape padding character - not in CLDR */
81
    "infinity",
82
    "nan",
83
    NULL, /* Significant digit symbol - not in CLDR */
84
    "currencyGroup",
85
    NULL, /* one digit - get it from the numbering system */
86
    NULL, /* two digit - get it from the numbering system */
87
    NULL, /* three digit - get it from the numbering system */
88
    NULL, /* four digit - get it from the numbering system */
89
    NULL, /* five digit - get it from the numbering system */
90
    NULL, /* six digit - get it from the numbering system */
91
    NULL, /* seven digit - get it from the numbering system */
92
    NULL, /* eight digit - get it from the numbering system */
93
    NULL, /* nine digit - get it from the numbering system */
94
    "superscriptingExponent", /* Multiplication (x) symbol for exponents */
95
};
96
97
// -------------------------------------
98
// Initializes this with the decimal format symbols in the default locale.
99
100
DecimalFormatSymbols::DecimalFormatSymbols(UErrorCode& status)
101
0
        : UObject(), locale(), currPattern(NULL) {
102
0
    initialize(locale, status, TRUE);
103
0
}
104
105
// -------------------------------------
106
// Initializes this with the decimal format symbols in the desired locale.
107
108
DecimalFormatSymbols::DecimalFormatSymbols(const Locale& loc, UErrorCode& status)
109
0
        : UObject(), locale(loc), currPattern(NULL) {
110
0
    initialize(locale, status);
111
0
}
112
113
DecimalFormatSymbols::DecimalFormatSymbols(const Locale& loc, const NumberingSystem& ns, UErrorCode& status)
114
0
        : UObject(), locale(loc), currPattern(NULL) {
115
0
    initialize(locale, status, FALSE, &ns);
116
0
}
117
118
DecimalFormatSymbols::DecimalFormatSymbols()
119
0
        : UObject(), locale(Locale::getRoot()), currPattern(NULL) {
120
0
    *validLocale = *actualLocale = 0;
121
0
    initialize();
122
0
}
123
124
DecimalFormatSymbols*
125
0
DecimalFormatSymbols::createWithLastResortData(UErrorCode& status) {
126
0
    if (U_FAILURE(status)) { return NULL; }
127
0
    DecimalFormatSymbols* sym = new DecimalFormatSymbols();
128
0
    if (sym == NULL) {
129
0
        status = U_MEMORY_ALLOCATION_ERROR;
130
0
    }
131
0
    return sym;
132
0
}
133
134
// -------------------------------------
135
136
DecimalFormatSymbols::~DecimalFormatSymbols()
137
0
{
138
0
}
139
140
// -------------------------------------
141
// copy constructor
142
143
DecimalFormatSymbols::DecimalFormatSymbols(const DecimalFormatSymbols &source)
144
    : UObject(source)
145
0
{
146
0
    *this = source;
147
0
}
148
149
// -------------------------------------
150
// assignment operator
151
152
DecimalFormatSymbols&
153
DecimalFormatSymbols::operator=(const DecimalFormatSymbols& rhs)
154
0
{
155
0
    if (this != &rhs) {
156
0
        for(int32_t i = 0; i < (int32_t)kFormatSymbolCount; ++i) {
157
0
            // fastCopyFrom is safe, see docs on fSymbols
158
0
            fSymbols[(ENumberFormatSymbol)i].fastCopyFrom(rhs.fSymbols[(ENumberFormatSymbol)i]);
159
0
        }
160
0
        for(int32_t i = 0; i < (int32_t)UNUM_CURRENCY_SPACING_COUNT; ++i) {
161
0
            currencySpcBeforeSym[i].fastCopyFrom(rhs.currencySpcBeforeSym[i]);
162
0
            currencySpcAfterSym[i].fastCopyFrom(rhs.currencySpcAfterSym[i]);
163
0
        }
164
0
        locale = rhs.locale;
165
0
        uprv_strcpy(validLocale, rhs.validLocale);
166
0
        uprv_strcpy(actualLocale, rhs.actualLocale);
167
0
        fIsCustomCurrencySymbol = rhs.fIsCustomCurrencySymbol; 
168
0
        fIsCustomIntlCurrencySymbol = rhs.fIsCustomIntlCurrencySymbol; 
169
0
        fCodePointZero = rhs.fCodePointZero;
170
0
    }
171
0
    return *this;
172
0
}
173
174
// -------------------------------------
175
176
UBool
177
DecimalFormatSymbols::operator==(const DecimalFormatSymbols& that) const
178
0
{
179
0
    if (this == &that) {
180
0
        return TRUE;
181
0
    }
182
0
    if (fIsCustomCurrencySymbol != that.fIsCustomCurrencySymbol) { 
183
0
        return FALSE; 
184
0
    } 
185
0
    if (fIsCustomIntlCurrencySymbol != that.fIsCustomIntlCurrencySymbol) { 
186
0
        return FALSE; 
187
0
    } 
188
0
    for(int32_t i = 0; i < (int32_t)kFormatSymbolCount; ++i) {
189
0
        if(fSymbols[(ENumberFormatSymbol)i] != that.fSymbols[(ENumberFormatSymbol)i]) {
190
0
            return FALSE;
191
0
        }
192
0
    }
193
0
    for(int32_t i = 0; i < (int32_t)UNUM_CURRENCY_SPACING_COUNT; ++i) {
194
0
        if(currencySpcBeforeSym[i] != that.currencySpcBeforeSym[i]) {
195
0
            return FALSE;
196
0
        }
197
0
        if(currencySpcAfterSym[i] != that.currencySpcAfterSym[i]) {
198
0
            return FALSE;
199
0
        }
200
0
    }
201
0
    // No need to check fCodePointZero since it is based on fSymbols
202
0
    return locale == that.locale &&
203
0
        uprv_strcmp(validLocale, that.validLocale) == 0 &&
204
0
        uprv_strcmp(actualLocale, that.actualLocale) == 0;
205
0
}
206
207
// -------------------------------------
208
209
namespace {
210
211
/**
212
 * Sink for enumerating all of the decimal format symbols (more specifically, anything
213
 * under the "NumberElements.symbols" tree).
214
 *
215
 * More specific bundles (en_GB) are enumerated before their parents (en_001, en, root):
216
 * Only store a value if it is still missing, that is, it has not been overridden.
217
 */
218
struct DecFmtSymDataSink : public ResourceSink {
219
220
    // Destination for data, modified via setters.
221
    DecimalFormatSymbols& dfs;
222
    // Boolean array of whether or not we have seen a particular symbol yet.
223
    // Can't simpy check fSymbols because it is pre-populated with defaults.
224
    UBool seenSymbol[DecimalFormatSymbols::kFormatSymbolCount];
225
226
    // Constructor/Destructor
227
0
    DecFmtSymDataSink(DecimalFormatSymbols& _dfs) : dfs(_dfs) {
228
0
        uprv_memset(seenSymbol, FALSE, sizeof(seenSymbol));
229
0
    }
230
    virtual ~DecFmtSymDataSink();
231
232
    virtual void put(const char *key, ResourceValue &value, UBool /*noFallback*/,
233
0
            UErrorCode &errorCode) {
234
0
        ResourceTable symbolsTable = value.getTable(errorCode);
235
0
        if (U_FAILURE(errorCode)) { return; }
236
0
        for (int32_t j = 0; symbolsTable.getKeyAndValue(j, key, value); ++j) {
237
0
            for (int32_t i=0; i<DecimalFormatSymbols::kFormatSymbolCount; i++) {
238
0
                if (gNumberElementKeys[i] != NULL && uprv_strcmp(key, gNumberElementKeys[i]) == 0) {
239
0
                    if (!seenSymbol[i]) {
240
0
                        seenSymbol[i] = TRUE;
241
0
                        dfs.setSymbol(
242
0
                            (DecimalFormatSymbols::ENumberFormatSymbol) i,
243
0
                            value.getUnicodeString(errorCode));
244
0
                        if (U_FAILURE(errorCode)) { return; }
245
0
                    }
246
0
                    break;
247
0
                }
248
0
            }
249
0
        }
250
0
    }
251
252
    // Returns true if all the symbols have been seen.
253
0
    UBool seenAll() {
254
0
        for (int32_t i=0; i<DecimalFormatSymbols::kFormatSymbolCount; i++) {
255
0
            if (!seenSymbol[i]) {
256
0
                return FALSE;
257
0
            }
258
0
        }
259
0
        return TRUE;
260
0
    }
261
262
    // If monetary decimal or grouping were not explicitly set, then set them to be the
263
    // same as their non-monetary counterparts.
264
0
    void resolveMissingMonetarySeparators(const UnicodeString* fSymbols) {
265
0
        if (!seenSymbol[DecimalFormatSymbols::kMonetarySeparatorSymbol]) {
266
0
            dfs.setSymbol(
267
0
                DecimalFormatSymbols::kMonetarySeparatorSymbol,
268
0
                fSymbols[DecimalFormatSymbols::kDecimalSeparatorSymbol]);
269
0
        }
270
0
        if (!seenSymbol[DecimalFormatSymbols::kMonetaryGroupingSeparatorSymbol]) {
271
0
            dfs.setSymbol(
272
0
                DecimalFormatSymbols::kMonetaryGroupingSeparatorSymbol,
273
0
                fSymbols[DecimalFormatSymbols::kGroupingSeparatorSymbol]);
274
0
        }
275
0
    }
276
};
277
278
struct CurrencySpacingSink : public ResourceSink {
279
    DecimalFormatSymbols& dfs;
280
    UBool hasBeforeCurrency;
281
    UBool hasAfterCurrency;
282
283
    CurrencySpacingSink(DecimalFormatSymbols& _dfs)
284
0
        : dfs(_dfs), hasBeforeCurrency(FALSE), hasAfterCurrency(FALSE) {}
285
    virtual ~CurrencySpacingSink();
286
287
    virtual void put(const char *key, ResourceValue &value, UBool /*noFallback*/,
288
0
            UErrorCode &errorCode) {
289
0
        ResourceTable spacingTypesTable = value.getTable(errorCode);
290
0
        for (int32_t i = 0; spacingTypesTable.getKeyAndValue(i, key, value); ++i) {
291
0
            UBool beforeCurrency;
292
0
            if (uprv_strcmp(key, gBeforeCurrencyTag) == 0) {
293
0
                beforeCurrency = TRUE;
294
0
                hasBeforeCurrency = TRUE;
295
0
            } else if (uprv_strcmp(key, gAfterCurrencyTag) == 0) {
296
0
                beforeCurrency = FALSE;
297
0
                hasAfterCurrency = TRUE;
298
0
            } else {
299
0
                continue;
300
0
            }
301
0
302
0
            ResourceTable patternsTable = value.getTable(errorCode);
303
0
            for (int32_t j = 0; patternsTable.getKeyAndValue(j, key, value); ++j) {
304
0
                UCurrencySpacing pattern;
305
0
                if (uprv_strcmp(key, gCurrencyMatchTag) == 0) {
306
0
                    pattern = UNUM_CURRENCY_MATCH;
307
0
                } else if (uprv_strcmp(key, gCurrencySudMatchTag) == 0) {
308
0
                    pattern = UNUM_CURRENCY_SURROUNDING_MATCH;
309
0
                } else if (uprv_strcmp(key, gCurrencyInsertBtnTag) == 0) {
310
0
                    pattern = UNUM_CURRENCY_INSERT;
311
0
                } else {
312
0
                    continue;
313
0
                }
314
0
315
0
                const UnicodeString& current = dfs.getPatternForCurrencySpacing(
316
0
                    pattern, beforeCurrency, errorCode);
317
0
                if (current.isEmpty()) {
318
0
                    dfs.setPatternForCurrencySpacing(
319
0
                        pattern, beforeCurrency, value.getUnicodeString(errorCode));
320
0
                }
321
0
            }
322
0
        }
323
0
    }
324
325
0
    void resolveMissing() {
326
0
        // For consistency with Java, this method overwrites everything with the defaults unless
327
0
        // both beforeCurrency and afterCurrency were found in CLDR.
328
0
        static const char* defaults[] = { "[:letter:]", "[:digit:]", " " };
329
0
        if (!hasBeforeCurrency || !hasAfterCurrency) {
330
0
            for (UBool beforeCurrency = 0; beforeCurrency <= TRUE; beforeCurrency++) {
331
0
                for (int32_t pattern = 0; pattern < UNUM_CURRENCY_SPACING_COUNT; pattern++) {
332
0
                    dfs.setPatternForCurrencySpacing((UCurrencySpacing)pattern,
333
0
                        beforeCurrency, UnicodeString(defaults[pattern], -1, US_INV));
334
0
                }
335
0
            }
336
0
        }
337
0
    }
338
};
339
340
// Virtual destructors must be defined out of line.
341
DecFmtSymDataSink::~DecFmtSymDataSink() {}
342
CurrencySpacingSink::~CurrencySpacingSink() {}
343
344
} // namespace
345
346
void
347
DecimalFormatSymbols::initialize(const Locale& loc, UErrorCode& status,
348
    UBool useLastResortData, const NumberingSystem* ns)
349
0
{
350
0
    if (U_FAILURE(status)) { return; }
351
0
    *validLocale = *actualLocale = 0;
352
0
353
0
    // First initialize all the symbols to the fallbacks for anything we can't find
354
0
    initialize();
355
0
356
0
    //
357
0
    // Next get the numbering system for this locale and set zero digit
358
0
    // and the digit string based on the numbering system for the locale
359
0
    //
360
0
    LocalPointer<NumberingSystem> nsLocal;
361
0
    if (ns == nullptr) {
362
0
        // Use the numbering system according to the locale.
363
0
        // Save it into a LocalPointer so it gets cleaned up.
364
0
        nsLocal.adoptInstead(NumberingSystem::createInstance(loc, status));
365
0
        ns = nsLocal.getAlias();
366
0
    }
367
0
    const char *nsName;
368
0
    if (U_SUCCESS(status) && ns->getRadix() == 10 && !ns->isAlgorithmic()) {
369
0
        nsName = ns->getName();
370
0
        UnicodeString digitString(ns->getDescription());
371
0
        int32_t digitIndex = 0;
372
0
        UChar32 digit = digitString.char32At(0);
373
0
        fSymbols[kZeroDigitSymbol].setTo(digit);
374
0
        for (int32_t i = kOneDigitSymbol; i <= kNineDigitSymbol; ++i) {
375
0
            digitIndex += U16_LENGTH(digit);
376
0
            digit = digitString.char32At(digitIndex);
377
0
            fSymbols[i].setTo(digit);
378
0
        }
379
0
    } else {
380
0
        nsName = gLatn;
381
0
    }
382
0
383
0
    // Open resource bundles
384
0
    const char* locStr = loc.getName();
385
0
    LocalUResourceBundlePointer resource(ures_open(NULL, locStr, &status));
386
0
    LocalUResourceBundlePointer numberElementsRes(
387
0
        ures_getByKeyWithFallback(resource.getAlias(), gNumberElements, NULL, &status));
388
0
389
0
    if (U_FAILURE(status)) {
390
0
        if ( useLastResortData ) {
391
0
            status = U_USING_DEFAULT_WARNING;
392
0
            initialize();
393
0
        }
394
0
        return;
395
0
    }
396
0
397
0
    // Set locale IDs
398
0
    // TODO: Is there a way to do this without depending on the resource bundle instance?
399
0
    U_LOCALE_BASED(locBased, *this);
400
0
    locBased.setLocaleIDs(
401
0
        ures_getLocaleByType(
402
0
            numberElementsRes.getAlias(),
403
0
            ULOC_VALID_LOCALE, &status),
404
0
        ures_getLocaleByType(
405
0
            numberElementsRes.getAlias(),
406
0
            ULOC_ACTUAL_LOCALE, &status));
407
0
408
0
    // Now load the rest of the data from the data sink.
409
0
    // Start with loading this nsName if it is not Latin.
410
0
    DecFmtSymDataSink sink(*this);
411
0
    if (uprv_strcmp(nsName, gLatn) != 0) {
412
0
        CharString path;
413
0
        path.append(gNumberElements, status)
414
0
            .append('/', status)
415
0
            .append(nsName, status)
416
0
            .append('/', status)
417
0
            .append(gSymbols, status);
418
0
        ures_getAllItemsWithFallback(resource.getAlias(), path.data(), sink, status);
419
0
420
0
        // If no symbols exist for the given nsName and resource bundle, silently ignore
421
0
        // and fall back to Latin.
422
0
        if (status == U_MISSING_RESOURCE_ERROR) {
423
0
            status = U_ZERO_ERROR;
424
0
        } else if (U_FAILURE(status)) {
425
0
            return;
426
0
        }
427
0
    }
428
0
429
0
    // Continue with Latin if necessary.
430
0
    if (!sink.seenAll()) {
431
0
        ures_getAllItemsWithFallback(resource.getAlias(), gNumberElementsLatnSymbols, sink, status);
432
0
        if (U_FAILURE(status)) { return; }
433
0
    }
434
0
435
0
    // Let the monetary number separators equal the default number separators if necessary.
436
0
    sink.resolveMissingMonetarySeparators(fSymbols);
437
0
438
0
    // Resolve codePointZero
439
0
    UChar32 tempCodePointZero;
440
0
    for (int32_t i=0; i<=9; i++) {
441
0
        const UnicodeString& stringDigit = getConstDigitSymbol(i);
442
0
        if (stringDigit.countChar32() != 1) {
443
0
            tempCodePointZero = -1;
444
0
            break;
445
0
        }
446
0
        UChar32 cp = stringDigit.char32At(0);
447
0
        if (i == 0) {
448
0
            tempCodePointZero = cp;
449
0
        } else if (cp != tempCodePointZero + i) {
450
0
            tempCodePointZero = -1;
451
0
            break;
452
0
        }
453
0
    }
454
0
    fCodePointZero = tempCodePointZero;
455
0
456
0
    // Obtain currency data from the currency API.  This is strictly
457
0
    // for backward compatibility; we don't use DecimalFormatSymbols
458
0
    // for currency data anymore.
459
0
    UErrorCode internalStatus = U_ZERO_ERROR; // don't propagate failures out
460
0
    UChar curriso[4];
461
0
    UnicodeString tempStr;
462
0
    int32_t currisoLength = ucurr_forLocale(locStr, curriso, UPRV_LENGTHOF(curriso), &internalStatus);
463
0
    if (U_SUCCESS(internalStatus) && currisoLength == 3) {
464
0
        uprv_getStaticCurrencyName(curriso, locStr, tempStr, internalStatus);
465
0
        if (U_SUCCESS(internalStatus)) {
466
0
            fSymbols[kIntlCurrencySymbol].setTo(curriso, currisoLength);
467
0
            fSymbols[kCurrencySymbol] = tempStr;
468
0
        }
469
0
    }
470
0
    /* else use the default values. */
471
0
472
0
    //load the currency data
473
0
    UChar ucc[4]={0}; //Currency Codes are always 3 chars long
474
0
    int32_t uccLen = 4;
475
0
    const char* locName = loc.getName();
476
0
    UErrorCode localStatus = U_ZERO_ERROR;
477
0
    uccLen = ucurr_forLocale(locName, ucc, uccLen, &localStatus);
478
0
479
0
    // TODO: Currency pattern data loading is duplicated in number_formatimpl.cpp
480
0
    if(U_SUCCESS(localStatus) && uccLen > 0) {
481
0
        char cc[4]={0};
482
0
        u_UCharsToChars(ucc, cc, uccLen);
483
0
        /* An explicit currency was requested */
484
0
        LocalUResourceBundlePointer currencyResource(ures_open(U_ICUDATA_CURR, locStr, &localStatus));
485
0
        LocalUResourceBundlePointer currency(
486
0
            ures_getByKeyWithFallback(currencyResource.getAlias(), "Currencies", NULL, &localStatus));
487
0
        ures_getByKeyWithFallback(currency.getAlias(), cc, currency.getAlias(), &localStatus);
488
0
        if(U_SUCCESS(localStatus) && ures_getSize(currency.getAlias())>2) { // the length is 3 if more data is present
489
0
            ures_getByIndex(currency.getAlias(), 2, currency.getAlias(), &localStatus);
490
0
            int32_t currPatternLen = 0;
491
0
            currPattern =
492
0
                ures_getStringByIndex(currency.getAlias(), (int32_t)0, &currPatternLen, &localStatus);
493
0
            UnicodeString decimalSep =
494
0
                ures_getUnicodeStringByIndex(currency.getAlias(), (int32_t)1, &localStatus);
495
0
            UnicodeString groupingSep =
496
0
                ures_getUnicodeStringByIndex(currency.getAlias(), (int32_t)2, &localStatus);
497
0
            if(U_SUCCESS(localStatus)){
498
0
                fSymbols[kMonetaryGroupingSeparatorSymbol] = groupingSep;
499
0
                fSymbols[kMonetarySeparatorSymbol] = decimalSep;
500
0
                //pattern.setTo(TRUE, currPattern, currPatternLen);
501
0
                status = localStatus;
502
0
            }
503
0
        }
504
0
        /* else An explicit currency was requested and is unknown or locale data is malformed. */
505
0
        /* ucurr_* API will get the correct value later on. */
506
0
    }
507
0
        // else ignore the error if no currency
508
0
509
0
    // Currency Spacing.
510
0
    LocalUResourceBundlePointer currencyResource(ures_open(U_ICUDATA_CURR, locStr, &status));
511
0
    CurrencySpacingSink currencySink(*this);
512
0
    ures_getAllItemsWithFallback(currencyResource.getAlias(), gCurrencySpacingTag, currencySink, status);
513
0
    currencySink.resolveMissing();
514
0
    if (U_FAILURE(status)) { return; }
515
0
}
516
517
void
518
0
DecimalFormatSymbols::initialize() {
519
0
    /*
520
0
     * These strings used to be in static arrays, but the HP/UX aCC compiler
521
0
     * cannot initialize a static array with class constructors.
522
0
     *  markus 2000may25
523
0
     */
524
0
    fSymbols[kDecimalSeparatorSymbol] = (UChar)0x2e;    // '.' decimal separator
525
0
    fSymbols[kGroupingSeparatorSymbol].remove();        //     group (thousands) separator
526
0
    fSymbols[kPatternSeparatorSymbol] = (UChar)0x3b;    // ';' pattern separator
527
0
    fSymbols[kPercentSymbol] = (UChar)0x25;             // '%' percent sign
528
0
    fSymbols[kZeroDigitSymbol] = (UChar)0x30;           // '0' native 0 digit
529
0
    fSymbols[kOneDigitSymbol] = (UChar)0x31;            // '1' native 1 digit
530
0
    fSymbols[kTwoDigitSymbol] = (UChar)0x32;            // '2' native 2 digit
531
0
    fSymbols[kThreeDigitSymbol] = (UChar)0x33;          // '3' native 3 digit
532
0
    fSymbols[kFourDigitSymbol] = (UChar)0x34;           // '4' native 4 digit
533
0
    fSymbols[kFiveDigitSymbol] = (UChar)0x35;           // '5' native 5 digit
534
0
    fSymbols[kSixDigitSymbol] = (UChar)0x36;            // '6' native 6 digit
535
0
    fSymbols[kSevenDigitSymbol] = (UChar)0x37;          // '7' native 7 digit
536
0
    fSymbols[kEightDigitSymbol] = (UChar)0x38;          // '8' native 8 digit
537
0
    fSymbols[kNineDigitSymbol] = (UChar)0x39;           // '9' native 9 digit
538
0
    fSymbols[kDigitSymbol] = (UChar)0x23;               // '#' pattern digit
539
0
    fSymbols[kPlusSignSymbol] = (UChar)0x002b;          // '+' plus sign
540
0
    fSymbols[kMinusSignSymbol] = (UChar)0x2d;           // '-' minus sign
541
0
    fSymbols[kCurrencySymbol] = (UChar)0xa4;            // 'OX' currency symbol
542
0
    fSymbols[kIntlCurrencySymbol].setTo(TRUE, INTL_CURRENCY_SYMBOL_STR, 2);
543
0
    fSymbols[kMonetarySeparatorSymbol] = (UChar)0x2e;   // '.' monetary decimal separator
544
0
    fSymbols[kExponentialSymbol] = (UChar)0x45;         // 'E' exponential
545
0
    fSymbols[kPerMillSymbol] = (UChar)0x2030;           // '%o' per mill
546
0
    fSymbols[kPadEscapeSymbol] = (UChar)0x2a;           // '*' pad escape symbol
547
0
    fSymbols[kInfinitySymbol] = (UChar)0x221e;          // 'oo' infinite
548
0
    fSymbols[kNaNSymbol] = (UChar)0xfffd;               // SUB NaN
549
0
    fSymbols[kSignificantDigitSymbol] = (UChar)0x0040;  // '@' significant digit
550
0
    fSymbols[kMonetaryGroupingSeparatorSymbol].remove(); // 
551
0
    fSymbols[kExponentMultiplicationSymbol] = (UChar)0xd7; // 'x' multiplication symbol for exponents
552
0
    fIsCustomCurrencySymbol = FALSE; 
553
0
    fIsCustomIntlCurrencySymbol = FALSE;
554
0
    fCodePointZero = 0x30;
555
0
    U_ASSERT(fCodePointZero == fSymbols[kZeroDigitSymbol].char32At(0));
556
0
557
0
}
558
559
Locale
560
0
DecimalFormatSymbols::getLocale(ULocDataLocaleType type, UErrorCode& status) const {
561
0
    U_LOCALE_BASED(locBased, *this);
562
0
    return locBased.getLocale(type, status);
563
0
}
564
565
const UnicodeString&
566
DecimalFormatSymbols::getPatternForCurrencySpacing(UCurrencySpacing type,
567
                                                 UBool beforeCurrency,
568
0
                                                 UErrorCode& status) const {
569
0
    if (U_FAILURE(status)) {
570
0
      return fNoSymbol;  // always empty.
571
0
    }
572
0
    if (beforeCurrency) {
573
0
      return currencySpcBeforeSym[(int32_t)type];
574
0
    } else {
575
0
      return currencySpcAfterSym[(int32_t)type];
576
0
    }
577
0
}
578
579
void
580
DecimalFormatSymbols::setPatternForCurrencySpacing(UCurrencySpacing type,
581
                                                   UBool beforeCurrency,
582
0
                                             const UnicodeString& pattern) {
583
0
  if (beforeCurrency) {
584
0
    currencySpcBeforeSym[(int32_t)type] = pattern;
585
0
  } else {
586
0
    currencySpcAfterSym[(int32_t)type] =  pattern;
587
0
  }
588
0
}
589
U_NAMESPACE_END
590
591
#endif /* #if !UCONFIG_NO_FORMATTING */
592
593
//eof