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"
21 #include "string_segment.h"
25 // Export an explicit template instantiation of the MaybeStackArray that is used as a data member of NumberParserImpl.
26 // When building DLLs for Windows this is required even though no direct access to the MaybeStackArray leaks out of the i18n library.
27 // (See numparse_compositions.h, numparse_affixes.h, datefmt.h, and others for similar examples.)
28 #if U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN
29 template class U_I18N_API MaybeStackArray
<const numparse::impl::NumberParseMatcher
*, 10>;
35 // Exported as U_I18N_API for tests
36 class U_I18N_API NumberParserImpl
: public MutableMatcherCollection
, public UMemory
{
38 virtual ~NumberParserImpl();
40 static NumberParserImpl
* createSimpleParser(const Locale
& locale
, const UnicodeString
& patternString
,
41 parse_flags_t parseFlags
, UErrorCode
& status
);
43 static NumberParserImpl
* createParserFromProperties(
44 const number::impl::DecimalFormatProperties
& properties
, const DecimalFormatSymbols
& symbols
,
45 bool parseCurrency
, UErrorCode
& status
);
48 * Does NOT take ownership of the matcher. The matcher MUST remain valid for the lifespan of the
50 * @param matcher The matcher to reference.
52 void addMatcher(NumberParseMatcher
& matcher
) override
;
56 parse_flags_t
getParseFlags() const;
58 void parse(const UnicodeString
& input
, bool greedy
, ParsedNumber
& result
, UErrorCode
& status
) const;
60 void parse(const UnicodeString
& input
, int32_t start
, bool greedy
, ParsedNumber
& result
,
61 UErrorCode
& status
) const;
63 UnicodeString
toString() const;
66 parse_flags_t fParseFlags
;
67 int32_t fNumMatchers
= 0;
68 // NOTE: The stack capacity for fMatchers and fLeads should be the same
69 MaybeStackArray
<const NumberParseMatcher
*, 10> fMatchers
;
72 // WARNING: All of these matchers start in an undefined state (default-constructed).
73 // You must use an assignment operator on them before using.
75 IgnorablesMatcher ignorables
;
76 InfinityMatcher infinity
;
77 MinusSignMatcher minusSign
;
79 PaddingMatcher padding
;
80 PercentMatcher percent
;
81 PermilleMatcher permille
;
82 PlusSignMatcher plusSign
;
83 DecimalMatcher decimal
;
84 ScientificMatcher scientific
;
85 CombinedCurrencyMatcher currency
;
86 AffixMatcherWarehouse affixMatcherWarehouse
;
87 AffixTokenMatcherWarehouse affixTokenMatcherWarehouse
;
90 RequireAffixValidator affix
;
91 RequireCurrencyValidator currency
;
92 RequireDecimalSeparatorValidator decimalSeparator
;
93 RequireNumberValidator number
;
94 MultiplierParseHandler multiplier
;
97 explicit NumberParserImpl(parse_flags_t parseFlags
);
99 void parseGreedy(StringSegment
& segment
, ParsedNumber
& result
, UErrorCode
& status
) const;
101 void parseLongestRecursive(
102 StringSegment
& segment
, ParsedNumber
& result
, int32_t recursionLevels
, UErrorCode
& status
) const;
107 } // namespace numparse
110 #endif //__NUMPARSE_IMPL_H__
111 #endif /* #if !UCONFIG_NO_FORMATTING */