Changeset 213447 in webkit


Ignore:
Timestamp:
Mar 6, 2017 6:06:18 AM (7 years ago)
Author:
commit-queue@webkit.org
Message:

Currency digits calculation in Intl.NumberFormat should call out to ICU
https://bugs.webkit.org/show_bug.cgi?id=169182

Patch by Daniel Ehrenberg <littledan@igalia.com> on 2017-03-06
Reviewed by Yusuke Suzuki.

  • runtime/IntlNumberFormat.cpp:

(JSC::computeCurrencyDigits):
(JSC::computeCurrencySortKey): Deleted.
(JSC::extractCurrencySortKey): Deleted.

Location:
trunk/Source/JavaScriptCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r213433 r213447  
     12017-03-06  Daniel Ehrenberg  <littledan@igalia.com>
     2
     3        Currency digits calculation in Intl.NumberFormat should call out to ICU
     4        https://bugs.webkit.org/show_bug.cgi?id=169182
     5
     6        Reviewed by Yusuke Suzuki.
     7
     8        * runtime/IntlNumberFormat.cpp:
     9        (JSC::computeCurrencyDigits):
     10        (JSC::computeCurrencySortKey): Deleted.
     11        (JSC::extractCurrencySortKey): Deleted.
     12
    1132017-03-05  Yusuke Suzuki  <utatane.tea@gmail.com>
    214
  • trunk/Source/JavaScriptCore/runtime/IntlNumberFormat.cpp

    r211247 r213447  
    3737#include "JSCInlines.h"
    3838#include "ObjectConstructor.h"
     39#include <unicode/ucurr.h>
    3940
    4041namespace JSC {
     
    9596}
    9697
    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 
    11698static unsigned computeCurrencyDigits(const String& currency)
    11799{
     
    119101    // "If the ISO 4217 currency and funds code list contains currency as an alphabetic code,
    120102    // then return the minor unit value corresponding to the currency from the list; else return 2.
    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;
     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;
    153109}
    154110
Note: See TracChangeset for help on using the changeset viewer.