1 5 package com.ibm.icu.text; 6 import com.ibm.icu.lang.*; 7 8 13 class UnicodeNameTransliterator extends Transliterator { 14 15 static final String _ID = "Any-Name"; 16 17 static final String OPEN_DELIM = "\\N{"; 18 static final char CLOSE_DELIM = '}'; 19 static final int OPEN_DELIM_LEN = 3; 20 21 24 static void register() { 25 Transliterator.registerFactory(_ID, new Transliterator.Factory() { 26 public Transliterator getInstance(String ID) { 27 return new UnicodeNameTransliterator(null); 28 } 29 }); 30 } 31 32 35 public UnicodeNameTransliterator(UnicodeFilter filter) { 36 super(_ID, filter); 37 } 38 39 42 protected void handleTransliterate(Replaceable text, 43 Position offsets, boolean isIncremental) { 44 int cursor = offsets.start; 45 int limit = offsets.limit; 46 47 StringBuffer str = new StringBuffer (); 48 str.append(OPEN_DELIM); 49 int len; 50 String name; 51 52 while (cursor < limit) { 53 int c = text.char32At(cursor); 54 if ((name=UCharacter.getExtendedName(c)) != null) { 55 56 str.setLength(OPEN_DELIM_LEN); 57 str.append(name).append(CLOSE_DELIM); 58 59 int clen = UTF16.getCharCount(c); 60 text.replace(cursor, cursor+clen, str.toString()); 61 len = str.length(); 62 cursor += len; limit += len-clen; } else { 65 ++cursor; 66 } 67 } 68 69 offsets.contextLimit += limit - offsets.limit; 70 offsets.limit = limit; 71 offsets.start = cursor; 72 } 73 } 74 | Popular Tags |