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 __NUMPARSE_DECIMAL_H__
8#define __NUMPARSE_DECIMAL_H__
9
10#include "unicode/uniset.h"
11#include "numparse_types.h"
12
13U_NAMESPACE_BEGIN namespace numparse {
14namespace impl {
15
16using ::icu::number::impl::Grouper;
17
18class DecimalMatcher : public NumberParseMatcher, public UMemory {
19 public:
20 DecimalMatcher() = default; // WARNING: Leaves the object in an unusable state
21
22 DecimalMatcher(const DecimalFormatSymbols& symbols, const Grouper& grouper,
23 parse_flags_t parseFlags);
24
25 bool match(StringSegment& segment, ParsedNumber& result, UErrorCode& status) const override;
26
27 bool
28 match(StringSegment& segment, ParsedNumber& result, int8_t exponentSign, UErrorCode& status) const;
29
30 bool smokeTest(const StringSegment& segment) const override;
31
32 UnicodeString toString() const override;
33
34 private:
35 /** If true, only accept strings whose grouping sizes match the locale */
36 bool requireGroupingMatch;
37
38 /** If true, do not accept grouping separators at all */
39 bool groupingDisabled;
40
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;
44
45 /** If true, do not accept numbers in the fraction */
46 bool integerOnly;
47
48 int16_t grouping1;
49 int16_t grouping2;
50
51 UnicodeString groupingSeparator;
52 UnicodeString decimalSeparator;
53
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;
60
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;
66
67 bool validateGroup(int32_t sepType, int32_t count, bool isPrimary) const;
68};
69
70
71} // namespace impl
72} // namespace numparse
73U_NAMESPACE_END
74
75#endif //__NUMPARSE_DECIMAL_H__
76#endif /* #if !UCONFIG_NO_FORMATTING */
77