1 /* GENERATED SOURCE. DO NOT MODIFY. */ 2 /* 3 ******************************************************************************* 4 * Copyright (C) 1996-2016, International Business Machines Corporation and * 5 * others. All Rights Reserved. * 6 ******************************************************************************* 7 */ 8 package android.icu.text; 9 10 /** 11 * <code>UnicodeFilter</code> defines a protocol for selecting a 12 * subset of the full range (U+0000 to U+FFFF) of Unicode characters. 13 */ 14 public abstract class UnicodeFilter implements UnicodeMatcher { 15 16 /** 17 * Returns <tt>true</tt> for characters that are in the selected 18 * subset. In other words, if a character is <b>to be 19 * filtered</b>, then <tt>contains()</tt> returns 20 * <b><tt>false</tt></b>. 21 */ contains(int c)22 public abstract boolean contains(int c); 23 24 /** 25 * Default implementation of UnicodeMatcher::matches() for Unicode 26 * filters. Matches a single 16-bit code unit at offset. 27 */ matches(Replaceable text, int[] offset, int limit, boolean incremental)28 public int matches(Replaceable text, 29 int[] offset, 30 int limit, 31 boolean incremental) { 32 int c; 33 if (offset[0] < limit && 34 contains(c = text.char32At(offset[0]))) { 35 offset[0] += UTF16.getCharCount(c); 36 return U_MATCH; 37 } 38 if (offset[0] > limit && contains(text.char32At(offset[0]))) { 39 // Backup offset by 1, unless the preceding character is a 40 // surrogate pair -- then backup by 2 (keep offset pointing at 41 // the lead surrogate). 42 --offset[0]; 43 if (offset[0] >= 0) { 44 offset[0] -= UTF16.getCharCount(text.char32At(offset[0])) - 1; 45 } 46 return U_MATCH; 47 } 48 if (incremental && offset[0] == limit) { 49 return U_PARTIAL_MATCH; 50 } 51 return U_MISMATCH; 52 } 53 54 // TODO Remove this when the JDK property implements MemberDoc.isSynthetic 55 /** 56 * (This should not be here; it is declared to make CheckTags 57 * happy. Java inserts a synthetic constructor and CheckTags 58 * can't tell that it's synthetic.) 59 * 60 * @deprecated This API is ICU internal only. 61 * @hide original deprecated declaration 62 * @hide draft / provisional / internal are hidden on Android 63 */ 64 @Deprecated UnicodeFilter()65 protected UnicodeFilter() {} 66 } 67