unicode-muncher.pl: Removed this file.

2006-03-28  Anthony Balkissoon  <abalkiss@redhat.com>

	* scripts/unicode-muncher.pl: Removed this file.
	* scripts/MakeCharTables.java: Likewise.
	* scripts/unicode-to-chartables.pl: New file.
	* java/lang/natCharacter.cc: 
	(UNASSIGNED_TYPE): New field.
	(UNASSIGNED_DIGIT): Likewise.
	(UNASSIGNED_DIRECTION): Likewise.
	(UNASSIGNED_NUMERIC_VALUE): Likewise.
	(PRIVATE_TYPE): Likewise.
	(PRIVATE_DIRECTION): Likewise.
	(readCodePoint): New method.
	(getType(jint)): Likewise.
	(toLowerCase(jint)): Likewise.
	(toUpperCase(jint)): Likewise.
	(toTitleCase(jint)): Likewise.
	(digit(jint, jint)): Likewise.
	(getNumericValue(jint)): Likewise.
	(getDirectionality(jint)): Likewise.
	(readChar),
	(getType(jchar)),
	(toLowerCase(jchar)),
	(toUpperCase(jchar)),
	(toTitleCase(jchar)),
	(digit(jchar, jint)),
	(getNumericValue(jchar)),
	(getDirectionality(jchar)): Changed references from data to data[0], 
	blocks to blocks[0], direction to direction[0], numValue to 
	numValue[0], upper to upper[0], lower to lower[0], and shift to 
	shift[0] to reflect the new structures in java-chartables.h.	
	* java/lang/Character.java:
	(readCodePoint): Declared new native method.
	(getType(int)): Likewise.
	(toLowerCase(int)): Likewise.
	(toUpperCase(int)): Likewise.
	(toTitleCase(int)): Likewise.
	(digit(int, int)): Likewise.
	(getNumericValue(int)): Likewise.
	(getDirectionality(int)): Likewise.
	(isLowerCase(int)): New method.
	(isUpperCase(int)): Likewise.
	(itTitleCase(int)): Likewise.
	(isDigit(int)): Likewise.
	(isDefined(int)): Likewise.
	(isLetter(int)): Likewise.
	(isLetterOrDigit(int)): Likewise.
	(isJavaIdentifierStart(int)): Likewise.
	(isJavaIdentifierPart(int)): Likewise.
	(isUnicodeIdentifierStart(int)): Likewise.
	(isUnicodeIdentifierPart(int)): Likewise.
	(isIdentifierIgnorable(int)): Likewise.
	(isSpaceChar(int)): Likewise.
	(isWhitespace(int)): Likewise.
	(isISOControl(int)): Likewise.
	(isMirrored(int)): Likewise.
	* include/java-chartables.h: Generated from 
	scripts/unicode-to-chartables.h.

From-SVN: r112454
This commit is contained in:
Anthony Balkissoon 2006-03-28 16:12:52 +00:00 committed by Anthony Balkissoon
parent 72922229b7
commit 792617a52a
5 changed files with 3111 additions and 887 deletions

View File

@ -1,3 +1,62 @@
2006-03-28 Anthony Balkissoon <abalkiss@redhat.com>
* scripts/unicode-muncher.pl: Removed this file.
* scripts/MakeCharTables.java: Likewise.
* scripts/unicode-to-chartables.pl: New file.
* java/lang/natCharacter.cc:
(UNASSIGNED_TYPE): New field.
(UNASSIGNED_DIGIT): Likewise.
(UNASSIGNED_DIRECTION): Likewise.
(UNASSIGNED_NUMERIC_VALUE): Likewise.
(PRIVATE_TYPE): Likewise.
(PRIVATE_DIRECTION): Likewise.
(readCodePoint): New method.
(getType(jint)): Likewise.
(toLowerCase(jint)): Likewise.
(toUpperCase(jint)): Likewise.
(toTitleCase(jint)): Likewise.
(digit(jint, jint)): Likewise.
(getNumericValue(jint)): Likewise.
(getDirectionality(jint)): Likewise.
(readChar),
(getType(jchar)),
(toLowerCase(jchar)),
(toUpperCase(jchar)),
(toTitleCase(jchar)),
(digit(jchar, jint)),
(getNumericValue(jchar)),
(getDirectionality(jchar)): Changed references from data to data[0],
blocks to blocks[0], direction to direction[0], numValue to
numValue[0], upper to upper[0], lower to lower[0], and shift to
shift[0] to reflect the new structures in java-chartables.h.
* java/lang/Character.java:
(readCodePoint): Declared new native method.
(getType(int)): Likewise.
(toLowerCase(int)): Likewise.
(toUpperCase(int)): Likewise.
(toTitleCase(int)): Likewise.
(digit(int, int)): Likewise.
(getNumericValue(int)): Likewise.
(getDirectionality(int)): Likewise.
(isLowerCase(int)): New method.
(isUpperCase(int)): Likewise.
(itTitleCase(int)): Likewise.
(isDigit(int)): Likewise.
(isDefined(int)): Likewise.
(isLetter(int)): Likewise.
(isLetterOrDigit(int)): Likewise.
(isJavaIdentifierStart(int)): Likewise.
(isJavaIdentifierPart(int)): Likewise.
(isUnicodeIdentifierStart(int)): Likewise.
(isUnicodeIdentifierPart(int)): Likewise.
(isIdentifierIgnorable(int)): Likewise.
(isSpaceChar(int)): Likewise.
(isWhitespace(int)): Likewise.
(isISOControl(int)): Likewise.
(isMirrored(int)): Likewise.
* include/java-chartables.h: Generated from
scripts/unicode-to-chartables.h.
2006-03-24 David Daney <ddaney@avtrex.com)
* testsuite/libjava.lang/PR26858.java: New test.

File diff suppressed because it is too large Load Diff

View File

@ -2168,6 +2168,21 @@ public final class Character implements Serializable, Comparable
*/
private static native char readChar(char ch);
/**
* Grabs an attribute offset from the Unicode attribute database. The lower
* 5 bits are the character type, the next 2 bits are flags, and the top
* 9 bits are the offset into the attribute tables. Note that the top 9
* bits are meaningless in this context; they are useful only in the native
* code.
*
* @param codePoint the character to look up
* @return the character's attribute offset and type
* @see #TYPE_MASK
* @see #NO_BREAK_MASK
* @see #MIRROR_MASK
*/
private static native char readCodePoint(int codePoint);
/**
* Wraps up a character.
*
@ -2256,6 +2271,26 @@ public final class Character implements Serializable, Comparable
return getType(ch) == LOWERCASE_LETTER;
}
/**
* Determines if a character is a Unicode lowercase letter. For example,
* <code>'a'</code> is lowercase. Unlike isLowerCase(char), this method
* supports supplementary Unicode code points.
* <br>
* lowercase = [Ll]
*
* @param codePoint character to test
* @return true if codePoint is a Unicode lowercase letter, else false
* @see #isUpperCase(int)
* @see #isTitleCase(int)
* @see #toLowerCase(int)
* @see #getType(int)
* @since 1.5
*/
public static boolean isLowerCase(int codePoint)
{
return getType(codePoint) == LOWERCASE_LETTER;
}
/**
* Determines if a character is a Unicode uppercase letter. For example,
* <code>'A'</code> is uppercase.
@ -2274,6 +2309,26 @@ public final class Character implements Serializable, Comparable
return getType(ch) == UPPERCASE_LETTER;
}
/**
* Determines if a character is a Unicode uppercase letter. For example,
* <code>'A'</code> is uppercase. Unlike isUpperCase(char), this method
* supports supplementary Unicode code points.
* <br>
* uppercase = [Lu]
*
* @param codePoint character to test
* @return true if codePoint is a Unicode uppercase letter, else false
* @see #isLowerCase(int)
* @see #isTitleCase(int)
* @see #toUpperCase(int)
* @see #getType(int)
* @since 1.5
*/
public static boolean isUpperCase(int codePoint)
{
return getType(codePoint) == UPPERCASE_LETTER;
}
/**
* Determines if a character is a Unicode titlecase letter. For example,
* the character "Lj" (Latin capital L with small letter j) is titlecase.
@ -2292,6 +2347,27 @@ public final class Character implements Serializable, Comparable
return getType(ch) == TITLECASE_LETTER;
}
/**
* Determines if a character is a Unicode titlecase letter. For example,
* the character "Lj" (Latin capital L with small letter j) is titlecase.
* Unlike isTitleCase(char), this method supports supplementary Unicode
* code points.
* <br>
* titlecase = [Lt]
*
* @param codePoint character to test
* @return true if codePoint is a Unicode titlecase letter, else false
* @see #isLowerCase(int)
* @see #isUpperCase(int)
* @see #toTitleCase(int)
* @see #getType(int)
* @since 1.5
*/
public static boolean isTitleCase(int codePoint)
{
return getType(codePoint) == TITLECASE_LETTER;
}
/**
* Determines if a character is a Unicode decimal digit. For example,
* <code>'0'</code> is a digit.
@ -2309,6 +2385,25 @@ public final class Character implements Serializable, Comparable
return getType(ch) == DECIMAL_DIGIT_NUMBER;
}
/**
* Determines if a character is a Unicode decimal digit. For example,
* <code>'0'</code> is a digit. Unlike isDigit(char), this method
* supports supplementary Unicode code points.
* <br>
* Unicode decimal digit = [Nd]
*
* @param codePoint character to test
* @return true if ccodePoint is a Unicode decimal digit, else false
* @see #digit(int, int)
* @see #forDigit(int, int)
* @see #getType(int)
* @since 1.5
*/
public static boolean isDigit(int codePoint)
{
return getType(codePoint) == DECIMAL_DIGIT_NUMBER;
}
/**
* Determines if a character is part of the Unicode Standard. This is an
* evolving standard, but covers every character in the data file.
@ -2329,6 +2424,28 @@ public final class Character implements Serializable, Comparable
return getType(ch) != UNASSIGNED;
}
/**
* Determines if a character is part of the Unicode Standard. This is an
* evolving standard, but covers every character in the data file. Unlike
* isDefined(char), this method supports supplementary Unicode code points.
* <br>
* defined = not [Cn]
*
* @param codePoint character to test
* @return true if codePoint is a Unicode character, else false
* @see #isDigit(int)
* @see #isLetter(int)
* @see #isLetterOrDigit(int)
* @see #isLowerCase(int)
* @see #isTitleCase(int)
* @see #isUpperCase(int)
* @since 1.5
*/
public static boolean isDefined(int codePoint)
{
return getType(codePoint) != UNASSIGNED;
}
/**
* Determines if a character is a Unicode letter. Not all letters have case,
* so this may return true when isLowerCase and isUpperCase return false.
@ -2357,6 +2474,37 @@ public final class Character implements Serializable, Comparable
| (1 << OTHER_LETTER))) != 0;
}
/**
* Determines if a character is a Unicode letter. Not all letters have case,
* so this may return true when isLowerCase and isUpperCase return false.
* Unlike isLetter(char), this method supports supplementary Unicode code
* points.
* <br>
* letter = [Lu]|[Ll]|[Lt]|[Lm]|[Lo]
*
* @param codePoint character to test
* @return true if codePoint is a Unicode letter, else false
* @see #isDigit(int)
* @see #isJavaIdentifierStart(int)
* @see #isJavaLetter(int)
* @see #isJavaLetterOrDigit(int)
* @see #isLetterOrDigit(int)
* @see #isLowerCase(int)
* @see #isTitleCase(int)
* @see #isUnicodeIdentifierStart(int)
* @see #isUpperCase(int)
* @since 1.5
*/
public static boolean isLetter(int codePoint)
{
return ((1 << getType(codePoint))
& ((1 << UPPERCASE_LETTER)
| (1 << LOWERCASE_LETTER)
| (1 << TITLECASE_LETTER)
| (1 << MODIFIER_LETTER)
| (1 << OTHER_LETTER))) != 0;
}
/**
* Determines if a character is a Unicode letter or a Unicode digit. This
* is the combination of isLetter and isDigit.
@ -2383,6 +2531,34 @@ public final class Character implements Serializable, Comparable
| (1 << DECIMAL_DIGIT_NUMBER))) != 0;
}
/**
* Determines if a character is a Unicode letter or a Unicode digit. This
* is the combination of isLetter and isDigit. Unlike isLetterOrDigit(char),
* this method supports supplementary Unicode code points.
* <br>
* letter or digit = [Lu]|[Ll]|[Lt]|[Lm]|[Lo]|[Nd]
*
* @param codePoint character to test
* @return true if codePoint is a Unicode letter or a Unicode digit, else false
* @see #isDigit(int)
* @see #isJavaIdentifierPart(int)
* @see #isJavaLetter(int)
* @see #isJavaLetterOrDigit(int)
* @see #isLetter(int)
* @see #isUnicodeIdentifierPart(int)
* @since 1.5
*/
public static boolean isLetterOrDigit(int codePoint)
{
return ((1 << getType(codePoint)
& ((1 << UPPERCASE_LETTER)
| (1 << LOWERCASE_LETTER)
| (1 << TITLECASE_LETTER)
| (1 << MODIFIER_LETTER)
| (1 << OTHER_LETTER)
| (1 << DECIMAL_DIGIT_NUMBER))) != 0);
}
/**
* Determines if a character can start a Java identifier. This is the
* combination of isLetter, any character where getType returns
@ -2404,6 +2580,35 @@ public final class Character implements Serializable, Comparable
return isJavaIdentifierStart(ch);
}
/**
* Determines if a character can start a Java identifier. This is the
* combination of isLetter, any character where getType returns
* LETTER_NUMBER, currency symbols (like '$'), and connecting punctuation
* (like '_'). Unlike isJavaIdentifierStart(char), this method supports
* supplementary Unicode code points.
* <br>
* Java identifier start = [Lu]|[Ll]|[Lt]|[Lm]|[Lo]|[Nl]|[Sc]|[Pc]
*
* @param codePoint character to test
* @return true if codePoint can start a Java identifier, else false
* @see #isJavaIdentifierPart(int)
* @see #isLetter(int)
* @see #isUnicodeIdentifierStart(int)
* @since 1.5
*/
public static boolean isJavaIdentifierStart(int codePoint)
{
return ((1 << getType(codePoint))
& ((1 << UPPERCASE_LETTER)
| (1 << LOWERCASE_LETTER)
| (1 << TITLECASE_LETTER)
| (1 << MODIFIER_LETTER)
| (1 << OTHER_LETTER)
| (1 << LETTER_NUMBER)
| (1 << CURRENCY_SYMBOL)
| (1 << CONNECTOR_PUNCTUATION))) != 0;
}
/**
* Determines if a character can follow the first letter in
* a Java identifier. This is the combination of isJavaLetter (isLetter,
@ -2493,6 +2698,45 @@ public final class Character implements Serializable, Comparable
|| (category == CONTROL && isIdentifierIgnorable(ch));
}
/**
* Determines if a character can follow the first letter in
* a Java identifier. This is the combination of isJavaLetter (isLetter,
* type of LETTER_NUMBER, currency, connecting punctuation) and digit,
* numeric letter (like Roman numerals), combining marks, non-spacing marks,
* or isIdentifierIgnorable. Unlike isJavaIdentifierPart(char), this method
* supports supplementary Unicode code points.
* <br>
* Java identifier extender =
* [Lu]|[Ll]|[Lt]|[Lm]|[Lo]|[Nl]|[Sc]|[Pc]|[Mn]|[Mc]|[Nd]|[Cf]
* |U+0000-U+0008|U+000E-U+001B|U+007F-U+009F
*
* @param codePoint character to test
* @return true if codePoint can follow the first letter in a Java identifier
* @see #isIdentifierIgnorable(int)
* @see #isJavaIdentifierStart(int)
* @see #isLetterOrDigit(int)
* @see #isUnicodeIdentifierPart(int)
* @since 1.5
*/
public static boolean isJavaIdentifierPart(int codePoint)
{
int category = getType(codePoint);
return ((1 << category)
& ((1 << UPPERCASE_LETTER)
| (1 << LOWERCASE_LETTER)
| (1 << TITLECASE_LETTER)
| (1 << MODIFIER_LETTER)
| (1 << OTHER_LETTER)
| (1 << NON_SPACING_MARK)
| (1 << COMBINING_SPACING_MARK)
| (1 << DECIMAL_DIGIT_NUMBER)
| (1 << LETTER_NUMBER)
| (1 << CURRENCY_SYMBOL)
| (1 << CONNECTOR_PUNCTUATION)
| (1 << FORMAT))) != 0
|| (category == CONTROL && isIdentifierIgnorable(codePoint));
}
/**
* Determines if a character can start a Unicode identifier. Only
* letters can start a Unicode identifier, but this includes characters
@ -2518,6 +2762,32 @@ public final class Character implements Serializable, Comparable
| (1 << LETTER_NUMBER))) != 0;
}
/**
* Determines if a character can start a Unicode identifier. Only
* letters can start a Unicode identifier, but this includes characters
* in LETTER_NUMBER. Unlike isUnicodeIdentifierStart(char), this method
* supports supplementary Unicode code points.
* <br>
* Unicode identifier start = [Lu]|[Ll]|[Lt]|[Lm]|[Lo]|[Nl]
*
* @param codePoint character to test
* @return true if codePoint can start a Unicode identifier, else false
* @see #isJavaIdentifierStart(int)
* @see #isLetter(int)
* @see #isUnicodeIdentifierPart(int)
* @since 1.5
*/
public static boolean isUnicodeIdentifierStart(int codePoint)
{
return ((1 << getType(codePoint))
& ((1 << UPPERCASE_LETTER)
| (1 << LOWERCASE_LETTER)
| (1 << TITLECASE_LETTER)
| (1 << MODIFIER_LETTER)
| (1 << OTHER_LETTER)
| (1 << LETTER_NUMBER))) != 0;
}
/**
* Determines if a character can follow the first letter in
* a Unicode identifier. This includes letters, connecting punctuation,
@ -2554,6 +2824,44 @@ public final class Character implements Serializable, Comparable
|| (category == CONTROL && isIdentifierIgnorable(ch));
}
/**
* Determines if a character can follow the first letter in
* a Unicode identifier. This includes letters, connecting punctuation,
* digits, numeric letters, combining marks, non-spacing marks, and
* isIdentifierIgnorable. Unlike isUnicodeIdentifierPart(char), this method
* supports supplementary Unicode code points.
* <br>
* Unicode identifier extender =
* [Lu]|[Ll]|[Lt]|[Lm]|[Lo]|[Nl]|[Mn]|[Mc]|[Nd]|[Pc]|[Cf]|
* |U+0000-U+0008|U+000E-U+001B|U+007F-U+009F
*
* @param codePoint character to test
* @return true if codePoint can follow the first letter in a Unicode
* identifier
* @see #isIdentifierIgnorable(int)
* @see #isJavaIdentifierPart(int)
* @see #isLetterOrDigit(int)
* @see #isUnicodeIdentifierStart(int)
* @since 1.5
*/
public static boolean isUnicodeIdentifierPart(int codePoint)
{
int category = getType(codePoint);
return ((1 << category)
& ((1 << UPPERCASE_LETTER)
| (1 << LOWERCASE_LETTER)
| (1 << TITLECASE_LETTER)
| (1 << MODIFIER_LETTER)
| (1 << OTHER_LETTER)
| (1 << NON_SPACING_MARK)
| (1 << COMBINING_SPACING_MARK)
| (1 << DECIMAL_DIGIT_NUMBER)
| (1 << LETTER_NUMBER)
| (1 << CONNECTOR_PUNCTUATION)
| (1 << FORMAT))) != 0
|| (category == CONTROL && isIdentifierIgnorable(codePoint));
}
/**
* Determines if a character is ignorable in a Unicode identifier. This
* includes the non-whitespace ISO control characters (<code>'\u0000'</code>
@ -2577,6 +2885,32 @@ public final class Character implements Serializable, Comparable
|| getType(ch) == FORMAT;
}
/**
* Determines if a character is ignorable in a Unicode identifier. This
* includes the non-whitespace ISO control characters (<code>'\u0000'</code>
* through <code>'\u0008'</code>, <code>'\u000E'</code> through
* <code>'\u001B'</code>, and <code>'\u007F'</code> through
* <code>'\u009F'</code>), and FORMAT characters. Unlike
* isIdentifierIgnorable(char), this method supports supplementary Unicode
* code points.
* <br>
* Unicode identifier ignorable = [Cf]|U+0000-U+0008|U+000E-U+001B
* |U+007F-U+009F
*
* @param codePoint character to test
* @return true if codePoint is ignorable in a Unicode or Java identifier
* @see #isJavaIdentifierPart(int)
* @see #isUnicodeIdentifierPart(int)
* @since 1.5
*/
public static boolean isIdentifierIgnorable(int codePoint)
{
return ((codePoint >= 0 && codePoint <= 0x0008)
|| (codePoint >= 0x000E && codePoint <= 0x001B)
|| (codePoint >= 0x007F && codePoint <= 0x009F)
|| getType(codePoint) == FORMAT);
}
/**
* Converts a Unicode character into its lowercase equivalent mapping.
* If a mapping does not exist, then the character passed is returned.
@ -2592,6 +2926,24 @@ public final class Character implements Serializable, Comparable
*/
public static native char toLowerCase(char ch);
/**
* Converts a Unicode character into its lowercase equivalent mapping.
* If a mapping does not exist, then the character passed is returned.
* Note that isLowerCase(toLowerCase(codePoint)) does not always return true.
* Unlike toLowerCase(char), this method supports supplementary Unicode
* code points.
*
* @param codePoint character to convert to lowercase
* @return lowercase mapping of codePoint, or codePoint if lowercase
* mapping does not exist
* @see #isLowerCase(int)
* @see #isUpperCase(int)
* @see #toTitleCase(int)
* @see #toUpperCase(int)
* @since 1.5
*/
public static native int toLowerCase(int codePoint);
/**
* Converts a Unicode character into its uppercase equivalent mapping.
* If a mapping does not exist, then the character passed is returned.
@ -2607,6 +2959,24 @@ public final class Character implements Serializable, Comparable
*/
public static native char toUpperCase(char ch);
/**
* Converts a Unicode character into its uppercase equivalent mapping.
* If a mapping does not exist, then the character passed is returned.
* Note that isUpperCase(toUpperCase(codePoint)) does not always return true.
* Unlike toUpperCase(char), this method supports supplementary
* Unicode code points.
*
* @param codePoint character to convert to uppercase
* @return uppercase mapping of codePoint, or codePoint if uppercase
* mapping does not exist
* @see #isLowerCase(int)
* @see #isUpperCase(int)
* @see #toLowerCase(int)
* @see #toTitleCase(int)
* @since 1.5
*/
public static native int toUpperCase(int codePoint);
/**
* Converts a Unicode character into its titlecase equivalent mapping.
* If a mapping does not exist, then the character passed is returned.
@ -2621,6 +2991,23 @@ public final class Character implements Serializable, Comparable
*/
public static native char toTitleCase(char ch);
/**
* Converts a Unicode character into its titlecase equivalent mapping.
* If a mapping does not exist, then the character passed is returned.
* Note that isTitleCase(toTitleCase(codePoint)) does not always return true.
* Unlike toTitleCase(char), this method supports supplementary
* Unicode code points.
*
* @param codePoint character to convert to titlecase
* @return titlecase mapping of codePoint, or codePoint if titlecase
* mapping does not exist
* @see #isTitleCase(int)
* @see #toLowerCase(int)
* @see #toUpperCase(int)
* @since 1.5
*/
public static native int toTitleCase(int codePoint);
/**
* Converts a character into a digit of the specified radix. If the radix
* exceeds MIN_RADIX or MAX_RADIX, or if the result of getNumericValue(ch)
@ -2641,6 +3028,28 @@ public final class Character implements Serializable, Comparable
*/
public static native int digit(char ch, int radix);
/**
* Converts a character into a digit of the specified radix. If the radix
* exceeds MIN_RADIX or MAX_RADIX, or if the result of getNumericValue(int)
* exceeds the radix, or if codePoint is not a decimal digit or in the case
* insensitive set of 'a'-'z', the result is -1. Unlike digit(char, int),
* this method supports supplementary Unicode code points.
* <br>
* character argument boundary = [Nd]|U+0041-U+005A|U+0061-U+007A
* |U+FF21-U+FF3A|U+FF41-U+FF5A
*
* @param codePoint character to convert into a digit
* @param radix radix in which codePoint is a digit
* @return digit which codePoint represents in radix, or -1 not a valid digit
* @see #MIN_RADIX
* @see #MAX_RADIX
* @see #forDigit(int, int)
* @see #isDigit(int)
* @see #getNumericValue(int)
* @since 1.5
*/
public static native int digit(int codePoint, int radix);
/**
* Returns the Unicode numeric value property of a character. For example,
* <code>'\\u216C'</code> (the Roman numeral fifty) returns 50.
@ -2670,6 +3079,38 @@ public final class Character implements Serializable, Comparable
*/
public static native int getNumericValue(char ch);
/**
* Returns the Unicode numeric value property of a character. For example,
* <code>'\\u216C'</code> (the Roman numeral fifty) returns 50.
*
* <p>This method also returns values for the letters A through Z, (not
* specified by Unicode), in these ranges: <code>'\u0041'</code>
* through <code>'\u005A'</code> (uppercase); <code>'\u0061'</code>
* through <code>'\u007A'</code> (lowercase); and <code>'\uFF21'</code>
* through <code>'\uFF3A'</code>, <code>'\uFF41'</code> through
* <code>'\uFF5A'</code> (full width variants).
*
* <p>If the character lacks a numeric value property, -1 is returned.
* If the character has a numeric value property which is not representable
* as a nonnegative integer, such as a fraction, -2 is returned.
*
* Unlike getNumericValue(char), this method supports supplementary Unicode
* code points.
*
* character argument boundary = [Nd]|[Nl]|[No]|U+0041-U+005A|U+0061-U+007A
* |U+FF21-U+FF3A|U+FF41-U+FF5A
*
* @param codePoint character from which the numeric value property will
* be retrieved
* @return the numeric value property of codePoint, or -1 if it does not
* exist, or -2 if it is not representable as a nonnegative integer
* @see #forDigit(int, int)
* @see #digit(int, int)
* @see #isDigit(int)
* @since 1.5
*/
public static native int getNumericValue(int codePoint);
/**
* Determines if a character is a ISO-LATIN-1 space. This is only the five
* characters <code>'\t'</code>, <code>'\n'</code>, <code>'\f'</code>,
@ -2713,6 +3154,26 @@ public final class Character implements Serializable, Comparable
| (1 << PARAGRAPH_SEPARATOR))) != 0;
}
/**
* Determines if a character is a Unicode space character. This includes
* SPACE_SEPARATOR, LINE_SEPARATOR, and PARAGRAPH_SEPARATOR. Unlike
* isSpaceChar(char), this method supports supplementary Unicode code points.
* <br>
* Unicode space = [Zs]|[Zp]|[Zl]
*
* @param codePoint character to test
* @return true if codePoint is a Unicode space, else false
* @see #isWhitespace(int)
* @since 1.5
*/
public static boolean isSpaceChar(int codePoint)
{
return ((1 << getType(codePoint))
& ((1 << SPACE_SEPARATOR)
| (1 << LINE_SEPARATOR)
| (1 << PARAGRAPH_SEPARATOR))) != 0;
}
/**
* Determines if a character is Java whitespace. This includes Unicode
* space characters (SPACE_SEPARATOR, LINE_SEPARATOR, and
@ -2750,6 +3211,47 @@ public final class Character implements Serializable, Comparable
| (1 << '\u001F'))) != 0);
}
/**
* Determines if a character is Java whitespace. This includes Unicode
* space characters (SPACE_SEPARATOR, LINE_SEPARATOR, and
* PARAGRAPH_SEPARATOR) except the non-breaking spaces
* (<code>'\u00A0'</code>, <code>'\u2007'</code>, and <code>'\u202F'</code>);
* and these characters: <code>'\u0009'</code>, <code>'\u000A'</code>,
* <code>'\u000B'</code>, <code>'\u000C'</code>, <code>'\u000D'</code>,
* <code>'\u001C'</code>, <code>'\u001D'</code>, <code>'\u001E'</code>,
* and <code>'\u001F'</code>. Unlike isWhitespace(char), this method
* supports supplementary Unicode code points.
* <br>
* Java whitespace = ([Zs] not Nb)|[Zl]|[Zp]|U+0009-U+000D|U+001C-U+001F
*
* @param codePoint character to test
* @return true if codePoint is Java whitespace, else false
* @see #isSpaceChar(int)
* @since 1.5
*/
public static boolean isWhitespace(int codePoint)
{
int plane = codePoint >>> 16;
if (plane > 2 && plane != 14)
return false;
int attr = readCodePoint(codePoint);
return ((((1 << (attr & TYPE_MASK))
& ((1 << SPACE_SEPARATOR)
| (1 << LINE_SEPARATOR)
| (1 << PARAGRAPH_SEPARATOR))) != 0)
&& (attr & NO_BREAK_MASK) == 0)
|| (codePoint <= '\u001F' && ((1 << codePoint)
& ((1 << '\t')
| (1 << '\n')
| (1 << '\u000B')
| (1 << '\u000C')
| (1 << '\r')
| (1 << '\u001C')
| (1 << '\u001D')
| (1 << '\u001E')
| (1 << '\u001F'))) != 0);
}
/**
* Determines if a character has the ISO Control property.
* <br>
@ -2766,6 +3268,24 @@ public final class Character implements Serializable, Comparable
return getType(ch) == CONTROL;
}
/**
* Determines if a character has the ISO Control property. Unlike
* isISOControl(char), this method supports supplementary unicode
* code points.
* <br>
* ISO Control = [Cc]
*
* @param codePoint character to test
* @return true if codePoint is an ISO Control character, else false
* @see #isSpaceChar(int)
* @see #isWhitespace(int)
* @since 1.5
*/
public static boolean isISOControl(int codePoint)
{
return getType(codePoint) == CONTROL;
}
/**
* Returns the Unicode general category property of a character.
*
@ -2805,6 +3325,46 @@ public final class Character implements Serializable, Comparable
*/
public static native int getType(char ch);
/**
* Returns the Unicode general category property of a character. Supports
* supplementary Unicode code points.
*
* @param codePoint character from which the general category property will
* be retrieved
* @return the character category property of codePoint as an integer
* @see #UNASSIGNED
* @see #UPPERCASE_LETTER
* @see #LOWERCASE_LETTER
* @see #TITLECASE_LETTER
* @see #MODIFIER_LETTER
* @see #OTHER_LETTER
* @see #NON_SPACING_MARK
* @see #ENCLOSING_MARK
* @see #COMBINING_SPACING_MARK
* @see #DECIMAL_DIGIT_NUMBER
* @see #LETTER_NUMBER
* @see #OTHER_NUMBER
* @see #SPACE_SEPARATOR
* @see #LINE_SEPARATOR
* @see #PARAGRAPH_SEPARATOR
* @see #CONTROL
* @see #FORMAT
* @see #PRIVATE_USE
* @see #SURROGATE
* @see #DASH_PUNCTUATION
* @see #START_PUNCTUATION
* @see #END_PUNCTUATION
* @see #CONNECTOR_PUNCTUATION
* @see #OTHER_PUNCTUATION
* @see #MATH_SYMBOL
* @see #CURRENCY_SYMBOL
* @see #MODIFIER_SYMBOL
* @see #INITIAL_QUOTE_PUNCTUATION
* @see #FINAL_QUOTE_PUNCTUATION
* @since 1.5
*/
public static native int getType(int codePoint);
/**
* Converts a digit into a character which represents that digit
* in a specified radix. If the radix exceeds MIN_RADIX or MAX_RADIX,
@ -2858,6 +3418,37 @@ public final class Character implements Serializable, Comparable
*/
public static native byte getDirectionality(char ch);
/**
* Returns the Unicode directionality property of the character. This
* is used in the visual ordering of text. Unlike getDirectionality(char),
* this method supports supplementary Unicode code points.
*
* @param codePoint the character to look up
* @return the directionality constant, or DIRECTIONALITY_UNDEFINED
* @see #DIRECTIONALITY_UNDEFINED
* @see #DIRECTIONALITY_LEFT_TO_RIGHT
* @see #DIRECTIONALITY_RIGHT_TO_LEFT
* @see #DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC
* @see #DIRECTIONALITY_EUROPEAN_NUMBER
* @see #DIRECTIONALITY_EUROPEAN_NUMBER_SEPARATOR
* @see #DIRECTIONALITY_EUROPEAN_NUMBER_TERMINATOR
* @see #DIRECTIONALITY_ARABIC_NUMBER
* @see #DIRECTIONALITY_COMMON_NUMBER_SEPARATOR
* @see #DIRECTIONALITY_NONSPACING_MARK
* @see #DIRECTIONALITY_BOUNDARY_NEUTRAL
* @see #DIRECTIONALITY_PARAGRAPH_SEPARATOR
* @see #DIRECTIONALITY_SEGMENT_SEPARATOR
* @see #DIRECTIONALITY_WHITESPACE
* @see #DIRECTIONALITY_OTHER_NEUTRALS
* @see #DIRECTIONALITY_LEFT_TO_RIGHT_EMBEDDING
* @see #DIRECTIONALITY_LEFT_TO_RIGHT_OVERRIDE
* @see #DIRECTIONALITY_RIGHT_TO_LEFT_EMBEDDING
* @see #DIRECTIONALITY_RIGHT_TO_LEFT_OVERRIDE
* @see #DIRECTIONALITY_POP_DIRECTIONAL_FORMAT
* @since 1.5
*/
public static native byte getDirectionality(int codePoint);
/**
* Determines whether the character is mirrored according to Unicode. For
* example, <code>\u0028</code> (LEFT PARENTHESIS) appears as '(' in
@ -2872,6 +3463,24 @@ public final class Character implements Serializable, Comparable
return (readChar(ch) & MIRROR_MASK) != 0;
}
/**
* Determines whether the character is mirrored according to Unicode. For
* example, <code>\u0028</code> (LEFT PARENTHESIS) appears as '(' in
* left-to-right text, but ')' in right-to-left text. Unlike
* isMirrored(char), this method supports supplementary Unicode code points.
*
* @param codePoint the character to look up
* @return true if the character is mirrored
* @since 1.5
*/
public static boolean isMirrored(int codePoint)
{
int plane = codePoint >>> 16;
if (plane > 2 && plane != 14)
return false;
return (readCodePoint(codePoint) & MIRROR_MASK) != 0;
}
/**
* Compares another Character to this Character, numerically.
*

View File

@ -45,30 +45,91 @@ exception statement from your version. */
// These constants define the return values for characters that are unassigned
// or reserved for private use.
#define UNASSIGNED_TYPE 0
#define UNASSIGNED_DIGIT -1
#define UNASSIGNED_DIRECTION -1
#define UNASSIGNED_NUMERIC_VALUE -1
#define PRIVATE_TYPE 18
#define PRIVATE_DIRECTION 0
// The methods that take a char as an argument all have counterparts that
// take ints. The ones that take chars only work for the BMP or plane 0 of the
// Unicode standard but the ones that take ints work for all Unicode code
// points. However, the ones that take chars don't simply redirect the calls
// because the BMP is by far the most used plane so saving a little time on
// each call makes sense.
jchar
java::lang::Character::readChar(jchar ch)
{
// Perform 16-bit addition to find the correct entry in data.
return data[(jchar) (blocks[ch >> SHIFT] + ch)];
return data[0][(jchar) (blocks[0][ch >> shift[0]] + ch)];
}
jchar
java::lang::Character::readCodePoint(jint codePoint)
{
jint plane = codePoint >> 16;
jchar offset = (jchar)(codePoint & 0xffff);
// Be careful not to call this method with an unassigned character. The only
// characters assigned as of Unicode 4.0.0 belong to planes 0, 1, 2, and 14.
return data[plane][(jchar) (blocks[plane][offset >> shift[plane]] + offset)];
}
jint
java::lang::Character::getType(jchar ch)
{
// Perform 16-bit addition to find the correct entry in data.
return (jint) (data[(jchar) (blocks[ch >> SHIFT] + ch)] & TYPE_MASK);
return (jint) (data[0][(jchar) (blocks[0][ch >> shift[0]] + ch)] & TYPE_MASK);
}
jint
java::lang::Character::getType(jint codePoint)
{
jint plane = codePoint >> 16;
if (plane > 2 && plane != 14)
{
if (plane > 14 && ((codePoint & 0xffff) < 0xfffe))
return (jint) PRIVATE_TYPE;
return (jint) UNASSIGNED_TYPE;
}
jint offset = codePoint & 0xffff;
return (jint)
(data[plane]
[(jchar) (blocks[plane][offset >> shift[plane]] + offset)] & TYPE_MASK);
}
jchar
java::lang::Character::toLowerCase(jchar ch)
{
return (jchar) (ch + lower[readChar(ch) >> 7]);
return (jchar) (ch + lower[0][readChar(ch) >> 7]);
}
jint
java::lang::Character::toLowerCase(jint codePoint)
{
jint plane = codePoint >> 16;
if (plane > 2 && plane != 14)
return codePoint;
return (lower[plane][readCodePoint(codePoint) >> 7]) + codePoint;
}
jchar
java::lang::Character::toUpperCase(jchar ch)
{
return (jchar) (ch + upper[readChar(ch) >> 7]);
return (jchar) (ch + upper[0][readChar(ch) >> 7]);
}
jint
java::lang::Character::toUpperCase(jint codePoint)
{
jint plane = codePoint >> 16;
if (plane > 2 && plane != 14)
return codePoint;
return (upper[plane][readCodePoint(codePoint) >> 7]) + codePoint;
}
jchar
@ -81,6 +142,16 @@ java::lang::Character::toTitleCase(jchar ch)
return toUpperCase(ch);
}
jint
java::lang::Character::toTitleCase(jint codePoint)
{
// As of Unicode 4.0.0 no characters outside of plane 0 have titlecase
// mappings that are different from their uppercase mapping.
if (codePoint < 0x10000)
return toTitleCase((jchar)codePoint);
return toUpperCase(codePoint);
}
jint
java::lang::Character::digit(jchar ch, jint radix)
{
@ -93,21 +164,74 @@ java::lang::Character::digit(jchar ch, jint radix)
| (1 << DECIMAL_DIGIT_NUMBER))))
{
// Signedness doesn't matter; 0xffff vs. -1 are both rejected.
jint digit = (jint) numValue[attr >> 7];
jint digit = (jint) numValue[0][attr >> 7];
return (digit >= 0 && digit < radix) ? digit : (jint) -1;
}
return (jint) -1;
}
jint
java::lang::Character::digit(jint codePoint, jint radix)
{
if (radix < MIN_RADIX || radix > MAX_RADIX)
return (jint) -1;
jint plane = codePoint >> 16;
if (plane > 2 && plane != 14)
return UNASSIGNED_DIGIT;
jchar attr = readCodePoint(codePoint);
if (((1 << (attr & TYPE_MASK))
& ((1 << UPPERCASE_LETTER)
| (1 << LOWERCASE_LETTER)
| (1 << DECIMAL_DIGIT_NUMBER))))
{
// Signedness doesn't matter; 0xffff vs. -1 are both rejected.
jint digit = (jint) numValue[plane][attr >> 7];
if (digit <= -3)
digit = largenums[-digit -3];
return (digit >= 0 && digit < radix) ? digit : (jint) -1;
}
return (jint) -1;
}
jint
java::lang::Character::getNumericValue(jchar ch)
{
// numValue is stored as an array of jshort, since 10000 is the maximum.
return (jint) numValue[readChar(ch) >> 7];
return (jint) numValue[0][readChar(ch) >> 7];
}
jint
java::lang::Character::getNumericValue(jint codePoint)
{
jint plane = codePoint >> 16;
if (plane > 2 && plane != 14)
return UNASSIGNED_NUMERIC_VALUE;
jshort num = numValue[plane][readCodePoint(codePoint) >> 7];
if (num <= -3)
return largenums[-num - 3];
return num;
}
jbyte
java::lang::Character::getDirectionality(jchar ch)
{
return direction[readChar(ch) >> 7];
return direction[0][readChar(ch) >> 7];
}
jbyte
java::lang::Character::getDirectionality(jint codePoint)
{
jint plane = codePoint >> 16;
if (plane > 2 && plane != 14)
{
if (plane > 14 && ((codePoint & 0xffff) < 0xfffe))
return (jint) PRIVATE_DIRECTION;
return (jint) UNASSIGNED_DIRECTION;
}
return direction[plane][readCodePoint(codePoint) >> 7];
}

View File

@ -0,0 +1,802 @@
#!/usr/bin/perl -w
# unicode-to-chartables.pl -- generate Unicode database for java.lang.Character
# Copyright (C) 1998, 2002, 2004, 2006 Free Software Foundation, Inc.
#
# This file is part of GNU Classpath.
#
# GNU Classpath is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# GNU Classpath is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Classpath; see the file COPYING. If not, write to the
# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301 USA.
#
# Linking this library statically or dynamically with other modules is
# making a combined work based on this library. Thus, the terms and
# conditions of the GNU General Public License cover the whole
# combination.
#
# As a special exception, the copyright holders of this library give you
# permission to link this library with independent modules to produce an
# executable, regardless of the license terms of these independent
# modules, and to copy and distribute the resulting executable under
# terms of your choice, provided that you also meet, for each linked
# independent module, the terms and conditions of the license of that
# module. An independent module is a module which is not derived from
# or based on this library. If you modify this library, you may extend
# this exception to your version of the library, but you are not
# obligated to do so. If you do not wish to do so, delete this
# exception statement from your version.
# Code for reading UnicodeData-4.0.0.txt and SpecialCasing-4.0.0.txt to generate
# the code for java-chartables.h. The relevant files can be found here:
#
# http://www.unicode.org/Public/4.0-Update/UnicodeData-4.0.0.txt
# http://www.unicode.org/Public/4.0-Update/SpecialCasing-4.0.0.txt
#
# Inspired by code from Jochen Hoenicke.
# author Eric Blake <ebb9@email.byu.edu>
# Unicode 4.0.0 support by Anthony Balkissoon <abalkiss@redhat.com>
#
# Usage: ./unicode-to-chartables.pl <UnicodeData> <SpecialCasing> <tables>
# where <UnicodeData.txt> is obtained from www.unicode.org (named
# UnicodeData-4.0.0.txt for Unicode version 4.0.0), <SpecialCasing>
# is obtained from www.unicode too (named SpecialCasing-4.0.0.txt for Unicode
# version 4.0.0), and <tables> is the final location for the header file
# java-chartables.h. As of JDK 1.5, use Unicode version 4.0.0
# for best results.
##
## Return the given variable interpreted as a 16 bit signed number.
##
sub cShort($) {
my ($char) = @_;
return unpack "s", pack "I", $char;
}
##
## Convert the text UnicodeData file from www.unicode.org into a header file
## interface with arrays holding the compressed information.
##
my @TYPECODES = qw(Cn Lu Ll Lt Lm Lo Mn Me Mc Nd Nl No Zs Zl Zp Cc Cf
SKIPPED Co Cs Pd Ps Pe Pc Po Sm Sc Sk So Pi Pf);
my @DIRCODES = qw(L R AL EN ES ET AN CS NSM BN B S WS ON LRE LRO RLE RLO PDF);
my $NOBREAK_FLAG = 32;
my $MIRRORED_FLAG = 64;
my %special = ();
# infoArray is an array where each element is a list of character information
# for characters in a plane. The index of each list is equal to the plane
# that it corresponds to even though most of these lists will currently be
# empty. This is done so that that this script can be easily modified to
# accomodate future versions of Unicode.
my @infoArray = \((), (), (), (), (), (), (), (),
(), (), (), (), (), (), (), (), ());
# info is a reference to one of the lists in infoArray, depending on which
# plane we're currently parsing.
my $info;
# largeNums is an array of numerical values that are too large to fit
# into the 16 bit char where most numerical values are stored.
# What is stored in the char then is a number N such that (-N - 3) is
# the index into largeNums where the numerical value can be found.
my @largeNums = ();
my $titlecase = "";
my $count = 0;
my $range = 0;
die "Usage: $0 <UnicodeData.txt> <SpecialCasing.txt> <java-chartables.h>"
unless @ARGV == 3;
$| = 1;
print "GNU Classpath Unicode Attribute Database Generator 2.1\n";
print "Copyright (C) 1998, 2002 Free Software Foundation, Inc.\n";
################################################################################
################################################################################
# Stage 0: Parse the special casing file
print "Parsing special casing file\n";
open (SPECIAL, "< $ARGV[1]") || die "Can't open special casing file: $!\n";
while (<SPECIAL>) {
next if /^\#/;
my ($ch, undef, undef, $upper) = split / *; */;
# This grabs only the special casing for multi-char uppercase. Note that
# there are no multi-char lowercase, and that Sun ignores multi-char
# titlecase rules. This script omits 3 special cases in Unicode 3.0.0,
# which must be hardcoded in java.lang.String:
# \u03a3 (Sun ignores this special case)
# \u0049 - lowercases to \u0131, but only in Turkish locale
# \u0069 - uppercases to \u0130, but only in Turkish locale
next unless defined $upper and $upper =~ / /;
$special{hex $ch} = [map {hex} split ' ', $upper];
}
close SPECIAL;
################################################################################
################################################################################
## Stage 1: Parse the attribute file
print "Parsing attributes file";
open (UNICODE, "< $ARGV[0]") || die "Can't open Unicode attribute file: $!\n";
while (<UNICODE>) {
print "." unless $count++ % 1000;
chomp;
s/\r//g;
my ($ch, $name, $category, undef, $bidir, $decomp, undef, undef, $numeric,
$mirrored, undef, undef, $upcase, $lowcase, $title) = split ';';
$ch = hex($ch);
# plane tells us which Unicode code plane we're currently in and is an
# index into infoArray.
my $plane = int($ch / 0x10000);
my $planeBase = $plane * 0x10000;
$info = \@{$infoArray[$plane]};
my ($type, $numValue, $upperchar, $lowerchar, $direction);
$type = 0;
while ($category !~ /^$TYPECODES[$type]$/) {
if (++$type == @TYPECODES) {
die "$ch: Unknown type: $category";
}
}
$type |= $NOBREAK_FLAG if ($decomp =~ /noBreak/);
$type |= $MIRRORED_FLAG if ($mirrored =~ /Y/);
if ($numeric =~ /^[0-9]+$/) {
$numValue = $numeric;
# If numeric takes more than 16 bits to store we want to store that
# number in a separate array and store a number N in numValue such
# that (-N - 3) is the offset into the separate array containing the
# large numerical value.
if ($numValue >= 0x7fff) {
$numValue = -3 - @largeNums;
push @largeNums, $numeric;
}
} elsif ($numeric eq "") {
# Special case sequences of 'a'-'z'
if ($ch >= 0x0041 && $ch <= 0x005a) {
$numValue = $ch - 0x0037;
} elsif ($ch >= 0x0061 && $ch <= 0x007a) {
$numValue = $ch - 0x0057;
} elsif ($ch >= 0xff21 && $ch <= 0xff3a) {
$numValue = $ch - 0xff17;
} elsif ($ch >= 0xff41 && $ch <= 0xff5a) {
$numValue = $ch - 0xff37;
} else {
$numValue = -1;
}
} else {
$numValue = -2;
}
$upperchar = $upcase ? hex($upcase) - $ch : 0;
$lowerchar = $lowcase ? hex($lowcase) - $ch : 0;
if ($title ne $upcase) {
my $titlechar = $title ? hex($title) : $ch;
$titlecase .= pack("n2", $ch, $titlechar);
}
$direction = 0;
while ($bidir !~ /^$DIRCODES[$direction]$/) {
if (++$direction == @DIRCODES) {
$direction = -1;
last;
}
}
$direction <<= 2;
$direction += $#{$special{$ch}} if defined $special{$ch};
if ($range) {
die "Expecting end of range at $ch\n" unless $name =~ /Last>$/;
for ($range + 1 .. $ch - 1) {
$info->[$_ - $planeBase] = pack("n5", $type, $numValue, $upperchar,
$lowerchar, $direction);
}
$range = 0;
} elsif ($name =~ /First>$/) {
$range = $ch;
}
# Store all this parsed information into the element in infoArray that info
# points to.
$info->[$ch - $planeBase] = pack("n5", $type, $numValue, $upperchar, $lowerchar,
$direction);
}
close UNICODE;
################################################################################
################################################################################
## Stage 2: Compress the data structures
printf "\nCompressing data structures";
$count = 0;
# data is a String that will be used to create the DATA String containing
# character information and offsets into the attribute tables.
my @data = ();
# charhashArray is an array of hashtables used so that we can reuse character
# attributes when characters share the same attributes ... this makes our
# attribute tables smaller. charhash is a pointer into this array.
my @charhashArray = ({}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {});
my $charhash = ();
# charinfoArray is an array of arrays, one per plane, for storing character
# information. charinfo is a pointer into this array.
my @charinfoArray = \((), (), (), (), (), (), (), (),
(), (), (), (), (), (), (), (), ());
my $charinfo;
# charlen is an array, one element per plane, that tells us how many unique
# character attributes there are for that plane.
my @charlen = ();
for my $plane (0 .. 0x10) {
$info = \@{$infoArray[$plane]};
my $planeBase = $plane * 0x10000;
$charhash = \%{$charhashArray[$plane]};
$charinfo = \@{$charinfoArray[$plane]};
for my $ch ($planeBase .. $planeBase + 0xffff) {
my $index = $ch - $planeBase;
print "." unless $count++ % 0x1000;
$info->[$index] = pack("n5", 0, -1, 0, 0, -4) unless defined $info->[$index];
my ($type, $numVal, $upper, $lower, $direction) = unpack("n5", $info->[$index]);
if (! exists $charhash->{$info->[$index]}) {
# If we entered this loop that means the character we're looking at
# now has attributes that are unique from those that we've looked
# at so far for this plane. So we push its attributes into charinfo
# and store in charhash the offset into charinfo where these
# attributes can later be found.
push @{$charinfo}, [ $numVal, $upper, $lower, $direction ];
$charhash->{$info->[$index]} = @{$charinfo} - 1;
# When the file is generaged, the number we just stored in charhas
# will be the upper 9 bits in the DATA String that are an offset
# into the attribute tables.
}
$data[$plane] .= pack("n", ($charhash->{$info->[$index]} << 7) | $type);
}
$charlen[$plane] = scalar(@{$charinfoArray[$plane]});
}
# the shift that results in the best compression of the table. This is an array
# because different shifts are better for the different tables for each plane.
my @bestshift;
# an initial guess.
my $bestest = 1000000;
my @bestblkstr;
my @blksize = ();
for my $plane (0 .. 0x10) {
print "\n\nplane: $plane\n";
print "Unique character entries: $charlen[$plane]\n";
$bestest = 1000000;
for my $i (3 .. 8) {
my $blksize = 1 << $i;
my %blocks = ();
my @blkarray = ();
my ($j, $k);
print "shift: $i";
for ($j = 0; $j < 0x10000; $j += $blksize) {
my $blkkey = substr $data[$plane], 2 * $j, 2 * $blksize;
if (! exists $blocks{$blkkey}) {
push @blkarray, $blkkey;
$blocks{$blkkey} = $#blkarray;
}
}
my $blknum = @blkarray;
my $blocklen = $blknum * $blksize;
printf " before %5d", $blocklen;
# Now we try to pack the blkarray as tight as possible by finding matching
# heads and tails.
for ($j = $blksize - 1; $j > 0; $j--) {
my %tails = ();
for $k (0 .. $#blkarray) {
next unless defined $blkarray[$k];
my $len = length $blkarray[$k];
my $tail = substr $blkarray[$k], $len - $j * 2;
if (exists $tails{$tail}) {
push @{$tails{$tail}}, $k;
} else {
$tails{$tail} = [ $k ];
}
}
# tails are calculated, now calculate the heads and merge.
BLOCK:
for $k (0 .. $#blkarray) {
next unless defined $blkarray[$k];
my $tomerge = $k;
while (1) {
my $head = substr($blkarray[$tomerge], 0, $j * 2);
my $entry = $tails{$head};
next BLOCK unless defined $entry;
my $other = shift @{$entry};
if ($other == $tomerge) {
if (@{$entry}) {
push @{$entry}, $other;
$other = shift @{$entry};
} else {
push @{$entry}, $other;
next BLOCK;
}
}
if (@{$entry} == 0) {
delete $tails{$head};
}
# a match was found
my $merge = $blkarray[$other]
. substr($blkarray[$tomerge], $j * 2);
$blocklen -= $j;
$blknum--;
if ($other < $tomerge) {
$blkarray[$tomerge] = undef;
$blkarray[$other] = $merge;
my $len = length $merge;
my $tail = substr $merge, $len - $j * 2;
$tails{$tail} = [ map { $_ == $tomerge ? $other : $_ }
@{$tails{$tail}} ];
next BLOCK;
}
$blkarray[$tomerge] = $merge;
$blkarray[$other] = undef;
}
}
}
my $blockstr;
for $k (0 .. $#blkarray) {
$blockstr .= $blkarray[$k] if defined $blkarray[$k];
}
die "Unexpected $blocklen" if length($blockstr) != 2 * $blocklen;
my $estimate = 2 * $blocklen + (0x20000 >> $i);
printf " after merge %5d: %6d bytes\n", $blocklen, $estimate;
if ($estimate < $bestest) {
$bestest = $estimate;
$bestshift[$plane] = $i;
$bestblkstr[$plane] = $blockstr;
}
}
$blksize[$plane] = 1 << $bestshift[$plane];
print "best shift: ", $bestshift[$plane];
print " blksize: ", $blksize[$plane];
}
my @blocksArray = \((), (), (), (), (), (), (), (),
(), (), (), (), (), (), (), (), ());
for my $plane (0 .. 0x10) {
for (my $j = 0; $j < 0x10000; $j += $blksize[$plane]) {
my $blkkey = substr $data[$plane], 2 * $j, 2 * $blksize[$plane];
my $index = index $bestblkstr[$plane], $blkkey;
while ($index & 1) {
die "not found: $j" if $index == -1;
$index = index $bestblkstr[$plane], $blkkey, $index + 1;
}
push @{$blocksArray[$plane]}, ($index / 2 - $j) & 0xffff;
}
}
################################################################################
################################################################################
## Stage 3: Generate the file
for my $plane (0 .. 0x10) {
die "UTF-8 limit of blocks may be exceeded for plane $plane: " . scalar(@{$blocksArray[$plane]}) . "\n"
if @{$blocksArray[$plane]} > 0xffff / 3;
die "UTF-8 limit of data may be exceeded for plane $plane: " . length($bestblkstr[$plane]) . "\n"
if length($bestblkstr[$plane]) > 0xffff / 3;
}
{
print "\nGenerating $ARGV[2].";
my ($i, $j);
open OUTPUT, "> $ARGV[2]" or die "Failed creating output file: $!\n";
print OUTPUT <<EOF;
/* java-chartables.h -- Character tables for java.lang.Character -*- c++ -*-
Copyright (C) 2002, 2006 Free Software Foundation, Inc.
*** This file is generated by scripts/unicode-to-chartables.pl ***
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
#ifndef __JAVA_CHARTABLES_H__
#define __JAVA_CHARTABLES_H__
// These tables are automatically generated by scripts/unicode_to_chartables.pl.
// The Unicode data comes from www.unicode.org; this header is based on
// UnicodeData-4.0.0.txt. JDK 1.5 uses Unicode version 4.0.0.
// DO NOT EDIT the tables. Instead, fix the upstream scripts and run
// them again.
// The data is stored in C style arrays of the appropriate CNI types, to
// guarantee that the data is constant and non-relocatable. The field
// <code>blocks</code> stores the offset of a block of 2<sup>SHIFT</sup>
// characters within <code>data</code>. The data field, in turn, stores
// information about each character in the low order bits, and an offset
// into the attribute tables <code>upper</code>, <code>lower</code>,
// <code>numValue</code>, and <code>direction</code>. Notice that the
// attribute tables are much smaller than 0xffff entries; as many characters
// in Unicode share common attributes. Finally, there is a listing for
// <code>title</code> exceptions (most characters just have the same title
// case as upper case).
// This file should only be included by natCharacter.cc
/**
* The array containing the numeric values that are too large to be stored as
* chars in NUM_VALUE. NUM_VALUE in this case will contain a negative integer
* N such that LARGENUMS[-N - 3] contains the correct numeric value.
*/
EOF
print OUTPUT "static const jint largenums[] = {\n ";
for ($i = 0; $i < @largeNums; $i++) {
print OUTPUT $largeNums[$i], ", ";
}
print OUTPUT "}";
print OUTPUT <<EOF;
;
/**
* The character shift amount to look up the block offset. In other words,
* <code>(char) (blocks[p][off >> SHIFT[p]] + off)</code> is the index where
* <code>ch</code> is described in <code>data</code>, where <code>off</code>
* is ch & 0xffff and <code>p</code> is the plane the character belongs to.
*/
EOF
print OUTPUT "static const int shift[] = {\n ";
for ($i = 0; $i < @bestshift; $i++) {
print OUTPUT $bestshift[$i], ", ";
}
print OUTPUT "}";
print OUTPUT <<EOF;
;
/**
* The mapping of character blocks to their location in <code>data</code>.
* Each entry has been adjusted so that a modulo 16 sum with the desired
* character gives the actual index into <code>data</code>.
*/
EOF
for ($plane = 0; $plane <= 0x10; $plane++) {
# The following if statement handles the cases of unassigned planes
# specially so we don't waste space with unused Strings. As of
# Unicode version 4.0.0 only planes 0, 1, 2, and 14 are used. If
# you are updating this script to work with a later version of
# Unicode you may have to alter this if statement.
next if ($plane > 2 && $plane != 14) ;
print OUTPUT "static const jchar blocks", $plane, "[] = {\n";
for ($i = 0; $i < @{$blocksArray[$plane]} / 10; $i++) {
print OUTPUT " ";
for $j (0 .. 9) {
last if @{$blocksArray[$plane]} <= $i * 10 + $j;
my $val = $blocksArray[$plane]->[$i * 10 + $j];
print OUTPUT $val, ", ";
}
print OUTPUT "\n";
}
print OUTPUT "};\n\n";
}
print OUTPUT "static const int blocks_length[] = {\n ";
for ($plane = 0; $plane <= 0x10; $plane++) {
if ($plane > 2 && $plane != 14){
print OUTPUT "-1, ";
}
else {
print OUTPUT scalar(@{$blocksArray[$plane]}), ", ";
}
}
print OUTPUT "};\n";
print OUTPUT <<EOF;
static const jchar* blocks[] = {
blocks0, blocks1, blocks2, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, blocks14, NULL, NULL};
/**
* Information about each character. The low order 5 bits form the
* character type, the next bit is a flag for non-breaking spaces, and the
* next bit is a flag for mirrored directionality. The high order 9 bits
* form the offset into the attribute tables. Note that this limits the
* number of unique character attributes per plane to 512, which is not a
* problem as of Unicode version 4.0.0, but may soon become one.
*/
EOF
for ($plane = 0; $plane <= 0x10; $plane++) {
# The following if statement handles the cases of unassigned planes
# specially so we don't waste space with unused Strings. As of
# Unicode version 4.0.0 only planes 0, 1, 2, and 14 are used. If
# you are updating this script to work with a later version of
# Unicode you may have to alter this if statement.
next if ($plane > 2 && $plane != 14);
print OUTPUT "static const jchar data", $plane, "[] = {\n";
my $len = length($bestblkstr[$plane]) / 2;
for ($i = 0; $i < $len / 10; $i++) {
print OUTPUT " ";
for $j (0 .. 9) {
last if $len <= $i * 10 + $j;
my $val = unpack "n", substr($bestblkstr[$plane], 2 * ($i * 10 + $j), 2);
print OUTPUT $val, ", ";
}
print OUTPUT "\n";
}
print OUTPUT "};\n\n";
}
print OUTPUT "static const int data_length[] = {\n ";
for ($plane = 0; $plane <= 0x10; $plane++) {
if ($plane > 2 && $plane != 14){
print OUTPUT "-1, ";
}
else {
print OUTPUT length($bestblkstr[$plane]) / 2, ", ";
}
}
print OUTPUT "};\n";
print OUTPUT <<EOF;
static const jchar* data[] = {
data0, data1, data2, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, data14, NULL, NULL};
/**
* This is the attribute table for computing the numeric value of a
* character. The value is -1 if Unicode does not define a value, -2
* if the value is not a positive integer, otherwise it is the value.
*/
EOF
for ($plane = 0; $plane <= 0x10; $plane++) {
# The following if statement handles the cases of unassigned planes
# specially so we don't waste space with unused Strings. As of
# Unicode version 4.0.0 only planes 0, 1, 2, and 14 are used. If
# you are updating this script to work with a later version of
# Unicode you may have to alter this if statement.
next if ($plane > 2 && $plane != 14);
print OUTPUT "static const jshort numValue", $plane, "[] = {\n";
$len = @{$charinfoArray[$plane]};
for ($i = 0; $i < $len / 13; $i++) {
print OUTPUT " ";
for $j (0 .. 12) {
last if $len <= $i * 13 + $j;
my $val = $charinfoArray[$plane]->[$i * 13 + $j][0];
print OUTPUT cShort($val), ", ";
}
print OUTPUT "\n";
}
print OUTPUT "};\n\n";
}
print OUTPUT "static const int numValue_length[] = {\n ";
for ($plane = 0; $plane <= 0x10; $plane++) {
if ($plane > 2 && $plane != 14){
print OUTPUT "-1, ";
}
else {
print OUTPUT scalar(@{$charinfoArray[$plane]}), ", ";
}
}
print OUTPUT "};\n";
print OUTPUT <<EOF;
static const jshort* numValue[] = {
numValue0, numValue1, numValue2, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, numValue14, NULL, NULL};
/**
* This is the attribute table for computing the uppercase representation
* of a character. The value is the difference between the character and
* its uppercase version.
*/
EOF
for ($plane = 0; $plane <= 0x10; $plane++) {
# The following if statement handles the cases of unassigned planes
# specially so we don't waste space with unused Strings. As of
# Unicode version 4.0.0 only planes 0, 1, 2, and 14 are used. If
# you are updating this script to work with a later version of
# Unicode you may have to alter this if statement.
next if ($plane > 2 && $plane != 14);
print OUTPUT "static const jshort upper", $plane, "[] = {\n";
$len = @{$charinfoArray[$plane]};
for ($i = 0; $i < $len / 13; $i++) {
print OUTPUT " ";
for $j (0 .. 12) {
last if $len <= $i * 13 + $j;
my $val = $charinfoArray[$plane]->[$i * 13 + $j][1];
print OUTPUT cShort($val), ", ";
}
print OUTPUT "\n";
}
print OUTPUT "};\n\n";
}
print OUTPUT "static const int upper_length[] = {\n ";
for ($plane = 0; $plane <= 0x10; $plane++) {
if ($plane > 2 && $plane != 14){
print OUTPUT "-1, ";
}
else {
print OUTPUT scalar(@{$charinfoArray[$plane]}), ", ";
}
}
print OUTPUT "};\n";
print OUTPUT <<EOF;
static const jshort* upper[] = {
upper0, upper1, upper2, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, upper14, NULL, NULL};
/**
* This is the attribute table for computing the lowercase representation
* of a character. The value is the difference between the character and
* its lowercase version.
*/
EOF
for ($plane = 0; $plane <= 0x10; $plane++) {
# The following if statement handles the cases of unassigned planes
# specially so we don't waste space with unused Strings. As of
# Unicode version 4.0.0 only planes 0, 1, 2, and 14 are used. If
# you are updating this script to work with a later version of
# Unicode you may have to alter this if statement.
next if ($plane > 2 && $plane != 14);
print OUTPUT "static const jshort lower", $plane, "[] = {\n";
$len = @{$charinfoArray[$plane]};
for ($i = 0; $i < $len / 13; $i++) {
print OUTPUT " ";
for $j (0 .. 12) {
last if $len <= $i * 13 + $j;
my $val = $charinfoArray[$plane]->[$i * 13 + $j][2];
print OUTPUT cShort($val), ", ";
}
print OUTPUT "\n";
}
print OUTPUT "};\n\n";
}
print OUTPUT "static const int lower_length[] = {\n ";
for ($plane = 0; $plane <= 0x10; $plane++) {
if ($plane > 2 && $plane != 14){
print OUTPUT "-1, ";
}
else {
print OUTPUT scalar(@{$charinfoArray[$plane]}), ", ";
}
}
print OUTPUT "};\n";
print OUTPUT <<EOF;
static const jshort* lower[] = {
lower0, lower1, lower2, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, lower14, NULL, NULL};
/**
* This is the attribute table for computing the directionality class
* of a character. At present, the value is in the range 0 - 18 if the
* character has a direction, otherwise it is -1.
*/
EOF
for ($plane = 0; $plane <= 0x10; $plane++) {
# The following if statement handles the cases of unassigned planes
# specially so we don't waste space with unused Strings. As of
# Unicode version 4.0.0 only planes 0, 1, 2, and 14 are used. If
# you are updating this script to work with a later version of
# Unicode you may have to alter this if statement.
next if ($plane > 2 && $plane != 14);
print OUTPUT "static const jbyte direction", $plane, "[] = {\n";
$len = @{$charinfoArray[$plane]};
for ($i = 0; $i < $len / 19; $i++) {
print OUTPUT " ";
for $j (0 .. 18) {
last if $len <= $i * 19 + $j;
my $val = $charinfoArray[$plane]->[$i * 19 + $j][3];
$val >>= 2;
if ($val < 0 || $val > 18){
$val = -1;
}
print OUTPUT cShort($val), ", ";
}
print OUTPUT "\n";
}
print OUTPUT "};\n\n";
}
print OUTPUT "static const int direction_length[] = {\n ";
for ($plane = 0; $plane <= 0x10; $plane++) {
if ($plane > 2 && $plane != 14){
print OUTPUT "-1, ";
}
else {
print OUTPUT scalar(@{$charinfoArray[$plane]}), ", ";
}
}
print OUTPUT "};\n";
print OUTPUT <<EOF;
static const jbyte* direction[] = {
direction0, direction1, direction2, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, direction14, NULL, NULL};
/**
* This is the listing of titlecase special cases (all other character
* can use <code>upper</code> to determine their titlecase). The listing
* is a sequence of character pairs; converting the first character of the
* pair to titlecase produces the second character.
*/
static const jchar title[] = {
EOF
$len = length($titlecase) / 2;
for ($i = 0; $i < $len / 10; $i++) {
print OUTPUT $i ? "\n " : " ";
for $j (0 .. 9) {
last if $len <= $i * 10 + $j;
my $val = unpack "n", substr($titlecase, 2 * ($i * 10 + $j), 2);
print OUTPUT $val, ", ";
}
}
print OUTPUT "\n };";
print OUTPUT "\n/** Length of title. */\nstatic const int title_length = ", $len;
print OUTPUT <<EOF;
;
#endif /* __JAVA_CHARTABLES_H__ */
EOF
close OUTPUT;
}
print "\nDone.\n";