Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(534)

Unified Diff: source/i18n/ucurr.cpp

Issue 845603002: Update ICU to 54.1 step 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/icu.git@master
Patch Set: remove unusued directories Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « source/i18n/ucoleitr.cpp ('k') | source/i18n/udat.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: source/i18n/ucurr.cpp
diff --git a/source/i18n/ucurr.cpp b/source/i18n/ucurr.cpp
index d2b4b2fe70cf9673e6a83ef982537446c4754779..5ee8ceef8cd882704d9a39970d05c9074cbdb381 100644
--- a/source/i18n/ucurr.cpp
+++ b/source/i18n/ucurr.cpp
@@ -1,6 +1,6 @@
/*
**********************************************************************
-* Copyright (c) 2002-2013, International Business Machines
+* Copyright (c) 2002-2014, International Business Machines
* Corporation and others. All Rights Reserved.
**********************************************************************
*/
@@ -119,6 +119,8 @@ static icu::UInitOnce gIsoCodesInitOnce = U_INITONCE_INITIALIZER;
static const icu::Hashtable* gCurrSymbolsEquiv = NULL;
static icu::UInitOnce gCurrSymbolsEquivInitOnce = U_INITONCE_INITIALIZER;
+U_NAMESPACE_BEGIN
+
// EquivIterator iterates over all strings that are equivalent to a given
// string, s. Note that EquivIterator will never yield s itself.
class EquivIterator : icu::UMemory {
@@ -154,6 +156,8 @@ EquivIterator::next() {
return _next;
}
+U_NAMESPACE_END
+
// makeEquivalent makes lhs and rhs equivalent by updating the equivalence
// relations in hash accordingly.
static void makeEquivalent(
@@ -167,8 +171,8 @@ static void makeEquivalent(
// already equivalent
return;
}
- EquivIterator leftIter(*hash, lhs);
- EquivIterator rightIter(*hash, rhs);
+ icu::EquivIterator leftIter(*hash, lhs);
+ icu::EquivIterator rightIter(*hash, rhs);
const icu::UnicodeString *firstLeft = leftIter.next();
const icu::UnicodeString *firstRight = rightIter.next();
const icu::UnicodeString *nextLeft = firstLeft;
@@ -220,7 +224,7 @@ static void makeEquivalent(
// countEquivalent does not include s itself in the count.
static int32_t countEquivalent(const icu::Hashtable &hash, const icu::UnicodeString &s) {
int32_t result = 0;
- EquivIterator iter(hash, s);
+ icu::EquivIterator iter(hash, s);
while (iter.next() != NULL) {
++result;
}
@@ -1067,7 +1071,7 @@ collectCurrencyNames(const char* locale,
(*currencySymbols)[(*total_currency_symbol_count)++].currencyNameLen = len;
// Add equivalent symbols
if (currencySymbolsEquiv != NULL) {
- EquivIterator iter(*currencySymbolsEquiv, UnicodeString(TRUE, s, len));
+ icu::EquivIterator iter(*currencySymbolsEquiv, UnicodeString(TRUE, s, len));
const UnicodeString *symbol;
while ((symbol = iter.next()) != NULL) {
(*currencySymbols)[*total_currency_symbol_count].IsoCode = iso;
@@ -1616,30 +1620,68 @@ uprv_getStaticCurrencyName(const UChar* iso, const char* loc,
U_CAPI int32_t U_EXPORT2
ucurr_getDefaultFractionDigits(const UChar* currency, UErrorCode* ec) {
- return (_findMetaData(currency, *ec))[0];
+ return ucurr_getDefaultFractionDigitsForUsage(currency,UCURR_USAGE_STANDARD,ec);
+}
+
+U_DRAFT int32_t U_EXPORT2
+ucurr_getDefaultFractionDigitsForUsage(const UChar* currency, const UCurrencyUsage usage, UErrorCode* ec) {
+ int32_t fracDigits = 0;
+ if (U_SUCCESS(*ec)) {
+ switch (usage) {
+ case UCURR_USAGE_STANDARD:
+ fracDigits = (_findMetaData(currency, *ec))[0];
+ break;
+ case UCURR_USAGE_CASH:
+ fracDigits = (_findMetaData(currency, *ec))[2];
+ break;
+ default:
+ *ec = U_UNSUPPORTED_ERROR;
+ }
+ }
+ return fracDigits;
}
U_CAPI double U_EXPORT2
ucurr_getRoundingIncrement(const UChar* currency, UErrorCode* ec) {
+ return ucurr_getRoundingIncrementForUsage(currency, UCURR_USAGE_STANDARD, ec);
+}
+
+U_DRAFT double U_EXPORT2
+ucurr_getRoundingIncrementForUsage(const UChar* currency, const UCurrencyUsage usage, UErrorCode* ec) {
+ double result = 0.0;
+
const int32_t *data = _findMetaData(currency, *ec);
+ if (U_SUCCESS(*ec)) {
+ int32_t fracDigits;
+ int32_t increment;
+ switch (usage) {
+ case UCURR_USAGE_STANDARD:
+ fracDigits = data[0];
+ increment = data[1];
+ break;
+ case UCURR_USAGE_CASH:
+ fracDigits = data[2];
+ increment = data[3];
+ break;
+ default:
+ *ec = U_UNSUPPORTED_ERROR;
+ return result;
+ }
- // If the meta data is invalid, return 0.0.
- if (data[0] < 0 || data[0] > MAX_POW10) {
- if (U_SUCCESS(*ec)) {
+ // If the meta data is invalid, return 0.0
+ if (fracDigits < 0 || fracDigits > MAX_POW10) {
*ec = U_INVALID_FORMAT_ERROR;
+ } else {
+ // A rounding value of 0 or 1 indicates no rounding.
+ if (increment >= 2) {
+ // Return (increment) / 10^(fracDigits). The only actual rounding data,
+ // as of this writing, is CHF { 2, 5 }.
+ result = double(increment) / POW10[fracDigits];
+ }
}
- return 0.0;
- }
-
- // If there is no rounding, return 0.0 to indicate no rounding. A
- // rounding value (data[1]) of 0 or 1 indicates no rounding.
- if (data[1] < 2) {
- return 0.0;
}
- // Return data[1] / 10^(data[0]). The only actual rounding data,
- // as of this writing, is CHF { 2, 5 }.
- return double(data[1]) / POW10[data[0]];
+ return result;
}
U_CDECL_BEGIN
@@ -2491,7 +2533,7 @@ U_CAPI UEnumeration *U_EXPORT2 ucurr_getKeywordValuesForLocale(const char *key,
char loc[ULOC_FULLNAME_CAPACITY] = "";
uloc_addLikelySubtags(locale, loc, sizeof(loc), status);
- prefRegionLength = uloc_getCountry(loc, prefRegion, sizeof(prefRegion), status);
+ /*prefRegionLength = */ uloc_getCountry(loc, prefRegion, sizeof(prefRegion), status);
}
// Read value from supplementalData
« no previous file with comments | « source/i18n/ucoleitr.cpp ('k') | source/i18n/udat.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698