KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ibm > icu > text > UnicodeMatcher


1 /*
2  *******************************************************************************
3  * Copyright (C) 2001-2004, International Business Machines Corporation and *
4  * others. All Rights Reserved. *
5  *******************************************************************************
6  */

7 package com.ibm.icu.text;
8
9 /**
10  * <code>UnicodeMatcher</code> defines a protocol for objects that can
11  * match a range of characters in a Replaceable string.
12  * @stable ICU 2.0
13  */

14 public interface UnicodeMatcher {
15
16     /**
17      * Constant returned by <code>matches()</code> indicating a
18      * mismatch between the text and this matcher. The text contains
19      * a character which does not match, or the text does not contain
20      * all desired characters for a non-incremental match.
21      * @stable ICU 2.0
22      */

23     public static final int U_MISMATCH = 0;
24
25     /**
26      * Constant returned by <code>matches()</code> indicating a
27      * partial match between the text and this matcher. This value is
28      * only returned for incremental match operations. All characters
29      * of the text match, but more characters are required for a
30      * complete match. Alternatively, for variable-length matchers,
31      * all characters of the text match, and if more characters were
32      * supplied at limit, they might also match.
33      * @stable ICU 2.0
34      */

35     public static final int U_PARTIAL_MATCH = 1;
36
37     /**
38      * Constant returned by <code>matches()</code> indicating a
39      * complete match between the text and this matcher. For an
40      * incremental variable-length match, this value is returned if
41      * the given text matches, and it is known that additional
42      * characters would not alter the extent of the match.
43      * @stable ICU 2.0
44      */

45     public static final int U_MATCH = 2;
46
47     /**
48      * The character at index i, where i < contextStart || i >= contextLimit,
49      * is ETHER. This allows explicit matching by rules and UnicodeSets
50      * of text outside the context. In traditional terms, this allows anchoring
51      * at the start and/or end.
52      * @stable ICU 2.0
53      */

54     static final char ETHER = '\uFFFF';
55
56     /**
57      * Return a UMatchDegree value indicating the degree of match for
58      * the given text at the given offset. Zero, one, or more
59      * characters may be matched.
60      *
61      * Matching in the forward direction is indicated by limit >
62      * offset. Characters from offset forwards to limit-1 will be
63      * considered for matching.
64      *
65      * Matching in the reverse direction is indicated by limit <
66      * offset. Characters from offset backwards to limit+1 will be
67      * considered for matching.
68      *
69      * If limit == offset then the only match possible is a zero
70      * character match (which subclasses may implement if desired).
71      *
72      * If U_MATCH is returned, then as a side effect, advance the
73      * offset parameter to the limit of the matched substring. In the
74      * forward direction, this will be the index of the last matched
75      * character plus one. In the reverse direction, this will be the
76      * index of the last matched character minus one.
77      *
78      * @param text the text to be matched
79      * @param offset on input, the index into text at which to begin
80      * matching. On output, the limit of the matched text. The
81      * number of matched characters is the output value of offset
82      * minus the input value. Offset should always point to the
83      * HIGH SURROGATE (leading code unit) of a pair of surrogates,
84      * both on entry and upon return.
85      * @param limit the limit index of text to be matched. Greater
86      * than offset for a forward direction match, less than offset for
87      * a backward direction match. The last character to be
88      * considered for matching will be text.charAt(limit-1) in the
89      * forward direction or text.charAt(limit+1) in the backward
90      * direction.
91      * @param incremental if TRUE, then assume further characters may
92      * be inserted at limit and check for partial matching. Otherwise
93      * assume the text as given is complete.
94      * @return a match degree value indicating a full match, a partial
95      * match, or a mismatch. If incremental is FALSE then
96      * U_PARTIAL_MATCH should never be returned.
97      * @stable ICU 2.0
98      */

99     public abstract int matches(Replaceable text,
100                                 int[] offset,
101                                 int limit,
102                                 boolean incremental);
103
104     /**
105      * Returns a string representation of this matcher. If the result of
106      * calling this function is passed to the appropriate parser, it
107      * will produce another matcher that is equal to this one.
108      * @param escapeUnprintable if TRUE then convert unprintable
109      * character to their hex escape representations, \\uxxxx or
110      * \\Uxxxxxxxx. Unprintable characters are those other than
111      * U+000A, U+0020..U+007E.
112      * @stable ICU 2.0
113      */

114     public abstract String JavaDoc toPattern(boolean escapeUnprintable);
115
116     /**
117      * Returns TRUE if this matcher will match a character c, where c
118      * & 0xFF == v, at offset, in the forward direction (with limit >
119      * offset). This is used by <tt>RuleBasedTransliterator</tt> for
120      * indexing.
121      *
122      * <p>Note: This API uses an int even though the value will be
123      * restricted to 8 bits in order to avoid complications with
124      * signedness (bytes convert to ints in the range -128..127).
125      * @stable ICU 2.0
126      */

127     public abstract boolean matchesIndexValue(int v);
128
129     /**
130      * Union the set of all characters that may be matched by this object
131      * into the given set.
132      * @param toUnionTo the set into which to union the source characters
133      * @stable ICU 2.2
134      */

135     public abstract void addMatchSetTo(UnicodeSet toUnionTo);
136 }
137
138 //eof
139
Popular Tags