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 LowercaseTransliterator extends Transliterator{ 22 23 26 static final String _ID = "Any-Lower"; 27 28 30 33 static void register() { 34 Transliterator.registerFactory(_ID, new Transliterator.Factory() { 35 public Transliterator getInstance(String ID) { 36 return new LowercaseTransliterator(ULocale.US); 37 } 38 }); 39 40 Transliterator.registerSpecialInverse("Lower", "Upper", true); 41 } 42 43 private ULocale locale; 44 45 private UCaseProps csp; 46 private ReplaceableContextIterator iter; 47 private StringBuffer result; 48 private int[] locCache; 49 50 53 54 public LowercaseTransliterator(ULocale loc) { 55 super(_ID, null); 56 locale = loc; 57 try { 58 csp=UCaseProps.getSingleton(); 59 } catch (IOException e) { 60 csp=null; 61 } 62 iter=new ReplaceableContextIterator(); 63 result = new StringBuffer (); 64 int[] locCache = new int[1]; 65 locCache[0]=0; 66 } 67 68 71 protected void handleTransliterate(Replaceable text, 72 Position offsets, boolean isIncremental) { 73 if(csp==null) { 74 return; 75 } 76 77 if(offsets.start >= offsets.limit) { 78 return; 79 } 80 81 iter.setText(text); 82 result.setLength(0); 83 int c, delta; 84 85 88 iter.setIndex(offsets.start); 89 iter.setLimit(offsets.limit); 90 iter.setContextLimits(offsets.contextStart, offsets.contextLimit); 91 while((c=iter.nextCaseMapCP())>=0) { 92 c=csp.toFullLower(c, iter, result, locale, locCache); 93 94 if(iter.didReachLimit() && isIncremental) { 95 offsets.start=iter.getCaseMapCPStart(); 98 return; 99 } 100 101 102 if(c<0) { 103 104 continue; 105 } else if(c<=UCaseProps.MAX_STRING_LENGTH) { 106 107 delta=iter.replace(result.toString()); 108 result.setLength(0); 109 } else { 110 111 delta=iter.replace(UTF16.valueOf(c)); 112 } 113 114 if(delta!=0) { 115 offsets.limit += delta; 116 offsets.contextLimit += delta; 117 } 118 } 119 offsets.start = offsets.limit; 120 } 121 } 122 | Popular Tags |