Changeset 214020 in webkit
- Timestamp:
- Mar 15, 2017 4:40:24 PM (7 years ago)
- Location:
- trunk/Source/JavaScriptCore
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/ChangeLog
r214018 r214020 1 2017-03-15 Daniel Ehrenberg <littledan@chromium.org> 2 3 Switch back to ISO 4217 for Intl CurrencyDigits data 4 https://bugs.webkit.org/show_bug.cgi?id=169182 5 6 Previously, a patch switched Intl.NumberFormat to use CLDR data through 7 ICU to get the default number of decimal digits for a currency. 8 However, that change actually violated the ECMA 402 specification, 9 which references ISO 4217 as the data source. This patch reverts to 10 an in-line implementation of that data. 11 12 Reviewed by Saam Barati. 13 14 * runtime/IntlNumberFormat.cpp: 15 (JSC::computeCurrencySortKey): 16 (JSC::extractCurrencySortKey): 17 (JSC::computeCurrencyDigits): 18 1 19 2017-03-15 Saam Barati <sbarati@apple.com> 2 20 -
trunk/Source/JavaScriptCore/runtime/IntlNumberFormat.cpp
r213447 r214020 37 37 #include "JSCInlines.h" 38 38 #include "ObjectConstructor.h" 39 #include <unicode/ucurr.h>40 39 41 40 namespace JSC { … … 96 95 } 97 96 97 static inline unsigned computeCurrencySortKey(const String& currency) 98 { 99 ASSERT(currency.length() == 3); 100 ASSERT(currency.isAllSpecialCharacters<isASCIIUpper>()); 101 return (currency[0] << 16) + (currency[1] << 8) + currency[2]; 102 } 103 104 static inline unsigned computeCurrencySortKey(const char* currency) 105 { 106 ASSERT(strlen(currency) == 3); 107 ASSERT(isAllSpecialCharacters<isASCIIUpper>(currency, 3)); 108 return (currency[0] << 16) + (currency[1] << 8) + currency[2]; 109 } 110 111 static unsigned extractCurrencySortKey(std::pair<const char*, unsigned>* currencyMinorUnit) 112 { 113 return computeCurrencySortKey(currencyMinorUnit->first); 114 } 115 98 116 static unsigned computeCurrencyDigits(const String& currency) 99 117 { … … 101 119 // "If the ISO 4217 currency and funds code list contains currency as an alphabetic code, 102 120 // then return the minor unit value corresponding to the currency from the list; else return 2. 103 Vector<UChar> chars = currency.charactersWithNullTermination(); 104 UErrorCode status = U_ZERO_ERROR; 105 uint32_t result = ucurr_getDefaultFractionDigits(chars.data(), &status); 106 if (U_FAILURE(status)) 107 result = 2; 108 return result; 121 std::pair<const char*, unsigned> currencyMinorUnits[] = { 122 { "BHD", 3 }, 123 { "BIF", 0 }, 124 { "BYR", 0 }, 125 { "CLF", 4 }, 126 { "CLP", 0 }, 127 { "DJF", 0 }, 128 { "GNF", 0 }, 129 { "IQD", 3 }, 130 { "ISK", 0 }, 131 { "JOD", 3 }, 132 { "JPY", 0 }, 133 { "KMF", 0 }, 134 { "KRW", 0 }, 135 { "KWD", 3 }, 136 { "LYD", 3 }, 137 { "OMR", 3 }, 138 { "PYG", 0 }, 139 { "RWF", 0 }, 140 { "TND", 3 }, 141 { "UGX", 0 }, 142 { "UYI", 0 }, 143 { "VND", 0 }, 144 { "VUV", 0 }, 145 { "XAF", 0 }, 146 { "XOF", 0 }, 147 { "XPF", 0 } 148 }; 149 auto* currencyMinorUnit = tryBinarySearch<std::pair<const char*, unsigned>>(currencyMinorUnits, WTF_ARRAY_LENGTH(currencyMinorUnits), computeCurrencySortKey(currency), extractCurrencySortKey); 150 if (currencyMinorUnit) 151 return currencyMinorUnit->second; 152 return 2; 109 153 } 110 154
Note: See TracChangeset
for help on using the changeset viewer.