KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ibm > icu > impl > UCharacterUtility


1 /**
2 *******************************************************************************
3 * Copyright (C) 1996-2004, International Business Machines Corporation and *
4 * others. All Rights Reserved. *
5 *******************************************************************************
6 */

7 package com.ibm.icu.impl;
8
9 /**
10 * Internal character utility class for simple data type conversion and String
11 * parsing functions. Does not have an analog in the JDK.
12 * @author Syn Wee Quek
13 * @since sep2900
14 */

15
16 public final class UCharacterUtility
17 {
18     // public methods -----------------------------------------------------
19

20     /**
21     * Determines if codepoint is a non character
22     * @param ch codepoint
23     * @return true if codepoint is a non character false otherwise
24     */

25     public static boolean isNonCharacter(int ch)
26     {
27         if ((ch & NON_CHARACTER_SUFFIX_MIN_3_0_) ==
28                                             NON_CHARACTER_SUFFIX_MIN_3_0_) {
29             return true;
30         }
31         
32         return ch >= NON_CHARACTER_MIN_3_1_ && ch <= NON_CHARACTER_MAX_3_1_;
33     }
34     
35     // package private methods ---------------------------------------------
36

37     /**
38     * joining 2 chars to form an int
39     * @param msc most significant char
40     * @param lsc least significant char
41     * @return int form
42     */

43     static int toInt(char msc, char lsc)
44     {
45         return ((msc << 16) | lsc);
46     }
47        
48     /**
49     * Retrieves a null terminated substring from an array of bytes.
50     * Substring is a set of non-zero bytes starting from argument start to the
51     * next zero byte. If the first byte is a zero, the next byte will be taken as
52     * the first byte.
53     * @param str stringbuffer to store data in, data will be store with each
54     * byte as a char
55     * @param array byte array
56     * @param index to start substring in byte count
57     * @return the end position of the substring within the character array
58     */

59     static int getNullTermByteSubString(StringBuffer JavaDoc str, byte[] array,
60                                                   int index)
61     {
62         byte b = 1;
63         
64         while (b != 0)
65         {
66             b = array[index];
67             if (b != 0) {
68                 str.append((char)(b & 0x00FF));
69             }
70             index ++;
71         }
72         return index;
73     }
74        
75     /**
76     * Compares a null terminated substring from an array of bytes.
77     * Substring is a set of non-zero bytes starting from argument start to the
78     * next zero byte. if the first byte is a zero, the next byte will be taken as
79     * the first byte.
80     * @param str string to compare
81     * @param array byte array
82     * @param strindex index within str to start comparing
83     * @param aindex array index to start in byte count
84     * @return the end position of the substring within str if matches otherwise
85     * a -1
86     */

87     static int compareNullTermByteSubString(String JavaDoc str, byte[] array,
88                                                       int strindex, int aindex)
89     {
90         byte b = 1;
91         int length = str.length();
92         
93         while (b != 0)
94         {
95             b = array[aindex];
96             aindex ++;
97             if (b == 0) {
98                 break;
99             }
100             // if we have reached the end of the string and yet the array has not
101
// reached the end of their substring yet, abort
102
if (strindex == length
103                 || (str.charAt(strindex) != (char)(b & 0xFF))) {
104               return -1;
105             }
106             strindex ++;
107         }
108         return strindex;
109     }
110        
111     /**
112     * Skip null terminated substrings from an array of bytes.
113     * Substring is a set of non-zero bytes starting from argument start to the
114     * next zero byte. If the first byte is a zero, the next byte will be taken as
115     * the first byte.
116     * @param array byte array
117     * @param index to start substrings in byte count
118     * @param skipcount number of null terminated substrings to skip
119     * @return the end position of the substrings within the character array
120     */

121     static int skipNullTermByteSubString(byte[] array, int index,
122                                                    int skipcount)
123     {
124         byte b;
125         for (int i = 0; i < skipcount; i ++)
126         {
127             b = 1;
128             while (b != 0)
129             {
130                 b = array[index];
131                 index ++;
132             }
133         }
134         return index;
135     }
136        
137     /**
138      * skip substrings from an array of characters, where each character is a set
139      * of 2 bytes. substring is a set of non-zero bytes starting from argument
140      * start to the byte of the argument value. skips up to a max number of
141      * characters
142      * @param array byte array to parse
143      * @param index to start substrings in byte count
144      * @param length the max number of bytes to skip
145      * @param skipend value of byte to skip to
146      * @return the number of bytes skipped
147      */

148     static int skipByteSubString(byte[] array, int index, int length,
149                                            byte skipend)
150     {
151         int result;
152         byte b;
153         
154         for (result = 0; result < length; result ++)
155         {
156             b = array[index + result];
157             if (b == skipend)
158             {
159                 result ++;
160                 break;
161             }
162         }
163         
164         return result;
165     }
166     
167     // private data member --------------------------------------------------
168

169     /**
170     * Minimum suffix value that indicates if a character is non character.
171     * Unicode 3.0 non characters
172     */

173     private static final int NON_CHARACTER_SUFFIX_MIN_3_0_ = 0xFFFE;
174     /**
175     * New minimum non character in Unicode 3.1
176     */

177     private static final int NON_CHARACTER_MIN_3_1_ = 0xFDD0;
178     /**
179     * New non character range in Unicode 3.1
180     */

181     private static final int NON_CHARACTER_MAX_3_1_ = 0xFDEF;
182     
183     // private constructor --------------------------------------------------
184

185     ///CLOVER:OFF
186
/**
187     * private constructor to avoid initialisation
188     */

189     private UCharacterUtility()
190     {
191     }
192     ///CLOVER:ON
193
}
194
195
Popular Tags