2018-02-08 08:49:50 +00:00
|
|
|
// © 2018 and later: Unicode, Inc. and others.
|
|
|
|
// License & terms of use: http://www.unicode.org/copyright.html
|
|
|
|
|
|
|
|
#include "unicode/utypes.h"
|
|
|
|
|
2018-04-23 23:02:26 +00:00
|
|
|
#if !UCONFIG_NO_FORMATTING
|
2018-02-08 08:49:50 +00:00
|
|
|
#ifndef __NUMPARSE_DECIMAL_H__
|
|
|
|
#define __NUMPARSE_DECIMAL_H__
|
|
|
|
|
|
|
|
#include "unicode/uniset.h"
|
|
|
|
#include "numparse_types.h"
|
|
|
|
|
|
|
|
U_NAMESPACE_BEGIN namespace numparse {
|
|
|
|
namespace impl {
|
|
|
|
|
|
|
|
using ::icu::number::impl::Grouper;
|
|
|
|
|
|
|
|
class DecimalMatcher : public NumberParseMatcher, public UMemory {
|
|
|
|
public:
|
2018-02-09 05:47:49 +00:00
|
|
|
DecimalMatcher() = default; // WARNING: Leaves the object in an unusable state
|
|
|
|
|
2018-02-08 08:49:50 +00:00
|
|
|
DecimalMatcher(const DecimalFormatSymbols& symbols, const Grouper& grouper,
|
|
|
|
parse_flags_t parseFlags);
|
|
|
|
|
|
|
|
bool match(StringSegment& segment, ParsedNumber& result, UErrorCode& status) const override;
|
|
|
|
|
|
|
|
bool
|
|
|
|
match(StringSegment& segment, ParsedNumber& result, int8_t exponentSign, UErrorCode& status) const;
|
|
|
|
|
2018-03-21 06:30:29 +00:00
|
|
|
bool smokeTest(const StringSegment& segment) const override;
|
2018-02-08 08:49:50 +00:00
|
|
|
|
2018-02-13 02:23:52 +00:00
|
|
|
UnicodeString toString() const override;
|
|
|
|
|
2018-02-08 08:49:50 +00:00
|
|
|
private:
|
|
|
|
/** If true, only accept strings whose grouping sizes match the locale */
|
|
|
|
bool requireGroupingMatch;
|
|
|
|
|
|
|
|
/** If true, do not accept grouping separators at all */
|
|
|
|
bool groupingDisabled;
|
|
|
|
|
2018-05-22 02:46:49 +00:00
|
|
|
// Fraction grouping parsing is disabled for now but could be enabled later.
|
|
|
|
// See http://bugs.icu-project.org/trac/ticket/10794
|
|
|
|
// bool fractionGrouping;
|
2018-02-08 08:49:50 +00:00
|
|
|
|
|
|
|
/** If true, do not accept numbers in the fraction */
|
|
|
|
bool integerOnly;
|
|
|
|
|
|
|
|
int16_t grouping1;
|
|
|
|
int16_t grouping2;
|
|
|
|
|
|
|
|
UnicodeString groupingSeparator;
|
|
|
|
UnicodeString decimalSeparator;
|
|
|
|
|
|
|
|
// Assumption: these sets all consist of single code points. If this assumption needs to be broken,
|
|
|
|
// fix getLeadCodePoints() as well as matching logic. Be careful of the performance impact.
|
|
|
|
const UnicodeSet* groupingUniSet;
|
|
|
|
const UnicodeSet* decimalUniSet;
|
|
|
|
const UnicodeSet* separatorSet;
|
|
|
|
const UnicodeSet* leadSet;
|
|
|
|
|
|
|
|
// Make this class the owner of a few objects that could be allocated.
|
2018-02-10 06:36:07 +00:00
|
|
|
// The first three LocalPointers are used for assigning ownership only.
|
2018-02-08 08:49:50 +00:00
|
|
|
LocalPointer<const UnicodeSet> fLocalDecimalUniSet;
|
|
|
|
LocalPointer<const UnicodeSet> fLocalSeparatorSet;
|
|
|
|
LocalArray<const UnicodeString> fLocalDigitStrings;
|
2018-05-22 02:46:49 +00:00
|
|
|
|
|
|
|
bool validateGroup(int32_t sepType, int32_t count, bool isPrimary) const;
|
2018-02-08 08:49:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace impl
|
|
|
|
} // namespace numparse
|
|
|
|
U_NAMESPACE_END
|
|
|
|
|
|
|
|
#endif //__NUMPARSE_DECIMAL_H__
|
|
|
|
#endif /* #if !UCONFIG_NO_FORMATTING */
|