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