numparse_symbols.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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_SYMBOLS_H__
  6. #define __NUMPARSE_SYMBOLS_H__
  7. #include "numparse_types.h"
  8. #include "unicode/uniset.h"
  9. #include "static_unicode_sets.h"
  10. U_NAMESPACE_BEGIN namespace numparse {
  11. namespace impl {
  12. /**
  13. * A base class for many matchers that performs a simple match against a UnicodeString and/or UnicodeSet.
  14. *
  15. * @author sffc
  16. */
  17. // Exported as U_I18N_API for tests
  18. class U_I18N_API SymbolMatcher : public NumberParseMatcher, public UMemory {
  19. public:
  20. SymbolMatcher() = default; // WARNING: Leaves the object in an unusable state
  21. const UnicodeSet* getSet() const;
  22. bool match(StringSegment& segment, ParsedNumber& result, UErrorCode& status) const override;
  23. bool smokeTest(const StringSegment& segment) const override;
  24. UnicodeString toString() const override;
  25. virtual bool isDisabled(const ParsedNumber& result) const = 0;
  26. virtual void accept(StringSegment& segment, ParsedNumber& result) const = 0;
  27. protected:
  28. UnicodeString fString;
  29. const UnicodeSet* fUniSet; // a reference from numparse_unisets.h; never owned
  30. SymbolMatcher(const UnicodeString& symbolString, unisets::Key key);
  31. };
  32. // Exported as U_I18N_API for tests
  33. class U_I18N_API IgnorablesMatcher : public SymbolMatcher {
  34. public:
  35. IgnorablesMatcher() = default; // WARNING: Leaves the object in an unusable state
  36. IgnorablesMatcher(parse_flags_t parseFlags);
  37. bool isFlexible() const override;
  38. UnicodeString toString() const override;
  39. protected:
  40. bool isDisabled(const ParsedNumber& result) const override;
  41. void accept(StringSegment& segment, ParsedNumber& result) const override;
  42. };
  43. class InfinityMatcher : public SymbolMatcher {
  44. public:
  45. InfinityMatcher() = default; // WARNING: Leaves the object in an unusable state
  46. InfinityMatcher(const DecimalFormatSymbols& dfs);
  47. protected:
  48. bool isDisabled(const ParsedNumber& result) const override;
  49. void accept(StringSegment& segment, ParsedNumber& result) const override;
  50. };
  51. // Exported as U_I18N_API for tests
  52. class U_I18N_API MinusSignMatcher : public SymbolMatcher {
  53. public:
  54. MinusSignMatcher() = default; // WARNING: Leaves the object in an unusable state
  55. MinusSignMatcher(const DecimalFormatSymbols& dfs, bool allowTrailing);
  56. protected:
  57. bool isDisabled(const ParsedNumber& result) const override;
  58. void accept(StringSegment& segment, ParsedNumber& result) const override;
  59. private:
  60. bool fAllowTrailing;
  61. };
  62. class NanMatcher : public SymbolMatcher {
  63. public:
  64. NanMatcher() = default; // WARNING: Leaves the object in an unusable state
  65. NanMatcher(const DecimalFormatSymbols& dfs);
  66. protected:
  67. bool isDisabled(const ParsedNumber& result) const override;
  68. void accept(StringSegment& segment, ParsedNumber& result) const override;
  69. };
  70. class PaddingMatcher : public SymbolMatcher {
  71. public:
  72. PaddingMatcher() = default; // WARNING: Leaves the object in an unusable state
  73. PaddingMatcher(const UnicodeString& padString);
  74. bool isFlexible() const override;
  75. protected:
  76. bool isDisabled(const ParsedNumber& result) const override;
  77. void accept(StringSegment& segment, ParsedNumber& result) const override;
  78. };
  79. // Exported as U_I18N_API for tests
  80. class U_I18N_API PercentMatcher : public SymbolMatcher {
  81. public:
  82. PercentMatcher() = default; // WARNING: Leaves the object in an unusable state
  83. PercentMatcher(const DecimalFormatSymbols& dfs);
  84. protected:
  85. bool isDisabled(const ParsedNumber& result) const override;
  86. void accept(StringSegment& segment, ParsedNumber& result) const override;
  87. };
  88. // Exported as U_I18N_API for tests
  89. class U_I18N_API PermilleMatcher : public SymbolMatcher {
  90. public:
  91. PermilleMatcher() = default; // WARNING: Leaves the object in an unusable state
  92. PermilleMatcher(const DecimalFormatSymbols& dfs);
  93. protected:
  94. bool isDisabled(const ParsedNumber& result) const override;
  95. void accept(StringSegment& segment, ParsedNumber& result) const override;
  96. };
  97. // Exported as U_I18N_API for tests
  98. class U_I18N_API PlusSignMatcher : public SymbolMatcher {
  99. public:
  100. PlusSignMatcher() = default; // WARNING: Leaves the object in an unusable state
  101. PlusSignMatcher(const DecimalFormatSymbols& dfs, bool allowTrailing);
  102. protected:
  103. bool isDisabled(const ParsedNumber& result) const override;
  104. void accept(StringSegment& segment, ParsedNumber& result) const override;
  105. private:
  106. bool fAllowTrailing;
  107. };
  108. } // namespace impl
  109. } // namespace numparse
  110. U_NAMESPACE_END
  111. #endif //__NUMPARSE_SYMBOLS_H__
  112. #endif /* #if !UCONFIG_NO_FORMATTING */