1 7 package com.ibm.icu.text; 8 9 import java.io.IOException ; 10 11 import com.ibm.icu.impl.UCaseProps; 12 13 import com.ibm.icu.util.ULocale; 14 15 import com.ibm.icu.text.ReplaceableContextIterator; 16 17 21 class UppercaseTransliterator extends Transliterator { 22 23 26 static final String _ID = "Any-Upper"; 27 29 32 static void register() { 33 Transliterator.registerFactory(_ID, new Transliterator.Factory() { 34 public Transliterator getInstance(String ID) { 35 return new UppercaseTransliterator(ULocale.US); 36 } 37 }); 38 } 39 40 private ULocale locale; 41 42 private UCaseProps csp; 43 private ReplaceableContextIterator iter; 44 private StringBuffer result; 45 private int[] locCache; 46 47 50 public UppercaseTransliterator(ULocale loc) { 51 super(_ID, null); 52 locale = loc; 53 try { 54 csp=UCaseProps.getSingleton(); 55 } catch (IOException e) { 56 csp=null; 57 } 58 iter=new ReplaceableContextIterator(); 59 result = new StringBuffer (); 60 int[] locCache = new int[1]; 61 locCache[0]=0; 62 } 63 64 67 protected void handleTransliterate(Replaceable text, 68 Position offsets, boolean isIncremental) { 69 if(csp==null) { 70 return; 71 } 72 73 if(offsets.start >= offsets.limit) { 74 return; 75 } 76 77 iter.setText(text); 78 result.setLength(0); 79 int c, delta; 80 81 84 iter.setIndex(offsets.start); 85 iter.setLimit(offsets.limit); 86 iter.setContextLimits(offsets.contextStart, offsets.contextLimit); 87 while((c=iter.nextCaseMapCP())>=0) { 88 c=csp.toFullUpper(c, iter, result, locale, locCache); 89 90 if(iter.didReachLimit() && isIncremental) { 91 offsets.start=iter.getCaseMapCPStart(); 94 return; 95 } 96 97 98 if(c<0) { 99 100 continue; 101 } else if(c<=UCaseProps.MAX_STRING_LENGTH) { 102 103 delta=iter.replace(result.toString()); 104 result.setLength(0); 105 } else { 106 107 delta=iter.replace(UTF16.valueOf(c)); 108 } 109 110 if(delta!=0) { 111 offsets.limit += delta; 112 offsets.contextLimit += delta; 113 } 114 } 115 offsets.start = offsets.limit; 116 } 117 } 118 | Popular Tags |