Android Utililty Methods Unicode Convert

List of utility methods to do Unicode Convert

Description

The list of methods to do Unicode Convert are organized into topic(s).

Method

StringzenkakuToHankaku(String value)
zenkaku To Hankaku
StringBuilder sb = new StringBuilder(value);
for (int i = 0; i < sb.length(); i++) {
    int c = (int) sb.charAt(i);
    if ((c >= 0xFF10 && c <= 0xFF19)
            || (c >= 0xFF21 && c <= 0xFF3A)
            || (c >= 0xFF41 && c <= 0xFF5A)) {
        sb.setCharAt(i, (char) (c - 0xFEE0));
value = sb.toString();
return value;
StringToDBC(String input)
To DBC
if (input == null) {
    return "";
char[] c = input.toCharArray();
for (int i = 0; i < c.length; i++) {
    if (c[i] == 12288) {
        c[i] = (char) 32;
        continue;
...
intunicodePreservingIndex(String paramString, int paramInt)
unicode Preserving Index
if (paramInt > 0) {
    int i = paramString.length();
    if (paramInt < i) {
        int j = paramInt + -1;
        if ((Character.isHighSurrogate(paramString.charAt(j)))
                && (Character.isLowSurrogate(paramString
                        .charAt(paramInt))))
            paramInt += -1;
...
intunicodePreservingIndex(String str, int index)
Normalizes index such that it respects Unicode character boundaries in str .
if (index > 0 && index < str.length()) {
    if (Character.isHighSurrogate(str.charAt(index - 1))
            && Character.isLowSurrogate(str.charAt(index))) {
        return index - 1;
return index;
StringfullWidthToHalfWidth(String s)
full Width To Half Width
if (isEmpty(s)) {
    return s;
char[] source = s.toCharArray();
for (int i = 0; i < source.length; i++) {
    if (source[i] == 12288) {
        source[i] = ' ';
    } else if (source[i] >= 65281 && source[i] <= 65374) {
...
intgetEncodedSize(String value)
get Encoded Size
int result = 2 + 1;
result += value.length() * (StringUtil.hasMultibyte(value) ? 2 : 1);
return result;
StringhalfWidthToFullWidth(String s)
half Width To Full Width
if (isEmpty(s)) {
    return s;
char[] source = s.toCharArray();
for (int i = 0; i < source.length; i++) {
    if (source[i] == ' ') {
        source[i] = (char) 12288;
    } else if (source[i] >= 33 && source[i] <= 126) {
...
Stringbytes2StringUNICODE(byte[] buf, int offset, int length, boolean bigEndian)
format the byte[] to String in UNICODE encode
if (buf != null && offset >= 0 && length >= 2
        && buf.length >= (offset + length)) {
    int charsLen = length / 2;
    char[] cbuf = new char[charsLen];
    for (int i = 0; i < charsLen; i++) {
        if (bigEndian) {
            cbuf[i] = (char) (((buf[i * 2 + offset] & 0xff) << 8 | (buf[i
                    * 2 + 1 + offset] & 0xff)) & 0xffff);
...
voidasciiToBCD(byte[] ascii_buf, int asc_offset, byte[] bcd_buf, int bcd_offset, int conv_len, int type)
ascii To BCD
int cnt;
byte ch, ch1;
int bcdOffset = bcd_offset;
int asciiOffset = asc_offset;
if (((conv_len & 0x01) > 0) && (type > 0)) {
    ch1 = 0;
} else {
    ch1 = 0x55;
...
byte[]convertToUnicodeByteArray(String s)
Converts the String to a UNICODE byte array.
if (s == null) {
    return null;
char c[] = s.toCharArray();
byte[] result = new byte[(c.length * 2) + 2];
for (int i = 0; i < c.length; i++) {
    result[(i * 2)] = (byte) (c[i] >> 8);
    result[((i * 2) + 1)] = (byte) c[i];
...