]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/i18n/numparse_impl.cpp
ICU-64260.0.1.tar.gz
[apple/icu.git] / icuSources / i18n / numparse_impl.cpp
index 412ea89c86b6518c5f368173be5214e4cef41ddb..6b71ea6c569a1f5893dd85f1cea573bfdfc8e3ce 100644 (file)
@@ -122,6 +122,10 @@ NumberParserImpl::createParserFromProperties(const number::impl::DecimalFormatPr
     }
     if (parseCurrency || affixProvider->hasCurrencySign()) {
         parseFlags |= PARSE_FLAG_MONETARY_SEPARATORS;
+        // Apple <rdar://problem/51938595> check for curr symbol in suffix; use affix API instead?
+        if (properties.positiveSuffixPattern.indexOf(u'ยค') >= 0) {
+            parseFlags |= PARSE_FLAG_HAS_TRAIL_CURRENCY;
+        }
     }
     if (!parseCurrency) {
         parseFlags |= PARSE_FLAG_NO_FOREIGN_CURRENCY;
@@ -269,10 +273,18 @@ void NumberParserImpl::parse(const UnicodeString& input, int32_t start, bool gre
 void NumberParserImpl::parseGreedy(StringSegment& segment, ParsedNumber& result,
                                             UErrorCode& status) const {
     // Note: this method is not recursive in order to avoid stack overflow.
+    bool extraLoop = FALSE;
     for (int i = 0; i <fNumMatchers;) {
         // Base Case
         if (segment.length() == 0) {
-            return;
+            if ((extraLoop && i==0) || (fParseFlags & PARSE_FLAG_HAS_TRAIL_CURRENCY) == 0 || result.currencyCode[0] != 0) { // Apple <rdar://problem/51938595>
+                return;
+            }
+            // If we are parsing for currency expected at the end but have not found it yet,
+            // allow one more loop to see if we are matching an empty currency symbol
+            if (extraLoop) {
+                extraLoop = TRUE; // Apple <rdar://problem/51938595>
+            }
         }
         const NumberParseMatcher* matcher = fMatchers[i];
         if (!matcher->smokeTest(segment)) {
@@ -285,7 +297,8 @@ void NumberParserImpl::parseGreedy(StringSegment& segment, ParsedNumber& result,
         if (U_FAILURE(status)) {
             return;
         }
-        if (segment.getOffset() != initialOffset) {
+        if (segment.getOffset() != initialOffset ||
+                (extraLoop && result.currencyCode[0] != 0)) { // Apple <rdar://problem/51938595>
             // Greedy heuristic: accept the match and loop back
             i = 0;
             continue;