]> gitweb.fperrin.net Git - Dictionary.git/blob - jars/icu4j-4_4_2-src/main/classes/core/src/com/ibm/icu/text/UnicodeMatcher.java
go
[Dictionary.git] / jars / icu4j-4_4_2-src / main / classes / core / src / com / ibm / icu / text / UnicodeMatcher.java
1 /*\r
2  *******************************************************************************\r
3  * Copyright (C) 2001-2004, International Business Machines Corporation and    *\r
4  * others. All Rights Reserved.                                                *\r
5  *******************************************************************************\r
6  */\r
7 package com.ibm.icu.text;\r
8 \r
9 /**\r
10  * <code>UnicodeMatcher</code> defines a protocol for objects that can\r
11  * match a range of characters in a Replaceable string.\r
12  * @stable ICU 2.0\r
13  */\r
14 public interface UnicodeMatcher {\r
15 \r
16     /**\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
21      * @stable ICU 2.0\r
22      */\r
23     public static final int U_MISMATCH = 0;\r
24 \r
25     /**\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
33      * @stable ICU 2.0\r
34      */\r
35     public static final int U_PARTIAL_MATCH = 1;\r
36 \r
37     /**\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
43      * @stable ICU 2.0\r
44      */\r
45     public static final int U_MATCH = 2;\r
46 \r
47     /**\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
52      * @stable ICU 2.0\r
53      */\r
54     static final char ETHER = '\uFFFF';\r
55 \r
56     /**\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
60      *\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
64      *\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
68      *\r
69      * If limit == offset then the only match possible is a zero\r
70      * character match (which subclasses may implement if desired).\r
71      *\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
77      *\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
90      * direction.\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
97      * @stable ICU 2.0\r
98      */\r
99     public abstract int matches(Replaceable text,\r
100                                 int[] offset,\r
101                                 int limit,\r
102                                 boolean incremental);\r
103 \r
104     /**\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
112      * @stable ICU 2.0\r
113      */\r
114     public abstract String toPattern(boolean escapeUnprintable);\r
115 \r
116     /**\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
120      * indexing.\r
121      *\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
125      * @stable ICU 2.0\r
126      */\r
127     public abstract boolean matchesIndexValue(int v);\r
128 \r
129     /**\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
133      * @stable ICU 2.2\r
134      */\r
135     public abstract void addMatchSetTo(UnicodeSet toUnionTo);\r
136 }\r
137 \r
138 //eof\r