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