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