numparse_validators.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 __SOURCE_NUMPARSE_VALIDATORS_H__
  6. #define __SOURCE_NUMPARSE_VALIDATORS_H__
  7. #include "numparse_types.h"
  8. #include "static_unicode_sets.h"
  9. U_NAMESPACE_BEGIN namespace numparse {
  10. namespace impl {
  11. class ValidationMatcher : public NumberParseMatcher {
  12. public:
  13. bool match(StringSegment&, ParsedNumber&, UErrorCode&) const override {
  14. // No-op
  15. return false;
  16. }
  17. bool smokeTest(const StringSegment&) const override {
  18. // No-op
  19. return false;
  20. }
  21. void postProcess(ParsedNumber& result) const override = 0;
  22. };
  23. class RequireAffixValidator : public ValidationMatcher, public UMemory {
  24. public:
  25. void postProcess(ParsedNumber& result) const override;
  26. UnicodeString toString() const override;
  27. };
  28. class RequireCurrencyValidator : public ValidationMatcher, public UMemory {
  29. public:
  30. void postProcess(ParsedNumber& result) const override;
  31. UnicodeString toString() const override;
  32. };
  33. class RequireDecimalSeparatorValidator : public ValidationMatcher, public UMemory {
  34. public:
  35. RequireDecimalSeparatorValidator() = default; // leaves instance in valid but undefined state
  36. RequireDecimalSeparatorValidator(bool patternHasDecimalSeparator);
  37. void postProcess(ParsedNumber& result) const override;
  38. UnicodeString toString() const override;
  39. private:
  40. bool fPatternHasDecimalSeparator;
  41. };
  42. class RequireNumberValidator : public ValidationMatcher, public UMemory {
  43. public:
  44. void postProcess(ParsedNumber& result) const override;
  45. UnicodeString toString() const override;
  46. };
  47. /**
  48. * Wraps a {@link Multiplier} for use in the number parsing pipeline.
  49. */
  50. class MultiplierParseHandler : public ValidationMatcher, public UMemory {
  51. public:
  52. MultiplierParseHandler() = default; // leaves instance in valid but undefined state
  53. MultiplierParseHandler(::icu::number::Scale multiplier);
  54. void postProcess(ParsedNumber& result) const override;
  55. UnicodeString toString() const override;
  56. private:
  57. ::icu::number::Scale fMultiplier;
  58. };
  59. } // namespace impl
  60. } // namespace numparse
  61. U_NAMESPACE_END
  62. #endif //__SOURCE_NUMPARSE_VALIDATORS_H__
  63. #endif /* #if !UCONFIG_NO_FORMATTING */