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