KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > thaiopensource > util > Utf16


1 package com.thaiopensource.util;
2
3 public abstract class Utf16 {
4   // 110110XX XXXXXX 110111XX XXXXXX
5
static public boolean isSurrogate(char c) {
6     return (c & 0xF800) == 0xD800;
7   }
8   static public boolean isSurrogate1(char c) {
9     return (c & 0xFC00) == 0xD800;
10   }
11   static public boolean isSurrogate2(char c) {
12     return (c & 0xFC00) == 0xDC00;
13   }
14   static public int scalarValue(char c1, char c2) {
15     return (((c1 & 0x3FF) << 10) | (c2 & 0x3FF)) + 0x10000;
16   }
17   static public char surrogate1(int c) {
18     return (char)(((c - 0x10000) >> 10) | 0xD800);
19   }
20   static public char surrogate2(int c) {
21     return (char)(((c - 0x10000) & 0x3FF) | 0xDC00);
22   }
23 }
24
25
Popular Tags