1 /* GENERATED SOURCE. DO NOT MODIFY. */
2 // © 2016 and later: Unicode, Inc. and others.
3 // License & terms of use: http://www.unicode.org/copyright.html#License
4 /*
5  *******************************************************************************
6  * Copyright (C) 2001-2016, International Business Machines Corporation and    *
7  * others. All Rights Reserved.                                                *
8  *******************************************************************************
9  */
10 package android.icu.text;
11 
12 /**
13  * <code>UnicodeMatcher</code> defines a protocol for objects that can
14  * match a range of characters in a Replaceable string.
15  */
16 public interface UnicodeMatcher {
17 
18     /**
19      * Constant returned by <code>matches()</code> indicating a
20      * mismatch between the text and this matcher.  The text contains
21      * a character which does not match, or the text does not contain
22      * all desired characters for a non-incremental match.
23      */
24     public static final int U_MISMATCH = 0;
25 
26     /**
27      * Constant returned by <code>matches()</code> indicating a
28      * partial match between the text and this matcher.  This value is
29      * only returned for incremental match operations.  All characters
30      * of the text match, but more characters are required for a
31      * complete match.  Alternatively, for variable-length matchers,
32      * all characters of the text match, and if more characters were
33      * supplied at limit, they might also match.
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      */
44     public static final int U_MATCH = 2;
45 
46     /**
47      * The character at index i, where i &lt; contextStart || i &gt;= contextLimit,
48      * is ETHER.  This allows explicit matching by rules and UnicodeSets
49      * of text outside the context.  In traditional terms, this allows anchoring
50      * at the start and/or end.
51      */
52     static final char ETHER = '\uFFFF';
53 
54     /**
55      * Return a UMatchDegree value indicating the degree of match for
56      * the given text at the given offset.  Zero, one, or more
57      * characters may be matched.
58      *
59      * Matching in the forward direction is indicated by limit &gt;
60      * offset.  Characters from offset forwards to limit-1 will be
61      * considered for matching.
62      *
63      * Matching in the reverse direction is indicated by limit &lt;
64      * offset.  Characters from offset backwards to limit+1 will be
65      * considered for matching.
66      *
67      * If limit == offset then the only match possible is a zero
68      * character match (which subclasses may implement if desired).
69      *
70      * If U_MATCH is returned, then as a side effect, advance the
71      * offset parameter to the limit of the matched substring.  In the
72      * forward direction, this will be the index of the last matched
73      * character plus one.  In the reverse direction, this will be the
74      * index of the last matched character minus one.
75      *
76      * @param text the text to be matched
77      * @param offset on input, the index into text at which to begin
78      * matching.  On output, the limit of the matched text.  The
79      * number of matched characters is the output value of offset
80      * minus the input value.  Offset should always point to the
81      * HIGH SURROGATE (leading code unit) of a pair of surrogates,
82      * both on entry and upon return.
83      * @param limit the limit index of text to be matched.  Greater
84      * than offset for a forward direction match, less than offset for
85      * a backward direction match.  The last character to be
86      * considered for matching will be text.charAt(limit-1) in the
87      * forward direction or text.charAt(limit+1) in the backward
88      * direction.
89      * @param incremental if TRUE, then assume further characters may
90      * be inserted at limit and check for partial matching.  Otherwise
91      * assume the text as given is complete.
92      * @return a match degree value indicating a full match, a partial
93      * match, or a mismatch.  If incremental is FALSE then
94      * U_PARTIAL_MATCH should never be returned.
95      */
matches(Replaceable text, int[] offset, int limit, boolean incremental)96     public abstract int matches(Replaceable text,
97                                 int[] offset,
98                                 int limit,
99                                 boolean incremental);
100 
101     /**
102      * Returns a string representation of this matcher.  If the result of
103      * calling this function is passed to the appropriate parser, it
104      * will produce another matcher that is equal to this one.
105      * @param escapeUnprintable if TRUE then convert unprintable
106      * character to their hex escape representations, \\uxxxx or
107      * \\Uxxxxxxxx.  Unprintable characters are those other than
108      * U+000A, U+0020..U+007E.
109      */
toPattern(boolean escapeUnprintable)110     public abstract String toPattern(boolean escapeUnprintable);
111 
112     /**
113      * Returns TRUE if this matcher will match a character c, where c
114      * &amp; 0xFF == v, at offset, in the forward direction (with limit &gt;
115      * offset).  This is used by <tt>RuleBasedTransliterator</tt> for
116      * indexing.
117      *
118      * <p>Note:  This API uses an int even though the value will be
119      * restricted to 8 bits in order to avoid complications with
120      * signedness (bytes convert to ints in the range -128..127).
121      */
matchesIndexValue(int v)122     public abstract boolean matchesIndexValue(int v);
123 
124     /**
125      * Union the set of all characters that may be matched by this object
126      * into the given set.
127      * @param toUnionTo the set into which to union the source characters
128      */
addMatchSetTo(UnicodeSet toUnionTo)129     public abstract void addMatchSetTo(UnicodeSet toUnionTo);
130 }
131 
132 //eof
133