quant.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. // © 2016 and later: Unicode, Inc. and others.
  2. // License & terms of use: http://www.unicode.org/copyright.html
  3. /*
  4. **********************************************************************
  5. * Copyright (C) 2001-2011, International Business Machines Corporation
  6. * and others. All Rights Reserved.
  7. **********************************************************************
  8. * Date Name Description
  9. * 07/26/01 aliu Creation.
  10. **********************************************************************
  11. */
  12. #ifndef QUANT_H
  13. #define QUANT_H
  14. #include "unicode/utypes.h"
  15. #if !UCONFIG_NO_TRANSLITERATION
  16. #include "unicode/unifunct.h"
  17. #include "unicode/unimatch.h"
  18. U_NAMESPACE_BEGIN
  19. class Quantifier : public UnicodeFunctor, public UnicodeMatcher {
  20. public:
  21. enum { MAX = 0x7FFFFFFF };
  22. Quantifier(UnicodeFunctor *adoptedMatcher,
  23. uint32_t minCount, uint32_t maxCount);
  24. Quantifier(const Quantifier& o);
  25. virtual ~Quantifier();
  26. /**
  27. * UnicodeFunctor API. Cast 'this' to a UnicodeMatcher* pointer
  28. * and return the pointer.
  29. * @return the UnicodeMatcher pointer.
  30. */
  31. virtual UnicodeMatcher* toMatcher() const override;
  32. /**
  33. * Implement UnicodeFunctor
  34. * @return a copy of the object.
  35. */
  36. virtual Quantifier* clone() const override;
  37. /**
  38. * Implement UnicodeMatcher
  39. * @param text the text to be matched
  40. * @param offset on input, the index into text at which to begin
  41. * matching. On output, the limit of the matched text. The
  42. * number of matched characters is the output value of offset
  43. * minus the input value. Offset should always point to the
  44. * HIGH SURROGATE (leading code unit) of a pair of surrogates,
  45. * both on entry and upon return.
  46. * @param limit the limit index of text to be matched. Greater
  47. * than offset for a forward direction match, less than offset for
  48. * a backward direction match. The last character to be
  49. * considered for matching will be text.charAt(limit-1) in the
  50. * forward direction or text.charAt(limit+1) in the backward
  51. * direction.
  52. * @param incremental if true, then assume further characters may
  53. * be inserted at limit and check for partial matching. Otherwise
  54. * assume the text as given is complete.
  55. * @return a match degree value indicating a full match, a partial
  56. * match, or a mismatch. If incremental is false then
  57. * U_PARTIAL_MATCH should never be returned.
  58. */
  59. virtual UMatchDegree matches(const Replaceable& text,
  60. int32_t& offset,
  61. int32_t limit,
  62. UBool incremental) override;
  63. /**
  64. * Implement UnicodeMatcher
  65. * @param result Output param to receive the pattern.
  66. * @param escapeUnprintable if True then escape the unprintable characters.
  67. * @return A reference to 'result'.
  68. */
  69. virtual UnicodeString& toPattern(UnicodeString& result,
  70. UBool escapeUnprintable = false) const override;
  71. /**
  72. * Implement UnicodeMatcher
  73. * @param v the given index value.
  74. * @return true if this rule matches the given index value.
  75. */
  76. virtual UBool matchesIndexValue(uint8_t v) const override;
  77. /**
  78. * Implement UnicodeMatcher
  79. */
  80. virtual void addMatchSetTo(UnicodeSet& toUnionTo) const override;
  81. /**
  82. * UnicodeFunctor API
  83. */
  84. virtual void setData(const TransliterationRuleData*) override;
  85. /**
  86. * ICU "poor man's RTTI", returns a UClassID for the actual class.
  87. */
  88. virtual UClassID getDynamicClassID() const override;
  89. /**
  90. * ICU "poor man's RTTI", returns a UClassID for this class.
  91. */
  92. static UClassID U_EXPORT2 getStaticClassID();
  93. private:
  94. UnicodeFunctor* matcher; // owned
  95. uint32_t minCount;
  96. uint32_t maxCount;
  97. };
  98. U_NAMESPACE_END
  99. #endif /* #if !UCONFIG_NO_TRANSLITERATION */
  100. #endif