1/* GENERATED SOURCE. DO NOT MODIFY. */
2/**
3*******************************************************************************
4* Copyright (C) 1996-2004, International Business Machines Corporation and    *
5* others. All Rights Reserved.                                                *
6*******************************************************************************
7*/
8package android.icu.impl;
9
10/**
11* Internal character utility class for simple data type conversion and String
12* parsing functions. Does not have an analog in the JDK.
13* @author Syn Wee Quek
14* @hide Only a subset of ICU is exposed in Android
15*/
16
17public final class UCharacterUtility
18{
19    // public methods -----------------------------------------------------
20
21    /**
22    * Determines if codepoint is a non character
23    * @param ch codepoint
24    * @return true if codepoint is a non character false otherwise
25    */
26    public static boolean isNonCharacter(int ch)
27    {
28        if ((ch & NON_CHARACTER_SUFFIX_MIN_3_0_) ==
29                                            NON_CHARACTER_SUFFIX_MIN_3_0_) {
30            return true;
31        }
32
33        return ch >= NON_CHARACTER_MIN_3_1_ && ch <=  NON_CHARACTER_MAX_3_1_;
34    }
35
36    // package private methods ---------------------------------------------
37
38    /**
39    * joining 2 chars to form an int
40    * @param msc most significant char
41    * @param lsc least significant char
42    * @return int form
43    */
44    static int toInt(char msc, char lsc)
45    {
46        return ((msc << 16) | lsc);
47    }
48
49    /**
50    * Retrieves a null terminated substring from an array of bytes.
51    * Substring is a set of non-zero bytes starting from argument start to the
52    * next zero byte. If the first byte is a zero, the next byte will be taken as
53    * the first byte.
54    * @param str stringbuffer to store data in, data will be store with each
55    *            byte as a char
56    * @param array byte array
57    * @param index to start substring in byte count
58    * @return the end position of the substring within the character array
59    */
60    static int getNullTermByteSubString(StringBuffer str, byte[] array,
61                                                  int index)
62    {
63        byte b = 1;
64
65        while (b != 0)
66        {
67            b = array[index];
68            if (b != 0) {
69                str.append((char)(b & 0x00FF));
70            }
71            index ++;
72        }
73        return index;
74    }
75
76    /**
77    * Compares a null terminated substring from an array of bytes.
78    * Substring is a set of non-zero bytes starting from argument start to the
79    * next zero byte. if the first byte is a zero, the next byte will be taken as
80    * the first byte.
81    * @param str string to compare
82    * @param array byte array
83    * @param strindex index within str to start comparing
84    * @param aindex array index to start in byte count
85    * @return the end position of the substring within str if matches otherwise
86    *         a -1
87    */
88    static int compareNullTermByteSubString(String str, byte[] array,
89                                                      int strindex, int aindex)
90    {
91        byte b = 1;
92        int length = str.length();
93
94        while (b != 0)
95        {
96            b = array[aindex];
97            aindex ++;
98            if (b == 0) {
99                break;
100            }
101            // if we have reached the end of the string and yet the array has not
102            // reached the end of their substring yet, abort
103            if (strindex == length
104                || (str.charAt(strindex) != (char)(b & 0xFF))) {
105              return -1;
106            }
107            strindex ++;
108        }
109        return strindex;
110    }
111
112    /**
113    * Skip null terminated substrings from an array of bytes.
114    * Substring is a set of non-zero bytes starting from argument start to the
115    * next zero byte. If the first byte is a zero, the next byte will be taken as
116    * the first byte.
117    * @param array byte array
118    * @param index to start substrings in byte count
119    * @param skipcount number of null terminated substrings to skip
120    * @return the end position of the substrings within the character array
121    */
122    static int skipNullTermByteSubString(byte[] array, int index,
123                                                   int skipcount)
124    {
125        byte b;
126        for (int i = 0; i < skipcount; i ++)
127        {
128            b = 1;
129            while (b != 0)
130            {
131                b = array[index];
132                index ++;
133            }
134        }
135        return index;
136    }
137
138    /**
139     * skip substrings from an array of characters, where each character is a set
140     * of 2 bytes. substring is a set of non-zero bytes starting from argument
141     * start to the byte of the argument value. skips up to a max number of
142     * characters
143     * @param array byte array to parse
144     * @param index to start substrings in byte count
145     * @param length the max number of bytes to skip
146     * @param skipend value of byte to skip to
147     * @return the number of bytes skipped
148     */
149    static int skipByteSubString(byte[] array, int index, int length,
150                                           byte skipend)
151    {
152        int result;
153        byte b;
154
155        for (result = 0; result < length; result ++)
156        {
157            b = array[index + result];
158            if (b == skipend)
159            {
160                result ++;
161                break;
162            }
163        }
164
165        return result;
166    }
167
168    // private data member --------------------------------------------------
169
170    /**
171    * Minimum suffix value that indicates if a character is non character.
172    * Unicode 3.0 non characters
173    */
174    private static final int NON_CHARACTER_SUFFIX_MIN_3_0_ = 0xFFFE;
175    /**
176    * New minimum non character in Unicode 3.1
177    */
178    private static final int NON_CHARACTER_MIN_3_1_ = 0xFDD0;
179    /**
180    * New non character range in Unicode 3.1
181    */
182    private static final int NON_CHARACTER_MAX_3_1_ = 0xFDEF;
183
184    // private constructor --------------------------------------------------
185
186    ///CLOVER:OFF
187    /**
188    * private constructor to avoid initialisation
189    */
190    private UCharacterUtility()
191    {
192    }
193    ///CLOVER:ON
194}
195
196