Android Byte Array to Unicode Convert convertLongVowel(byte[] b)

Here you can find the source of convertLongVowel(byte[] b)

Description

convert Long Vowel

Declaration

public static void convertLongVowel(byte[] b) 

Method Source Code

//package com.java2s;

public class Main {
    private static final byte[] LONG_VOWEL_TABLE = { 0x22, /* a (21) -> A(22) */
    0x22, /* A (22) -> A(22) */
    0x24, /* i (23) -> I(24) */0x24, /* I (24) -> I(24) */
    0x26, /* u (25) -> U(26) */0x26, /* U (26) -> U(26) */
    0x28, /* e (27) -> E(28) */0x28, /* E (28) -> E(28) */
    0x2a, /* o (29) -> O(2a) */0x2a, /* O (2a) -> O(2a) */
    0x22, /* KA(2b) -> A(22) */0x22, /* GA(2c) -> A(22) */
    0x24, /* KI(2d) -> I(24) */0x24, /* GI(2e) -> I(24) */
    0x26, /* KU(2f) -> U(26) */0x26, /* GU(30) -> U(26) */
    0x28, /* KE(31) -> E(28) */0x28, /* GE(32) -> E(28) */
    0x2a, /* KO(33) -> O(2a) */0x2a, /* GO(34) -> O(2a) */
    0x22, /* SA(35) -> A(22) */0x22, /* ZA(36) -> A(22) */
    0x24, /* SI(37) -> I(24) */0x24, /* ZI(38) -> I(24) */
    0x26, /* SU(39) -> U(26) */0x26, /* ZU(3a) -> U(26) */
    0x28, /* SE(3b) -> E(28) */0x28, /* ZE(3c) -> E(28) */
    0x2a, /* SO(3d) -> O(2a) */0x2a, /* ZO(3e) -> O(2a) */
    0x22, /* TA(3f) -> A(22) */0x22, /* DA(40) -> A(22) */
    0x24, /* TI(41) -> I(24) */0x24, /* DI(42) -> I(24) */
    0x26, /* tu(43) -> U(26) */0x26, /* TU(44) -> U(26) */
    0x26, /* DU(45) -> U(26) */0x28, /* TE(46) -> E(28) */
    0x28, /* DE(47) -> E(28) */0x2a, /* TO(48) -> O(2a) */
    0x2a, /* DO(49) -> O(2a) */0x22, /* NA(4a) -> A(22) */
    0x24, /* NI(4b) -> I(24) */0x26, /* NU(4c) -> U(26) */
    0x28, /* NE(4d) -> E(28) */0x2a, /* NO(4e) -> O(2a) */
    0x22, /* HA(4f) -> A(22) */0x22, /* BA(50) -> A(22) */
    0x22, /* PA(51) -> A(22) */0x24, /* HI(52) -> I(24) */
    0x24, /* BI(53) -> I(24) */0x24, /* PI(54) -> I(24) */
    0x26, /* HU(55) -> U(26) */0x26, /* BU(56) -> U(26) */
    0x26, /* PU(57) -> U(26) */0x28, /* HE(58) -> E(28) */
    0x28, /* BE(59) -> E(28) */0x28, /* PE(5a) -> E(28) */
    0x2a, /* HO(5b) -> O(2a) */0x2a, /* BO(5c) -> O(2a) */
    0x2a, /* PO(5d) -> O(2a) */0x22, /* MA(5e) -> A(22) */
    0x24, /* MI(5f) -> I(24) */0x26, /* MU(60) -> U(26) */
    0x28, /* ME(61) -> E(28) */0x2a, /* MO(62) -> O(2a) */
    0x22, /* ya(63) -> A(22) */0x22, /* YA(64) -> A(22) */
    0x26, /* yu(65) -> U(26) */0x26, /* YU(66) -> U(26) */
    0x2a, /* yo(67) -> O(2a) */0x2a, /* YO(68) -> O(2a) */
    0x22, /* RA(69) -> A(22) */0x24, /* RI(6a) -> I(24) */
    0x26, /* RU(6b) -> U(26) */0x28, /* RE(6c) -> E(28) */
    0x2a, /* RO(6d) -> O(2a) */0x22, /* wa(6e) -> A(22) */
    0x22, /* WA(6f) -> A(22) */0x24, /* WI(70) -> I(24) */
    0x28, /* WE(71) -> E(28) */0x2a, /* WO(72) -> O(2a) */
    0x73, /* N (73) -> N(73) */0x26, /* VU(74) -> U(26) */
    0x22, /* ka(75) -> A(22) */0x28 /* ke(76) -> E(28) */
    };//from  ww w  . ja  va  2  s . c o m

    public static void convertLongVowel(byte[] b) {
        int len = b.length;
        if ((len & 1) == 1) {
            b[len - 1] = '\0';
            len--;
        }
        int prevHigh = 0;
        int prevLow = 0;
        for (int i = 0; i < len; i += 2) {
            int high = b[i] & 0xff;
            int low = b[i + 1] & 0xff;
            if (high == '\0' || low == '\0') {
                break;
            } else if (high == 0x21 && low == 0x3c) {
                if ((prevHigh == 0x24 || prevHigh == 0x25)
                        && (prevLow >= 0x21 && prevLow <= 0x76)) {
                    b[i] = (byte) prevHigh;
                    b[i + 1] = LONG_VOWEL_TABLE[prevLow - 0x21];
                }
            }
            prevHigh = high;
            prevLow = low;
        }
    }
}

Related

  1. jisx0208ToString(byte[] b)
  2. jisx0208ToString(byte[] b, int offset, int len)
  3. toBase58(byte[] b)
  4. ushort2bytesBE(int val, byte[] b, int off)
  5. ushort2bytesLE(int val, byte[] b, int off)
  6. bcdToString(byte[] data, int offset, int length)
  7. upperToLower(byte[] b)
  8. upperToLowerLatin(byte[] b)
  9. tag2bytesBE(int tag, byte[] b, int off)