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-2014, International Business Machines Corporation and * 7 * others. All Rights Reserved. * 8 ******************************************************************************* 9 */ 10 package ohos.global.icu.text; 11 12 13 /** 14 * A transliterator that removes characters. This is useful in conjunction 15 * with a filter. 16 */ 17 class RemoveTransliterator extends Transliterator { 18 19 /** 20 * ID for this transliterator. 21 */ 22 private static final String _ID = "Any-Remove"; 23 24 /** 25 * System registration hook. 26 */ register()27 static void register() { 28 Transliterator.registerFactory(_ID, new Transliterator.Factory() { 29 @Override 30 public Transliterator getInstance(String ID) { 31 return new RemoveTransliterator(); 32 } 33 }); 34 Transliterator.registerSpecialInverse("Remove", "Null", false); 35 } 36 37 /** 38 * Constructs a transliterator. 39 */ RemoveTransliterator()40 public RemoveTransliterator() { 41 super(_ID, null); 42 } 43 44 /** 45 * Implements {@link Transliterator#handleTransliterate}. 46 */ 47 @Override handleTransliterate(Replaceable text, Position index, boolean incremental)48 protected void handleTransliterate(Replaceable text, 49 Position index, boolean incremental) { 50 // Our caller (filteredTransliterate) has already narrowed us 51 // to an unfiltered run. Delete it. 52 text.replace(index.start, index.limit, ""); 53 int len = index.limit - index.start; 54 index.contextLimit -= len; 55 index.limit -= len; 56 } 57 58 /* (non-Javadoc) 59 * @see ohos.global.icu.text.Transliterator#addSourceTargetSet(boolean, ohos.global.icu.text.UnicodeSet, ohos.global.icu.text.UnicodeSet) 60 */ 61 @Override addSourceTargetSet(UnicodeSet inputFilter, UnicodeSet sourceSet, UnicodeSet targetSet)62 public void addSourceTargetSet(UnicodeSet inputFilter, UnicodeSet sourceSet, UnicodeSet targetSet) { 63 // intersect myFilter with the input filter 64 UnicodeSet myFilter = getFilterAsUnicodeSet(inputFilter); 65 sourceSet.addAll(myFilter); 66 // do nothing with the target 67 } 68 } 69