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 __SOURCE_NUMPARSE_VALIDATORS_H__ 8 #define __SOURCE_NUMPARSE_VALIDATORS_H__ 9 10 #include "numparse_types.h" 11 #include "static_unicode_sets.h" 12 13 U_NAMESPACE_BEGIN 14 namespace numparse::impl { 15 16 class ValidationMatcher : public NumberParseMatcher { 17 public: match(StringSegment &,ParsedNumber &,UErrorCode &)18 bool match(StringSegment&, ParsedNumber&, UErrorCode&) const override { 19 // No-op 20 return false; 21 } 22 smokeTest(const StringSegment &)23 bool smokeTest(const StringSegment&) const override { 24 // No-op 25 return false; 26 } 27 28 void postProcess(ParsedNumber& result) const override = 0; 29 }; 30 31 32 class RequireAffixValidator : public ValidationMatcher, public UMemory { 33 public: 34 void postProcess(ParsedNumber& result) const override; 35 36 UnicodeString toString() const override; 37 }; 38 39 40 class RequireCurrencyValidator : public ValidationMatcher, public UMemory { 41 public: 42 void postProcess(ParsedNumber& result) const override; 43 44 UnicodeString toString() const override; 45 }; 46 47 48 class RequireDecimalSeparatorValidator : public ValidationMatcher, public UMemory { 49 public: 50 RequireDecimalSeparatorValidator() = default; // leaves instance in valid but undefined state 51 52 RequireDecimalSeparatorValidator(bool patternHasDecimalSeparator); 53 54 void postProcess(ParsedNumber& result) const override; 55 56 UnicodeString toString() const override; 57 58 private: 59 bool fPatternHasDecimalSeparator; 60 }; 61 62 63 class RequireNumberValidator : public ValidationMatcher, public UMemory { 64 public: 65 void postProcess(ParsedNumber& result) const override; 66 67 UnicodeString toString() const override; 68 }; 69 70 71 /** 72 * Wraps a {@link Multiplier} for use in the number parsing pipeline. 73 */ 74 class MultiplierParseHandler : public ValidationMatcher, public UMemory { 75 public: 76 MultiplierParseHandler() = default; // leaves instance in valid but undefined state 77 78 MultiplierParseHandler(::icu::number::Scale multiplier); 79 80 void postProcess(ParsedNumber& result) const override; 81 82 UnicodeString toString() const override; 83 84 private: 85 ::icu::number::Scale fMultiplier; 86 }; 87 88 } // namespace numparse::impl 89 U_NAMESPACE_END 90 91 #endif //__SOURCE_NUMPARSE_VALIDATORS_H__ 92 #endif /* #if !UCONFIG_NO_FORMATTING */ 93