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 __SOURCE_NUMPARSE_COMPOSITIONS__
8 #define __SOURCE_NUMPARSE_COMPOSITIONS__
10 #include "numparse_types.h"
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>;
25 * Base class for AnyMatcher and SeriesMatcher.
27 // Exported as U_I18N_API for tests
28 class U_I18N_API CompositionMatcher
: public NumberParseMatcher
{
30 // No construction except by subclasses!
31 CompositionMatcher() = default;
33 // To be overridden by subclasses (used for iteration):
34 virtual const NumberParseMatcher
* const* begin() const = 0;
36 // To be overridden by subclasses (used for iteration):
37 virtual const NumberParseMatcher
* const* end() const = 0;
41 // NOTE: AnyMatcher is no longer being used. The previous definition is shown below.
42 // The implementation can be found in SVN source control, deleted around March 30, 2018.
44 // * Composes a number of matchers, and succeeds if any of the matchers succeed. Always greedily chooses
45 // * the first matcher in the list to succeed.
47 // * NOTE: In C++, this is a base class, unlike ICU4J, which uses a factory-style interface.
50 // * @see SeriesMatcher
52 //class AnyMatcher : public CompositionMatcher {
54 // bool match(StringSegment& segment, ParsedNumber& result, UErrorCode& status) const override;
56 // bool smokeTest(const StringSegment& segment) const override;
58 // void postProcess(ParsedNumber& result) const override;
61 // // No construction except by subclasses!
62 // AnyMatcher() = default;
67 * Composes a number of matchers, running one after another. Matches the input string only if all of the
68 * matchers in the series succeed. Performs greedy matches within the context of the series.
73 // Exported as U_I18N_API for tests
74 class U_I18N_API SeriesMatcher
: public CompositionMatcher
{
76 bool match(StringSegment
& segment
, ParsedNumber
& result
, UErrorCode
& status
) const override
;
78 bool smokeTest(const StringSegment
& segment
) const override
;
80 void postProcess(ParsedNumber
& result
) const override
;
82 virtual int32_t length() const = 0;
85 // No construction except by subclasses!
86 SeriesMatcher() = default;
90 * An implementation of SeriesMatcher that references an array of matchers.
92 * The object adopts the array, but NOT the matchers contained inside the array.
94 // Exported as U_I18N_API for tests
95 class U_I18N_API ArraySeriesMatcher
: public SeriesMatcher
{
97 ArraySeriesMatcher(); // WARNING: Leaves the object in an unusable state
99 typedef MaybeStackArray
<const NumberParseMatcher
*, 3> MatcherArray
;
101 /** The array is std::move'd */
102 ArraySeriesMatcher(MatcherArray
& matchers
, int32_t matchersLen
);
104 UnicodeString
toString() const override
;
106 int32_t length() const override
;
109 const NumberParseMatcher
* const* begin() const override
;
111 const NumberParseMatcher
* const* end() const override
;
114 MatcherArray fMatchers
;
115 int32_t fMatchersLen
;
120 } // namespace numparse
123 #endif //__SOURCE_NUMPARSE_COMPOSITIONS__
124 #endif /* #if !UCONFIG_NO_FORMATTING */