2 * Copyright (C) 2001-2005, International Business Machines Corporation and others. All Rights Reserved.
3 **********************************************************************
4 * Date Name Description
5 * 07/18/01 aliu Creation.
6 **********************************************************************
11 #include "unicode/utypes.h"
15 * \brief C++ API: Unicode Matcher
26 * Constants returned by <code>UnicodeMatcher::matches()</code>
27 * indicating the degree of match.
32 * Constant returned by <code>matches()</code> indicating a
33 * mismatch between the text and this matcher. The text contains
34 * a character which does not match, or the text does not contain
35 * all desired characters for a non-incremental match.
41 * Constant returned by <code>matches()</code> indicating a
42 * partial match between the text and this matcher. This value is
43 * only returned for incremental match operations. All characters
44 * of the text match, but more characters are required for a
45 * complete match. Alternatively, for variable-length matchers,
46 * all characters of the text match, and if more characters were
47 * supplied at limit, they might also match.
53 * Constant returned by <code>matches()</code> indicating a
54 * complete match between the text and this matcher. For an
55 * incremental variable-length match, this value is returned if
56 * the given text matches, and it is known that additional
57 * characters would not alter the extent of the match.
64 * <code>UnicodeMatcher</code> defines a protocol for objects that can
65 * match a range of characters in a Replaceable string.
68 class U_COMMON_API UnicodeMatcher
/* not : public UObject because this is an interface/mixin class */ {
75 virtual ~UnicodeMatcher();
78 * Return a UMatchDegree value indicating the degree of match for
79 * the given text at the given offset. Zero, one, or more
80 * characters may be matched.
82 * Matching in the forward direction is indicated by limit >
83 * offset. Characters from offset forwards to limit-1 will be
84 * considered for matching.
86 * Matching in the reverse direction is indicated by limit <
87 * offset. Characters from offset backwards to limit+1 will be
88 * considered for matching.
90 * If limit == offset then the only match possible is a zero
91 * character match (which subclasses may implement if desired).
93 * As a side effect, advance the offset parameter to the limit of
94 * the matched substring. In the forward direction, this will be
95 * the index of the last matched character plus one. In the
96 * reverse direction, this will be the index of the last matched
97 * character minus one.
99 * <p>Note: This method is not const because some classes may
100 * modify their state as the result of a match.
102 * @param text the text to be matched
103 * @param offset on input, the index into text at which to begin
104 * matching. On output, the limit of the matched text. The
105 * number of matched characters is the output value of offset
106 * minus the input value. Offset should always point to the
107 * HIGH SURROGATE (leading code unit) of a pair of surrogates,
108 * both on entry and upon return.
109 * @param limit the limit index of text to be matched. Greater
110 * than offset for a forward direction match, less than offset for
111 * a backward direction match. The last character to be
112 * considered for matching will be text.charAt(limit-1) in the
113 * forward direction or text.charAt(limit+1) in the backward
115 * @param incremental if TRUE, then assume further characters may
116 * be inserted at limit and check for partial matching. Otherwise
117 * assume the text as given is complete.
118 * @return a match degree value indicating a full match, a partial
119 * match, or a mismatch. If incremental is FALSE then
120 * U_PARTIAL_MATCH should never be returned.
123 virtual UMatchDegree
matches(const Replaceable
& text
,
126 UBool incremental
) = 0;
129 * Returns a string representation of this matcher. If the result of
130 * calling this function is passed to the appropriate parser, it
131 * will produce another matcher that is equal to this one.
132 * @param result the string to receive the pattern. Previous
133 * contents will be deleted.
134 * @param escapeUnprintable if TRUE then convert unprintable
135 * character to their hex escape representations, \\uxxxx or
136 * \\Uxxxxxxxx. Unprintable characters are those other than
137 * U+000A, U+0020..U+007E.
140 virtual UnicodeString
& toPattern(UnicodeString
& result
,
141 UBool escapeUnprintable
= FALSE
) const = 0;
144 * Returns TRUE if this matcher will match a character c, where c
145 * & 0xFF == v, at offset, in the forward direction (with limit >
146 * offset). This is used by <tt>RuleBasedTransliterator</tt> for
150 virtual UBool
matchesIndexValue(uint8_t v
) const = 0;
153 * Union the set of all characters that may be matched by this object
154 * into the given set.
155 * @param toUnionTo the set into which to union the source characters
158 virtual void addMatchSetTo(UnicodeSet
& toUnionTo
) const = 0;