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