sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (C) 2001-2005, International Business Machines Corporation and others. All Rights Reserved.
|
sl@0
|
3 |
**********************************************************************
|
sl@0
|
4 |
* Date Name Description
|
sl@0
|
5 |
* 07/18/01 aliu Creation.
|
sl@0
|
6 |
**********************************************************************
|
sl@0
|
7 |
*/
|
sl@0
|
8 |
#ifndef UNIMATCH_H
|
sl@0
|
9 |
#define UNIMATCH_H
|
sl@0
|
10 |
|
sl@0
|
11 |
#include "unicode/utypes.h"
|
sl@0
|
12 |
|
sl@0
|
13 |
/**
|
sl@0
|
14 |
* \file
|
sl@0
|
15 |
* \brief C++ API: Unicode Matcher
|
sl@0
|
16 |
*/
|
sl@0
|
17 |
|
sl@0
|
18 |
|
sl@0
|
19 |
U_NAMESPACE_BEGIN
|
sl@0
|
20 |
|
sl@0
|
21 |
class Replaceable;
|
sl@0
|
22 |
class UnicodeString;
|
sl@0
|
23 |
class UnicodeSet;
|
sl@0
|
24 |
|
sl@0
|
25 |
/**
|
sl@0
|
26 |
* Constants returned by <code>UnicodeMatcher::matches()</code>
|
sl@0
|
27 |
* indicating the degree of match.
|
sl@0
|
28 |
* @stable ICU 2.4
|
sl@0
|
29 |
*/
|
sl@0
|
30 |
enum UMatchDegree {
|
sl@0
|
31 |
/**
|
sl@0
|
32 |
* Constant returned by <code>matches()</code> indicating a
|
sl@0
|
33 |
* mismatch between the text and this matcher. The text contains
|
sl@0
|
34 |
* a character which does not match, or the text does not contain
|
sl@0
|
35 |
* all desired characters for a non-incremental match.
|
sl@0
|
36 |
* @stable ICU 2.4
|
sl@0
|
37 |
*/
|
sl@0
|
38 |
U_MISMATCH,
|
sl@0
|
39 |
|
sl@0
|
40 |
/**
|
sl@0
|
41 |
* Constant returned by <code>matches()</code> indicating a
|
sl@0
|
42 |
* partial match between the text and this matcher. This value is
|
sl@0
|
43 |
* only returned for incremental match operations. All characters
|
sl@0
|
44 |
* of the text match, but more characters are required for a
|
sl@0
|
45 |
* complete match. Alternatively, for variable-length matchers,
|
sl@0
|
46 |
* all characters of the text match, and if more characters were
|
sl@0
|
47 |
* supplied at limit, they might also match.
|
sl@0
|
48 |
* @stable ICU 2.4
|
sl@0
|
49 |
*/
|
sl@0
|
50 |
U_PARTIAL_MATCH,
|
sl@0
|
51 |
|
sl@0
|
52 |
/**
|
sl@0
|
53 |
* Constant returned by <code>matches()</code> indicating a
|
sl@0
|
54 |
* complete match between the text and this matcher. For an
|
sl@0
|
55 |
* incremental variable-length match, this value is returned if
|
sl@0
|
56 |
* the given text matches, and it is known that additional
|
sl@0
|
57 |
* characters would not alter the extent of the match.
|
sl@0
|
58 |
* @stable ICU 2.4
|
sl@0
|
59 |
*/
|
sl@0
|
60 |
U_MATCH
|
sl@0
|
61 |
};
|
sl@0
|
62 |
|
sl@0
|
63 |
/**
|
sl@0
|
64 |
* <code>UnicodeMatcher</code> defines a protocol for objects that can
|
sl@0
|
65 |
* match a range of characters in a Replaceable string.
|
sl@0
|
66 |
* @stable ICU 2.4
|
sl@0
|
67 |
*/
|
sl@0
|
68 |
class U_COMMON_API UnicodeMatcher /* not : public UObject because this is an interface/mixin class */ {
|
sl@0
|
69 |
|
sl@0
|
70 |
public:
|
sl@0
|
71 |
/**
|
sl@0
|
72 |
* Destructor.
|
sl@0
|
73 |
* @stable ICU 2.4
|
sl@0
|
74 |
*/
|
sl@0
|
75 |
virtual ~UnicodeMatcher();
|
sl@0
|
76 |
|
sl@0
|
77 |
/**
|
sl@0
|
78 |
* Return a UMatchDegree value indicating the degree of match for
|
sl@0
|
79 |
* the given text at the given offset. Zero, one, or more
|
sl@0
|
80 |
* characters may be matched.
|
sl@0
|
81 |
*
|
sl@0
|
82 |
* Matching in the forward direction is indicated by limit >
|
sl@0
|
83 |
* offset. Characters from offset forwards to limit-1 will be
|
sl@0
|
84 |
* considered for matching.
|
sl@0
|
85 |
*
|
sl@0
|
86 |
* Matching in the reverse direction is indicated by limit <
|
sl@0
|
87 |
* offset. Characters from offset backwards to limit+1 will be
|
sl@0
|
88 |
* considered for matching.
|
sl@0
|
89 |
*
|
sl@0
|
90 |
* If limit == offset then the only match possible is a zero
|
sl@0
|
91 |
* character match (which subclasses may implement if desired).
|
sl@0
|
92 |
*
|
sl@0
|
93 |
* As a side effect, advance the offset parameter to the limit of
|
sl@0
|
94 |
* the matched substring. In the forward direction, this will be
|
sl@0
|
95 |
* the index of the last matched character plus one. In the
|
sl@0
|
96 |
* reverse direction, this will be the index of the last matched
|
sl@0
|
97 |
* character minus one.
|
sl@0
|
98 |
*
|
sl@0
|
99 |
* <p>Note: This method is not const because some classes may
|
sl@0
|
100 |
* modify their state as the result of a match.
|
sl@0
|
101 |
*
|
sl@0
|
102 |
* @param text the text to be matched
|
sl@0
|
103 |
* @param offset on input, the index into text at which to begin
|
sl@0
|
104 |
* matching. On output, the limit of the matched text. The
|
sl@0
|
105 |
* number of matched characters is the output value of offset
|
sl@0
|
106 |
* minus the input value. Offset should always point to the
|
sl@0
|
107 |
* HIGH SURROGATE (leading code unit) of a pair of surrogates,
|
sl@0
|
108 |
* both on entry and upon return.
|
sl@0
|
109 |
* @param limit the limit index of text to be matched. Greater
|
sl@0
|
110 |
* than offset for a forward direction match, less than offset for
|
sl@0
|
111 |
* a backward direction match. The last character to be
|
sl@0
|
112 |
* considered for matching will be text.charAt(limit-1) in the
|
sl@0
|
113 |
* forward direction or text.charAt(limit+1) in the backward
|
sl@0
|
114 |
* direction.
|
sl@0
|
115 |
* @param incremental if TRUE, then assume further characters may
|
sl@0
|
116 |
* be inserted at limit and check for partial matching. Otherwise
|
sl@0
|
117 |
* assume the text as given is complete.
|
sl@0
|
118 |
* @return a match degree value indicating a full match, a partial
|
sl@0
|
119 |
* match, or a mismatch. If incremental is FALSE then
|
sl@0
|
120 |
* U_PARTIAL_MATCH should never be returned.
|
sl@0
|
121 |
* @stable ICU 2.4
|
sl@0
|
122 |
*/
|
sl@0
|
123 |
virtual UMatchDegree matches(const Replaceable& text,
|
sl@0
|
124 |
int32_t& offset,
|
sl@0
|
125 |
int32_t limit,
|
sl@0
|
126 |
UBool incremental) = 0;
|
sl@0
|
127 |
|
sl@0
|
128 |
/**
|
sl@0
|
129 |
* Returns a string representation of this matcher. If the result of
|
sl@0
|
130 |
* calling this function is passed to the appropriate parser, it
|
sl@0
|
131 |
* will produce another matcher that is equal to this one.
|
sl@0
|
132 |
* @param result the string to receive the pattern. Previous
|
sl@0
|
133 |
* contents will be deleted.
|
sl@0
|
134 |
* @param escapeUnprintable if TRUE then convert unprintable
|
sl@0
|
135 |
* character to their hex escape representations, \\uxxxx or
|
sl@0
|
136 |
* \\Uxxxxxxxx. Unprintable characters are those other than
|
sl@0
|
137 |
* U+000A, U+0020..U+007E.
|
sl@0
|
138 |
* @stable ICU 2.4
|
sl@0
|
139 |
*/
|
sl@0
|
140 |
virtual UnicodeString& toPattern(UnicodeString& result,
|
sl@0
|
141 |
UBool escapeUnprintable = FALSE) const = 0;
|
sl@0
|
142 |
|
sl@0
|
143 |
/**
|
sl@0
|
144 |
* Returns TRUE if this matcher will match a character c, where c
|
sl@0
|
145 |
* & 0xFF == v, at offset, in the forward direction (with limit >
|
sl@0
|
146 |
* offset). This is used by <tt>RuleBasedTransliterator</tt> for
|
sl@0
|
147 |
* indexing.
|
sl@0
|
148 |
* @stable ICU 2.4
|
sl@0
|
149 |
*/
|
sl@0
|
150 |
virtual UBool matchesIndexValue(uint8_t v) const = 0;
|
sl@0
|
151 |
|
sl@0
|
152 |
/**
|
sl@0
|
153 |
* Union the set of all characters that may be matched by this object
|
sl@0
|
154 |
* into the given set.
|
sl@0
|
155 |
* @param toUnionTo the set into which to union the source characters
|
sl@0
|
156 |
* @stable ICU 2.4
|
sl@0
|
157 |
*/
|
sl@0
|
158 |
virtual void addMatchSetTo(UnicodeSet& toUnionTo) const = 0;
|
sl@0
|
159 |
};
|
sl@0
|
160 |
|
sl@0
|
161 |
U_NAMESPACE_END
|
sl@0
|
162 |
|
sl@0
|
163 |
#endif
|