/src/icu/icu4c/source/i18n/numparse_symbols.h
Line | Count | Source |
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_SYMBOLS_H__ |
8 | | #define __NUMPARSE_SYMBOLS_H__ |
9 | | |
10 | | #include "numparse_types.h" |
11 | | #include "unicode/uniset.h" |
12 | | #include "static_unicode_sets.h" |
13 | | |
14 | | U_NAMESPACE_BEGIN |
15 | | namespace numparse::impl { |
16 | | |
17 | | /** |
18 | | * A base class for many matchers that performs a simple match against a UnicodeString and/or UnicodeSet. |
19 | | * |
20 | | * @author sffc |
21 | | */ |
22 | | // Exported as U_I18N_API for tests |
23 | | class U_I18N_API SymbolMatcher : public NumberParseMatcher, public UMemory { |
24 | | public: |
25 | 1.67M | SymbolMatcher() = default; // WARNING: Leaves the object in an unusable state |
26 | | |
27 | | const UnicodeSet* getSet() const; |
28 | | |
29 | | bool match(StringSegment& segment, ParsedNumber& result, UErrorCode& status) const override; |
30 | | |
31 | | bool smokeTest(const StringSegment& segment) const override; |
32 | | |
33 | | UnicodeString toString() const override; |
34 | | |
35 | | virtual bool isDisabled(const ParsedNumber& result) const = 0; |
36 | | |
37 | | virtual void accept(StringSegment& segment, ParsedNumber& result) const = 0; |
38 | | |
39 | | protected: |
40 | | UnicodeString fString; |
41 | | const UnicodeSet* fUniSet; // a reference from numparse_unisets.h; never owned |
42 | | |
43 | | SymbolMatcher(const UnicodeString& symbolString, unisets::Key key); |
44 | | }; |
45 | | |
46 | | |
47 | | // Exported as U_I18N_API for tests |
48 | | class U_I18N_API IgnorablesMatcher : public SymbolMatcher { |
49 | | public: |
50 | 167k | IgnorablesMatcher() = default; // WARNING: Leaves the object in an unusable state |
51 | | |
52 | | IgnorablesMatcher(parse_flags_t parseFlags); |
53 | | |
54 | | bool isFlexible() const override; |
55 | | |
56 | | UnicodeString toString() const override; |
57 | | |
58 | | protected: |
59 | | bool isDisabled(const ParsedNumber& result) const override; |
60 | | |
61 | | void accept(StringSegment& segment, ParsedNumber& result) const override; |
62 | | }; |
63 | | |
64 | | |
65 | | class InfinityMatcher : public SymbolMatcher { |
66 | | public: |
67 | 83.7k | InfinityMatcher() = default; // WARNING: Leaves the object in an unusable state |
68 | | |
69 | | InfinityMatcher(const DecimalFormatSymbols& dfs); |
70 | | |
71 | | protected: |
72 | | bool isDisabled(const ParsedNumber& result) const override; |
73 | | |
74 | | void accept(StringSegment& segment, ParsedNumber& result) const override; |
75 | | }; |
76 | | |
77 | | |
78 | | // Exported as U_I18N_API for tests |
79 | | class U_I18N_API MinusSignMatcher : public SymbolMatcher { |
80 | | public: |
81 | 251k | MinusSignMatcher() = default; // WARNING: Leaves the object in an unusable state |
82 | | |
83 | | MinusSignMatcher(const DecimalFormatSymbols& dfs, bool allowTrailing); |
84 | | |
85 | | protected: |
86 | | bool isDisabled(const ParsedNumber& result) const override; |
87 | | |
88 | | void accept(StringSegment& segment, ParsedNumber& result) const override; |
89 | | |
90 | | private: |
91 | | bool fAllowTrailing; |
92 | | }; |
93 | | |
94 | | |
95 | | class NanMatcher : public SymbolMatcher { |
96 | | public: |
97 | 83.7k | NanMatcher() = default; // WARNING: Leaves the object in an unusable state |
98 | | |
99 | | NanMatcher(const DecimalFormatSymbols& dfs); |
100 | | |
101 | | protected: |
102 | | bool isDisabled(const ParsedNumber& result) const override; |
103 | | |
104 | | void accept(StringSegment& segment, ParsedNumber& result) const override; |
105 | | }; |
106 | | |
107 | | |
108 | | class PaddingMatcher : public SymbolMatcher { |
109 | | public: |
110 | 83.7k | PaddingMatcher() = default; // WARNING: Leaves the object in an unusable state |
111 | | |
112 | | PaddingMatcher(const UnicodeString& padString); |
113 | | |
114 | | bool isFlexible() const override; |
115 | | |
116 | | protected: |
117 | | bool isDisabled(const ParsedNumber& result) const override; |
118 | | |
119 | | void accept(StringSegment& segment, ParsedNumber& result) const override; |
120 | | }; |
121 | | |
122 | | |
123 | | // Exported as U_I18N_API for tests |
124 | | class U_I18N_API PercentMatcher : public SymbolMatcher { |
125 | | public: |
126 | 251k | PercentMatcher() = default; // WARNING: Leaves the object in an unusable state |
127 | | |
128 | | PercentMatcher(const DecimalFormatSymbols& dfs); |
129 | | |
130 | | protected: |
131 | | bool isDisabled(const ParsedNumber& result) const override; |
132 | | |
133 | | void accept(StringSegment& segment, ParsedNumber& result) const override; |
134 | | }; |
135 | | |
136 | | // Exported as U_I18N_API for tests |
137 | | class U_I18N_API PermilleMatcher : public SymbolMatcher { |
138 | | public: |
139 | 251k | PermilleMatcher() = default; // WARNING: Leaves the object in an unusable state |
140 | | |
141 | | PermilleMatcher(const DecimalFormatSymbols& dfs); |
142 | | |
143 | | protected: |
144 | | bool isDisabled(const ParsedNumber& result) const override; |
145 | | |
146 | | void accept(StringSegment& segment, ParsedNumber& result) const override; |
147 | | }; |
148 | | |
149 | | |
150 | | // Exported as U_I18N_API for tests |
151 | | class U_I18N_API PlusSignMatcher : public SymbolMatcher { |
152 | | public: |
153 | 251k | PlusSignMatcher() = default; // WARNING: Leaves the object in an unusable state |
154 | | |
155 | | PlusSignMatcher(const DecimalFormatSymbols& dfs, bool allowTrailing); |
156 | | |
157 | | protected: |
158 | | bool isDisabled(const ParsedNumber& result) const override; |
159 | | |
160 | | void accept(StringSegment& segment, ParsedNumber& result) const override; |
161 | | |
162 | | private: |
163 | | bool fAllowTrailing; |
164 | | }; |
165 | | |
166 | | |
167 | | // Exported as U_I18N_API for tests |
168 | | class U_I18N_API ApproximatelySignMatcher : public SymbolMatcher { |
169 | | public: |
170 | 251k | ApproximatelySignMatcher() = default; // WARNING: Leaves the object in an unusable state |
171 | | |
172 | | ApproximatelySignMatcher(const DecimalFormatSymbols& dfs, bool allowTrailing); |
173 | | |
174 | | protected: |
175 | | bool isDisabled(const ParsedNumber& result) const override; |
176 | | |
177 | | void accept(StringSegment& segment, ParsedNumber& result) const override; |
178 | | |
179 | | private: |
180 | | bool fAllowTrailing; |
181 | | }; |
182 | | |
183 | | } // namespace numparse::impl |
184 | | U_NAMESPACE_END |
185 | | |
186 | | #endif //__NUMPARSE_SYMBOLS_H__ |
187 | | #endif /* #if !UCONFIG_NO_FORMATTING */ |