2 *******************************************************************************
\r
3 * Copyright (C) 1996-2004, International Business Machines Corporation and *
\r
4 * others. All Rights Reserved. *
\r
5 *******************************************************************************
\r
7 package com.ibm.icu.impl;
\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
16 public final class UCharacterUtility
\r
18 // public methods -----------------------------------------------------
\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
25 public static boolean isNonCharacter(int ch)
\r
27 if ((ch & NON_CHARACTER_SUFFIX_MIN_3_0_) ==
\r
28 NON_CHARACTER_SUFFIX_MIN_3_0_) {
\r
32 return ch >= NON_CHARACTER_MIN_3_1_ && ch <= NON_CHARACTER_MAX_3_1_;
\r
35 // package private methods ---------------------------------------------
\r
38 * joining 2 chars to form an int
\r
39 * @param msc most significant char
\r
40 * @param lsc least significant char
\r
43 static int toInt(char msc, char lsc)
\r
45 return ((msc << 16) | lsc);
\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
53 * @param str stringbuffer to store data in, data will be store with each
\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
59 static int getNullTermByteSubString(StringBuffer str, byte[] array,
\r
68 str.append((char)(b & 0x00FF));
\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
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
87 static int compareNullTermByteSubString(String str, byte[] array,
\r
88 int strindex, int aindex)
\r
91 int length = str.length();
\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
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
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
121 static int skipNullTermByteSubString(byte[] array, int index,
\r
125 for (int i = 0; i < skipcount; i ++)
\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
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
148 static int skipByteSubString(byte[] array, int index, int length,
\r
154 for (result = 0; result < length; result ++)
\r
156 b = array[index + result];
\r
167 // private data member --------------------------------------------------
\r
170 * Minimum suffix value that indicates if a character is non character.
\r
171 * Unicode 3.0 non characters
\r
173 private static final int NON_CHARACTER_SUFFIX_MIN_3_0_ = 0xFFFE;
\r
175 * New minimum non character in Unicode 3.1
\r
177 private static final int NON_CHARACTER_MIN_3_1_ = 0xFDD0;
\r
179 * New non character range in Unicode 3.1
\r
181 private static final int NON_CHARACTER_MAX_3_1_ = 0xFDEF;
\r
183 // private constructor --------------------------------------------------
\r
187 * private constructor to avoid initialisation
\r
189 private UCharacterUtility()
\r