]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/i18n/numparse_currency.cpp
ICU-64260.0.1.tar.gz
[apple/icu.git] / icuSources / i18n / numparse_currency.cpp
index ae8196ec483799f0ec1fd328bab1110e60d0d30d..1065b6bb41f3d1cdc05d39517955efc4250997f5 100644 (file)
@@ -25,6 +25,7 @@ CombinedCurrencyMatcher::CombinedCurrencyMatcher(const CurrencySymbols& currency
         : fCurrency1(currencySymbols.getCurrencySymbol(status)),
           fCurrency2(currencySymbols.getIntlCurrencySymbol(status)),
           fUseFullCurrencyData(0 == (parseFlags & PARSE_FLAG_NO_FOREIGN_CURRENCY)),
+          fCurrencyTrails(0 != (parseFlags & PARSE_FLAG_HAS_TRAIL_CURRENCY)), // Apple <rdar://problem/51938595>
           afterPrefixInsert(dfs.getPatternForCurrencySpacing(UNUM_CURRENCY_INSERT, false, status)),
           beforeSuffixInsert(dfs.getPatternForCurrencySpacing(UNUM_CURRENCY_INSERT, true, status)),
           fLocaleName(dfs.getLocale().getName(), -1, status) {
@@ -62,7 +63,8 @@ CombinedCurrencyMatcher::match(StringSegment& segment, ParsedNumber& result, UEr
     // Try to match a currency spacing separator.
     int32_t initialOffset = segment.getOffset();
     bool maybeMore = false;
-    if (result.seenNumber() && !beforeSuffixInsert.isEmpty()) {
+    if (result.seenNumber() && !beforeSuffixInsert.isEmpty()
+            && segment.length() != 0) { // Apple <rdar://problem/51938595>
         int32_t overlap = segment.getCommonPrefixLength(beforeSuffixInsert);
         if (overlap == beforeSuffixInsert.length()) {
             segment.adjustOffset(overlap);
@@ -79,7 +81,8 @@ CombinedCurrencyMatcher::match(StringSegment& segment, ParsedNumber& result, UEr
     }
 
     // Try to match a currency spacing separator.
-    if (!result.seenNumber() && !afterPrefixInsert.isEmpty()) {
+    if (!result.seenNumber() && !afterPrefixInsert.isEmpty()
+            && segment.length() != 0) { // Apple <rdar://problem/51938595>
         int32_t overlap = segment.getCommonPrefixLength(afterPrefixInsert);
         if (overlap == afterPrefixInsert.length()) {
             segment.adjustOffset(overlap);
@@ -98,6 +101,8 @@ bool CombinedCurrencyMatcher::matchCurrency(StringSegment& segment, ParsedNumber
     int32_t overlap1;
     if (!fCurrency1.isEmpty()) {
         overlap1 = segment.getCaseSensitivePrefixLength(fCurrency1);
+    } else if (!fUseFullCurrencyData && (!fCurrencyTrails || result.seenNumber())) { // Apple <rdar://problem/46915356><rdar://problem/51938595>
+        overlap1 = 0;
     } else {
         overlap1 = -1;
     }
@@ -111,7 +116,9 @@ bool CombinedCurrencyMatcher::matchCurrency(StringSegment& segment, ParsedNumber
 
     int32_t overlap2;
     if (!fCurrency2.isEmpty()) {
-        overlap2 = segment.getCaseSensitivePrefixLength(fCurrency2);
+        // ISO codes should be accepted case-insensitive.
+        // https://unicode-org.atlassian.net/browse/ICU-13696
+        overlap2 = segment.getCommonPrefixLength(fCurrency2);
     } else {
         overlap2 = -1;
     }