~ubuntu-branches/ubuntu/gutsy/icu/gutsy-updates

« back to all changes in this revision

Viewing changes to source/i18n/dcfmtsym.cpp

  • Committer: Package Import Robot
  • Author(s): Jay Berkenbilt
  • Date: 2005-11-19 11:29:31 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20051119112931-vcizkrp10tli4enw
Tags: 3.4-3
Explicitly build with g++ 3.4.  The current ICU fails its test suite
with 4.0 but not with 3.4.  Future versions should work properly with
4.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
*******************************************************************************
3
 
* Copyright (C) 1997-1999, International Business Machines Corporation and    *
4
 
* others. All Rights Reserved.                                                *
5
 
*******************************************************************************
6
 
*
7
 
* File DCFMTSYM.CPP
8
 
*
9
 
* Modification History:
10
 
*
11
 
*   Date        Name        Description
12
 
*   02/19/97    aliu        Converted from java.
13
 
*   03/18/97    clhuang     Implemented with C++ APIs.
14
 
*   03/27/97    helena      Updated to pass the simple test after code review.
15
 
*   08/26/97    aliu        Added currency/intl currency symbol support.
16
 
*    07/20/98    stephen        Slightly modified initialization of monetarySeparator
17
 
********************************************************************************
18
 
*/
19
 
 
20
 
#include "unicode/dcfmtsym.h"
21
 
#include "unicode/resbund.h"
22
 
#include "unicode/decimfmt.h"
23
 
 
24
 
// *****************************************************************************
25
 
// class DecimalFormatSymbols
26
 
// *****************************************************************************
27
 
 
28
 
U_NAMESPACE_BEGIN
29
 
 
30
 
const char DecimalFormatSymbols::fgNumberElements[] = "NumberElements";
31
 
const char DecimalFormatSymbols::fgCurrencyElements[] = "CurrencyElements";
32
 
 
33
 
// -------------------------------------
34
 
// Initializes this with the decimal format symbols in the default locale.
35
 
 
36
 
DecimalFormatSymbols::DecimalFormatSymbols(UErrorCode& status)
37
 
{
38
 
    initialize(Locale::getDefault(), status, TRUE);
39
 
}
40
 
 
41
 
// -------------------------------------
42
 
// Initializes this with the decimal format symbols in the desired locale.
43
 
 
44
 
DecimalFormatSymbols::DecimalFormatSymbols(const Locale& locale, UErrorCode& status)
45
 
{
46
 
    initialize(locale, status);
47
 
}
48
 
 
49
 
// -------------------------------------
50
 
 
51
 
DecimalFormatSymbols::~DecimalFormatSymbols()
52
 
{
53
 
}
54
 
 
55
 
// -------------------------------------
56
 
// copy constructor
57
 
 
58
 
DecimalFormatSymbols::DecimalFormatSymbols(const DecimalFormatSymbols &source) {
59
 
    int i;
60
 
    for(i = 0; i < (int)kFormatSymbolCount; ++i) {
61
 
        fSymbols[(ENumberFormatSymbol)i] = source.fSymbols[(ENumberFormatSymbol)i];
62
 
    }
63
 
}
64
 
 
65
 
// -------------------------------------
66
 
// assignment operator
67
 
 
68
 
DecimalFormatSymbols&
69
 
DecimalFormatSymbols::operator=(const DecimalFormatSymbols& rhs)
70
 
{
71
 
    if (this != &rhs)
72
 
    {
73
 
        int i;
74
 
        for(i = 0; i < (int)kFormatSymbolCount; ++i) {
75
 
            fSymbols[(ENumberFormatSymbol)i] = rhs.fSymbols[(ENumberFormatSymbol)i];
76
 
        }
77
 
    }
78
 
    return *this;
79
 
}
80
 
 
81
 
// -------------------------------------
82
 
 
83
 
UBool
84
 
DecimalFormatSymbols::operator==(const DecimalFormatSymbols& that) const
85
 
{
86
 
    if (this == &that) {
87
 
        return TRUE;
88
 
    }
89
 
 
90
 
    int i;
91
 
    for(i = 0; i < (int)kFormatSymbolCount; ++i) {
92
 
        if(fSymbols[(ENumberFormatSymbol)i] != that.fSymbols[(ENumberFormatSymbol)i]) {
93
 
            return FALSE;
94
 
        }
95
 
    }
96
 
    return TRUE;
97
 
}
98
 
 
99
 
// -------------------------------------
100
 
 
101
 
void
102
 
DecimalFormatSymbols::initialize(const Locale& locale, UErrorCode& status,
103
 
                                 UBool useLastResortData)
104
 
{
105
 
    if (U_FAILURE(status)) return;
106
 
 
107
 
    ResourceBundle resource((char *)0, locale, status);
108
 
    if (U_FAILURE(status))
109
 
    {
110
 
        // Initializes with last resort data if necessary.
111
 
        if (useLastResortData)
112
 
        {
113
 
            status = U_USING_FALLBACK_ERROR;
114
 
            initialize();
115
 
        }
116
 
        return;
117
 
    }
118
 
 
119
 
    // Gets the number element array.
120
 
    int32_t i = 0;
121
 
    ResourceBundle numberElementsRes = resource.get(fgNumberElements, status);
122
 
    int32_t numberElementsLength = numberElementsRes.getSize();
123
 
    UnicodeString* numberElements = new UnicodeString[numberElementsLength];
124
 
    for(i = 0; i<numberElementsLength; i++) {
125
 
        numberElements[i] = numberElementsRes.getStringEx(i, status);
126
 
    }
127
 
 
128
 
    // Gets the currency element array.
129
 
    ResourceBundle currencyElementsRes = resource.get(fgCurrencyElements, status);
130
 
    int32_t currencyElementsLength = currencyElementsRes.getSize();
131
 
    UnicodeString* currencyElements = new UnicodeString[currencyElementsLength];
132
 
    for(i = 0; i<currencyElementsLength; i++) {
133
 
        currencyElements[i] = currencyElementsRes.getStringEx(i, status);
134
 
    }
135
 
 
136
 
    if (U_FAILURE(status)) return;
137
 
 
138
 
    // If the array size is too small, something is wrong with the resource
139
 
    // bundle, returns the failure error code.
140
 
    if (numberElementsLength < 11 ||
141
 
        currencyElementsLength < 3) {
142
 
        status = U_INVALID_FORMAT_ERROR;
143
 
        return;
144
 
    }
145
 
 
146
 
    initialize(numberElements, currencyElements);
147
 
 
148
 
    delete[] numberElements;
149
 
    delete[] currencyElements;
150
 
}
151
 
 
152
 
// Initializes the DecimalFormatSymbol instance with the data obtained
153
 
// from ResourceBundle in the desired locale.
154
 
 
155
 
void
156
 
DecimalFormatSymbols::initialize(const UnicodeString* numberElements, const UnicodeString* currencyElements)
157
 
{
158
 
    fSymbols[kDecimalSeparatorSymbol] = numberElements[0];
159
 
    fSymbols[kGroupingSeparatorSymbol] = numberElements[1];
160
 
    fSymbols[kPatternSeparatorSymbol] = numberElements[2];
161
 
    fSymbols[kPercentSymbol] = numberElements[3];
162
 
    fSymbols[kZeroDigitSymbol] = numberElements[4];
163
 
    fSymbols[kDigitSymbol] = numberElements[5];
164
 
    fSymbols[kMinusSignSymbol] = numberElements[6];
165
 
    fSymbols[kPlusSignSymbol] = (UChar)0x002b; // '+' Hard coded for now; get from resource later
166
 
    fSymbols[kCurrencySymbol] = currencyElements[0];
167
 
    fSymbols[kIntlCurrencySymbol] = currencyElements[1];
168
 
 
169
 
    // if the resource data specified the empty string as the monetary decimal
170
 
    // separator, that means we should just use the regular separator as the
171
 
    // monetary separator
172
 
    fSymbols[kMonetarySeparatorSymbol] =
173
 
        currencyElements[2].length() > 0 ?
174
 
            currencyElements[2] :
175
 
            fSymbols[kDecimalSeparatorSymbol];
176
 
 
177
 
    fSymbols[kExponentialSymbol] = numberElements[7];
178
 
    fSymbols[kPerMillSymbol] = numberElements[8];
179
 
    fSymbols[kPadEscapeSymbol] = (UChar)0x002a; // '*' Hard coded for now; get from resource later
180
 
    fSymbols[kInfinitySymbol] = numberElements[9];
181
 
    fSymbols[kNaNSymbol] = numberElements[10];
182
 
}
183
 
 
184
 
// initialize with default values
185
 
void
186
 
DecimalFormatSymbols::initialize() {
187
 
    /*
188
 
     * These strings used to be in static arrays, but the HP/UX aCC compiler
189
 
     * cannot initialize a static array with class constructors.
190
 
     *  markus 2000may25
191
 
     */
192
 
    fSymbols[kDecimalSeparatorSymbol] = (UChar)0x2e;    // '.' decimal separator
193
 
    fSymbols[kGroupingSeparatorSymbol].remove();        //     group (thousands) separator
194
 
    fSymbols[kPatternSeparatorSymbol] = (UChar)0x3b;    // ';' pattern separator
195
 
    fSymbols[kPercentSymbol] = (UChar)0x25;             // '%' percent sign
196
 
    fSymbols[kZeroDigitSymbol] = (UChar)0x30;           // '0' native 0 digit
197
 
    fSymbols[kDigitSymbol] = (UChar)0x23;               // '#' pattern digit
198
 
    fSymbols[kMinusSignSymbol] = (UChar)0x2d;           // '-' minus sign
199
 
    fSymbols[kPlusSignSymbol] = (UChar)0x002b;          // '+' plus sign
200
 
    fSymbols[kCurrencySymbol] = (UChar)0xa4;            // 'OX' currency symbol
201
 
    (fSymbols[kIntlCurrencySymbol] = (UChar)0xa4).append((UChar)0xa4);
202
 
    fSymbols[kMonetarySeparatorSymbol] = (UChar)0x2e;   // '.' monetary decimal separator
203
 
    fSymbols[kExponentialSymbol] = (UChar)0x45;         // 'E' exponential
204
 
    fSymbols[kPerMillSymbol] = (UChar)0x2030;           // '%o' per mill
205
 
    fSymbols[kPadEscapeSymbol] = (UChar)0x2a;           // '*' pad escape symbol
206
 
    fSymbols[kInfinitySymbol] = (UChar)0x221e;          // 'oo' infinite
207
 
    fSymbols[kNaNSymbol] = (UChar)0xfffd;               // SUB NaN
208
 
}
209
 
 
210
 
U_NAMESPACE_END
211
 
 
212
 
//eof