LEFT | RIGHT |
(no file at all) | |
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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 parseFlags |= PARSE_FLAG_EXACT_AFFIX; | 117 parseFlags |= PARSE_FLAG_EXACT_AFFIX; |
118 } else { | 118 } else { |
119 parseFlags |= PARSE_FLAG_INCLUDE_UNPAIRED_AFFIXES; | 119 parseFlags |= PARSE_FLAG_INCLUDE_UNPAIRED_AFFIXES; |
120 } | 120 } |
121 if (grouper.getPrimary() <= 0) { | 121 if (grouper.getPrimary() <= 0) { |
122 parseFlags |= PARSE_FLAG_GROUPING_DISABLED; | 122 parseFlags |= PARSE_FLAG_GROUPING_DISABLED; |
123 } | 123 } |
124 if (parseCurrency || affixProvider->hasCurrencySign()) { | 124 if (parseCurrency || affixProvider->hasCurrencySign()) { |
125 parseFlags |= PARSE_FLAG_MONETARY_SEPARATORS; | 125 parseFlags |= PARSE_FLAG_MONETARY_SEPARATORS; |
126 } | 126 } |
| 127 if (!parseCurrency) { |
| 128 parseFlags |= PARSE_FLAG_NO_FOREIGN_CURRENCY; |
| 129 } |
127 | 130 |
128 LocalPointer<NumberParserImpl> parser(new NumberParserImpl(parseFlags)); | 131 LocalPointer<NumberParserImpl> parser(new NumberParserImpl(parseFlags)); |
129 | 132 |
130 parser->fLocalMatchers.ignorables = { | 133 parser->fLocalMatchers.ignorables = { |
131 isStrict ? unisets::STRICT_IGNORABLES : unisets::DEFAULT_IGNORABLES}
; | 134 isStrict ? unisets::STRICT_IGNORABLES : unisets::DEFAULT_IGNORABLES}
; |
132 IgnorablesMatcher& ignorables = parser->fLocalMatchers.ignorables; | 135 IgnorablesMatcher& ignorables = parser->fLocalMatchers.ignorables; |
133 | 136 |
134 ////////////////////// | 137 ////////////////////// |
135 /// AFFIX MATCHERS /// | 138 /// AFFIX MATCHERS /// |
136 ////////////////////// | 139 ////////////////////// |
137 | 140 |
138 // The following statements set up the affix matchers. | 141 // The following statements set up the affix matchers. |
139 AffixTokenMatcherSetupData affixSetupData = { | 142 AffixTokenMatcherSetupData affixSetupData = { |
140 currencySymbols, symbols, ignorables, locale}; | 143 currencySymbols, symbols, ignorables, locale, parseFlags}; |
141 parser->fLocalMatchers.affixTokenMatcherWarehouse = {&affixSetupData}; | 144 parser->fLocalMatchers.affixTokenMatcherWarehouse = {&affixSetupData}; |
142 parser->fLocalMatchers.affixMatcherWarehouse = {&parser->fLocalMatchers.affi
xTokenMatcherWarehouse}; | 145 parser->fLocalMatchers.affixMatcherWarehouse = {&parser->fLocalMatchers.affi
xTokenMatcherWarehouse}; |
143 parser->fLocalMatchers.affixMatcherWarehouse.createAffixMatchers( | 146 parser->fLocalMatchers.affixMatcherWarehouse.createAffixMatchers( |
144 *affixProvider, *parser, ignorables, parseFlags, status); | 147 *affixProvider, *parser, ignorables, parseFlags, status); |
145 | 148 |
146 //////////////////////// | 149 //////////////////////// |
147 /// CURRENCY MATCHER /// | 150 /// CURRENCY MATCHER /// |
148 //////////////////////// | 151 //////////////////////// |
149 | 152 |
150 if (parseCurrency || affixProvider->hasCurrencySign()) { | 153 if (parseCurrency || affixProvider->hasCurrencySign()) { |
151 parser->addMatcher(parser->fLocalMatchers.currency = {currencySymbols, s
ymbols, status}); | 154 parser->addMatcher(parser->fLocalMatchers.currency = {currencySymbols, s
ymbols, parseFlags, status}); |
152 } | 155 } |
153 | 156 |
154 /////////////// | 157 /////////////// |
155 /// PERCENT /// | 158 /// PERCENT /// |
156 /////////////// | 159 /////////////// |
157 | 160 |
158 // ICU-TC meeting, April 11, 2018: accept percent/permille only if it is in
the pattern, | 161 // ICU-TC meeting, April 11, 2018: accept percent/permille only if it is in
the pattern, |
159 // and to maintain regressive behavior, divide by 100 even if no percent sig
n is present. | 162 // and to maintain regressive behavior, divide by 100 even if no percent sig
n is present. |
160 if (affixProvider->containsSymbolType(AffixPatternType::TYPE_PERCENT, status
)) { | 163 if (affixProvider->containsSymbolType(AffixPatternType::TYPE_PERCENT, status
)) { |
161 parser->addMatcher(parser->fLocalMatchers.percent = {symbols}); | 164 parser->addMatcher(parser->fLocalMatchers.percent = {symbols}); |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 for (int32_t i = 0; i < fNumMatchers; i++) { | 353 for (int32_t i = 0; i < fNumMatchers; i++) { |
351 result.append(u' '); | 354 result.append(u' '); |
352 result.append(fMatchers[i]->toString()); | 355 result.append(fMatchers[i]->toString()); |
353 } | 356 } |
354 result.append(u" ]>", -1); | 357 result.append(u" ]>", -1); |
355 return result; | 358 return result; |
356 } | 359 } |
357 | 360 |
358 | 361 |
359 #endif /* #if !UCONFIG_NO_FORMATTING */ | 362 #endif /* #if !UCONFIG_NO_FORMATTING */ |
LEFT | RIGHT |