ICU-7385 changed ECurrencySpacing into a C enum.

X-SVN-Rev: 29212
This commit is contained in:
Claire Ho 2010-12-15 23:46:53 +00:00
parent dd03794570
commit 4c38ef650d
4 changed files with 36 additions and 34 deletions

View File

@ -28,6 +28,7 @@
#include "unicode/choicfmt.h"
#include "unicode/unistr.h"
#include "unicode/numsys.h"
#include "unicode/unum.h"
#include "ucurrimp.h"
#include "cstring.h"
#include "locbased.h"
@ -99,7 +100,7 @@ DecimalFormatSymbols::operator=(const DecimalFormatSymbols& rhs)
// fastCopyFrom is safe, see docs on fSymbols
fSymbols[(ENumberFormatSymbol)i].fastCopyFrom(rhs.fSymbols[(ENumberFormatSymbol)i]);
}
for(int32_t i = 0; i < (int32_t)kCurrencySpacingCount; ++i) {
for(int32_t i = 0; i < (int32_t)UNUM_CURRENCY_SPACING_COUNT; ++i) {
currencySpcBeforeSym[i].fastCopyFrom(rhs.currencySpcBeforeSym[i]);
currencySpcAfterSym[i].fastCopyFrom(rhs.currencySpcAfterSym[i]);
}
@ -123,7 +124,7 @@ DecimalFormatSymbols::operator==(const DecimalFormatSymbols& that) const
return FALSE;
}
}
for(int32_t i = 0; i < (int32_t)kCurrencySpacingCount; ++i) {
for(int32_t i = 0; i < (int32_t)UNUM_CURRENCY_SPACING_COUNT; ++i) {
if(currencySpcBeforeSym[i] != that.currencySpcBeforeSym[i]) {
return FALSE;
}
@ -343,7 +344,7 @@ DecimalFormatSymbols::initialize(const Locale& loc, UErrorCode& status, UBool us
gCurrencySpacingTag, NULL, &localStatus);
if (localStatus == U_USING_FALLBACK_WARNING || U_SUCCESS(localStatus)) {
const char* keywords[kCurrencySpacingCount] = {
const char* keywords[UNUM_CURRENCY_SPACING_COUNT] = {
gCurrencyMatchTag, gCurrencySudMatchTag, gCurrencyInsertBtnTag
};
localStatus = U_ZERO_ERROR;
@ -351,7 +352,7 @@ DecimalFormatSymbols::initialize(const Locale& loc, UErrorCode& status, UBool us
gBeforeCurrencyTag, NULL, &localStatus);
if (localStatus == U_USING_FALLBACK_WARNING || U_SUCCESS(localStatus)) {
localStatus = U_ZERO_ERROR;
for (int32_t i = 0; i < kCurrencySpacingCount; i++) {
for (int32_t i = 0; i < UNUM_CURRENCY_SPACING_COUNT; i++) {
currencySpcBeforeSym[i] = ures_getStringByKey(dataRes, keywords[i],
NULL, &localStatus);
}
@ -361,7 +362,7 @@ DecimalFormatSymbols::initialize(const Locale& loc, UErrorCode& status, UBool us
gAfterCurrencyTag, NULL, &localStatus);
if (localStatus == U_USING_FALLBACK_WARNING || U_SUCCESS(localStatus)) {
localStatus = U_ZERO_ERROR;
for (int32_t i = 0; i < kCurrencySpacingCount; i++) {
for (int32_t i = 0; i < UNUM_CURRENCY_SPACING_COUNT; i++) {
currencySpcAfterSym[i] = ures_getStringByKey(dataRes, keywords[i],
NULL, &localStatus);
}
@ -419,7 +420,7 @@ DecimalFormatSymbols::getLocale(ULocDataLocaleType type, UErrorCode& status) con
}
const UnicodeString&
DecimalFormatSymbols::getPatternForCurrencySpacing(ECurrencySpacing type,
DecimalFormatSymbols::getPatternForCurrencySpacing(UCurrencySpacing type,
UBool beforeCurrency,
UErrorCode& status) const {
if (U_FAILURE(status)) {
@ -433,7 +434,7 @@ DecimalFormatSymbols::getPatternForCurrencySpacing(ECurrencySpacing type,
}
void
DecimalFormatSymbols::setPatternForCurrencySpacing(ECurrencySpacing type,
DecimalFormatSymbols::setPatternForCurrencySpacing(UCurrencySpacing type,
UBool beforeCurrency,
const UnicodeString& pattern) {
if (beforeCurrency) {

View File

@ -32,6 +32,7 @@
#include "unicode/uobject.h"
#include "unicode/locid.h"
#include "unum.h"
/**
* \file
@ -166,17 +167,6 @@ public:
kFormatSymbolCount
};
/**
* Constants for specifying currency spacing
* @draft ICU 4.2
*/
enum ECurrencySpacing {
kCurrencyMatch,
kSurroundingMatch,
kInsert,
kCurrencySpacingCount
};
/**
* Create a DecimalFormatSymbols object for the given locale.
*
@ -279,7 +269,7 @@ public:
* This API gets the CurrencySpacing data from ResourceBundle. The pattern can
* be empty if there is no data from current locale and its parent locales.
*
* @param type : kCurrencyMatch, kSurroundingMatch or kInsert.
* @param type : UNUM_CURRENCY_MATCH, UNUM_CURRENCY_SURROUNDING_MATCH or UNUM_CURRENCY_INSERT.
* @param beforeCurrency : true if the pattern is for before currency symbol.
* false if the pattern is for after currency symbol.
* @param status: Input/output parameter, set to success or
@ -287,22 +277,22 @@ public:
* @return pattern string for currencyMatch, surroundingMatch or spaceInsert.
* Return empty string if there is no data for this locale and its parent
* locales.
* @draft ICU 4.2
* @draft ICU 4.8
*/
const UnicodeString& getPatternForCurrencySpacing(ECurrencySpacing type,
const UnicodeString& getPatternForCurrencySpacing(UCurrencySpacing type,
UBool beforeCurrency,
UErrorCode& status) const;
/**
* Set pattern string for 'CurrencySpacing' that can be applied to
* currency format.
*
* @param type : kCurrencyMatch, kSurroundingMatch or kInsert.
* @param type : UNUM_CURRENCY_MATCH, UNUM_CURRENCY_SURROUNDING_MATCH or UNUM_CURRENCY_INSERT.
* @param beforeCurrency : true if the pattern is for before currency symbol.
* false if the pattern is for after currency symbol.
* @param pattern : pattern string to override current setting.
* @draft ICU 4.2
* @draft ICU 4.8
*/
void setPatternForCurrencySpacing(ECurrencySpacing type,
void setPatternForCurrencySpacing(UCurrencySpacing type,
UBool beforeCurrency,
const UnicodeString& pattern);
@ -392,8 +382,8 @@ private:
char validLocale[ULOC_FULLNAME_CAPACITY];
const UChar* currPattern;
UnicodeString currencySpcBeforeSym[kCurrencySpacingCount];
UnicodeString currencySpcAfterSym[kCurrencySpacingCount];
UnicodeString currencySpcBeforeSym[UNUM_CURRENCY_SPACING_COUNT];
UnicodeString currencySpcAfterSym[UNUM_CURRENCY_SPACING_COUNT];
};
// -------------------------------------

View File

@ -206,6 +206,17 @@ typedef enum UNumberFormatPadPosition {
UNUM_PAD_AFTER_SUFFIX
} UNumberFormatPadPosition;
/**
* Constants for specifying currency spacing
* @draft ICU 4.8
*/
typedef enum UCurrencySpacing {
UNUM_CURRENCY_MATCH,
UNUM_CURRENCY_SURROUNDING_MATCH,
UNUM_CURRENCY_INSERT,
UNUM_CURRENCY_SPACING_COUNT
} UCurrencySpacing;
/**
* Create and return a new UNumberFormat for formatting and parsing
* numbers. A UNumberFormat may be used to format numbers by calling

View File

@ -124,15 +124,15 @@ void IntlTestDecimalFormatSymbols::testSymbols(/* char *par */)
// Test get currency spacing before the currency.
status = U_ZERO_ERROR;
for (int32_t i = 0; i < (int32_t)DecimalFormatSymbols::kCurrencySpacingCount; i++) {
for (int32_t i = 0; i < (int32_t)UNUM_CURRENCY_SPACING_COUNT; i++) {
UnicodeString enCurrencyPattern = en.getPatternForCurrencySpacing(
(DecimalFormatSymbols::ECurrencySpacing)i, TRUE, status);
(UCurrencySpacing)i, TRUE, status);
if(U_FAILURE(status)) {
errln("Error: cannot get CurrencyMatch for locale:en");
status = U_ZERO_ERROR;
}
UnicodeString frCurrencyPattern = fr.getPatternForCurrencySpacing(
(DecimalFormatSymbols::ECurrencySpacing)i, TRUE, status);
(UCurrencySpacing)i, TRUE, status);
if(U_FAILURE(status)) {
errln("Error: cannot get CurrencyMatch for locale:fr");
}
@ -142,15 +142,15 @@ void IntlTestDecimalFormatSymbols::testSymbols(/* char *par */)
}
// Test get currencySpacing after the currency.
status = U_ZERO_ERROR;
for (int32_t i = 0; i < DecimalFormatSymbols::kCurrencySpacingCount; i++) {
for (int32_t i = 0; i < UNUM_CURRENCY_SPACING_COUNT; i++) {
UnicodeString enCurrencyPattern = en.getPatternForCurrencySpacing(
(DecimalFormatSymbols::ECurrencySpacing)i, FALSE, status);
(UCurrencySpacing)i, FALSE, status);
if(U_FAILURE(status)) {
errln("Error: cannot get CurrencyMatch for locale:en");
status = U_ZERO_ERROR;
}
UnicodeString frCurrencyPattern = fr.getPatternForCurrencySpacing(
(DecimalFormatSymbols::ECurrencySpacing)i, FALSE, status);
(UCurrencySpacing)i, FALSE, status);
if(U_FAILURE(status)) {
errln("Error: cannot get CurrencyMatch for locale:fr");
}
@ -161,9 +161,9 @@ void IntlTestDecimalFormatSymbols::testSymbols(/* char *par */)
// Test set curerncySpacing APIs
status = U_ZERO_ERROR;
UnicodeString dash = UnicodeString("-");
en.setPatternForCurrencySpacing(DecimalFormatSymbols::kInsert, TRUE, dash);
en.setPatternForCurrencySpacing(UNUM_CURRENCY_INSERT, TRUE, dash);
UnicodeString enCurrencyInsert = en.getPatternForCurrencySpacing(
DecimalFormatSymbols::kInsert, TRUE, status);
UNUM_CURRENCY_INSERT, TRUE, status);
if (dash != enCurrencyInsert) {
errln("Error: Failed to setCurrencyInsert for locale:en");
}