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