numparse_decimal.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // © 2018 and later: Unicode, Inc. and others.
  2. // License & terms of use: http://www.unicode.org/copyright.html
  3. #include "unicode/utypes.h"
  4. #if !UCONFIG_NO_FORMATTING
  5. #ifndef __NUMPARSE_DECIMAL_H__
  6. #define __NUMPARSE_DECIMAL_H__
  7. #include "unicode/uniset.h"
  8. #include "numparse_types.h"
  9. U_NAMESPACE_BEGIN namespace numparse {
  10. namespace impl {
  11. using ::icu::number::impl::Grouper;
  12. class DecimalMatcher : public NumberParseMatcher, public UMemory {
  13. public:
  14. DecimalMatcher() = default; // WARNING: Leaves the object in an unusable state
  15. DecimalMatcher(const DecimalFormatSymbols& symbols, const Grouper& grouper,
  16. parse_flags_t parseFlags);
  17. bool match(StringSegment& segment, ParsedNumber& result, UErrorCode& status) const override;
  18. bool
  19. match(StringSegment& segment, ParsedNumber& result, int8_t exponentSign, UErrorCode& status) const;
  20. bool smokeTest(const StringSegment& segment) const override;
  21. UnicodeString toString() const override;
  22. private:
  23. /** If true, only accept strings whose grouping sizes match the locale */
  24. bool requireGroupingMatch;
  25. /** If true, do not accept grouping separators at all */
  26. bool groupingDisabled;
  27. // Fraction grouping parsing is disabled for now but could be enabled later.
  28. // See https://unicode-org.atlassian.net/browse/ICU-10794
  29. // bool fractionGrouping;
  30. /** If true, do not accept numbers in the fraction */
  31. bool integerOnly;
  32. int16_t grouping1;
  33. int16_t grouping2;
  34. UnicodeString groupingSeparator;
  35. UnicodeString decimalSeparator;
  36. // Assumption: these sets all consist of single code points. If this assumption needs to be broken,
  37. // fix getLeadCodePoints() as well as matching logic. Be careful of the performance impact.
  38. const UnicodeSet* groupingUniSet;
  39. const UnicodeSet* decimalUniSet;
  40. const UnicodeSet* separatorSet;
  41. const UnicodeSet* leadSet;
  42. // Make this class the owner of a few objects that could be allocated.
  43. // The first three LocalPointers are used for assigning ownership only.
  44. LocalPointer<const UnicodeSet> fLocalDecimalUniSet;
  45. LocalPointer<const UnicodeSet> fLocalSeparatorSet;
  46. LocalArray<const UnicodeString> fLocalDigitStrings;
  47. bool validateGroup(int32_t sepType, int32_t count, bool isPrimary) const;
  48. };
  49. } // namespace impl
  50. } // namespace numparse
  51. U_NAMESPACE_END
  52. #endif //__NUMPARSE_DECIMAL_H__
  53. #endif /* #if !UCONFIG_NO_FORMATTING */