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_COMPOSITIONS__ 8 #define __SOURCE_NUMPARSE_COMPOSITIONS__ 9 10 #include "numparse_types.h" 11 12 U_NAMESPACE_BEGIN 13 14 // Export an explicit template instantiation of the MaybeStackArray that is used as a data member of ArraySeriesMatcher. 15 // When building DLLs for Windows this is required even though no direct access to the MaybeStackArray leaks out of the i18n library. 16 // (See digitlst.h, pluralaffix.h, datefmt.h, and others for similar examples.) 17 #if U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN 18 template class U_I18N_API MaybeStackArray<const numparse::impl::NumberParseMatcher*, 3>; 19 #endif 20 21 namespace numparse::impl { 22 23 /** 24 * Base class for AnyMatcher and SeriesMatcher. 25 */ 26 // Exported as U_I18N_API for tests 27 class U_I18N_API CompositionMatcher : public NumberParseMatcher { 28 protected: 29 // No construction except by subclasses! 30 CompositionMatcher() = default; 31 32 // To be overridden by subclasses (used for iteration): 33 virtual const NumberParseMatcher* const* begin() const = 0; 34 35 // To be overridden by subclasses (used for iteration): 36 virtual const NumberParseMatcher* const* end() const = 0; 37 }; 38 39 40 // NOTE: AnyMatcher is no longer being used. The previous definition is shown below. 41 // The implementation can be found in SVN source control, deleted around March 30, 2018. 42 ///** 43 // * Composes a number of matchers, and succeeds if any of the matchers succeed. Always greedily chooses 44 // * the first matcher in the list to succeed. 45 // * 46 // * NOTE: In C++, this is a base class, unlike ICU4J, which uses a factory-style interface. 47 // * 48 // * @author sffc 49 // * @see SeriesMatcher 50 // */ 51 //class AnyMatcher : public CompositionMatcher { 52 // public: 53 // bool match(StringSegment& segment, ParsedNumber& result, UErrorCode& status) const override; 54 // 55 // bool smokeTest(const StringSegment& segment) const override; 56 // 57 // void postProcess(ParsedNumber& result) const override; 58 // 59 // protected: 60 // // No construction except by subclasses! 61 // AnyMatcher() = default; 62 //}; 63 64 65 /** 66 * Composes a number of matchers, running one after another. Matches the input string only if all of the 67 * matchers in the series succeed. Performs greedy matches within the context of the series. 68 * 69 * @author sffc 70 * @see AnyMatcher 71 */ 72 // Exported as U_I18N_API for tests 73 class U_I18N_API SeriesMatcher : public CompositionMatcher { 74 public: 75 bool match(StringSegment& segment, ParsedNumber& result, UErrorCode& status) const override; 76 77 bool smokeTest(const StringSegment& segment) const override; 78 79 void postProcess(ParsedNumber& result) const override; 80 81 virtual int32_t length() const = 0; 82 83 protected: 84 // No construction except by subclasses! 85 SeriesMatcher() = default; 86 }; 87 88 /** 89 * An implementation of SeriesMatcher that references an array of matchers. 90 * 91 * The object adopts the array, but NOT the matchers contained inside the array. 92 */ 93 // Exported as U_I18N_API for tests 94 class U_I18N_API ArraySeriesMatcher : public SeriesMatcher { 95 public: 96 ArraySeriesMatcher(); // WARNING: Leaves the object in an unusable state 97 98 typedef MaybeStackArray<const NumberParseMatcher*, 3> MatcherArray; 99 100 /** The array is std::move'd */ 101 ArraySeriesMatcher(MatcherArray& matchers, int32_t matchersLen); 102 103 UnicodeString toString() const override; 104 105 int32_t length() const override; 106 107 protected: 108 const NumberParseMatcher* const* begin() const override; 109 110 const NumberParseMatcher* const* end() const override; 111 112 private: 113 MatcherArray fMatchers; 114 int32_t fMatchersLen; 115 }; 116 117 } // namespace numparse::impl 118 119 U_NAMESPACE_END 120 121 #endif //__SOURCE_NUMPARSE_COMPOSITIONS__ 122 #endif /* #if !UCONFIG_NO_FORMATTING */ 123