1 7 package com.ibm.icu.impl; 8 9 import com.ibm.icu.text.Replaceable; 10 import com.ibm.icu.text.ReplaceableString; 11 import com.ibm.icu.text.UnicodeMatcher; 12 import com.ibm.icu.text.Transliterator; 13 16 public class UtilityExtensions { 19 23 public static void appendToRule(StringBuffer rule, 24 String text, 25 boolean isLiteral, 26 boolean escapeUnprintable, 27 StringBuffer quoteBuf) { 28 for (int i=0; i<text.length(); ++i) { 29 Utility.appendToRule(rule, text.charAt(i), isLiteral, escapeUnprintable, quoteBuf); 31 } 32 } 33 34 35 39 public static void appendToRule(StringBuffer rule, 40 UnicodeMatcher matcher, 41 boolean escapeUnprintable, 42 StringBuffer quoteBuf) { 43 if (matcher != null) { 44 appendToRule(rule, matcher.toPattern(escapeUnprintable), 45 true, escapeUnprintable, quoteBuf); 46 } 47 } 48 53 public static String formatInput(ReplaceableString input, 54 Transliterator.Position pos) { 55 StringBuffer appendTo = new StringBuffer (); 56 formatInput(appendTo, input, pos); 57 return com.ibm.icu.impl.Utility.escape(appendTo.toString()); 58 } 59 60 65 public static StringBuffer formatInput(StringBuffer appendTo, 66 ReplaceableString input, 67 Transliterator.Position pos) { 68 if (0 <= pos.contextStart && 69 pos.contextStart <= pos.start && 70 pos.start <= pos.limit && 71 pos.limit <= pos.contextLimit && 72 pos.contextLimit <= input.length()) { 73 74 String b, c, d; 75 b = input.substring(pos.contextStart, pos.start); 77 c = input.substring(pos.start, pos.limit); 78 d = input.substring(pos.limit, pos.contextLimit); 79 appendTo. append('{').append(b). 82 append('|').append(c).append('|').append(d). 83 append('}') 84 ; 86 } else { 87 appendTo.append("INVALID Position {cs=" + 88 pos.contextStart + ", s=" + pos.start + ", l=" + 89 pos.limit + ", cl=" + pos.contextLimit + "} on " + 90 input); 91 } 92 return appendTo; 93 } 94 95 98 public static String formatInput(Replaceable input, 99 Transliterator.Position pos) { 100 return formatInput((ReplaceableString) input, pos); 101 } 102 103 106 public static StringBuffer formatInput(StringBuffer appendTo, 107 Replaceable input, 108 Transliterator.Position pos) { 109 return formatInput(appendTo, (ReplaceableString) input, pos); 110 } 111 112 } 113 | Popular Tags |