]> git.saurik.com Git - apple/icu.git/blob - icuSources/i18n/numparse_impl.h
ICU-62141.0.1.tar.gz
[apple/icu.git] / icuSources / i18n / numparse_impl.h
1 // © 2018 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3
4 #include "unicode/utypes.h"
5
6 #if !UCONFIG_NO_FORMATTING
7 #ifndef __NUMPARSE_IMPL_H__
8 #define __NUMPARSE_IMPL_H__
9
10 #include "numparse_types.h"
11 #include "numparse_decimal.h"
12 #include "numparse_symbols.h"
13 #include "numparse_scientific.h"
14 #include "unicode/uniset.h"
15 #include "numparse_currency.h"
16 #include "numparse_affixes.h"
17 #include "number_decimfmtprops.h"
18 #include "unicode/localpointer.h"
19 #include "numparse_validators.h"
20 #include "number_multiplier.h"
21
22 U_NAMESPACE_BEGIN
23
24 // Export an explicit template instantiation of the MaybeStackArray that is used as a data member of NumberParserImpl.
25 // When building DLLs for Windows this is required even though no direct access to the MaybeStackArray leaks out of the i18n library.
26 // (See numparse_compositions.h, numparse_affixes.h, datefmt.h, and others for similar examples.)
27 #if U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN
28 template class U_I18N_API MaybeStackArray<const numparse::impl::NumberParseMatcher*, 10>;
29 #endif
30
31 namespace numparse {
32 namespace impl {
33
34 // Exported as U_I18N_API for tests
35 class U_I18N_API NumberParserImpl : public MutableMatcherCollection, public UMemory {
36 public:
37 virtual ~NumberParserImpl();
38
39 static NumberParserImpl* createSimpleParser(const Locale& locale, const UnicodeString& patternString,
40 parse_flags_t parseFlags, UErrorCode& status);
41
42 static NumberParserImpl* createParserFromProperties(
43 const number::impl::DecimalFormatProperties& properties, const DecimalFormatSymbols& symbols,
44 bool parseCurrency, UErrorCode& status);
45
46 /**
47 * Does NOT take ownership of the matcher. The matcher MUST remain valid for the lifespan of the
48 * NumberParserImpl.
49 * @param matcher The matcher to reference.
50 */
51 void addMatcher(NumberParseMatcher& matcher) override;
52
53 void freeze();
54
55 parse_flags_t getParseFlags() const;
56
57 void parse(const UnicodeString& input, bool greedy, ParsedNumber& result, UErrorCode& status) const;
58
59 void parse(const UnicodeString& input, int32_t start, bool greedy, ParsedNumber& result,
60 UErrorCode& status) const;
61
62 UnicodeString toString() const;
63
64 private:
65 parse_flags_t fParseFlags;
66 int32_t fNumMatchers = 0;
67 // NOTE: The stack capacity for fMatchers and fLeads should be the same
68 MaybeStackArray<const NumberParseMatcher*, 10> fMatchers;
69 bool fFrozen = false;
70
71 // WARNING: All of these matchers start in an undefined state (default-constructed).
72 // You must use an assignment operator on them before using.
73 struct {
74 IgnorablesMatcher ignorables;
75 InfinityMatcher infinity;
76 MinusSignMatcher minusSign;
77 NanMatcher nan;
78 PaddingMatcher padding;
79 PercentMatcher percent;
80 PermilleMatcher permille;
81 PlusSignMatcher plusSign;
82 DecimalMatcher decimal;
83 ScientificMatcher scientific;
84 CombinedCurrencyMatcher currency;
85 AffixMatcherWarehouse affixMatcherWarehouse;
86 AffixTokenMatcherWarehouse affixTokenMatcherWarehouse;
87 } fLocalMatchers;
88 struct {
89 RequireAffixValidator affix;
90 RequireCurrencyValidator currency;
91 RequireDecimalSeparatorValidator decimalSeparator;
92 RequireNumberValidator number;
93 MultiplierParseHandler multiplier;
94 } fLocalValidators;
95
96 explicit NumberParserImpl(parse_flags_t parseFlags);
97
98 void parseGreedyRecursive(StringSegment& segment, ParsedNumber& result, UErrorCode& status) const;
99
100 void parseLongestRecursive(StringSegment& segment, ParsedNumber& result, UErrorCode& status) const;
101 };
102
103
104 } // namespace impl
105 } // namespace numparse
106 U_NAMESPACE_END
107
108 #endif //__NUMPARSE_IMPL_H__
109 #endif /* #if !UCONFIG_NO_FORMATTING */