OLD | NEW |
1 // © 2018 and later: Unicode, Inc. and others. | 1 // © 2018 and later: Unicode, Inc. and others. |
2 // License & terms of use: http://www.unicode.org/copyright.html | 2 // License & terms of use: http://www.unicode.org/copyright.html |
3 | 3 |
4 #include "unicode/utypes.h" | 4 #include "unicode/utypes.h" |
5 | 5 |
6 #if !UCONFIG_NO_FORMATTING | 6 #if !UCONFIG_NO_FORMATTING |
7 | 7 |
8 // Allow implicit conversion from char16_t* to UnicodeString for this file: | 8 // Allow implicit conversion from char16_t* to UnicodeString for this file: |
9 // Helpful in toString methods and elsewhere. | 9 // Helpful in toString methods and elsewhere. |
10 #define UNISTR_FROM_STRING_EXPLICIT | 10 #define UNISTR_FROM_STRING_EXPLICIT |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 DecimalFormatSymbols dfs(locale, status); | 46 DecimalFormatSymbols dfs(locale, status); |
47 dfs.setSymbol(DecimalFormatSymbols::kCurrencySymbol, u"IU$", status); | 47 dfs.setSymbol(DecimalFormatSymbols::kCurrencySymbol, u"IU$", status); |
48 dfs.setSymbol(DecimalFormatSymbols::kIntlCurrencySymbol, u"ICU", status); | 48 dfs.setSymbol(DecimalFormatSymbols::kIntlCurrencySymbol, u"ICU", status); |
49 CurrencySymbols currencySymbols({u"ICU", status}, locale, dfs, status); | 49 CurrencySymbols currencySymbols({u"ICU", status}, locale, dfs, status); |
50 | 50 |
51 ParsedPatternInfo patternInfo; | 51 ParsedPatternInfo patternInfo; |
52 PatternParser::parseToPatternInfo(patternString, patternInfo, status); | 52 PatternParser::parseToPatternInfo(patternString, patternInfo, status); |
53 | 53 |
54 // The following statements set up the affix matchers. | 54 // The following statements set up the affix matchers. |
55 AffixTokenMatcherSetupData affixSetupData = { | 55 AffixTokenMatcherSetupData affixSetupData = { |
56 currencySymbols, symbols, ignorables, locale}; | 56 currencySymbols, symbols, ignorables, locale, parseFlags}; |
57 parser->fLocalMatchers.affixTokenMatcherWarehouse = {&affixSetupData}; | 57 parser->fLocalMatchers.affixTokenMatcherWarehouse = {&affixSetupData}; |
58 parser->fLocalMatchers.affixMatcherWarehouse = {&parser->fLocalMatchers.affi
xTokenMatcherWarehouse}; | 58 parser->fLocalMatchers.affixMatcherWarehouse = {&parser->fLocalMatchers.affi
xTokenMatcherWarehouse}; |
59 parser->fLocalMatchers.affixMatcherWarehouse.createAffixMatchers( | 59 parser->fLocalMatchers.affixMatcherWarehouse.createAffixMatchers( |
60 patternInfo, *parser, ignorables, parseFlags, status); | 60 patternInfo, *parser, ignorables, parseFlags, status); |
61 | 61 |
62 Grouper grouper = Grouper::forStrategy(UNUM_GROUPING_AUTO); | 62 Grouper grouper = Grouper::forStrategy(UNUM_GROUPING_AUTO); |
63 grouper.setLocaleData(patternInfo, locale); | 63 grouper.setLocaleData(patternInfo, locale); |
64 | 64 |
65 parser->addMatcher(parser->fLocalMatchers.ignorables); | 65 parser->addMatcher(parser->fLocalMatchers.ignorables); |
66 parser->addMatcher(parser->fLocalMatchers.decimal = {symbols, grouper, parse
Flags}); | 66 parser->addMatcher(parser->fLocalMatchers.decimal = {symbols, grouper, parse
Flags}); |
67 parser->addMatcher(parser->fLocalMatchers.minusSign = {symbols, false}); | 67 parser->addMatcher(parser->fLocalMatchers.minusSign = {symbols, false}); |
68 parser->addMatcher(parser->fLocalMatchers.plusSign = {symbols, false}); | 68 parser->addMatcher(parser->fLocalMatchers.plusSign = {symbols, false}); |
69 parser->addMatcher(parser->fLocalMatchers.percent = {symbols}); | 69 parser->addMatcher(parser->fLocalMatchers.percent = {symbols}); |
70 parser->addMatcher(parser->fLocalMatchers.permille = {symbols}); | 70 parser->addMatcher(parser->fLocalMatchers.permille = {symbols}); |
71 parser->addMatcher(parser->fLocalMatchers.nan = {symbols}); | 71 parser->addMatcher(parser->fLocalMatchers.nan = {symbols}); |
72 parser->addMatcher(parser->fLocalMatchers.infinity = {symbols}); | 72 parser->addMatcher(parser->fLocalMatchers.infinity = {symbols}); |
73 parser->addMatcher(parser->fLocalMatchers.padding = {u"@"}); | 73 parser->addMatcher(parser->fLocalMatchers.padding = {u"@"}); |
74 parser->addMatcher(parser->fLocalMatchers.scientific = {symbols, grouper}); | 74 parser->addMatcher(parser->fLocalMatchers.scientific = {symbols, grouper}); |
75 parser->addMatcher(parser->fLocalMatchers.currency = {currencySymbols, symbo
ls, status}); | 75 parser->addMatcher(parser->fLocalMatchers.currency = {currencySymbols, symbo
ls, parseFlags, status}); |
76 // parser.addMatcher(new RequireNumberMatcher()); | 76 // parser.addMatcher(new RequireNumberMatcher()); |
77 | 77 |
78 parser->freeze(); | 78 parser->freeze(); |
79 return parser.orphan(); | 79 return parser.orphan(); |
80 } | 80 } |
81 | 81 |
82 NumberParserImpl* | 82 NumberParserImpl* |
83 NumberParserImpl::createParserFromProperties(const number::impl::DecimalFormatPr
operties& properties, | 83 NumberParserImpl::createParserFromProperties(const number::impl::DecimalFormatPr
operties& properties, |
84 const DecimalFormatSymbols& symbols
, bool parseCurrency, | 84 const DecimalFormatSymbols& symbols
, bool parseCurrency, |
85 UErrorCode& status) { | 85 UErrorCode& status) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 parseFlags |= PARSE_FLAG_EXACT_AFFIX; | 119 parseFlags |= PARSE_FLAG_EXACT_AFFIX; |
120 } else { | 120 } else { |
121 parseFlags |= PARSE_FLAG_INCLUDE_UNPAIRED_AFFIXES; | 121 parseFlags |= PARSE_FLAG_INCLUDE_UNPAIRED_AFFIXES; |
122 } | 122 } |
123 if (grouper.getPrimary() <= 0) { | 123 if (grouper.getPrimary() <= 0) { |
124 parseFlags |= PARSE_FLAG_GROUPING_DISABLED; | 124 parseFlags |= PARSE_FLAG_GROUPING_DISABLED; |
125 } | 125 } |
126 if (parseCurrency || affixProvider->hasCurrencySign()) { | 126 if (parseCurrency || affixProvider->hasCurrencySign()) { |
127 parseFlags |= PARSE_FLAG_MONETARY_SEPARATORS; | 127 parseFlags |= PARSE_FLAG_MONETARY_SEPARATORS; |
128 } | 128 } |
| 129 if (!parseCurrency) { |
| 130 parseFlags |= PARSE_FLAG_NO_FOREIGN_CURRENCY; |
| 131 } |
129 | 132 |
130 LocalPointer<NumberParserImpl> parser(new NumberParserImpl(parseFlags)); | 133 LocalPointer<NumberParserImpl> parser(new NumberParserImpl(parseFlags)); |
131 | 134 |
132 parser->fLocalMatchers.ignorables = { | 135 parser->fLocalMatchers.ignorables = { |
133 isStrict ? unisets::STRICT_IGNORABLES : unisets::DEFAULT_IGNORABLES}
; | 136 isStrict ? unisets::STRICT_IGNORABLES : unisets::DEFAULT_IGNORABLES}
; |
134 IgnorablesMatcher& ignorables = parser->fLocalMatchers.ignorables; | 137 IgnorablesMatcher& ignorables = parser->fLocalMatchers.ignorables; |
135 | 138 |
136 ////////////////////// | 139 ////////////////////// |
137 /// AFFIX MATCHERS /// | 140 /// AFFIX MATCHERS /// |
138 ////////////////////// | 141 ////////////////////// |
139 | 142 |
140 // The following statements set up the affix matchers. | 143 // The following statements set up the affix matchers. |
141 AffixTokenMatcherSetupData affixSetupData = { | 144 AffixTokenMatcherSetupData affixSetupData = { |
142 currencySymbols, symbols, ignorables, locale}; | 145 currencySymbols, symbols, ignorables, locale, parseFlags}; |
143 parser->fLocalMatchers.affixTokenMatcherWarehouse = {&affixSetupData}; | 146 parser->fLocalMatchers.affixTokenMatcherWarehouse = {&affixSetupData}; |
144 parser->fLocalMatchers.affixMatcherWarehouse = {&parser->fLocalMatchers.affi
xTokenMatcherWarehouse}; | 147 parser->fLocalMatchers.affixMatcherWarehouse = {&parser->fLocalMatchers.affi
xTokenMatcherWarehouse}; |
145 parser->fLocalMatchers.affixMatcherWarehouse.createAffixMatchers( | 148 parser->fLocalMatchers.affixMatcherWarehouse.createAffixMatchers( |
146 *affixProvider, *parser, ignorables, parseFlags, status); | 149 *affixProvider, *parser, ignorables, parseFlags, status); |
147 | 150 |
148 //////////////////////// | 151 //////////////////////// |
149 /// CURRENCY MATCHER /// | 152 /// CURRENCY MATCHER /// |
150 //////////////////////// | 153 //////////////////////// |
151 | 154 |
152 if (parseCurrency || affixProvider->hasCurrencySign()) { | 155 if (parseCurrency || affixProvider->hasCurrencySign()) { |
153 parser->addMatcher(parser->fLocalMatchers.currency = {currencySymbols, s
ymbols, status}); | 156 parser->addMatcher(parser->fLocalMatchers.currency = {currencySymbols, s
ymbols, parseFlags, status}); |
154 } | 157 } |
155 | 158 |
156 /////////////// | 159 /////////////// |
157 /// PERCENT /// | 160 /// PERCENT /// |
158 /////////////// | 161 /////////////// |
159 | 162 |
160 // ICU-TC meeting, April 11, 2018: accept percent/permille only if it is in
the pattern, | 163 // ICU-TC meeting, April 11, 2018: accept percent/permille only if it is in
the pattern, |
161 // and to maintain regressive behavior, divide by 100 even if no percent sig
n is present. | 164 // and to maintain regressive behavior, divide by 100 even if no percent sig
n is present. |
162 if (affixProvider->containsSymbolType(AffixPatternType::TYPE_PERCENT, status
)) { | 165 if (affixProvider->containsSymbolType(AffixPatternType::TYPE_PERCENT, status
)) { |
163 parser->addMatcher(parser->fLocalMatchers.percent = {symbols}); | 166 parser->addMatcher(parser->fLocalMatchers.percent = {symbols}); |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 for (int32_t i = 0; i < fNumMatchers; i++) { | 355 for (int32_t i = 0; i < fNumMatchers; i++) { |
353 result.append(u' '); | 356 result.append(u' '); |
354 result.append(fMatchers[i]->toString()); | 357 result.append(fMatchers[i]->toString()); |
355 } | 358 } |
356 result.append(u" ]>", -1); | 359 result.append(u" ]>", -1); |
357 return result; | 360 return result; |
358 } | 361 } |
359 | 362 |
360 | 363 |
361 #endif /* #if !UCONFIG_NO_FORMATTING */ | 364 #endif /* #if !UCONFIG_NO_FORMATTING */ |
OLD | NEW |