1 // © 2018 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 #include "unicode/utypes.h"
6 #if !UCONFIG_NO_FORMATTING
7 #ifndef __NUMPARSE_SYMBOLS_H__
8 #define __NUMPARSE_SYMBOLS_H__
10 #include "numparse_types.h"
11 #include "unicode/uniset.h"
12 #include "static_unicode_sets.h"
14 U_NAMESPACE_BEGIN
namespace numparse
{
19 * A base class for many matchers that performs a simple match against a UnicodeString and/or UnicodeSet.
23 // Exported as U_I18N_API for tests
24 class U_I18N_API SymbolMatcher
: public NumberParseMatcher
, public UMemory
{
26 SymbolMatcher() = default; // WARNING: Leaves the object in an unusable state
28 const UnicodeSet
* getSet() const;
30 bool match(StringSegment
& segment
, ParsedNumber
& result
, UErrorCode
& status
) const override
;
32 bool smokeTest(const StringSegment
& segment
) const override
;
34 UnicodeString
toString() const override
;
36 virtual bool isDisabled(const ParsedNumber
& result
) const = 0;
38 virtual void accept(StringSegment
& segment
, ParsedNumber
& result
) const = 0;
41 UnicodeString fString
;
42 const UnicodeSet
* fUniSet
; // a reference from numparse_unisets.h; never owned
44 SymbolMatcher(const UnicodeString
& symbolString
, unisets::Key key
);
48 // Exported as U_I18N_API for tests
49 class U_I18N_API IgnorablesMatcher
: public SymbolMatcher
{
51 IgnorablesMatcher() = default; // WARNING: Leaves the object in an unusable state
53 IgnorablesMatcher(unisets::Key key
);
55 bool isFlexible() const override
;
57 UnicodeString
toString() const override
;
60 bool isDisabled(const ParsedNumber
& result
) const override
;
62 void accept(StringSegment
& segment
, ParsedNumber
& result
) const override
;
66 class InfinityMatcher
: public SymbolMatcher
{
68 InfinityMatcher() = default; // WARNING: Leaves the object in an unusable state
70 InfinityMatcher(const DecimalFormatSymbols
& dfs
);
73 bool isDisabled(const ParsedNumber
& result
) const override
;
75 void accept(StringSegment
& segment
, ParsedNumber
& result
) const override
;
79 // Exported as U_I18N_API for tests
80 class U_I18N_API MinusSignMatcher
: public SymbolMatcher
{
82 MinusSignMatcher() = default; // WARNING: Leaves the object in an unusable state
84 MinusSignMatcher(const DecimalFormatSymbols
& dfs
, bool allowTrailing
);
87 bool isDisabled(const ParsedNumber
& result
) const override
;
89 void accept(StringSegment
& segment
, ParsedNumber
& result
) const override
;
96 class NanMatcher
: public SymbolMatcher
{
98 NanMatcher() = default; // WARNING: Leaves the object in an unusable state
100 NanMatcher(const DecimalFormatSymbols
& dfs
);
103 bool isDisabled(const ParsedNumber
& result
) const override
;
105 void accept(StringSegment
& segment
, ParsedNumber
& result
) const override
;
109 class PaddingMatcher
: public SymbolMatcher
{
111 PaddingMatcher() = default; // WARNING: Leaves the object in an unusable state
113 PaddingMatcher(const UnicodeString
& padString
);
115 bool isFlexible() const override
;
118 bool isDisabled(const ParsedNumber
& result
) const override
;
120 void accept(StringSegment
& segment
, ParsedNumber
& result
) const override
;
124 // Exported as U_I18N_API for tests
125 class U_I18N_API PercentMatcher
: public SymbolMatcher
{
127 PercentMatcher() = default; // WARNING: Leaves the object in an unusable state
129 PercentMatcher(const DecimalFormatSymbols
& dfs
);
132 bool isDisabled(const ParsedNumber
& result
) const override
;
134 void accept(StringSegment
& segment
, ParsedNumber
& result
) const override
;
137 // Exported as U_I18N_API for tests
138 class U_I18N_API PermilleMatcher
: public SymbolMatcher
{
140 PermilleMatcher() = default; // WARNING: Leaves the object in an unusable state
142 PermilleMatcher(const DecimalFormatSymbols
& dfs
);
145 bool isDisabled(const ParsedNumber
& result
) const override
;
147 void accept(StringSegment
& segment
, ParsedNumber
& result
) const override
;
151 // Exported as U_I18N_API for tests
152 class U_I18N_API PlusSignMatcher
: public SymbolMatcher
{
154 PlusSignMatcher() = default; // WARNING: Leaves the object in an unusable state
156 PlusSignMatcher(const DecimalFormatSymbols
& dfs
, bool allowTrailing
);
159 bool isDisabled(const ParsedNumber
& result
) const override
;
161 void accept(StringSegment
& segment
, ParsedNumber
& result
) const override
;
169 } // namespace numparse
172 #endif //__NUMPARSE_SYMBOLS_H__
173 #endif /* #if !UCONFIG_NO_FORMATTING */