xref: /aosp_15_r20/external/icu/libicu/cts_headers/numparse_symbols.h (revision 0e209d3975ff4a8c132096b14b0e9364a753506e)
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     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     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     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     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     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     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     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     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     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 } // namespace numparse::impl
167 U_NAMESPACE_END
168 
169 #endif //__NUMPARSE_SYMBOLS_H__
170 #endif /* #if !UCONFIG_NO_FORMATTING */
171