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