1999-08-16 21:50:52 +00:00
|
|
|
/*
|
1999-11-22 20:25:35 +00:00
|
|
|
*******************************************************************************
|
|
|
|
* Copyright (C) 1997-1999, International Business Machines Corporation and *
|
|
|
|
* others. All Rights Reserved. *
|
|
|
|
*******************************************************************************
|
1999-08-16 21:50:52 +00:00
|
|
|
*
|
|
|
|
* File DCFMTSYM.CPP
|
|
|
|
*
|
|
|
|
* Modification History:
|
|
|
|
*
|
|
|
|
* Date Name Description
|
|
|
|
* 02/19/97 aliu Converted from java.
|
|
|
|
* 03/18/97 clhuang Implemented with C++ APIs.
|
|
|
|
* 03/27/97 helena Updated to pass the simple test after code review.
|
|
|
|
* 08/26/97 aliu Added currency/intl currency symbol support.
|
|
|
|
* 07/20/98 stephen Slightly modified initialization of monetarySeparator
|
|
|
|
********************************************************************************
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "dcfmtsym.h"
|
|
|
|
#include "resbund.h"
|
|
|
|
#include "decimfmt.h"
|
|
|
|
|
|
|
|
// *****************************************************************************
|
|
|
|
// class DecimalFormatSymbols
|
|
|
|
// *****************************************************************************
|
|
|
|
|
|
|
|
const int32_t DecimalFormatSymbols::fgNumberElementsLength = 11;
|
|
|
|
const int32_t DecimalFormatSymbols::fgCurrencyElementsLength = 3;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* These are the tags we expect to see in normal resource bundle files associated
|
|
|
|
* with a locale.
|
|
|
|
*/
|
1999-12-01 21:27:44 +00:00
|
|
|
const char *DecimalFormatSymbols::fgNumberElements="NumberElements";
|
|
|
|
const char *DecimalFormatSymbols::fgCurrencyElements="CurrencyElements";
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
// Because the C-compiler doesn't parse \u escape sequences, we encode the
|
|
|
|
// \u last resort strings as UChar arrays.
|
|
|
|
const UChar DecimalFormatSymbols::fgLastResortPerMill[] = { 0x2030, 0 };
|
|
|
|
const UChar DecimalFormatSymbols::fgLastResortInfinity[] = { 0x221E, 0 };
|
|
|
|
const UChar DecimalFormatSymbols::fgLastResortNaN[] = { 0xFFFD, 0 };
|
|
|
|
const UChar DecimalFormatSymbols::fgLastResortCurrency[] = { 0x00A4, 0 };
|
|
|
|
const UChar DecimalFormatSymbols::fgLastResortIntlCurrency[] = { 0x00A4, 0x00A4, 0 };
|
|
|
|
|
|
|
|
const UnicodeString DecimalFormatSymbols::fgLastResortNumberElements[] =
|
|
|
|
{
|
1999-12-01 22:57:20 +00:00
|
|
|
UnicodeString(".", ""), // decimal separator
|
|
|
|
UnicodeString(), // group (thousands) separator
|
|
|
|
UnicodeString(";", ""), // pattern separator
|
|
|
|
UnicodeString("%", ""), // percent sign
|
|
|
|
UnicodeString("0", ""), // native 0 digit
|
|
|
|
UnicodeString("#", ""), // pattern digit
|
|
|
|
UnicodeString("-", ""), // minus sign
|
|
|
|
UnicodeString("E", ""), // exponential
|
1999-08-16 21:50:52 +00:00
|
|
|
DecimalFormatSymbols::fgLastResortPerMill, // per mill
|
|
|
|
DecimalFormatSymbols::fgLastResortInfinity, // infinite
|
|
|
|
DecimalFormatSymbols::fgLastResortNaN // NaN
|
|
|
|
};
|
|
|
|
|
|
|
|
const UnicodeString DecimalFormatSymbols::fgLastResortCurrencyElements[] =
|
|
|
|
{
|
|
|
|
DecimalFormatSymbols::fgLastResortCurrency,
|
|
|
|
DecimalFormatSymbols::fgLastResortIntlCurrency,
|
1999-12-01 22:57:20 +00:00
|
|
|
UnicodeString(".", "") // monetary decimal separator
|
1999-08-16 21:50:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// -------------------------------------
|
|
|
|
// Initializes this with the decimal format symbols in the default locale.
|
|
|
|
|
|
|
|
DecimalFormatSymbols::DecimalFormatSymbols(UErrorCode& status)
|
|
|
|
{
|
|
|
|
initialize(Locale::getDefault(), status, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------
|
|
|
|
// Initializes this with the decimal format symbols in the desired locale.
|
|
|
|
|
|
|
|
DecimalFormatSymbols::DecimalFormatSymbols(const Locale& locale, UErrorCode& status)
|
|
|
|
{
|
|
|
|
initialize(locale, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------
|
|
|
|
|
|
|
|
DecimalFormatSymbols::~DecimalFormatSymbols()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------
|
|
|
|
// copy constructor
|
|
|
|
|
|
|
|
DecimalFormatSymbols::DecimalFormatSymbols(const DecimalFormatSymbols &source)
|
|
|
|
: fZeroDigit(source.fZeroDigit),
|
|
|
|
fGroupingSeparator(source.fGroupingSeparator),
|
|
|
|
fDecimalSeparator(source.fDecimalSeparator),
|
|
|
|
fPercent(source.fPercent),
|
|
|
|
fPerMill(source.fPerMill),
|
|
|
|
fDigit(source.fDigit),
|
|
|
|
fPlusSign(source.fPlusSign),
|
|
|
|
fMinusSign(source.fMinusSign),
|
|
|
|
fExponential(source.fExponential),
|
|
|
|
fPatternSeparator(source.fPatternSeparator),
|
|
|
|
fInfinity(source.fInfinity),
|
|
|
|
fNaN(source.fNaN),
|
|
|
|
fCurrencySymbol(source.fCurrencySymbol),
|
|
|
|
fIntlCurrencySymbol(source.fIntlCurrencySymbol),
|
|
|
|
fMonetarySeparator(source.fMonetarySeparator),
|
|
|
|
fPadEscape(source.fPadEscape)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------
|
|
|
|
// assignment operator
|
|
|
|
|
|
|
|
DecimalFormatSymbols&
|
|
|
|
DecimalFormatSymbols::operator=(const DecimalFormatSymbols& rhs)
|
|
|
|
{
|
|
|
|
if (this != &rhs)
|
|
|
|
{
|
|
|
|
fZeroDigit = rhs.fZeroDigit;
|
|
|
|
fGroupingSeparator = rhs.fGroupingSeparator;
|
|
|
|
fDecimalSeparator = rhs.fDecimalSeparator;
|
|
|
|
fPercent = rhs.fPercent;
|
|
|
|
fPerMill = rhs.fPerMill;
|
|
|
|
fDigit = rhs.fDigit;
|
|
|
|
fPlusSign = rhs.fPlusSign;
|
|
|
|
fMinusSign = rhs.fMinusSign;
|
|
|
|
fExponential = rhs.fExponential;
|
|
|
|
fPatternSeparator = rhs.fPatternSeparator;
|
|
|
|
fInfinity = rhs.fInfinity;
|
|
|
|
fNaN = rhs.fNaN;
|
|
|
|
fCurrencySymbol = rhs.fCurrencySymbol;
|
|
|
|
fIntlCurrencySymbol = rhs.fIntlCurrencySymbol;
|
|
|
|
fMonetarySeparator = rhs.fMonetarySeparator;
|
|
|
|
fPadEscape = rhs.fPadEscape;
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------
|
|
|
|
|
|
|
|
bool_t
|
|
|
|
DecimalFormatSymbols::operator==(const DecimalFormatSymbols& that) const
|
|
|
|
{
|
|
|
|
if (this == &that) return TRUE;
|
|
|
|
|
|
|
|
return (fZeroDigit == that.fZeroDigit &&
|
|
|
|
fGroupingSeparator == that.fGroupingSeparator &&
|
|
|
|
fDecimalSeparator == that.fDecimalSeparator &&
|
|
|
|
fPercent == that.fPercent &&
|
|
|
|
fPerMill == that.fPerMill &&
|
|
|
|
fDigit == that.fDigit &&
|
|
|
|
fPlusSign == that.fPlusSign &&
|
|
|
|
fMinusSign == that.fMinusSign &&
|
|
|
|
fExponential == that.fExponential &&
|
|
|
|
fPatternSeparator == that.fPatternSeparator &&
|
|
|
|
fInfinity == that.fInfinity &&
|
|
|
|
fNaN == that.fNaN &&
|
|
|
|
fCurrencySymbol == that.fCurrencySymbol &&
|
|
|
|
fIntlCurrencySymbol == that.fIntlCurrencySymbol &&
|
|
|
|
fMonetarySeparator == that.fMonetarySeparator &&
|
|
|
|
fPadEscape == that.fPadEscape
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------
|
|
|
|
|
|
|
|
void
|
|
|
|
DecimalFormatSymbols::initialize(const Locale& locale, UErrorCode& status,
|
|
|
|
bool_t useLastResortData)
|
|
|
|
{
|
1999-10-18 22:48:32 +00:00
|
|
|
if (U_FAILURE(status)) return;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
ResourceBundle resource(Locale::getDataDirectory(), locale, status);
|
1999-10-18 22:48:32 +00:00
|
|
|
if (U_FAILURE(status))
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
// Initializes with last resort data if necessary.
|
|
|
|
if (useLastResortData)
|
|
|
|
{
|
1999-10-07 00:07:53 +00:00
|
|
|
status = U_USING_FALLBACK_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
initialize(fgLastResortNumberElements, fgLastResortCurrencyElements);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t numberElementsLength=0;
|
|
|
|
// Gets the number element array.
|
|
|
|
const UnicodeString* numberElements = resource.getStringArray(fgNumberElements, numberElementsLength, status);
|
|
|
|
int32_t currencyElementsLength=0;
|
|
|
|
// Gets the currency element array.
|
|
|
|
const UnicodeString* currencyElements = resource.getStringArray(fgCurrencyElements, currencyElementsLength, status);
|
1999-10-18 22:48:32 +00:00
|
|
|
if (U_FAILURE(status)) return;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
// If the array size is too small, something is wrong with the resource
|
|
|
|
// bundle, returns the failure error code.
|
|
|
|
if (numberElementsLength < fgNumberElementsLength ||
|
|
|
|
currencyElementsLength < fgCurrencyElementsLength) {
|
1999-10-07 00:07:53 +00:00
|
|
|
status = U_INVALID_FORMAT_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
initialize(numberElements, currencyElements);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Initializes the DecimalFormatSymbol instance with the data obtained
|
|
|
|
// from ResourceBundle in the desired locale.
|
|
|
|
|
|
|
|
void
|
|
|
|
DecimalFormatSymbols::initialize(const UnicodeString* numberElements, const UnicodeString* currencyElements)
|
|
|
|
{
|
|
|
|
fDecimalSeparator = numberElements[0][(UTextOffset)0];
|
|
|
|
fGroupingSeparator = numberElements[1][(UTextOffset)0];
|
|
|
|
fPatternSeparator = numberElements[2][(UTextOffset)0];
|
|
|
|
fPercent = numberElements[3][(UTextOffset)0];
|
|
|
|
fZeroDigit = numberElements[4][(UTextOffset)0];
|
|
|
|
fDigit = numberElements[5][(UTextOffset)0];
|
|
|
|
fPlusSign = 0x002B; // '+' Hard coded for now; get from resource later
|
|
|
|
fMinusSign = numberElements[6][(UTextOffset)0];
|
|
|
|
fExponential = numberElements[7][(UTextOffset)0];
|
|
|
|
fPerMill = numberElements[8][(UTextOffset)0];
|
|
|
|
fInfinity = numberElements[9];
|
|
|
|
fNaN = numberElements[10];
|
|
|
|
fCurrencySymbol = currencyElements[0];
|
|
|
|
fIntlCurrencySymbol = currencyElements[1];
|
|
|
|
fPadEscape = 0x002A; // '*' Hard coded for now; get from resource later
|
|
|
|
|
|
|
|
// if the resource data specified the empty string as the monetary decimal
|
|
|
|
// separator, that means we should just use the regular separator as the
|
|
|
|
// monetary separator
|
|
|
|
if(currencyElements[2].size() == 0)
|
|
|
|
fMonetarySeparator = fDecimalSeparator;
|
|
|
|
else
|
|
|
|
fMonetarySeparator = currencyElements[2][(UTextOffset)0];
|
|
|
|
}
|
|
|
|
|
|
|
|
//eof
|