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 __NUMPARSE_IMPL_H__
8 #define __NUMPARSE_IMPL_H__
10 #include "numparse_types.h"
11 #include "numparse_decimal.h"
12 #include "numparse_symbols.h"
13 #include "numparse_scientific.h"
14 #include "unicode/uniset.h"
15 #include "numparse_currency.h"
16 #include "numparse_affixes.h"
17 #include "number_decimfmtprops.h"
18 #include "unicode/localpointer.h"
19 #include "numparse_validators.h"
20 #include "number_multiplier.h"
24 // Export an explicit template instantiation of the MaybeStackArray that is used as a data member of NumberParserImpl.
25 // When building DLLs for Windows this is required even though no direct access to the MaybeStackArray leaks out of the i18n library.
26 // (See numparse_compositions.h, numparse_affixes.h, datefmt.h, and others for similar examples.)
27 #if U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN
28 template class U_I18N_API MaybeStackArray
<const numparse::impl::NumberParseMatcher
*, 10>;
34 // Exported as U_I18N_API for tests
35 class U_I18N_API NumberParserImpl
: public MutableMatcherCollection
, public UMemory
{
37 virtual ~NumberParserImpl();
39 static NumberParserImpl
* createSimpleParser(const Locale
& locale
, const UnicodeString
& patternString
,
40 parse_flags_t parseFlags
, UErrorCode
& status
);
42 static NumberParserImpl
* createParserFromProperties(
43 const number::impl::DecimalFormatProperties
& properties
, const DecimalFormatSymbols
& symbols
,
44 bool parseCurrency
, UErrorCode
& status
);
47 * Does NOT take ownership of the matcher. The matcher MUST remain valid for the lifespan of the
49 * @param matcher The matcher to reference.
51 void addMatcher(NumberParseMatcher
& matcher
) override
;
55 parse_flags_t
getParseFlags() const;
57 void parse(const UnicodeString
& input
, bool greedy
, ParsedNumber
& result
, UErrorCode
& status
) const;
59 void parse(const UnicodeString
& input
, int32_t start
, bool greedy
, ParsedNumber
& result
,
60 UErrorCode
& status
) const;
62 UnicodeString
toString() const;
65 parse_flags_t fParseFlags
;
66 int32_t fNumMatchers
= 0;
67 // NOTE: The stack capacity for fMatchers and fLeads should be the same
68 MaybeStackArray
<const NumberParseMatcher
*, 10> fMatchers
;
71 // WARNING: All of these matchers start in an undefined state (default-constructed).
72 // You must use an assignment operator on them before using.
74 IgnorablesMatcher ignorables
;
75 InfinityMatcher infinity
;
76 MinusSignMatcher minusSign
;
78 PaddingMatcher padding
;
79 PercentMatcher percent
;
80 PermilleMatcher permille
;
81 PlusSignMatcher plusSign
;
82 DecimalMatcher decimal
;
83 ScientificMatcher scientific
;
84 CombinedCurrencyMatcher currency
;
85 AffixMatcherWarehouse affixMatcherWarehouse
;
86 AffixTokenMatcherWarehouse affixTokenMatcherWarehouse
;
89 RequireAffixValidator affix
;
90 RequireCurrencyValidator currency
;
91 RequireDecimalSeparatorValidator decimalSeparator
;
92 RequireNumberValidator number
;
93 MultiplierParseHandler multiplier
;
96 explicit NumberParserImpl(parse_flags_t parseFlags
);
98 void parseGreedy(StringSegment
& segment
, ParsedNumber
& result
, UErrorCode
& status
) const;
100 void parseLongestRecursive(
101 StringSegment
& segment
, ParsedNumber
& result
, int32_t recursionLevels
, UErrorCode
& status
) const;
106 } // namespace numparse
109 #endif //__NUMPARSE_IMPL_H__
110 #endif /* #if !UCONFIG_NO_FORMATTING */