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