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_DECIMAL_H__
8 #define __NUMPARSE_DECIMAL_H__
10 #include "unicode/uniset.h"
11 #include "numparse_types.h"
13 U_NAMESPACE_BEGIN
namespace numparse
{
16 using ::icu::number::impl::Grouper
;
18 class DecimalMatcher
: public NumberParseMatcher
, public UMemory
{
20 DecimalMatcher() = default; // WARNING: Leaves the object in an unusable state
22 DecimalMatcher(const DecimalFormatSymbols
& symbols
, const Grouper
& grouper
,
23 parse_flags_t parseFlags
);
25 bool match(StringSegment
& segment
, ParsedNumber
& result
, UErrorCode
& status
) const override
;
28 match(StringSegment
& segment
, ParsedNumber
& result
, int8_t exponentSign
, UErrorCode
& status
) const;
30 bool smokeTest(const StringSegment
& segment
) const override
;
32 UnicodeString
toString() const override
;
35 /** If true, only accept strings whose grouping sizes match the locale */
36 bool requireGroupingMatch
;
38 /** If true, do not accept grouping separators at all */
39 bool groupingDisabled
;
41 // Fraction grouping parsing is disabled for now but could be enabled later.
42 // See http://bugs.icu-project.org/trac/ticket/10794
43 // bool fractionGrouping;
45 /** If true, do not accept numbers in the fraction */
51 UnicodeString groupingSeparator
;
52 UnicodeString decimalSeparator
;
54 // Assumption: these sets all consist of single code points. If this assumption needs to be broken,
55 // fix getLeadCodePoints() as well as matching logic. Be careful of the performance impact.
56 const UnicodeSet
* groupingUniSet
;
57 const UnicodeSet
* decimalUniSet
;
58 const UnicodeSet
* separatorSet
;
59 const UnicodeSet
* leadSet
;
61 // Make this class the owner of a few objects that could be allocated.
62 // The first three LocalPointers are used for assigning ownership only.
63 LocalPointer
<const UnicodeSet
> fLocalDecimalUniSet
;
64 LocalPointer
<const UnicodeSet
> fLocalSeparatorSet
;
65 LocalArray
<const UnicodeString
> fLocalDigitStrings
;
67 bool validateGroup(int32_t sepType
, int32_t count
, bool isPrimary
) const;
72 } // namespace numparse
75 #endif //__NUMPARSE_DECIMAL_H__
76 #endif /* #if !UCONFIG_NO_FORMATTING */