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