Made code review changes

X-SVN-Rev: 3936
This commit is contained in:
Syn Wee Quek 2001-03-07 02:52:05 +00:00
parent 02d076091f
commit 71d1d249d7
14 changed files with 762 additions and 576 deletions

View File

@ -5,8 +5,8 @@
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/lang/UCharacter.java,v $
* $Date: 2001/02/28 20:59:44 $
* $Revision: 1.1 $
* $Date: 2001/03/07 02:52:05 $
* $Revision: 1.2 $
*
*******************************************************************************
*/
@ -354,36 +354,40 @@ public final class UCharacter
int props = getProps(ch);
int result = -1;
// if props == 0, it will just fall through and return -1
if (!UCharacterPropertyDB.isExceptionIndicator(props))
{
if (!UCharacterPropertyDB.isExceptionIndicator(props)) {
// not contained in exception data
if (UCharacterPropertyDB.getPropType(props) ==
UCharacterCategory.DECIMAL_DIGIT_NUMBER)
UCharacterCategory.DECIMAL_DIGIT_NUMBER) {
result = UCharacterPropertyDB.getSignedValue(props);
}
}
else
{
else {
// contained in exception data
int index = UCharacterPropertyDB.getExceptionIndex(props);
if (PROPERTY_DB_.hasExceptionValue(index,
UCharacterPropertyDB.EXC_DIGIT_VALUE_))
UCharacterPropertyDB.EXC_DIGIT_VALUE_)) {
result = PROPERTY_DB_.getException(index,
UCharacterPropertyDB.EXC_DIGIT_VALUE_) &
LAST_CHAR_MASK_;
else
}
else {
if (!PROPERTY_DB_.hasExceptionValue(index,
UCharacterPropertyDB.EXC_DENOMINATOR_VALUE_)
UCharacterPropertyDB.EXC_DENOMINATOR_VALUE_)
&& PROPERTY_DB_.hasExceptionValue(index,
UCharacterPropertyDB.EXC_NUMERIC_VALUE_))
result = PROPERTY_DB_.getException(index,
UCharacterPropertyDB.EXC_NUMERIC_VALUE_);
UCharacterPropertyDB.EXC_NUMERIC_VALUE_)) {
result = PROPERTY_DB_.getException(index,
UCharacterPropertyDB.EXC_NUMERIC_VALUE_);
}
}
}
if (result < 0)
if (result < 0) {
result = getHanDigit(ch);
}
if (result < 0 || result >= radix)
if (result < 0 || result >= radix) {
return -1;
}
return result;
}
@ -420,35 +424,41 @@ public final class UCharacter
// if props == 0, it will just fall through and return -1
if (type != UCharacterCategory.DECIMAL_DIGIT_NUMBER &&
type != UCharacterCategory.LETTER_NUMBER &&
type != UCharacterCategory.OTHER_NUMBER)
type != UCharacterCategory.OTHER_NUMBER) {
return -1;
}
int result = -1;
if (!UCharacterPropertyDB.isExceptionIndicator(props))
if (!UCharacterPropertyDB.isExceptionIndicator(props)) {
// not contained in exception data
result = UCharacterPropertyDB.getSignedValue(props);
else
{
}
else {
// contained in exception data
int index = UCharacterPropertyDB.getExceptionIndex(props);
if (PROPERTY_DB_.hasExceptionValue(index,
UCharacterPropertyDB.EXC_DIGIT_VALUE_))
UCharacterPropertyDB.EXC_DIGIT_VALUE_)) {
result = PROPERTY_DB_.getException(index,
UCharacterPropertyDB.EXC_DIGIT_VALUE_);
else
}
else {
if (!PROPERTY_DB_.hasExceptionValue(index,
UCharacterPropertyDB.EXC_DENOMINATOR_VALUE_)
UCharacterPropertyDB.EXC_DENOMINATOR_VALUE_)
&& PROPERTY_DB_.hasExceptionValue(index,
UCharacterPropertyDB.EXC_NUMERIC_VALUE_))
result = PROPERTY_DB_.getException(index,
UCharacterPropertyDB.EXC_NUMERIC_VALUE_)) {
result = PROPERTY_DB_.getException(index,
UCharacterPropertyDB.EXC_NUMERIC_VALUE_);
}
}
}
if (result < 0)
if (result < 0) {
result = getHanDigit(ch);
}
if (result < 0)
if (result < 0) {
return -2;
}
return result;
}
@ -755,20 +765,21 @@ public final class UCharacter
{
int props = getProps(ch);
// if props == 0, it will just fall through and return itself
if(!UCharacterPropertyDB.isExceptionIndicator(props))
{
if(!UCharacterPropertyDB.isExceptionIndicator(props)) {
int cat = UCharacterPropertyDB.getPropType(props);
if (cat == UCharacterCategory.UPPERCASE_LETTER ||
cat == UCharacterCategory.TITLECASE_LETTER)
cat == UCharacterCategory.TITLECASE_LETTER) {
return ch + UCharacterPropertyDB.getSignedValue(props);
}
}
else
{
int index = UCharacterPropertyDB.getExceptionIndex(props);
if (PROPERTY_DB_.hasExceptionValue(index,
UCharacterPropertyDB.EXC_LOWERCASE_))
UCharacterPropertyDB.EXC_LOWERCASE_)) {
return PROPERTY_DB_.getException(index,
UCharacterPropertyDB.EXC_LOWERCASE_);
}
}
return ch;
}
@ -787,11 +798,13 @@ public final class UCharacter
*/
public static String toString(int ch)
{
if (ch < MIN_VALUE || ch > MAX_VALUE)
if (ch < MIN_VALUE || ch > MAX_VALUE) {
return null;
}
if (ch < UCharacter.SUPPLEMENTARY_MIN_VALUE)
if (ch < UCharacter.SUPPLEMENTARY_MIN_VALUE) {
return String.valueOf((char)ch);
}
char result[] = new char[2];
result[0] = (char)UTF16.getLeadSurrogate(ch);
@ -819,26 +832,28 @@ public final class UCharacter
{
int props = getProps(ch);
// if props == 0, it will just fall through and return itself
if (!UCharacterPropertyDB.isExceptionIndicator(props))
{
if (!UCharacterPropertyDB.isExceptionIndicator(props)) {
if (UCharacterPropertyDB.getPropType(props) ==
UCharacterCategory.LOWERCASE_LETTER)
UCharacterCategory.LOWERCASE_LETTER) {
// here, titlecase is same as uppercase
return ch - UCharacterPropertyDB.getSignedValue(props);
}
}
else
{
else {
int index = UCharacterPropertyDB.getExceptionIndex(props);
if (PROPERTY_DB_.hasExceptionValue(index,
UCharacterPropertyDB.EXC_TITLECASE_))
UCharacterPropertyDB.EXC_TITLECASE_)) {
return PROPERTY_DB_.getException(index,
UCharacterPropertyDB.EXC_TITLECASE_);
else
}
else {
// here, titlecase is same as uppercase
if (PROPERTY_DB_.hasExceptionValue(index,
UCharacterPropertyDB.EXC_UPPERCASE_))
UCharacterPropertyDB.EXC_UPPERCASE_)) {
return PROPERTY_DB_.getException(index,
UCharacterPropertyDB.EXC_UPPERCASE_);
}
}
}
return ch; // no mapping - return c itself
}
@ -860,20 +875,21 @@ public final class UCharacter
{
int props = getProps(ch);
// if props == 0, it will just fall through and return itself
if (!UCharacterPropertyDB.isExceptionIndicator(props))
{
if (!UCharacterPropertyDB.isExceptionIndicator(props)) {
if (UCharacterPropertyDB.getPropType(props) ==
UCharacterCategory.LOWERCASE_LETTER)
UCharacterCategory.LOWERCASE_LETTER) {
// here, titlecase is same as uppercase */
return ch - UCharacterPropertyDB.getSignedValue(props);
}
}
else
{
int index = UCharacterPropertyDB.getExceptionIndex(props);
if (PROPERTY_DB_.hasExceptionValue(index,
UCharacterPropertyDB.EXC_UPPERCASE_))
UCharacterPropertyDB.EXC_UPPERCASE_)) {
return PROPERTY_DB_.getException(index,
UCharacterPropertyDB.EXC_UPPERCASE_);
}
}
return ch; // no mapping - return c itself
}
@ -1000,8 +1016,9 @@ public final class UCharacter
public static int getDirection(int ch)
{
int props = getProps(ch);
if (props != 0)
if (props != 0) {
return UCharacterPropertyDB.getDirection(props);
}
return UCharacterDirection.LEFT_TO_RIGHT;
}
@ -1038,9 +1055,10 @@ public final class UCharacter
int props = getProps(ch);
// mirrored - the value is a mirror offset
// if props == 0, it will just fall through and return false
if (UCharacterPropertyDB.isMirrored(props))
if(!UCharacterPropertyDB.isExceptionIndicator(props))
if (UCharacterPropertyDB.isMirrored(props)) {
if(!UCharacterPropertyDB.isExceptionIndicator(props)) {
return ch + UCharacterPropertyDB.getSignedValue(props);
}
else
{
int index = UCharacterPropertyDB.getExceptionIndex(props);
@ -1049,6 +1067,7 @@ public final class UCharacter
return PROPERTY_DB_.getException(index,
UCharacterPropertyDB.EXC_MIRROR_MAPPING_);
}
}
return ch;
}
@ -1060,17 +1079,21 @@ public final class UCharacter
public static byte getCombiningClass(int ch)
{
int props = getProps(ch);
if(!UCharacterPropertyDB.isExceptionIndicator(props))
if(!UCharacterPropertyDB.isExceptionIndicator(props)) {
if (UCharacterPropertyDB.getPropType(props) ==
UCharacterCategory.NON_SPACING_MARK)
UCharacterCategory.NON_SPACING_MARK) {
return (byte)(PROPERTY_DB_.getUnsignedValue(props));
else
}
else {
return 0;
else
}
}
else {
// the combining class is in bits 23..16 of the first exception value
return (byte)((PROPERTY_DB_.getException(PROPERTY_DB_.getExceptionIndex(
props), UCharacterPropertyDB.EXC_COMBINING_CLASS_)
>> SHIFT_16_) & LAST_BYTE_MASK_);
}
}
/**
@ -1086,12 +1109,18 @@ public final class UCharacter
*/
public static boolean isLegal(int ch)
{
if (ch < MIN_VALUE) return false;
if (ch < SURROGATE_MIN_VALUE_) return true;
if (ch <= SURROGATE_MAX_VALUE_) return false;
if ((ch & LAST_CHAR_MASK_) >= NOT_A_CHAR_SUFFIX_MIN_)
if (ch < MIN_VALUE) {
return false;
}
if (ch < SURROGATE_MIN_VALUE_) {
return true;
}
if (ch <= SURROGATE_MAX_VALUE_) {
return false;
}
if ((ch & LAST_CHAR_MASK_) >= NOT_A_CHAR_SUFFIX_MIN_) {
return false;
}
return (ch <= MAX_VALUE);
}
@ -1116,10 +1145,12 @@ public final class UCharacter
for (int i = 0; i < size; i ++)
{
codepoint = UTF16.charAt(str, i);
if (!isLegal(codepoint))
if (!isLegal(codepoint)) {
return false;
if (isSupplementary(codepoint))
}
if (isSupplementary(codepoint)) {
i ++;
}
}
return true;
}
@ -1201,8 +1232,9 @@ public final class UCharacter
*/
public static int getCodePoint(char lead, char trail)
{
if (UTF16.isLeadSurrogate(lead) && UTF16.isTrailSurrogate(trail))
if (UTF16.isLeadSurrogate(lead) && UTF16.isTrailSurrogate(trail)) {
return getRawSupplementary(lead, trail);
}
return UCharacter.REPLACEMENT_CHAR;
}
@ -1218,8 +1250,9 @@ public final class UCharacter
*/
public static int getCodePoint(char char16)
{
if (UCharacter.isLegal(char16))
if (UCharacter.isLegal(char16)) {
return char16;
}
throw new IllegalArgumentException("Illegal codepoint");
}
@ -1254,7 +1287,7 @@ public final class UCharacter
*/
public static String toUpperCase(Locale locale, String str)
{
int size = UTF16.countCP(str);
int size = UTF16.countCodePoint(str);
StringBuffer result = new StringBuffer(size << 1); // initial buffer
int props;
int exception;
@ -1266,26 +1299,30 @@ public final class UCharacter
for (int i = 0; i < size; i ++)
{
ch = UTF16.charAtCPOffset(str, i);
ch = UTF16.charAtCodePointOffset(str, i);
props = PROPERTY_DB_.getProperty(ch);
if (!UCharacterPropertyDB.isExceptionIndicator(props))
{
if (UCharacterPropertyDB.getPropType(props) ==
UCharacterCategory.LOWERCASE_LETTER)
UCharacterCategory.LOWERCASE_LETTER) {
ch -= UCharacterPropertyDB.getSignedValue(props);
}
UTF16.append(result, ch);
}
else
{
index = UCharacterPropertyDB.getExceptionIndex(props);
if (PROPERTY_DB_.hasExceptionValue(index,
UCharacterPropertyDB.EXC_SPECIAL_CASING_))
getSpecialUpperCase(ch, index, result, str, i, tr_az, lt);
else
UCharacterPropertyDB.EXC_SPECIAL_CASING_)) {
getSpecialUpperCase(ch, index, result, str, i, tr_az, lt);
}
else {
if (PROPERTY_DB_.hasExceptionValue(index,
UCharacterPropertyDB.EXC_UPPERCASE_))
UCharacterPropertyDB.EXC_UPPERCASE_)) {
UTF16.append(result, PROPERTY_DB_.getException(index,
UCharacterPropertyDB.EXC_UPPERCASE_));
UCharacterPropertyDB.EXC_UPPERCASE_));
}
}
}
}
return result.toString();
@ -1300,7 +1337,7 @@ public final class UCharacter
*/
public static String toLowerCase(Locale locale, String str)
{
int size = UTF16.countCP(str);
int size = UTF16.countCodePoint(str);
StringBuffer result = new StringBuffer(size << 1); // initial buffer
int props;
int exception;
@ -1313,27 +1350,29 @@ public final class UCharacter
for (int i = 0; i < size; i ++)
{
ch = UTF16.charAtCPOffset(str, i);
ch = UTF16.charAtCodePointOffset(str, i);
props = PROPERTY_DB_.getProperty(ch);
if (!UCharacterPropertyDB.isExceptionIndicator(props))
{
if (!UCharacterPropertyDB.isExceptionIndicator(props)) {
type = UCharacterPropertyDB.getPropType(props);
if (type == UCharacterCategory.UPPERCASE_LETTER ||
type == UCharacterCategory.TITLECASE_LETTER)
type == UCharacterCategory.TITLECASE_LETTER) {
ch += UCharacterPropertyDB.getSignedValue(props);
}
UTF16.append(result, ch);
}
else
{
else {
index = UCharacterPropertyDB.getExceptionIndex(props);
if (PROPERTY_DB_.hasExceptionValue(index,
UCharacterPropertyDB.EXC_SPECIAL_CASING_))
getSpecialLowerCase(ch, index, result, str, i, tr_az, lt);
else
UCharacterPropertyDB.EXC_SPECIAL_CASING_)) {
getSpecialLowerCase(ch, index, result, str, i, tr_az, lt);
}
else {
if (PROPERTY_DB_.hasExceptionValue(index,
UCharacterPropertyDB.EXC_LOWERCASE_))
UCharacterPropertyDB.EXC_LOWERCASE_)) {
UTF16.append(result, PROPERTY_DB_.getException(index,
UCharacterPropertyDB.EXC_LOWERCASE_));
UCharacterPropertyDB.EXC_LOWERCASE_));
}
}
}
}
return result.toString();
@ -1363,8 +1402,9 @@ public final class UCharacter
*/
private static int getProps(int ch)
{
if (ch >= UCharacter.MIN_VALUE & ch <= UCharacter.MAX_VALUE)
if (ch >= UCharacter.MIN_VALUE & ch <= UCharacter.MAX_VALUE) {
return PROPERTY_DB_.getProperty(ch);
}
return 0;
}
@ -1419,41 +1459,42 @@ public final class UCharacter
{
int exception = PROPERTY_DB_.getException(index,
UCharacterPropertyDB.EXC_SPECIAL_CASING_);
if (exception < 0)
{
if (exception < 0) {
// use hardcoded conditions and mappings
if (ch == LATIN_SMALL_LETTER_I_)
{
if (tr_az)
if (ch == LATIN_SMALL_LETTER_I_) {
if (tr_az) {
// turkish and azerbaijani : i maps to dotted I
buffer.append(LATIN_CAPITAL_LETTER_I_WITH_DOT_ABOVE_);
else
}
else {
// other languages: i maps to I
buffer.append(LATIN_CAPITAL_LETTER_I_);
}
}
else
if (ch == COMBINING_DOT_ABOVE_ && lt)
{
else {
if (ch == COMBINING_DOT_ABOVE_ && lt) {
// lithuanian: remove DOT ABOVE after U+0069 "i" with upper
// or titlecase
for (int j = chindex; j > 0; j ++)
{
ch = UTF16.charAtCPOffset(str, j);
if (getType(ch) != UCharacterCategory.NON_SPACING_MARK)
for (int j = chindex; j > 0; j ++) {
ch = UTF16.charAtCodePointOffset(str, j);
if (getType(ch) != UCharacterCategory.NON_SPACING_MARK) {
break;
}
}
// if the base letter is not an 'i' (U+0069)? keep the dot
if (ch != LATIN_SMALL_LETTER_I_)
if (ch != LATIN_SMALL_LETTER_I_) {
buffer.append(COMBINING_DOT_ABOVE_);
}
else
// no known conditional special case mapping, output the code
// point itself
UTF16.append(buffer, ch);
}
}
else {
// no known conditional special case mapping, output the code
// point itself
UTF16.append(buffer, ch);
}
}
}
else
{
else {
// get the special case mapping string from the data file
index = exception & LAST_CHAR_MASK_;
PROPERTY_DB_.getUpperCase(index, buffer);
@ -1478,34 +1519,37 @@ public final class UCharacter
{
int exception = PROPERTY_DB_.getException(index,
UCharacterPropertyDB.EXC_SPECIAL_CASING_);
if (exception < 0)
{
if (exception < 0) {
// use hardcoded conditions and mappings
if (ch == LATIN_CAPITAL_LETTER_I_)
{
if (tr_az)
if (ch == LATIN_CAPITAL_LETTER_I_) {
if (tr_az) {
// turkish and azerbaijani : I maps to dotless i
buffer.append(LATIN_SMALL_LETTER_DOTLESS_I_);
else
}
else {
// other languages: I maps to i
buffer.append(LATIN_SMALL_LETTER_I_);
}
}
else
if (ch == GREEK_CAPITAL_LETTER_SIGMA_)
{
else {
if (ch == GREEK_CAPITAL_LETTER_SIGMA_) {
// greek capital sigma maps depending on whether the following
// character is a letter
chindex ++;
if (chindex != str.length() &&
isLetter(UTF16.charAtCPOffset(str, chindex)))
isLetter(UTF16.charAtCodePointOffset(str, chindex))) {
buffer.append(GREEK_SMALL_LETTER_SIGMA_);
else
}
else {
buffer.append(GREEK_SMALL_LETTER_RHO_);
}
}
else
else {
// no known conditional special case mapping, output the code
// point itself
UTF16.append(buffer, ch);
}
}
}
else
{

View File

@ -6,8 +6,8 @@
*
* $Source:
* /usr/cvs/icu4j/icu4j/src/com/ibm/icu/text/UCharacterName.java $
* $Date: 2001/02/28 20:59:44 $
* $Revision: 1.1 $
* $Date: 2001/03/07 02:52:05 $
* $Revision: 1.2 $
*
*******************************************************************************
*/
@ -75,8 +75,9 @@ final class UCharacterName
protected static String getName(int ch, int choice)
{
if (ch < 0 || ch > 0x1ffff ||
choice >= UCharacterNameChoice.U_CHAR_NAME_CHOICE_COUNT)
choice >= UCharacterNameChoice.U_CHAR_NAME_CHOICE_COUNT) {
return null;
}
String result = "";
@ -84,13 +85,15 @@ final class UCharacterName
// the same as the modern ones, extension A was only introduced with
// Unicode 3.0, and the Hangul syllable block was moved and changed around
// Unicode 1.1.5.
if (choice == UCharacterNameChoice.U_UNICODE_CHAR_NAME)
if (choice == UCharacterNameChoice.U_UNICODE_CHAR_NAME) {
// try getting algorithmic name first
result = getAlgName(ch);
}
// getting normal character name
if (result == null || result.length() == 0)
if (result == null || result.length() == 0) {
result = NAME_DB_.getGroupName(ch, choice);
}
return result;
}
@ -106,13 +109,15 @@ final class UCharacterName
{
// checks for illegal arguments
if (choice >= UCharacterNameChoice.U_CHAR_NAME_CHOICE_COUNT ||
name == null || name.length() == 0)
name == null || name.length() == 0) {
return -1;
}
// try algorithmic names first, if fails then try group names
int result = getAlgorithmChar(choice, name);
if (result >= 0)
if (result >= 0) {
return result;
}
return getGroupChar(name, choice);
}
@ -129,8 +134,7 @@ final class UCharacterName
StringBuffer s = new StringBuffer();
int index = NAME_DB_.getAlgorithmIndex(ch);
if (index >= 0)
{
if (index >= 0) {
NAME_DB_.appendAlgorithmName(index, ch, s);
return s.toString();
}
@ -145,14 +149,15 @@ final class UCharacterName
private static int getAlgorithmChar(int choice, String name)
{
// 1.0 has no algorithmic names
if (choice != UCharacterNameChoice.U_UNICODE_CHAR_NAME)
if (choice != UCharacterNameChoice.U_UNICODE_CHAR_NAME) {
return -1;
}
int result;
for (int count = NAME_DB_.countAlgorithm() - 1; count >= 0; count --)
{
for (int count = NAME_DB_.countAlgorithm() - 1; count >= 0; count --) {
result = NAME_DB_.getAlgorithmChar(count, name);
if (result >= 0)
if (result >= 0) {
return result;
}
}
return -1;
}
@ -168,11 +173,11 @@ final class UCharacterName
int groupcount = NAME_DB_.countGroup();
int result = 0;
for (int i = 0; i < groupcount; i ++)
{
for (int i = 0; i < groupcount; i ++) {
result = NAME_DB_.getGroupChar(i, name, choice);
if (result != -1)
if (result != -1) {
return result;
}
}
return -1;
}

View File

@ -5,8 +5,8 @@
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/lang/Attic/UCharacterUtil.java,v $
* $Date: 2001/02/28 20:59:44 $
* $Revision: 1.1 $
* $Date: 2001/03/07 02:52:05 $
* $Revision: 1.2 $
*
*******************************************************************************
*/
@ -51,10 +51,12 @@ final class UCharacterUtil
*/
protected static char toChar(byte bytes[])
{
if (bytes == null || bytes.length == 0)
if (bytes == null || bytes.length == 0) {
return 0;
if (bytes.length == 1)
}
if (bytes.length == 1) {
return toChar(bytes[0]);
}
char firstbyte = (char)(toChar(bytes[0]) << 8);
char secondbyte = toChar(bytes[1]);
@ -141,8 +143,9 @@ final class UCharacterUtil
while (b != 0)
{
b = array[index];
if (b != 0)
if (b != 0) {
str.append((char)(b & 0x00FF));
}
index ++;
}
return index;
@ -170,12 +173,14 @@ final class UCharacterUtil
{
b = array[aindex];
aindex ++;
if (b == 0)
if (b == 0) {
break;
}
// if we have reached the end of the string and yet the array has not
// reached the end of their substring yet, abort
if (strindex == length || (str.charAt(strindex) != (char)(b & 0xFF)))
if (strindex == length || (str.charAt(strindex) != (char)(b & 0xFF))) {
return -1;
}
strindex ++;
}
return strindex;
@ -255,8 +260,9 @@ final class UCharacterUtil
{
b = array[index + result];
result ++;
if (b == skipend)
if (b == skipend) {
break;
}
}
return result;

View File

@ -5,8 +5,8 @@
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/text/UTF16.java,v $
* $Date: 2001/02/28 20:59:44 $
* $Revision: 1.1 $
* $Date: 2001/03/07 02:52:05 $
* $Revision: 1.2 $
*
*******************************************************************************
*/
@ -149,7 +149,7 @@ public final class UTF16
* <code>UTF16.getCharCount()</code>, as well as random access. If a validity
* check is required, use <code><a href="../UCharacter.html#isLegal(char)">
* UCharacter.isLegal()</a></code> on the return value.
* If tbe char retrieved is part of a surrogate pair, its supplementary
* If the char retrieved is part of a surrogate pair, its supplementary
* character will be returned. If a complete supplementary character is not
* found the incomplete character will be returned
* @param source array of UTF-16 chars
@ -161,7 +161,7 @@ public final class UTF16
*/
public static int charAt(String source, int offset16)
{
if (offset16 >= source.length())
if (offset16 < 0 || offset16 >= source.length())
return -1;
char single = source.charAt(offset16);
@ -211,9 +211,9 @@ public final class UTF16
* @param offset32 UTF-32 offset to the start of the character.
* @return a single UTF32 value, otherwise -1 if there's an error
*/
public static int charAtCPOffset(String source, int offset32)
public static int charAtCodePointOffset(String source, int offset32)
{
int offset16 = findOffsetFromCP(source, offset32);
int offset16 = findOffsetFromCodePoint(source, offset32);
return charAt(source, offset16);
}
@ -227,8 +227,9 @@ public final class UTF16
*/
public static int getCharCount(int char32)
{
if (char32 < UCharacter.SUPPLEMENTARY_MIN_VALUE)
if (char32 < UCharacter.SUPPLEMENTARY_MIN_VALUE) {
return 1;
}
return 2;
}
@ -260,13 +261,15 @@ public final class UTF16
if (isLeadSurrogate(ch))
{
if (++ offset16 < source.length() &&
isTrailSurrogate(source.charAt(offset16)))
isTrailSurrogate(source.charAt(offset16))) {
return LEAD_SURROGATE_BOUNDARY;
}
}
else
// isTrailSurrogate(ch), so
if (-- offset16 >= 0 && isLeadSurrogate(source.charAt(offset16)))
if (-- offset16 >= 0 && isLeadSurrogate(source.charAt(offset16))) {
return TRAIL_SURROGATE_BOUNDARY;
}
return SINGLE_CHAR_BOUNDARY;
}
@ -292,9 +295,9 @@ public final class UTF16
* [offset32 - (value >> 2), offset32 + (value & 3)].
* @exception StringIndexOutOfBoundsException if offset32 is out of bounds.
*/
public static int boundsAtCPOffset(String source, int offset32)
public static int boundsAtCodePointOffset(String source, int offset32)
{
int offset16 = findOffsetFromCP(source, offset32);
int offset16 = findOffsetFromCodePoint(source, offset32);
return bounds(source, offset16);
}
@ -342,9 +345,10 @@ public final class UTF16
*/
public static int getLeadSurrogate(int char32)
{
if (char32 >= UCharacter.SUPPLEMENTARY_MIN_VALUE)
if (char32 >= UCharacter.SUPPLEMENTARY_MIN_VALUE) {
return LEAD_SURROGATE_OFFSET_ +
(char32 >> UCharacter.LEAD_SURROGATE_SHIFT_);
}
return 0;
}
@ -360,9 +364,10 @@ public final class UTF16
*/
public static int getTrailSurrogate(int char32)
{
if (char32 >= UCharacter.SUPPLEMENTARY_MIN_VALUE)
if (char32 >= UCharacter.SUPPLEMENTARY_MIN_VALUE) {
return TRAIL_SURROGATE_MIN_VALUE_ + (char32 &
UCharacter.TRAIL_SURROGATE_MASK_);
}
return (char)char32;
}
@ -379,10 +384,12 @@ public final class UTF16
*/
public static String valueOf(int char32)
{
if (char32 < UCharacter.MIN_VALUE || char32 > UCharacter.MAX_VALUE)
if (char32 < UCharacter.MIN_VALUE || char32 > UCharacter.MAX_VALUE) {
throw new IllegalArgumentException("Illegal codepoint");
if (char32 < UCharacter.SUPPLEMENTARY_MIN_VALUE)
}
if (char32 < UCharacter.SUPPLEMENTARY_MIN_VALUE) {
return String.valueOf((char)char32);
}
char str[] = new char[2];
str[0] = (char)(LEAD_SURROGATE_OFFSET_ +
(char32 >> UCharacter.LEAD_SURROGATE_SHIFT_));
@ -400,7 +407,7 @@ public final class UTF16
* @return UTF-16 offset
* @exception StringIndexOutOfBoundsException if offset32 is out of bounds.
*/
public static int findOffsetFromCP(String source, int offset32)
public static int findOffsetFromCodePoint(String source, int offset32)
{
char ch;
int size = source.length(),
@ -410,14 +417,16 @@ public final class UTF16
{
ch = source.charAt(result);
if (isLeadSurrogate(ch) && ((result + 1) < size) &&
isTrailSurrogate(source.charAt(result + 1)))
isTrailSurrogate(source.charAt(result + 1))) {
result ++;
}
count --;
result ++;
}
if (result >= size)
if (result >= size) {
throw new StringIndexOutOfBoundsException(offset32);
}
return result;
}
@ -440,10 +449,11 @@ public final class UTF16
* @return UTF-32 offset
* @exception StringIndexOutOfBoundsException if offset16 is out of bounds.
*/
public static int findCPOffset(String source, int offset16)
public static int findCodePointOffset(String source, int offset16)
{
if (offset16 >= source.length())
throw new StringIndexOutOfBoundsException(offset16);
if (offset16 >= source.length()) {
throw new StringIndexOutOfBoundsException(offset16);
}
int result = 0;
char ch;
@ -452,8 +462,9 @@ public final class UTF16
for (int i = 0; i < offset16; ++ i)
{
ch = source.charAt(i);
if (hadLeadSurrogate && isTrailSurrogate(ch))
if (hadLeadSurrogate && isTrailSurrogate(ch)) {
hadLeadSurrogate = false; // count valid trail as zero
}
else
{
hadLeadSurrogate = isLeadSurrogate(ch);
@ -462,8 +473,9 @@ public final class UTF16
}
// end of source being a supplementary character
// shift result back to the start of the supplementary character
if (hadLeadSurrogate && isTrailSurrogate(source.charAt(offset16)))
if (hadLeadSurrogate && isTrailSurrogate(source.charAt(offset16))) {
result --;
}
return result;
}
@ -480,8 +492,9 @@ public final class UTF16
public static StringBuffer append(StringBuffer target, int char32)
{
// Check for irregular values
if (char32 < UCharacter.MIN_VALUE || char32 > UCharacter.MAX_VALUE)
if (char32 < UCharacter.MIN_VALUE || char32 > UCharacter.MAX_VALUE) {
throw new IllegalArgumentException("Illegal codepoint");
}
// Write the UTF-16 values
if (char32 >= UCharacter.SUPPLEMENTARY_MIN_VALUE)
@ -491,8 +504,9 @@ public final class UTF16
target.append((char)(TRAIL_SURROGATE_MIN_VALUE_ +
(char32 & UCharacter.TRAIL_SURROGATE_MASK_)));
}
else
else {
target.append((char)char32);
}
return target;
}
@ -508,49 +522,59 @@ public final class UTF16
*/
public int compare(Object a, Object b)
{
if (a == b)
if (a == b) {
return 0;
if (a == null)
}
if (a == null) {
return -1;
if (b == null)
}
if (b == null) {
return 1;
}
String sa = (String) a;
String sb = (String) b;
int lena = sa.length();
int lenb = sb.length();
int len = lena;
if (len > lenb)
if (len > lenb) {
len = lenb;
}
for (int i = 0; i < len; ++i)
{
char ca = sa.charAt(i);
char cb = sb.charAt(i);
if (ca == cb)
if (ca == cb) {
continue; // skip remap if equal
}
// start of only different section
// what this part does is to rearrange the characters 0xE000 to 0xFFFF
// to the region starting from 0xD800
// and shift the surrogate characters to above this region
if (ca >= LEAD_SURROGATE_MIN_VALUE_)
if (ca >= LEAD_SURROGATE_MIN_VALUE_) {
ca += (ca <= TRAIL_SURROGATE_MAX_VALUE_) ? 0x2000 : -0x800;
if (cb >= LEAD_SURROGATE_MIN_VALUE_)
}
if (cb >= LEAD_SURROGATE_MIN_VALUE_) {
cb += (cb <= TRAIL_SURROGATE_MAX_VALUE_) ? 0x2000 : -0x800;
}
// end of only different section
if (ca < cb)
if (ca < cb) {
return -1;
}
return 1; // wasn't equal, so return 1
}
if (lena < lenb)
if (lena < lenb) {
return -1;
}
if (lena > lenb)
if (lena > lenb) {
return 1;
}
return 0;
}
@ -561,9 +585,9 @@ public final class UTF16
* @param s UTF16 string
* @return number of codepoint in string
*/
public static int countCP(String s)
public static int countCodePoint(String s)
{
return findCPOffset(s, s.length() - 1) + 1;
return findCodePointOffset(s, s.length() - 1) + 1;
}
/**
@ -572,10 +596,10 @@ public final class UTF16
* @param offset32 UTF32 position to insert into
* @param char32 code point
*/
public static void setCharAtCPOffset(StringBuffer str, int offset32,
public static void setCharAtCodePointOffset(StringBuffer str, int offset32,
int char32)
{
int offset16 = findOffsetFromCP(str.toString(), offset32);
int offset16 = findOffsetFromCodePoint(str.toString(), offset32);
setCharAt(str, offset16, char32);
}
@ -587,9 +611,6 @@ public final class UTF16
*/
public static void setCharAt(StringBuffer source, int offset16, int char32)
{
if (offset16 >= source.length())
throw new StringIndexOutOfBoundsException(offset16);
int count = 1;
char single = source.charAt(offset16);
@ -598,9 +619,10 @@ public final class UTF16
{
// pairs of the surrogate with offset16 at the lead char found
if (isLeadSurrogate(single) && (source.length() > offset16 + 1) &&
isTrailSurrogate(source.charAt(offset16 + 1)))
isTrailSurrogate(source.charAt(offset16 + 1))) {
count ++;
else
}
else {
// pairs of the surrogate with offset16 at the trail char found
if (isTrailSurrogate(single) && (offset16 > 0) &&
isLeadSurrogate(source.charAt(offset16 -1)))
@ -608,6 +630,7 @@ public final class UTF16
offset16 --;
count ++;
}
}
}
source.replace(offset16, offset16 + count, valueOf(char32));
}

View File

@ -5,8 +5,8 @@
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/text/Attic/UCharacter.java,v $
* $Date: 2001/02/28 20:59:44 $
* $Revision: 1.1 $
* $Date: 2001/03/07 02:52:05 $
* $Revision: 1.2 $
*
*******************************************************************************
*/
@ -354,36 +354,40 @@ public final class UCharacter
int props = getProps(ch);
int result = -1;
// if props == 0, it will just fall through and return -1
if (!UCharacterPropertyDB.isExceptionIndicator(props))
{
if (!UCharacterPropertyDB.isExceptionIndicator(props)) {
// not contained in exception data
if (UCharacterPropertyDB.getPropType(props) ==
UCharacterCategory.DECIMAL_DIGIT_NUMBER)
UCharacterCategory.DECIMAL_DIGIT_NUMBER) {
result = UCharacterPropertyDB.getSignedValue(props);
}
}
else
{
else {
// contained in exception data
int index = UCharacterPropertyDB.getExceptionIndex(props);
if (PROPERTY_DB_.hasExceptionValue(index,
UCharacterPropertyDB.EXC_DIGIT_VALUE_))
UCharacterPropertyDB.EXC_DIGIT_VALUE_)) {
result = PROPERTY_DB_.getException(index,
UCharacterPropertyDB.EXC_DIGIT_VALUE_) &
LAST_CHAR_MASK_;
else
}
else {
if (!PROPERTY_DB_.hasExceptionValue(index,
UCharacterPropertyDB.EXC_DENOMINATOR_VALUE_)
UCharacterPropertyDB.EXC_DENOMINATOR_VALUE_)
&& PROPERTY_DB_.hasExceptionValue(index,
UCharacterPropertyDB.EXC_NUMERIC_VALUE_))
result = PROPERTY_DB_.getException(index,
UCharacterPropertyDB.EXC_NUMERIC_VALUE_);
UCharacterPropertyDB.EXC_NUMERIC_VALUE_)) {
result = PROPERTY_DB_.getException(index,
UCharacterPropertyDB.EXC_NUMERIC_VALUE_);
}
}
}
if (result < 0)
if (result < 0) {
result = getHanDigit(ch);
}
if (result < 0 || result >= radix)
if (result < 0 || result >= radix) {
return -1;
}
return result;
}
@ -420,35 +424,41 @@ public final class UCharacter
// if props == 0, it will just fall through and return -1
if (type != UCharacterCategory.DECIMAL_DIGIT_NUMBER &&
type != UCharacterCategory.LETTER_NUMBER &&
type != UCharacterCategory.OTHER_NUMBER)
type != UCharacterCategory.OTHER_NUMBER) {
return -1;
}
int result = -1;
if (!UCharacterPropertyDB.isExceptionIndicator(props))
if (!UCharacterPropertyDB.isExceptionIndicator(props)) {
// not contained in exception data
result = UCharacterPropertyDB.getSignedValue(props);
else
{
}
else {
// contained in exception data
int index = UCharacterPropertyDB.getExceptionIndex(props);
if (PROPERTY_DB_.hasExceptionValue(index,
UCharacterPropertyDB.EXC_DIGIT_VALUE_))
UCharacterPropertyDB.EXC_DIGIT_VALUE_)) {
result = PROPERTY_DB_.getException(index,
UCharacterPropertyDB.EXC_DIGIT_VALUE_);
else
}
else {
if (!PROPERTY_DB_.hasExceptionValue(index,
UCharacterPropertyDB.EXC_DENOMINATOR_VALUE_)
UCharacterPropertyDB.EXC_DENOMINATOR_VALUE_)
&& PROPERTY_DB_.hasExceptionValue(index,
UCharacterPropertyDB.EXC_NUMERIC_VALUE_))
result = PROPERTY_DB_.getException(index,
UCharacterPropertyDB.EXC_NUMERIC_VALUE_)) {
result = PROPERTY_DB_.getException(index,
UCharacterPropertyDB.EXC_NUMERIC_VALUE_);
}
}
}
if (result < 0)
if (result < 0) {
result = getHanDigit(ch);
}
if (result < 0)
if (result < 0) {
return -2;
}
return result;
}
@ -755,20 +765,21 @@ public final class UCharacter
{
int props = getProps(ch);
// if props == 0, it will just fall through and return itself
if(!UCharacterPropertyDB.isExceptionIndicator(props))
{
if(!UCharacterPropertyDB.isExceptionIndicator(props)) {
int cat = UCharacterPropertyDB.getPropType(props);
if (cat == UCharacterCategory.UPPERCASE_LETTER ||
cat == UCharacterCategory.TITLECASE_LETTER)
cat == UCharacterCategory.TITLECASE_LETTER) {
return ch + UCharacterPropertyDB.getSignedValue(props);
}
}
else
{
int index = UCharacterPropertyDB.getExceptionIndex(props);
if (PROPERTY_DB_.hasExceptionValue(index,
UCharacterPropertyDB.EXC_LOWERCASE_))
UCharacterPropertyDB.EXC_LOWERCASE_)) {
return PROPERTY_DB_.getException(index,
UCharacterPropertyDB.EXC_LOWERCASE_);
}
}
return ch;
}
@ -787,11 +798,13 @@ public final class UCharacter
*/
public static String toString(int ch)
{
if (ch < MIN_VALUE || ch > MAX_VALUE)
if (ch < MIN_VALUE || ch > MAX_VALUE) {
return null;
}
if (ch < UCharacter.SUPPLEMENTARY_MIN_VALUE)
if (ch < UCharacter.SUPPLEMENTARY_MIN_VALUE) {
return String.valueOf((char)ch);
}
char result[] = new char[2];
result[0] = (char)UTF16.getLeadSurrogate(ch);
@ -819,26 +832,28 @@ public final class UCharacter
{
int props = getProps(ch);
// if props == 0, it will just fall through and return itself
if (!UCharacterPropertyDB.isExceptionIndicator(props))
{
if (!UCharacterPropertyDB.isExceptionIndicator(props)) {
if (UCharacterPropertyDB.getPropType(props) ==
UCharacterCategory.LOWERCASE_LETTER)
UCharacterCategory.LOWERCASE_LETTER) {
// here, titlecase is same as uppercase
return ch - UCharacterPropertyDB.getSignedValue(props);
}
}
else
{
else {
int index = UCharacterPropertyDB.getExceptionIndex(props);
if (PROPERTY_DB_.hasExceptionValue(index,
UCharacterPropertyDB.EXC_TITLECASE_))
UCharacterPropertyDB.EXC_TITLECASE_)) {
return PROPERTY_DB_.getException(index,
UCharacterPropertyDB.EXC_TITLECASE_);
else
}
else {
// here, titlecase is same as uppercase
if (PROPERTY_DB_.hasExceptionValue(index,
UCharacterPropertyDB.EXC_UPPERCASE_))
UCharacterPropertyDB.EXC_UPPERCASE_)) {
return PROPERTY_DB_.getException(index,
UCharacterPropertyDB.EXC_UPPERCASE_);
}
}
}
return ch; // no mapping - return c itself
}
@ -860,20 +875,21 @@ public final class UCharacter
{
int props = getProps(ch);
// if props == 0, it will just fall through and return itself
if (!UCharacterPropertyDB.isExceptionIndicator(props))
{
if (!UCharacterPropertyDB.isExceptionIndicator(props)) {
if (UCharacterPropertyDB.getPropType(props) ==
UCharacterCategory.LOWERCASE_LETTER)
UCharacterCategory.LOWERCASE_LETTER) {
// here, titlecase is same as uppercase */
return ch - UCharacterPropertyDB.getSignedValue(props);
}
}
else
{
int index = UCharacterPropertyDB.getExceptionIndex(props);
if (PROPERTY_DB_.hasExceptionValue(index,
UCharacterPropertyDB.EXC_UPPERCASE_))
UCharacterPropertyDB.EXC_UPPERCASE_)) {
return PROPERTY_DB_.getException(index,
UCharacterPropertyDB.EXC_UPPERCASE_);
}
}
return ch; // no mapping - return c itself
}
@ -1000,8 +1016,9 @@ public final class UCharacter
public static int getDirection(int ch)
{
int props = getProps(ch);
if (props != 0)
if (props != 0) {
return UCharacterPropertyDB.getDirection(props);
}
return UCharacterDirection.LEFT_TO_RIGHT;
}
@ -1038,9 +1055,10 @@ public final class UCharacter
int props = getProps(ch);
// mirrored - the value is a mirror offset
// if props == 0, it will just fall through and return false
if (UCharacterPropertyDB.isMirrored(props))
if(!UCharacterPropertyDB.isExceptionIndicator(props))
if (UCharacterPropertyDB.isMirrored(props)) {
if(!UCharacterPropertyDB.isExceptionIndicator(props)) {
return ch + UCharacterPropertyDB.getSignedValue(props);
}
else
{
int index = UCharacterPropertyDB.getExceptionIndex(props);
@ -1049,6 +1067,7 @@ public final class UCharacter
return PROPERTY_DB_.getException(index,
UCharacterPropertyDB.EXC_MIRROR_MAPPING_);
}
}
return ch;
}
@ -1060,17 +1079,21 @@ public final class UCharacter
public static byte getCombiningClass(int ch)
{
int props = getProps(ch);
if(!UCharacterPropertyDB.isExceptionIndicator(props))
if(!UCharacterPropertyDB.isExceptionIndicator(props)) {
if (UCharacterPropertyDB.getPropType(props) ==
UCharacterCategory.NON_SPACING_MARK)
UCharacterCategory.NON_SPACING_MARK) {
return (byte)(PROPERTY_DB_.getUnsignedValue(props));
else
}
else {
return 0;
else
}
}
else {
// the combining class is in bits 23..16 of the first exception value
return (byte)((PROPERTY_DB_.getException(PROPERTY_DB_.getExceptionIndex(
props), UCharacterPropertyDB.EXC_COMBINING_CLASS_)
>> SHIFT_16_) & LAST_BYTE_MASK_);
}
}
/**
@ -1086,12 +1109,18 @@ public final class UCharacter
*/
public static boolean isLegal(int ch)
{
if (ch < MIN_VALUE) return false;
if (ch < SURROGATE_MIN_VALUE_) return true;
if (ch <= SURROGATE_MAX_VALUE_) return false;
if ((ch & LAST_CHAR_MASK_) >= NOT_A_CHAR_SUFFIX_MIN_)
if (ch < MIN_VALUE) {
return false;
}
if (ch < SURROGATE_MIN_VALUE_) {
return true;
}
if (ch <= SURROGATE_MAX_VALUE_) {
return false;
}
if ((ch & LAST_CHAR_MASK_) >= NOT_A_CHAR_SUFFIX_MIN_) {
return false;
}
return (ch <= MAX_VALUE);
}
@ -1116,10 +1145,12 @@ public final class UCharacter
for (int i = 0; i < size; i ++)
{
codepoint = UTF16.charAt(str, i);
if (!isLegal(codepoint))
if (!isLegal(codepoint)) {
return false;
if (isSupplementary(codepoint))
}
if (isSupplementary(codepoint)) {
i ++;
}
}
return true;
}
@ -1201,8 +1232,9 @@ public final class UCharacter
*/
public static int getCodePoint(char lead, char trail)
{
if (UTF16.isLeadSurrogate(lead) && UTF16.isTrailSurrogate(trail))
if (UTF16.isLeadSurrogate(lead) && UTF16.isTrailSurrogate(trail)) {
return getRawSupplementary(lead, trail);
}
return UCharacter.REPLACEMENT_CHAR;
}
@ -1218,8 +1250,9 @@ public final class UCharacter
*/
public static int getCodePoint(char char16)
{
if (UCharacter.isLegal(char16))
if (UCharacter.isLegal(char16)) {
return char16;
}
throw new IllegalArgumentException("Illegal codepoint");
}
@ -1254,7 +1287,7 @@ public final class UCharacter
*/
public static String toUpperCase(Locale locale, String str)
{
int size = UTF16.countCP(str);
int size = UTF16.countCodePoint(str);
StringBuffer result = new StringBuffer(size << 1); // initial buffer
int props;
int exception;
@ -1266,26 +1299,30 @@ public final class UCharacter
for (int i = 0; i < size; i ++)
{
ch = UTF16.charAtCPOffset(str, i);
ch = UTF16.charAtCodePointOffset(str, i);
props = PROPERTY_DB_.getProperty(ch);
if (!UCharacterPropertyDB.isExceptionIndicator(props))
{
if (UCharacterPropertyDB.getPropType(props) ==
UCharacterCategory.LOWERCASE_LETTER)
UCharacterCategory.LOWERCASE_LETTER) {
ch -= UCharacterPropertyDB.getSignedValue(props);
}
UTF16.append(result, ch);
}
else
{
index = UCharacterPropertyDB.getExceptionIndex(props);
if (PROPERTY_DB_.hasExceptionValue(index,
UCharacterPropertyDB.EXC_SPECIAL_CASING_))
getSpecialUpperCase(ch, index, result, str, i, tr_az, lt);
else
UCharacterPropertyDB.EXC_SPECIAL_CASING_)) {
getSpecialUpperCase(ch, index, result, str, i, tr_az, lt);
}
else {
if (PROPERTY_DB_.hasExceptionValue(index,
UCharacterPropertyDB.EXC_UPPERCASE_))
UCharacterPropertyDB.EXC_UPPERCASE_)) {
UTF16.append(result, PROPERTY_DB_.getException(index,
UCharacterPropertyDB.EXC_UPPERCASE_));
UCharacterPropertyDB.EXC_UPPERCASE_));
}
}
}
}
return result.toString();
@ -1300,7 +1337,7 @@ public final class UCharacter
*/
public static String toLowerCase(Locale locale, String str)
{
int size = UTF16.countCP(str);
int size = UTF16.countCodePoint(str);
StringBuffer result = new StringBuffer(size << 1); // initial buffer
int props;
int exception;
@ -1313,27 +1350,29 @@ public final class UCharacter
for (int i = 0; i < size; i ++)
{
ch = UTF16.charAtCPOffset(str, i);
ch = UTF16.charAtCodePointOffset(str, i);
props = PROPERTY_DB_.getProperty(ch);
if (!UCharacterPropertyDB.isExceptionIndicator(props))
{
if (!UCharacterPropertyDB.isExceptionIndicator(props)) {
type = UCharacterPropertyDB.getPropType(props);
if (type == UCharacterCategory.UPPERCASE_LETTER ||
type == UCharacterCategory.TITLECASE_LETTER)
type == UCharacterCategory.TITLECASE_LETTER) {
ch += UCharacterPropertyDB.getSignedValue(props);
}
UTF16.append(result, ch);
}
else
{
else {
index = UCharacterPropertyDB.getExceptionIndex(props);
if (PROPERTY_DB_.hasExceptionValue(index,
UCharacterPropertyDB.EXC_SPECIAL_CASING_))
getSpecialLowerCase(ch, index, result, str, i, tr_az, lt);
else
UCharacterPropertyDB.EXC_SPECIAL_CASING_)) {
getSpecialLowerCase(ch, index, result, str, i, tr_az, lt);
}
else {
if (PROPERTY_DB_.hasExceptionValue(index,
UCharacterPropertyDB.EXC_LOWERCASE_))
UCharacterPropertyDB.EXC_LOWERCASE_)) {
UTF16.append(result, PROPERTY_DB_.getException(index,
UCharacterPropertyDB.EXC_LOWERCASE_));
UCharacterPropertyDB.EXC_LOWERCASE_));
}
}
}
}
return result.toString();
@ -1363,8 +1402,9 @@ public final class UCharacter
*/
private static int getProps(int ch)
{
if (ch >= UCharacter.MIN_VALUE & ch <= UCharacter.MAX_VALUE)
if (ch >= UCharacter.MIN_VALUE & ch <= UCharacter.MAX_VALUE) {
return PROPERTY_DB_.getProperty(ch);
}
return 0;
}
@ -1419,41 +1459,42 @@ public final class UCharacter
{
int exception = PROPERTY_DB_.getException(index,
UCharacterPropertyDB.EXC_SPECIAL_CASING_);
if (exception < 0)
{
if (exception < 0) {
// use hardcoded conditions and mappings
if (ch == LATIN_SMALL_LETTER_I_)
{
if (tr_az)
if (ch == LATIN_SMALL_LETTER_I_) {
if (tr_az) {
// turkish and azerbaijani : i maps to dotted I
buffer.append(LATIN_CAPITAL_LETTER_I_WITH_DOT_ABOVE_);
else
}
else {
// other languages: i maps to I
buffer.append(LATIN_CAPITAL_LETTER_I_);
}
}
else
if (ch == COMBINING_DOT_ABOVE_ && lt)
{
else {
if (ch == COMBINING_DOT_ABOVE_ && lt) {
// lithuanian: remove DOT ABOVE after U+0069 "i" with upper
// or titlecase
for (int j = chindex; j > 0; j ++)
{
ch = UTF16.charAtCPOffset(str, j);
if (getType(ch) != UCharacterCategory.NON_SPACING_MARK)
for (int j = chindex; j > 0; j ++) {
ch = UTF16.charAtCodePointOffset(str, j);
if (getType(ch) != UCharacterCategory.NON_SPACING_MARK) {
break;
}
}
// if the base letter is not an 'i' (U+0069)? keep the dot
if (ch != LATIN_SMALL_LETTER_I_)
if (ch != LATIN_SMALL_LETTER_I_) {
buffer.append(COMBINING_DOT_ABOVE_);
}
else
// no known conditional special case mapping, output the code
// point itself
UTF16.append(buffer, ch);
}
}
else {
// no known conditional special case mapping, output the code
// point itself
UTF16.append(buffer, ch);
}
}
}
else
{
else {
// get the special case mapping string from the data file
index = exception & LAST_CHAR_MASK_;
PROPERTY_DB_.getUpperCase(index, buffer);
@ -1478,34 +1519,37 @@ public final class UCharacter
{
int exception = PROPERTY_DB_.getException(index,
UCharacterPropertyDB.EXC_SPECIAL_CASING_);
if (exception < 0)
{
if (exception < 0) {
// use hardcoded conditions and mappings
if (ch == LATIN_CAPITAL_LETTER_I_)
{
if (tr_az)
if (ch == LATIN_CAPITAL_LETTER_I_) {
if (tr_az) {
// turkish and azerbaijani : I maps to dotless i
buffer.append(LATIN_SMALL_LETTER_DOTLESS_I_);
else
}
else {
// other languages: I maps to i
buffer.append(LATIN_SMALL_LETTER_I_);
}
}
else
if (ch == GREEK_CAPITAL_LETTER_SIGMA_)
{
else {
if (ch == GREEK_CAPITAL_LETTER_SIGMA_) {
// greek capital sigma maps depending on whether the following
// character is a letter
chindex ++;
if (chindex != str.length() &&
isLetter(UTF16.charAtCPOffset(str, chindex)))
isLetter(UTF16.charAtCodePointOffset(str, chindex))) {
buffer.append(GREEK_SMALL_LETTER_SIGMA_);
else
}
else {
buffer.append(GREEK_SMALL_LETTER_RHO_);
}
}
else
else {
// no known conditional special case mapping, output the code
// point itself
UTF16.append(buffer, ch);
}
}
}
else
{

View File

@ -5,8 +5,8 @@
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/text/Attic/UCharacterDB.java,v $
* $Date: 2001/02/28 20:59:44 $
* $Revision: 1.1 $
* $Date: 2001/03/07 02:52:05 $
* $Revision: 1.2 $
*
*******************************************************************************
*/
@ -55,14 +55,6 @@ class UCharacterDB
public String toString()
{
StringBuffer result = new StringBuffer();
/*for (int i = 0; i < size; i ++)
{
result.append(" ");
result.append(0x0000FFFF & m_db_[i]);
}
result.append('\n');
*/
result.append("\nunicode version number ");
result.append(m_unicodeversion_);
@ -79,21 +71,24 @@ class UCharacterDB
protected boolean setUnicodeVersion(byte[] version)
{
int size = 0;
if (version != null)
if (version != null) {
size = version.length;
}
boolean result = false;
StringBuffer s = new StringBuffer(size);
for (int i = 0; i < size; i++)
{
for (int i = 0; i < size; i++) {
s.append((int)version[i]);
s.append('.');
if (version[i] < 0 || version[i] > 9)
if (version[i] < 0 || version[i] > 9) {
return false;
if (version[i] != 0)
}
if (version[i] != 0) {
result = true;
}
}
if (result)
if (result) {
m_unicodeversion_ = s.substring(0, (size << 1) - 1);
}
return true;
}
}

View File

@ -6,8 +6,8 @@
*
* $Source:
* /usr/cvs/icu4j/icu4j/src/com/ibm/icu/text/UCharacterName.java $
* $Date: 2001/02/28 20:59:44 $
* $Revision: 1.1 $
* $Date: 2001/03/07 02:52:05 $
* $Revision: 1.2 $
*
*******************************************************************************
*/
@ -75,8 +75,9 @@ final class UCharacterName
protected static String getName(int ch, int choice)
{
if (ch < 0 || ch > 0x1ffff ||
choice >= UCharacterNameChoice.U_CHAR_NAME_CHOICE_COUNT)
choice >= UCharacterNameChoice.U_CHAR_NAME_CHOICE_COUNT) {
return null;
}
String result = "";
@ -84,13 +85,15 @@ final class UCharacterName
// the same as the modern ones, extension A was only introduced with
// Unicode 3.0, and the Hangul syllable block was moved and changed around
// Unicode 1.1.5.
if (choice == UCharacterNameChoice.U_UNICODE_CHAR_NAME)
if (choice == UCharacterNameChoice.U_UNICODE_CHAR_NAME) {
// try getting algorithmic name first
result = getAlgName(ch);
}
// getting normal character name
if (result == null || result.length() == 0)
if (result == null || result.length() == 0) {
result = NAME_DB_.getGroupName(ch, choice);
}
return result;
}
@ -106,13 +109,15 @@ final class UCharacterName
{
// checks for illegal arguments
if (choice >= UCharacterNameChoice.U_CHAR_NAME_CHOICE_COUNT ||
name == null || name.length() == 0)
name == null || name.length() == 0) {
return -1;
}
// try algorithmic names first, if fails then try group names
int result = getAlgorithmChar(choice, name);
if (result >= 0)
if (result >= 0) {
return result;
}
return getGroupChar(name, choice);
}
@ -129,8 +134,7 @@ final class UCharacterName
StringBuffer s = new StringBuffer();
int index = NAME_DB_.getAlgorithmIndex(ch);
if (index >= 0)
{
if (index >= 0) {
NAME_DB_.appendAlgorithmName(index, ch, s);
return s.toString();
}
@ -145,14 +149,15 @@ final class UCharacterName
private static int getAlgorithmChar(int choice, String name)
{
// 1.0 has no algorithmic names
if (choice != UCharacterNameChoice.U_UNICODE_CHAR_NAME)
if (choice != UCharacterNameChoice.U_UNICODE_CHAR_NAME) {
return -1;
}
int result;
for (int count = NAME_DB_.countAlgorithm() - 1; count >= 0; count --)
{
for (int count = NAME_DB_.countAlgorithm() - 1; count >= 0; count --) {
result = NAME_DB_.getAlgorithmChar(count, name);
if (result >= 0)
if (result >= 0) {
return result;
}
}
return -1;
}
@ -168,11 +173,11 @@ final class UCharacterName
int groupcount = NAME_DB_.countGroup();
int result = 0;
for (int i = 0; i < groupcount; i ++)
{
for (int i = 0; i < groupcount; i ++) {
result = NAME_DB_.getGroupChar(i, name, choice);
if (result != -1)
if (result != -1) {
return result;
}
}
return -1;
}

View File

@ -5,8 +5,8 @@
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/text/Attic/UCharacterNameDB.java,v $
* $Date: 2001/02/28 20:59:44 $
* $Revision: 1.1 $
* $Date: 2001/03/07 02:52:05 $
* $Revision: 1.2 $
*
*******************************************************************************
*/
@ -16,6 +16,7 @@ package com.ibm.text;
import java.io.InputStream;
import java.io.DataInputStream;
import java.io.BufferedInputStream;
import java.io.IOException;
/**
* Internal class used for Unicode character name database.
@ -106,14 +107,13 @@ final class UCharacterNameDB extends UCharacterDB
* protected constructor
* @exception thrown when data reading fails or when data has been corrupted
*/
protected UCharacterNameDB() throws Exception
protected UCharacterNameDB() throws IOException
{
UGenNameReader reader = new UGenNameReader();
InputStream i = getClass().getResourceAsStream(NAME_FILE_NAME_);
BufferedInputStream b = new BufferedInputStream(i, NAME_BUFFER_SIZE_);
DataInputStream d = new DataInputStream(b);
if (!reader.read(d, this))
throw new Exception("Data corrupted in " + NAME_FILE_NAME_);
reader.read(d, this);
d.close();
UNICODE_1_ = (';' >= m_tokentable_.length) ||
(m_tokentable_[(int)';'] == 0xFFFF);
@ -156,8 +156,7 @@ final class UCharacterNameDB extends UCharacterDB
protected boolean setToken(char token[], byte tokenstring[])
{
if (token != null && tokenstring != null && token.length > 0 &&
tokenstring.length > 0)
{
tokenstring.length > 0) {
m_tokentable_ = token;
m_tokenstring_ = tokenstring;
return true;
@ -173,8 +172,9 @@ final class UCharacterNameDB extends UCharacterDB
*/
protected boolean setGroupCountSize(int count, int size)
{
if (count <= 0 || size <= 0)
if (count <= 0 || size <= 0) {
return false;
}
m_groupcount_ = count;
m_groupsize_ = size;
return true;
@ -189,8 +189,7 @@ final class UCharacterNameDB extends UCharacterDB
protected boolean setGroup(char group[], byte groupstring[])
{
if (group != null && groupstring != null && group.length > 0 &&
groupstring.length > 0)
{
groupstring.length > 0) {
m_groupinfo_ = group;
m_groupstring_ = groupstring;
return true;
@ -216,18 +215,18 @@ final class UCharacterNameDB extends UCharacterDB
gindex = 0;
// binary search for the group of names that contains the one for code
for (start = 0; start < end - 1;)
{
for (start = 0; start < end - 1;) {
gindex = (start + end) >> 1;
if (msb < getGroupMSB(gindex))
if (msb < getGroupMSB(gindex)) {
end = gindex;
else
}
else {
start = gindex;
}
}
// return this if it is an exact match
if (msb == getGroupMSB(start))
{
if (msb == getGroupMSB(start)) {
start = start * m_groupsize_;
return UCharacterUtil.toInt(m_groupinfo_[start + OFFSET_HIGH_OFFSET_],
m_groupinfo_[start + OFFSET_LOW_OFFSET_]);
@ -251,11 +250,12 @@ final class UCharacterNameDB extends UCharacterDB
*/
protected String getGroupName(int ch, int choice)
{
if (choice != UCharacterNameChoice.U_UNICODE_CHAR_NAME && !UNICODE_1_)
if (choice != UCharacterNameChoice.U_UNICODE_CHAR_NAME && !UNICODE_1_) {
// if not modern name requested and semicolon byte value is a character,
// not a token number, otherwise since only modern names are stored in
// unames.dat and there is no such requested Unicode 1.0 name here
return null;
}
// gets the msb
int msb = ch >> GROUP_SHIFT_,
@ -264,18 +264,18 @@ final class UCharacterNameDB extends UCharacterDB
gindex = 0;
// binary search for the group of names that contains the one for code
for (start = 0; start < end - 1;)
{
for (start = 0; start < end - 1;) {
gindex = (start + end) >> 1;
if (msb < getGroupMSB(gindex))
if (msb < getGroupMSB(gindex)) {
end = gindex;
else
}
else {
start = gindex;
}
}
// return this if it is an exact match
if (msb == getGroupMSB(start))
{
if (msb == getGroupMSB(start)) {
char offsets[] = new char[LINES_PER_GROUP_ + 1];
char lengths[] = new char[LINES_PER_GROUP_ + 1];
@ -298,11 +298,12 @@ final class UCharacterNameDB extends UCharacterDB
protected int getGroupChar(int index, String name, int choice)
{
if (choice != UCharacterNameChoice.U_UNICODE_CHAR_NAME &&
!UNICODE_1_)
!UNICODE_1_) {
// semicolon byte value is a token number , therefore only modern
// names are stored in unames.dat and there is no such requested
// Unicode 1.0 name here
return -1;
}
// populating the data set of grouptable
char offsets[] = new char[LINES_PER_GROUP_ + 1];
@ -311,8 +312,9 @@ final class UCharacterNameDB extends UCharacterDB
// shift out to function
int result = getGroupChar(startgpstrindex, lengths, name, choice);
if (result != -1)
if (result != -1) {
return (getGroupMSB(index) << GROUP_SHIFT_) | result;
}
return -1;
}
@ -323,8 +325,7 @@ final class UCharacterNameDB extends UCharacterDB
*/
protected boolean setAlgorithm(AlgorithmName alg[])
{
if (alg != null && alg.length != 0)
{
if (alg != null && alg.length != 0) {
m_algorithm_ = alg;
return true;
}
@ -337,8 +338,9 @@ final class UCharacterNameDB extends UCharacterDB
*/
protected int countAlgorithm()
{
if (m_algorithm_ == null)
if (m_algorithm_ == null) {
return 0;
}
return m_algorithm_.length;
}
@ -350,9 +352,11 @@ final class UCharacterNameDB extends UCharacterDB
*/
protected int getAlgorithmIndex(int ch)
{
for (int index = m_algorithm_.length - 1; index >= 0; index --)
if (m_algorithm_[index].contains(ch))
for (int index = m_algorithm_.length - 1; index >= 0; index --) {
if (m_algorithm_[index].contains(ch)) {
return index;
}
}
return -1;
}
@ -421,26 +425,27 @@ final class UCharacterNameDB extends UCharacterDB
offsets[0] = 0;
// all 32 lengths must be read to get the offset of the first group string
for (int i = 0; i < LINES_PER_GROUP_; stringoffset ++)
{
for (int i = 0; i < LINES_PER_GROUP_; stringoffset ++) {
b = m_groupstring_[stringoffset];
shift = 4;
while (shift >= 0)
{
while (shift >= 0) {
// getting nibble
n = (byte)((b >> shift) & 0x0F);
if (length == 0xffff && n > SINGLE_NIBBLE_MAX_)
if (length == 0xffff && n > SINGLE_NIBBLE_MAX_) {
length = (char)((n - 12) << 4);
else
{
if (length != 0xffff)
}
else {
if (length != 0xffff) {
lengths[i] = (char)((length | n) + 12);
else
}
else {
lengths[i] = (char)n;
}
if (i < LINES_PER_GROUP_)
if (i < LINES_PER_GROUP_) {
offsets[i + 1] = (char)(offsets[i] + lengths[i]);
}
length = 0xffff;
i ++;
@ -461,8 +466,7 @@ final class UCharacterNameDB extends UCharacterDB
*/
private String getGroupName(int index, int length, int choice)
{
if (choice != UCharacterNameChoice.U_UNICODE_CHAR_NAME)
{
if (choice != UCharacterNameChoice.U_UNICODE_CHAR_NAME) {
int oldindex = index;
index += UCharacterUtil.skipByteSubString(m_groupstring_, index, length,
(byte)';');
@ -472,39 +476,38 @@ final class UCharacterNameDB extends UCharacterDB
StringBuffer s = new StringBuffer();
byte b;
char token;
for (int i = 0; i < length;)
{
for (int i = 0; i < length;) {
b = m_groupstring_[index + i];
i ++;
if (b >= m_tokentable_.length)
{
if (b == ';')
if (b >= m_tokentable_.length) {
if (b == ';') {
break;
}
s.append(b); // implicit letter
}
else
{
else {
token = m_tokentable_[b & 0x00ff];
if (token == 0xFFFE)
{
if (token == 0xFFFE) {
// this is a lead byte for a double-byte token
token = m_tokentable_[b << 8 | (m_groupstring_[index + i] & 0x00ff)];
i ++;
}
if (token == 0xFFFF)
{
if (b == ';')
if (token == 0xFFFF) {
if (b == ';') {
break;
}
s.append((char)(b & 0x00ff)); // explicit letter
}
else // write token word
else { // write token word
UCharacterUtil.getNullTermByteSubString(s, m_tokenstring_, token);
}
}
}
if (s.length() == 0)
if (s.length() == 0) {
return null;
}
return s.toString();
}
@ -527,13 +530,11 @@ final class UCharacterNameDB extends UCharacterDB
int nindex;
int count;
for (int result = 0; result <= LINES_PER_GROUP_; result ++)
{
for (int result = 0; result <= LINES_PER_GROUP_; result ++) {
nindex = 0;
len = length[result];
if (choice != UCharacterNameChoice.U_UNICODE_CHAR_NAME)
{
if (choice != UCharacterNameChoice.U_UNICODE_CHAR_NAME) {
int oldindex = index;
index += UCharacterUtil.skipByteSubString(m_groupstring_, index, len,
(byte)';');
@ -542,41 +543,40 @@ final class UCharacterNameDB extends UCharacterDB
// number of tokens is > the length of the name
// write each letter directly, and write a token word per token
for (count = 0; count < len && nindex != -1 && nindex < namelen;)
{
for (count = 0; count < len && nindex != -1 && nindex < namelen;) {
b = m_groupstring_[index + count];
count ++;
if (b >= m_tokentable_.length)
{
if (name.charAt(nindex ++) != (b & 0xFF))
if (b >= m_tokentable_.length) {
if (name.charAt(nindex ++) != (b & 0xFF)) {
nindex = -1;
}
}
else
{
else {
token = m_tokentable_[b & 0xFF];
if (token == 0xFFFE)
{
if (token == 0xFFFE) {
// this is a lead byte for a double-byte token
token = m_tokentable_[b << 8 |
(m_groupstring_[index + count] & 0x00ff)];
count ++;
}
if (token == 0xFFFF)
{
if (name.charAt(nindex ++) != (b & 0xFF))
if (token == 0xFFFF) {
if (name.charAt(nindex ++) != (b & 0xFF)) {
nindex = -1;
}
}
else
else {
// compare token with name
nindex = UCharacterUtil.compareNullTermByteSubString(name,
m_tokenstring_, nindex, token);
}
}
}
if (namelen == nindex &&
(count == len || m_groupstring_[index + count] == ';'))
(count == len || m_groupstring_[index + count] == ';')) {
return result;
}
index += len;
}
@ -637,8 +637,7 @@ final class UCharacterNameDB extends UCharacterDB
{
if (rangestart >= UCharacter.MIN_VALUE && rangestart <= rangeend &&
rangeend <= UCharacter.MAX_VALUE &&
(type == TYPE_0_ || type == TYPE_1_))
{
(type == TYPE_0_ || type == TYPE_1_)) {
m_rangestart_ = rangestart;
m_rangeend_ = rangeend;
m_type_ = type;
@ -655,8 +654,7 @@ final class UCharacterNameDB extends UCharacterDB
*/
protected boolean setFactor(char factor[])
{
if (factor.length == m_variant_)
{
if (factor.length == m_variant_) {
m_factor_ = factor;
return true;
}
@ -670,8 +668,7 @@ final class UCharacterNameDB extends UCharacterDB
*/
protected boolean setPrefix(String prefix)
{
if (prefix != null && prefix.length() > 0)
{
if (prefix != null && prefix.length() > 0) {
m_prefix_ = prefix;
return true;
}
@ -755,8 +752,9 @@ final class UCharacterNameDB extends UCharacterDB
{
int prefixlen = m_prefix_.length();
if (name.length() < prefixlen ||
!m_prefix_.equals(name.substring(0, prefixlen)))
!m_prefix_.equals(name.substring(0, prefixlen))) {
return -1;
}
switch (m_type_)
{
@ -765,8 +763,9 @@ final class UCharacterNameDB extends UCharacterDB
{
int result = Integer.parseInt(name.substring(prefixlen), 16);
// does it fit into the range?
if (m_rangestart_ <= result && result <= m_rangeend_)
if (m_rangestart_ <= result && result <= m_rangeend_) {
return result;
}
}
catch (NumberFormatException e)
{
@ -795,8 +794,9 @@ final class UCharacterNameDB extends UCharacterDB
indexes[0] = offset;
// joining up the factorized strings
if (compareFactorString(indexes, name.substring(prefixlen)))
if (compareFactorString(indexes, name.substring(prefixlen))) {
return ch;
}
}
}
@ -813,24 +813,25 @@ final class UCharacterNameDB extends UCharacterDB
private String[] getFactorString(int index[])
{
int size = m_factor_.length;
if (index == null || index.length != size)
if (index == null || index.length != size) {
return null;
}
String result[] = new String[size];
StringBuffer str = new StringBuffer();
int count = 0;
int factor;
size --;
for (int i = 0; i <= size; i ++)
{
for (int i = 0; i <= size; i ++) {
factor = m_factor_[i];
count = UCharacterUtil.skipNullTermByteSubString(m_factorstring_,
count, index[i]);
count = UCharacterUtil.getNullTermByteSubString(str, m_factorstring_,
count);
if (i != size)
if (i != size) {
count = UCharacterUtil.skipNullTermByteSubString(m_factorstring_,
count, factor - index[i] - 1);
}
result[i] = str.toString();
str.delete(0, str.length());
}
@ -861,15 +862,18 @@ final class UCharacterNameDB extends UCharacterDB
count, index[i]);
strcount = UCharacterUtil.compareNullTermByteSubString(str,
m_factorstring_, strcount, count);
if (strcount < 0)
if (strcount < 0) {
return false;
}
if (i != size)
if (i != size) {
count = UCharacterUtil.skipNullTermByteSubString(m_factorstring_,
count, factor - index[i]);
}
}
if (strcount != str.length())
if (strcount != str.length()) {
return false;
}
return true;
}
}

View File

@ -6,8 +6,8 @@
*
* $Source:
* /usr/cvs/icu4j/icu4j/src/com/ibm/icu/text/UCharacterPropertyDB.java $
* $Date: 2001/02/28 20:59:44 $
* $Revision: 1.1 $
* $Date: 2001/03/07 02:52:05 $
* $Revision: 1.2 $
*
*******************************************************************************
*/
@ -17,6 +17,7 @@ package com.ibm.text;
import java.io.InputStream;
import java.io.DataInputStream;
import java.io.BufferedInputStream;
import java.io.IOException;
/**
* Internal class used for Unicode character property database.
@ -189,15 +190,14 @@ final class UCharacterPropertyDB extends UCharacterDB
* Constructor
* @exception thrown when data reading fails or data corrupted
*/
protected UCharacterPropertyDB() throws Exception
protected UCharacterPropertyDB() throws IOException
{
UGenPropReader reader = new UGenPropReader();
InputStream i = getClass().getResourceAsStream(DATA_FILE_NAME_);
BufferedInputStream b = new BufferedInputStream(i, DATA_BUFFER_SIZE_);
DataInputStream d = new DataInputStream(b);
if (!reader.read(d, this))
throw new Exception("Data corrupted in " + DATA_FILE_NAME_);
reader.read(d, this);
d.close();
}
@ -263,8 +263,9 @@ final class UCharacterPropertyDB extends UCharacterDB
*/
protected boolean setStage(char stages[])
{
if (stages == null || stages.length <= 0)
if (stages == null || stages.length <= 0) {
return false;
}
m_stages_ = stages;
return true;
}
@ -276,8 +277,9 @@ final class UCharacterPropertyDB extends UCharacterDB
*/
protected boolean setProperty(int property[])
{
if (property == null || property.length <= 0)
if (property == null || property.length <= 0) {
return false;
}
m_property_ = property;
return true;
}
@ -289,8 +291,9 @@ final class UCharacterPropertyDB extends UCharacterDB
*/
protected boolean setCase(char casetable[])
{
if (casetable == null || casetable.length <= 0)
if (casetable == null || casetable.length == 0) {
return false;
}
m_case_ = casetable;
return true;
}
@ -303,8 +306,9 @@ final class UCharacterPropertyDB extends UCharacterDB
*/
protected boolean setException(int exception[])
{
if (exception == null || exception.length <= 0)
if (exception == null || exception.length <= 0) {
return false;
}
m_exception_ = exception;
return true;
}
@ -340,8 +344,9 @@ final class UCharacterPropertyDB extends UCharacterDB
index += (count & LAST_5_BIT_MASK_) + 1;
count = (count >> SHIFT_5_) & LAST_5_BIT_MASK_;
for (int j = 0; j < count; j ++)
for (int j = 0; j < count; j ++) {
buffer.append(m_case_[index + j]);
}
}
/**
@ -355,8 +360,9 @@ final class UCharacterPropertyDB extends UCharacterDB
// last 5 bits of the first char in m_case_ gives the size of the
// lowercase characters
index ++;
for (int j = 0; j < count; j ++)
for (int j = 0; j < count; j ++) {
buffer.append(m_case_[index + j]);
}
}
/**
@ -419,8 +425,9 @@ final class UCharacterPropertyDB extends UCharacterDB
*/
protected static boolean isExceptionIndicator(int props)
{
if ((props & EXCEPTION_MASK_) != 0)
if ((props & EXCEPTION_MASK_) != 0) {
return true;
}
return false;
}
@ -487,8 +494,9 @@ final class UCharacterPropertyDB extends UCharacterDB
private int addExceptionOffset(int evalue, int indicator, int address)
{
int result = address;
if (indicator >= EXC_GROUP_)
if (indicator >= EXC_GROUP_) {
result += (FLAGS_OFFSET_[evalue & EXC_GROUP_MASK_] << 1);
}
// evalue >>= EXC_GROUP_;
// indicator -= EXC_GROUP_;
else

View File

@ -5,8 +5,8 @@
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/text/Attic/UCharacterUtil.java,v $
* $Date: 2001/02/28 20:59:44 $
* $Revision: 1.1 $
* $Date: 2001/03/07 02:52:05 $
* $Revision: 1.2 $
*
*******************************************************************************
*/
@ -51,10 +51,12 @@ final class UCharacterUtil
*/
protected static char toChar(byte bytes[])
{
if (bytes == null || bytes.length == 0)
if (bytes == null || bytes.length == 0) {
return 0;
if (bytes.length == 1)
}
if (bytes.length == 1) {
return toChar(bytes[0]);
}
char firstbyte = (char)(toChar(bytes[0]) << 8);
char secondbyte = toChar(bytes[1]);
@ -141,8 +143,9 @@ final class UCharacterUtil
while (b != 0)
{
b = array[index];
if (b != 0)
if (b != 0) {
str.append((char)(b & 0x00FF));
}
index ++;
}
return index;
@ -170,12 +173,14 @@ final class UCharacterUtil
{
b = array[aindex];
aindex ++;
if (b == 0)
if (b == 0) {
break;
}
// if we have reached the end of the string and yet the array has not
// reached the end of their substring yet, abort
if (strindex == length || (str.charAt(strindex) != (char)(b & 0xFF)))
if (strindex == length || (str.charAt(strindex) != (char)(b & 0xFF))) {
return -1;
}
strindex ++;
}
return strindex;
@ -255,8 +260,9 @@ final class UCharacterUtil
{
b = array[index + result];
result ++;
if (b == skipend)
if (b == skipend) {
break;
}
}
return result;

View File

@ -5,14 +5,15 @@
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/text/Attic/UGenNameReader.java,v $
* $Date: 2001/02/28 20:59:44 $
* $Revision: 1.1 $
* $Date: 2001/03/07 02:52:05 $
* $Revision: 1.2 $
*
*******************************************************************************
*/
package com.ibm.text;
import java.io.DataInputStream;
import java.io.IOException;
/**
* Internal reader class reading binary data from unames.dat created by ICU
@ -63,6 +64,12 @@ final class UGenNameReader extends UGenReader
{(byte)0x1, (byte)0x0, (byte)0x0, (byte)0x0};
private static final byte DATA_FORMAT_ID_[] = {(byte)0x75, (byte)0x6E,
(byte)0x61, (byte)0x6D};
/**
* Corrupted error string
*/
private static final String CORRUPTED_DATA_ERROR_ =
"Data corrupted in character name data file";
// constructor ==================================================
@ -81,20 +88,16 @@ final class UGenNameReader extends UGenReader
* If unsuccessful false will be returned.
* @param input data input stream
* @param data instance of datablock
* @return true if successfully filled UCharacterNameDB
* @exception thrown if there is a failure reading file
* @exception thrown when there's a data error.
*/
protected boolean read(DataInputStream input, UCharacterNameDB data)
throws Exception
protected void read(DataInputStream input, UCharacterNameDB data)
throws IOException
{
if (super.read(input, data))
{
// read the indexes
if (readIndex(input) && readToken(input, data) && readGroup(input, data)
&& readAlg(input, data))
return true;
if (!(super.read(input, data) && readIndex(input) &&
readToken(input, data) && readGroup(input, data) &&
readAlg(input, data))) {
throw new IOException(CORRUPTED_DATA_ERROR_);
}
return false;
}
/**
@ -107,13 +110,17 @@ final class UGenNameReader extends UGenReader
byte dataformatversion[])
{
int size = DATA_FORMAT_ID_.length;
for (int i = 0; i < size; i ++)
if (DATA_FORMAT_ID_[i] != dataformatid[i])
for (int i = 0; i < size; i ++) {
if (DATA_FORMAT_ID_[i] != dataformatid[i]) {
return false;
}
}
size = DATA_FORMAT_VERSION_.length;
for (int i = 0; i < size; i ++)
if (DATA_FORMAT_VERSION_[i] != dataformatversion[i])
for (int i = 0; i < size; i ++) {
if (DATA_FORMAT_VERSION_[i] != dataformatversion[i]) {
return false;
}
}
return true;
}
@ -143,7 +150,7 @@ final class UGenNameReader extends UGenReader
* @return true if successfully read
* @exception thrown when data reading fails
*/
private boolean readIndex(DataInputStream input) throws Exception
private boolean readIndex(DataInputStream input) throws IOException
{
m_tokenstringindex_ = input.readInt();
m_groupindex_ = input.readInt();
@ -160,12 +167,13 @@ final class UGenNameReader extends UGenReader
* @exception thrown when data reading fails
*/
private boolean readToken(DataInputStream input, UCharacterNameDB data)
throws Exception
throws IOException
{
char count = input.readChar();
char token[] = new char[count];
for (char i = 0; i < count; i ++)
for (char i = 0; i < count; i ++) {
token[i] = input.readChar();
}
int size = m_groupindex_ - m_tokenstringindex_;
byte tokenstr[] = new byte[size];
@ -181,15 +189,16 @@ final class UGenNameReader extends UGenReader
* @exception thrown when data reading fails
*/
private boolean readGroup(DataInputStream input, UCharacterNameDB data)
throws Exception
throws IOException
{
// reading the group information records
int count = input.readChar();
data.setGroupCountSize(count, GROUP_INFO_SIZE_);
count *= GROUP_INFO_SIZE_;
char group[] = new char[count];
for (int i = 0; i < count; i ++)
for (int i = 0; i < count; i ++) {
group[i] = input.readChar();
}
int size = m_algnamesindex_ - m_groupstringindex_;
byte groupstring[] = new byte[size];
@ -205,7 +214,7 @@ final class UGenNameReader extends UGenReader
* @exception thrown when data reading fails
*/
private boolean readAlg(DataInputStream input, UCharacterNameDB data)
throws Exception
throws IOException
{
int count = input.readInt();
UCharacterNameDB.AlgorithmName alg[] =
@ -214,8 +223,9 @@ final class UGenNameReader extends UGenReader
for (int i = 0; i < count; i ++)
{
UCharacterNameDB.AlgorithmName an = readAlg(input);
if (an == null)
if (an == null) {
return false;
}
alg[i] = an;
}
data.setAlgorithm(alg);
@ -229,7 +239,7 @@ final class UGenNameReader extends UGenReader
* @exception thrown when file read error occurs or data is corrupted
*/
private UCharacterNameDB.AlgorithmName readAlg(DataInputStream input)
throws Exception
throws IOException
{
UCharacterNameDB.AlgorithmName result =
new UCharacterNameDB.AlgorithmName();
@ -237,15 +247,17 @@ final class UGenNameReader extends UGenReader
int rangeend = input.readInt();
byte type = input.readByte();
byte variant = input.readByte();
if (!result.setInfo(rangestart, rangeend, type, variant))
if (!result.setInfo(rangestart, rangeend, type, variant)) {
return null;
}
int size = input.readChar();
if (type == UCharacterNameDB.AlgorithmName.TYPE_1_)
{
char factor[] = new char[variant];
for (int j = 0; j < variant; j ++)
for (int j = 0; j < variant; j ++) {
factor[j] = input.readChar();
}
result.setFactor(factor);
size -= (variant << 1);

View File

@ -5,8 +5,8 @@
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/text/Attic/UGenPropReader.java,v $
* $Date: 2001/02/28 20:59:44 $
* $Revision: 1.1 $
* $Date: 2001/03/07 02:52:05 $
* $Revision: 1.2 $
*
*******************************************************************************
*/
@ -14,6 +14,7 @@ package com.ibm.text;
import java.io.DataInputStream;
import java.util.Arrays;
import java.io.IOException;
/**
* Internal reader class reading binary data from uprops.dat created by ICU
@ -66,6 +67,12 @@ final class UGenPropReader extends UGenReader
(byte)0x72, (byte)0x6F};
private static final byte DATA_FORMAT_VERSION_[] =
{(byte)0x1, (byte)0x2, (byte)0x0, (byte)0x0};
/**
* Corrupted error string
*/
private static final String CORRUPTED_DATA_ERROR_ =
"Data corrupted in character property data file";
// constructor =============================================
@ -83,13 +90,12 @@ final class UGenPropReader extends UGenReader
* If unsuccessful false will be returned
* @param input data stream
* @param data data instance
* @return true if successfully filled
* @exception thrown when data reading fails
*/
protected boolean read(DataInputStream input, UCharacterPropertyDB data)
throws Exception
protected void read(DataInputStream input, UCharacterPropertyDB data)
throws IOException
{
if (super.read(input, data) &&
if (!(super.read(input, data) &&
// read the indexes
readIndex(input, data) &&
// read the stages block
@ -99,9 +105,9 @@ final class UGenPropReader extends UGenReader
// read the exception data
readException(input, data) &&
// read the case data
readCase(input,data))
return true;
return false;
readCase(input,data))) {
throw new IOException(CORRUPTED_DATA_ERROR_);
}
}
/**
@ -143,10 +149,10 @@ final class UGenPropReader extends UGenReader
* @param input data stream
* @param data instance of UCharacterPropertyDB
* @return true if successfully read
* @exception thrown when data reading fails
* @exception thrown when there's an IOException
*/
private boolean readIndex(DataInputStream input, UCharacterPropertyDB data)
throws Exception
private boolean readIndex(DataInputStream input, UCharacterPropertyDB data)
throws IOException
{
int count = INDEX_SIZE_;
m_stage2indexsize_ = input.readChar();
@ -180,7 +186,7 @@ final class UGenPropReader extends UGenReader
* @exception thrown when data reading fails
*/
private boolean readStage(DataInputStream input, UCharacterPropertyDB data)
throws Exception
throws IOException
{
// size of the 3 stages
int stagesize = (m_prop_ << 1) - INDEX_SIZE_;
@ -193,23 +199,19 @@ final class UGenPropReader extends UGenReader
for (int count = 0; count < stagesize; count ++)
{
array[count] = (char)(input.readChar() - INDEX_SIZE_);
if (max < array[count] && count < 0x448)
if (max < array[count] && count < 0x448) {
max = array[count];
}
// setting up the property index for stage 3
// uprops.dat contain data that includes the address from the top of
// index to property data. since the blocks are split up, so now i have
// to subtract the excess address from it.
if (count >= m_stage3_ - INDEX_SIZE_)
if (count >= m_stage3_ - INDEX_SIZE_) {
array[count] -= props;
}
}
// synwee : hmm... gaps in stage 2.
/*
System.out.println("stage 3 " + (int)m_stage3_);
System.out.println("stage 2 top " + (max - 0x440 - INDEX_SIZE_));
*/
// setting up the stages block in the instance of UCharacterPropertyDB
return data.setStage(array);
}
@ -223,13 +225,14 @@ final class UGenPropReader extends UGenReader
* @exception thrown when data reading fails
*/
private boolean readProperty(DataInputStream input,
UCharacterPropertyDB data) throws Exception
UCharacterPropertyDB data) throws IOException
{
// getting size of the property block
int size = m_exception_ - m_prop_;
int ppty[] = new int[size];
for (int i = 0; i < size; i ++)
for (int i = 0; i < size; i ++) {
ppty[i] = input.readInt();
}
// setting up the property block in the instance of UCharacterPropertyDB
return data.setProperty(ppty);
@ -244,13 +247,14 @@ final class UGenPropReader extends UGenReader
* @exception thrown when data reading fails
*/
private boolean readCase(DataInputStream input,
UCharacterPropertyDB data) throws Exception
UCharacterPropertyDB data) throws IOException
{
// getting size of the case block
int size = (m_end_ - m_case_) << 1;
char casetable[] = new char[size];
for (int i = 0; i < size; i ++)
for (int i = 0; i < size; i ++) {
casetable[i] = input.readChar();
}
// setting up the case block in the instance of UCharacterPropertyDB
return data.setCase(casetable);
@ -265,12 +269,13 @@ final class UGenPropReader extends UGenReader
* @exception thrown when data reading fails
*/
private boolean readException(DataInputStream input,
UCharacterPropertyDB data) throws Exception
UCharacterPropertyDB data) throws IOException
{
int size = m_case_ - m_exception_;
int exception[] = new int[size];
for (int i = 0; i < size; i ++)
exception[i] = input.readInt();
for (int i = 0; i < size; i ++) {
exception[i] = input.readInt();
}
// setting up the property block in the instance of UCharacterPropertyDB
return data.setException(exception);

View File

@ -5,8 +5,8 @@
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/text/Attic/UGenReader.java,v $
* $Date: 2001/02/28 20:59:44 $
* $Revision: 1.1 $
* $Date: 2001/03/07 02:52:05 $
* $Revision: 1.2 $
*
*******************************************************************************
*/
@ -72,45 +72,49 @@ abstract class UGenReader
* @param input data stream
* @param data data instance
* @return true if successfully filled
* @exception thrown when error reading data
*/
protected boolean read(DataInputStream input, UCharacterDB data)
throws Exception
protected boolean read(DataInputStream input, UCharacterDB data)
{
char headersize = input.readChar();
headersize -= 2;
//reading the header format
byte magic1 = input.readByte();
headersize --;
byte magic2 = input.readByte();
headersize --;
input.skipBytes(SKIP_BYTES_);
headersize -= SKIP_BYTES_;
if (authenticate(magic1, magic2))
try
{
byte bigendian = input.readByte();
char headersize = input.readChar();
headersize -= 2;
//reading the header format
byte magic1 = input.readByte();
headersize --;
byte charset = input.readByte();
byte magic2 = input.readByte();
headersize --;
byte charsize = input.readByte();
headersize --;
byte reserved = input.readByte();
headersize --;
byte dataformatid[] = new byte[getFileFormatIDSize()];
input.readFully(dataformatid);
headersize -= getFileFormatIDSize();
byte dataformatversion[] = new byte[getFileFormatVersionSize()];
input.readFully(dataformatversion);
headersize -= getFileFormatVersionSize();
byte unicodeversion[] = new byte[UNICODE_VERSION_.length];
input.readFully(unicodeversion);
headersize -= UNICODE_VERSION_.length;
input.skipBytes(headersize);
if (authenticate(bigendian, charset, charsize, unicodeversion) &&
authenticate(dataformatid, dataformatversion))
return setUCharacterDB(data, unicodeversion);
input.skipBytes(SKIP_BYTES_);
headersize -= SKIP_BYTES_;
if (authenticate(magic1, magic2))
{
byte bigendian = input.readByte();
headersize --;
byte charset = input.readByte();
headersize --;
byte charsize = input.readByte();
headersize --;
byte reserved = input.readByte();
headersize --;
byte dataformatid[] = new byte[getFileFormatIDSize()];
input.readFully(dataformatid);
headersize -= getFileFormatIDSize();
byte dataformatversion[] = new byte[getFileFormatVersionSize()];
input.readFully(dataformatversion);
headersize -= getFileFormatVersionSize();
byte unicodeversion[] = new byte[UNICODE_VERSION_.length];
input.readFully(unicodeversion);
headersize -= UNICODE_VERSION_.length;
input.skipBytes(headersize);
if (authenticate(bigendian, charset, charsize, unicodeversion) &&
authenticate(dataformatid, dataformatversion)) {
return setUCharacterDB(data, unicodeversion);
}
}
}
catch (Exception e) {
}
return false;
}
@ -146,8 +150,9 @@ abstract class UGenReader
*/
private boolean authenticate(byte m1, byte m2)
{
if (m1 == MAGIC1 && m2 == MAGIC2)
if (m1 == MAGIC1 && m2 == MAGIC2) {
return true;
}
return false;
}
@ -167,8 +172,9 @@ abstract class UGenReader
byte unicodeversion[])
{
if (bigendian != BIG_ENDIAN_ || charset != CHAR_SET_ ||
charsize != CHAR_SIZE_)
charsize != CHAR_SIZE_) {
return false;
}
return Arrays.equals(UNICODE_VERSION_, unicodeversion);
}

View File

@ -5,8 +5,8 @@
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/text/Attic/UTF16.java,v $
* $Date: 2001/02/28 20:59:44 $
* $Revision: 1.1 $
* $Date: 2001/03/07 02:52:05 $
* $Revision: 1.2 $
*
*******************************************************************************
*/
@ -149,7 +149,7 @@ public final class UTF16
* <code>UTF16.getCharCount()</code>, as well as random access. If a validity
* check is required, use <code><a href="../UCharacter.html#isLegal(char)">
* UCharacter.isLegal()</a></code> on the return value.
* If tbe char retrieved is part of a surrogate pair, its supplementary
* If the char retrieved is part of a surrogate pair, its supplementary
* character will be returned. If a complete supplementary character is not
* found the incomplete character will be returned
* @param source array of UTF-16 chars
@ -161,7 +161,7 @@ public final class UTF16
*/
public static int charAt(String source, int offset16)
{
if (offset16 >= source.length())
if (offset16 < 0 || offset16 >= source.length())
return -1;
char single = source.charAt(offset16);
@ -211,9 +211,9 @@ public final class UTF16
* @param offset32 UTF-32 offset to the start of the character.
* @return a single UTF32 value, otherwise -1 if there's an error
*/
public static int charAtCPOffset(String source, int offset32)
public static int charAtCodePointOffset(String source, int offset32)
{
int offset16 = findOffsetFromCP(source, offset32);
int offset16 = findOffsetFromCodePoint(source, offset32);
return charAt(source, offset16);
}
@ -227,8 +227,9 @@ public final class UTF16
*/
public static int getCharCount(int char32)
{
if (char32 < UCharacter.SUPPLEMENTARY_MIN_VALUE)
if (char32 < UCharacter.SUPPLEMENTARY_MIN_VALUE) {
return 1;
}
return 2;
}
@ -260,13 +261,15 @@ public final class UTF16
if (isLeadSurrogate(ch))
{
if (++ offset16 < source.length() &&
isTrailSurrogate(source.charAt(offset16)))
isTrailSurrogate(source.charAt(offset16))) {
return LEAD_SURROGATE_BOUNDARY;
}
}
else
// isTrailSurrogate(ch), so
if (-- offset16 >= 0 && isLeadSurrogate(source.charAt(offset16)))
if (-- offset16 >= 0 && isLeadSurrogate(source.charAt(offset16))) {
return TRAIL_SURROGATE_BOUNDARY;
}
return SINGLE_CHAR_BOUNDARY;
}
@ -292,9 +295,9 @@ public final class UTF16
* [offset32 - (value >> 2), offset32 + (value & 3)].
* @exception StringIndexOutOfBoundsException if offset32 is out of bounds.
*/
public static int boundsAtCPOffset(String source, int offset32)
public static int boundsAtCodePointOffset(String source, int offset32)
{
int offset16 = findOffsetFromCP(source, offset32);
int offset16 = findOffsetFromCodePoint(source, offset32);
return bounds(source, offset16);
}
@ -342,9 +345,10 @@ public final class UTF16
*/
public static int getLeadSurrogate(int char32)
{
if (char32 >= UCharacter.SUPPLEMENTARY_MIN_VALUE)
if (char32 >= UCharacter.SUPPLEMENTARY_MIN_VALUE) {
return LEAD_SURROGATE_OFFSET_ +
(char32 >> UCharacter.LEAD_SURROGATE_SHIFT_);
}
return 0;
}
@ -360,9 +364,10 @@ public final class UTF16
*/
public static int getTrailSurrogate(int char32)
{
if (char32 >= UCharacter.SUPPLEMENTARY_MIN_VALUE)
if (char32 >= UCharacter.SUPPLEMENTARY_MIN_VALUE) {
return TRAIL_SURROGATE_MIN_VALUE_ + (char32 &
UCharacter.TRAIL_SURROGATE_MASK_);
}
return (char)char32;
}
@ -379,10 +384,12 @@ public final class UTF16
*/
public static String valueOf(int char32)
{
if (char32 < UCharacter.MIN_VALUE || char32 > UCharacter.MAX_VALUE)
if (char32 < UCharacter.MIN_VALUE || char32 > UCharacter.MAX_VALUE) {
throw new IllegalArgumentException("Illegal codepoint");
if (char32 < UCharacter.SUPPLEMENTARY_MIN_VALUE)
}
if (char32 < UCharacter.SUPPLEMENTARY_MIN_VALUE) {
return String.valueOf((char)char32);
}
char str[] = new char[2];
str[0] = (char)(LEAD_SURROGATE_OFFSET_ +
(char32 >> UCharacter.LEAD_SURROGATE_SHIFT_));
@ -400,7 +407,7 @@ public final class UTF16
* @return UTF-16 offset
* @exception StringIndexOutOfBoundsException if offset32 is out of bounds.
*/
public static int findOffsetFromCP(String source, int offset32)
public static int findOffsetFromCodePoint(String source, int offset32)
{
char ch;
int size = source.length(),
@ -410,14 +417,16 @@ public final class UTF16
{
ch = source.charAt(result);
if (isLeadSurrogate(ch) && ((result + 1) < size) &&
isTrailSurrogate(source.charAt(result + 1)))
isTrailSurrogate(source.charAt(result + 1))) {
result ++;
}
count --;
result ++;
}
if (result >= size)
if (result >= size) {
throw new StringIndexOutOfBoundsException(offset32);
}
return result;
}
@ -440,10 +449,11 @@ public final class UTF16
* @return UTF-32 offset
* @exception StringIndexOutOfBoundsException if offset16 is out of bounds.
*/
public static int findCPOffset(String source, int offset16)
public static int findCodePointOffset(String source, int offset16)
{
if (offset16 >= source.length())
throw new StringIndexOutOfBoundsException(offset16);
if (offset16 >= source.length()) {
throw new StringIndexOutOfBoundsException(offset16);
}
int result = 0;
char ch;
@ -452,8 +462,9 @@ public final class UTF16
for (int i = 0; i < offset16; ++ i)
{
ch = source.charAt(i);
if (hadLeadSurrogate && isTrailSurrogate(ch))
if (hadLeadSurrogate && isTrailSurrogate(ch)) {
hadLeadSurrogate = false; // count valid trail as zero
}
else
{
hadLeadSurrogate = isLeadSurrogate(ch);
@ -462,8 +473,9 @@ public final class UTF16
}
// end of source being a supplementary character
// shift result back to the start of the supplementary character
if (hadLeadSurrogate && isTrailSurrogate(source.charAt(offset16)))
if (hadLeadSurrogate && isTrailSurrogate(source.charAt(offset16))) {
result --;
}
return result;
}
@ -480,8 +492,9 @@ public final class UTF16
public static StringBuffer append(StringBuffer target, int char32)
{
// Check for irregular values
if (char32 < UCharacter.MIN_VALUE || char32 > UCharacter.MAX_VALUE)
if (char32 < UCharacter.MIN_VALUE || char32 > UCharacter.MAX_VALUE) {
throw new IllegalArgumentException("Illegal codepoint");
}
// Write the UTF-16 values
if (char32 >= UCharacter.SUPPLEMENTARY_MIN_VALUE)
@ -491,8 +504,9 @@ public final class UTF16
target.append((char)(TRAIL_SURROGATE_MIN_VALUE_ +
(char32 & UCharacter.TRAIL_SURROGATE_MASK_)));
}
else
else {
target.append((char)char32);
}
return target;
}
@ -508,49 +522,59 @@ public final class UTF16
*/
public int compare(Object a, Object b)
{
if (a == b)
if (a == b) {
return 0;
if (a == null)
}
if (a == null) {
return -1;
if (b == null)
}
if (b == null) {
return 1;
}
String sa = (String) a;
String sb = (String) b;
int lena = sa.length();
int lenb = sb.length();
int len = lena;
if (len > lenb)
if (len > lenb) {
len = lenb;
}
for (int i = 0; i < len; ++i)
{
char ca = sa.charAt(i);
char cb = sb.charAt(i);
if (ca == cb)
if (ca == cb) {
continue; // skip remap if equal
}
// start of only different section
// what this part does is to rearrange the characters 0xE000 to 0xFFFF
// to the region starting from 0xD800
// and shift the surrogate characters to above this region
if (ca >= LEAD_SURROGATE_MIN_VALUE_)
if (ca >= LEAD_SURROGATE_MIN_VALUE_) {
ca += (ca <= TRAIL_SURROGATE_MAX_VALUE_) ? 0x2000 : -0x800;
if (cb >= LEAD_SURROGATE_MIN_VALUE_)
}
if (cb >= LEAD_SURROGATE_MIN_VALUE_) {
cb += (cb <= TRAIL_SURROGATE_MAX_VALUE_) ? 0x2000 : -0x800;
}
// end of only different section
if (ca < cb)
if (ca < cb) {
return -1;
}
return 1; // wasn't equal, so return 1
}
if (lena < lenb)
if (lena < lenb) {
return -1;
}
if (lena > lenb)
if (lena > lenb) {
return 1;
}
return 0;
}
@ -561,9 +585,9 @@ public final class UTF16
* @param s UTF16 string
* @return number of codepoint in string
*/
public static int countCP(String s)
public static int countCodePoint(String s)
{
return findCPOffset(s, s.length() - 1) + 1;
return findCodePointOffset(s, s.length() - 1) + 1;
}
/**
@ -572,10 +596,10 @@ public final class UTF16
* @param offset32 UTF32 position to insert into
* @param char32 code point
*/
public static void setCharAtCPOffset(StringBuffer str, int offset32,
public static void setCharAtCodePointOffset(StringBuffer str, int offset32,
int char32)
{
int offset16 = findOffsetFromCP(str.toString(), offset32);
int offset16 = findOffsetFromCodePoint(str.toString(), offset32);
setCharAt(str, offset16, char32);
}
@ -587,9 +611,6 @@ public final class UTF16
*/
public static void setCharAt(StringBuffer source, int offset16, int char32)
{
if (offset16 >= source.length())
throw new StringIndexOutOfBoundsException(offset16);
int count = 1;
char single = source.charAt(offset16);
@ -598,9 +619,10 @@ public final class UTF16
{
// pairs of the surrogate with offset16 at the lead char found
if (isLeadSurrogate(single) && (source.length() > offset16 + 1) &&
isTrailSurrogate(source.charAt(offset16 + 1)))
isTrailSurrogate(source.charAt(offset16 + 1))) {
count ++;
else
}
else {
// pairs of the surrogate with offset16 at the trail char found
if (isTrailSurrogate(single) && (offset16 > 0) &&
isLeadSurrogate(source.charAt(offset16 -1)))
@ -608,6 +630,7 @@ public final class UTF16
offset16 --;
count ++;
}
}
}
source.replace(offset16, offset16 + count, valueOf(char32));
}