2 *******************************************************************************
\r
3 * Copyright (C) 2001-2004, International Business Machines Corporation and *
\r
4 * others. All Rights Reserved. *
\r
5 *******************************************************************************
\r
7 package com.ibm.icu.text;
\r
10 * <code>UnicodeMatcher</code> defines a protocol for objects that can
\r
11 * match a range of characters in a Replaceable string.
\r
14 public interface UnicodeMatcher {
\r
17 * Constant returned by <code>matches()</code> indicating a
\r
18 * mismatch between the text and this matcher. The text contains
\r
19 * a character which does not match, or the text does not contain
\r
20 * all desired characters for a non-incremental match.
\r
23 public static final int U_MISMATCH = 0;
\r
26 * Constant returned by <code>matches()</code> indicating a
\r
27 * partial match between the text and this matcher. This value is
\r
28 * only returned for incremental match operations. All characters
\r
29 * of the text match, but more characters are required for a
\r
30 * complete match. Alternatively, for variable-length matchers,
\r
31 * all characters of the text match, and if more characters were
\r
32 * supplied at limit, they might also match.
\r
35 public static final int U_PARTIAL_MATCH = 1;
\r
38 * Constant returned by <code>matches()</code> indicating a
\r
39 * complete match between the text and this matcher. For an
\r
40 * incremental variable-length match, this value is returned if
\r
41 * the given text matches, and it is known that additional
\r
42 * characters would not alter the extent of the match.
\r
45 public static final int U_MATCH = 2;
\r
48 * The character at index i, where i < contextStart || i >= contextLimit,
\r
49 * is ETHER. This allows explicit matching by rules and UnicodeSets
\r
50 * of text outside the context. In traditional terms, this allows anchoring
\r
51 * at the start and/or end.
\r
54 static final char ETHER = '\uFFFF';
\r
57 * Return a UMatchDegree value indicating the degree of match for
\r
58 * the given text at the given offset. Zero, one, or more
\r
59 * characters may be matched.
\r
61 * Matching in the forward direction is indicated by limit >
\r
62 * offset. Characters from offset forwards to limit-1 will be
\r
63 * considered for matching.
\r
65 * Matching in the reverse direction is indicated by limit <
\r
66 * offset. Characters from offset backwards to limit+1 will be
\r
67 * considered for matching.
\r
69 * If limit == offset then the only match possible is a zero
\r
70 * character match (which subclasses may implement if desired).
\r
72 * If U_MATCH is returned, then as a side effect, advance the
\r
73 * offset parameter to the limit of the matched substring. In the
\r
74 * forward direction, this will be the index of the last matched
\r
75 * character plus one. In the reverse direction, this will be the
\r
76 * index of the last matched character minus one.
\r
78 * @param text the text to be matched
\r
79 * @param offset on input, the index into text at which to begin
\r
80 * matching. On output, the limit of the matched text. The
\r
81 * number of matched characters is the output value of offset
\r
82 * minus the input value. Offset should always point to the
\r
83 * HIGH SURROGATE (leading code unit) of a pair of surrogates,
\r
84 * both on entry and upon return.
\r
85 * @param limit the limit index of text to be matched. Greater
\r
86 * than offset for a forward direction match, less than offset for
\r
87 * a backward direction match. The last character to be
\r
88 * considered for matching will be text.charAt(limit-1) in the
\r
89 * forward direction or text.charAt(limit+1) in the backward
\r
91 * @param incremental if TRUE, then assume further characters may
\r
92 * be inserted at limit and check for partial matching. Otherwise
\r
93 * assume the text as given is complete.
\r
94 * @return a match degree value indicating a full match, a partial
\r
95 * match, or a mismatch. If incremental is FALSE then
\r
96 * U_PARTIAL_MATCH should never be returned.
\r
99 public abstract int matches(Replaceable text,
\r
102 boolean incremental);
\r
105 * Returns a string representation of this matcher. If the result of
\r
106 * calling this function is passed to the appropriate parser, it
\r
107 * will produce another matcher that is equal to this one.
\r
108 * @param escapeUnprintable if TRUE then convert unprintable
\r
109 * character to their hex escape representations, \\uxxxx or
\r
110 * \\Uxxxxxxxx. Unprintable characters are those other than
\r
111 * U+000A, U+0020..U+007E.
\r
114 public abstract String toPattern(boolean escapeUnprintable);
\r
117 * Returns TRUE if this matcher will match a character c, where c
\r
118 * & 0xFF == v, at offset, in the forward direction (with limit >
\r
119 * offset). This is used by <tt>RuleBasedTransliterator</tt> for
\r
122 * <p>Note: This API uses an int even though the value will be
\r
123 * restricted to 8 bits in order to avoid complications with
\r
124 * signedness (bytes convert to ints in the range -128..127).
\r
127 public abstract boolean matchesIndexValue(int v);
\r
130 * Union the set of all characters that may be matched by this object
\r
131 * into the given set.
\r
132 * @param toUnionTo the set into which to union the source characters
\r
135 public abstract void addMatchSetTo(UnicodeSet toUnionTo);
\r