| 1 |
// 2009-01-27-22:19 |
| 2 |
package xtpipes; |
| 3 |
public class XtpipesUni{ |
| 4 |
private static int D800 = Integer.parseInt("D800", 16); |
| 5 |
private static int DFFF = Integer.parseInt("DFFF", 16); |
| 6 |
private static int DC00 = Integer.parseInt("DC00", 16); |
| 7 |
private static int X400 = Integer.parseInt("400",16); |
| 8 |
private static int X10000 = Integer.parseInt("10000",16); |
| 9 |
|
| 10 |
|
| 11 |
public static String toUni( char[] ch, int start, int length, |
| 12 |
String filter ){ |
| 13 |
StringBuffer buf = new StringBuffer(length); |
| 14 |
for (int i = 0; i < length; i++) { |
| 15 |
int chr = ch[ start + i ]; |
| 16 |
boolean ascii = (chr == '\n') |
| 17 |
|| (chr > 31) && (chr < 127) ; |
| 18 |
if( filter.indexOf(chr) > -1 ){ ascii = false; } |
| 19 |
|
| 20 |
if( (chr >= D800) && (chr<= DFFF) ){ |
| 21 |
chr = ((ch[i] - D800) * X400 + (ch[++i] - DC00)) + X10000; |
| 22 |
} |
| 23 |
|
| 24 |
|
| 25 |
buf.append( |
| 26 |
ascii ? Character.toString((char) chr) |
| 27 |
: ("&#x" |
| 28 |
+ Integer.toHexString(chr).toUpperCase() |
| 29 |
+ ";" ) ); |
| 30 |
} |
| 31 |
return new String(buf); |
| 32 |
} |
| 33 |
|
| 34 |
public static String toUni( String s, String filter ){ |
| 35 |
char [] ch = s.toCharArray(); |
| 36 |
int length = ch.length; |
| 37 |
return toUni(ch, 0, length, filter); |
| 38 |
} |
| 39 |
|
| 40 |
} |
| 41 |
|