1 /* GENERATED SOURCE. DO NOT MODIFY. */ 2 /* 3 ********************************************************************** 4 * Copyright (c) 2002-2010, International Business Machines Corporation 5 * and others. All Rights Reserved. 6 ********************************************************************** 7 * Date Name Description 8 * 01/14/2002 aliu Creation. 9 ********************************************************************** 10 */ 11 12 package android.icu.text; 13 14 /** 15 * A replacer that calls a transliterator to generate its output text. 16 * The input text to the transliterator is the output of another 17 * UnicodeReplacer object. That is, this replacer wraps another 18 * replacer with a transliterator. 19 * @author Alan Liu 20 */ 21 class FunctionReplacer implements UnicodeReplacer { 22 23 /** 24 * The transliterator. Must not be null. 25 */ 26 private Transliterator translit; 27 28 /** 29 * The replacer object. This generates text that is then 30 * processed by 'translit'. Must not be null. 31 */ 32 private UnicodeReplacer replacer; 33 34 /** 35 * Construct a replacer that takes the output of the given 36 * replacer, passes it through the given transliterator, and emits 37 * the result as output. 38 */ FunctionReplacer(Transliterator theTranslit, UnicodeReplacer theReplacer)39 public FunctionReplacer(Transliterator theTranslit, 40 UnicodeReplacer theReplacer) { 41 translit = theTranslit; 42 replacer = theReplacer; 43 } 44 45 /** 46 * UnicodeReplacer API 47 */ replace(Replaceable text, int start, int limit, int[] cursor)48 public int replace(Replaceable text, 49 int start, 50 int limit, 51 int[] cursor) { 52 53 // First delegate to subordinate replacer 54 int len = replacer.replace(text, start, limit, cursor); 55 limit = start + len; 56 57 // Now transliterate 58 limit = translit.transliterate(text, start, limit); 59 60 return limit - start; 61 } 62 63 /** 64 * UnicodeReplacer API 65 */ toReplacerPattern(boolean escapeUnprintable)66 public String toReplacerPattern(boolean escapeUnprintable) { 67 StringBuilder rule = new StringBuilder("&"); 68 rule.append(translit.getID()); 69 rule.append("( "); 70 rule.append(replacer.toReplacerPattern(escapeUnprintable)); 71 rule.append(" )"); 72 return rule.toString(); 73 } 74 75 /** 76 * Union the set of all characters that may output by this object 77 * into the given set. 78 * @param toUnionTo the set into which to union the output characters 79 */ addReplacementSetTo(UnicodeSet toUnionTo)80 public void addReplacementSetTo(UnicodeSet toUnionTo) { 81 toUnionTo.addAll(translit.getTargetSet()); 82 } 83 } 84 85 //eof 86