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