The UCharacter class provides extensions to the java.lang.Character class. These extensions provide support for more Unicode properties and together with the UTF16 class, provide support for supplementary characters (those with code points above U+FFFF). Each ICU release supports the latest version of Unicode available at that time.
Code points are represented in these API using ints. While it would be more convenient in Java to have a separate primitive datatype for them, ints suffice in the meantime.
To use this class please add the jar file name icu4j.jar to the
class path, since it contains data files which supply the information used
by this file.
E.g. In Windows
set CLASSPATH=%CLASSPATH%;$JAR_FILE_PATH/ucharacter.jar.
Otherwise, another method would be to copy the files uprops.dat and
unames.icu from the icu4j source subdirectory
$ICU4J_SRC/src/com.ibm.icu.impl.data to your class directory
$ICU4J_CLASS/com.ibm.icu.impl.data.
Aside from the additions for UTF-16 support, and the updated Unicode properties, the main differences between UCharacter and Character are:
Further detail on differences can be determined using the program com.ibm.icu.dev.test.lang.UCharacterCompare
In addition to Java compatibility functions, which calculate derived properties, this API provides low-level access to the Unicode Character Database.
Unicode assigns each code point (not just assigned character) values for many properties. Most of them are simple boolean flags, or constants from a small enumerated list. For some properties, values are strings or other relatively more complex types.
For more information see "About the Unicode Character Database" (http://www.unicode.org/ucd/) and the ICU User Guide chapter on Properties (https://unicode-org.github.io/icu/userguide/strings/properties).
There are also functions that provide easy migration from C/POSIX functions like isblank(). Their use is generally discouraged because the C/POSIX standards do not define their semantics beyond the ASCII range, which means that different implementations exhibit very different behavior. Instead, Unicode properties should be used directly.
There are also only a few, broad C/POSIX character classes, and they tend to be used for conflicting purposes. For example, the "isalpha()" class is sometimes used to determine word boundaries, while a more sophisticated approach would at least distinguish initial letters from continuation characters (the latter including combining marks). (In ICU, BreakIterator is the most sophisticated API for word boundaries.) Another example: There is no "istitle()" class for titlecase characters.
ICU 3.4 and later provides API access for all twelve C/POSIX character classes. ICU implements them according to the Standard Recommendations in Annex C: Compatibility Properties of UTS #18 Unicode Regular Expressions (http://www.unicode.org/reports/tr18/#Compatibility_Properties).
API access for C/POSIX character classes is as follows:
- alpha: isUAlphabetic(c) or hasBinaryProperty(c, UProperty.ALPHABETIC)
- lower: isULowercase(c) or hasBinaryProperty(c, UProperty.LOWERCASE)
- upper: isUUppercase(c) or hasBinaryProperty(c, UProperty.UPPERCASE)
- punct: ((1<<getType(c)) & ((1<<DASH_PUNCTUATION)|(1<<START_PUNCTUATION)|
(1<<END_PUNCTUATION)|(1<<CONNECTOR_PUNCTUATION)|(1<<OTHER_PUNCTUATION)|
(1<<INITIAL_PUNCTUATION)|(1<<FINAL_PUNCTUATION)))!=0
- digit: isDigit(c) or getType(c)==DECIMAL_DIGIT_NUMBER
- xdigit: hasBinaryProperty(c, UProperty.POSIX_XDIGIT)
- alnum: hasBinaryProperty(c, UProperty.POSIX_ALNUM)
- space: isUWhiteSpace(c) or hasBinaryProperty(c, UProperty.WHITE_SPACE)
- blank: hasBinaryProperty(c, UProperty.POSIX_BLANK)
- cntrl: getType(c)==CONTROL
- graph: hasBinaryProperty(c, UProperty.POSIX_GRAPH)
- print: hasBinaryProperty(c, UProperty.POSIX_PRINT)
The C/POSIX character classes are also available in UnicodeSet patterns, using patterns like [:graph:] or \p{graph}.
There are several ICU (and Java) whitespace functions. Comparison:This class is not subclassable.
com.ibm.icu.lang.UCharacterEnums
| Modifier and Type | Class and Description |
|---|---|
| public static interface | UCharacter.
Hangul Syllable Type constants. |
| public static interface | UCharacter.
Joining Group constants. |
| public static interface | UCharacter.
Numeric Type constants. |
| Modifier and Type | Field and Description |
|---|---|
| public static final byte | CHAR_CATEGORY_COUNT
Character type count |
| public static final byte | COMBINING_SPACING_MARK
Character type Mc |
| public static final byte | ENCLOSING_MARK
Character type Me |
| public static final int | MAX_VALUE
The highest Unicode code point value (scalar value) according to the Unicode Standard. |
| public static final int | MIN_VALUE
The lowest Unicode code point value. |
| public static final byte | NON_SPACING_MARK
Character type Mn |
| public static final int | RIGHT_TO_LEFT
Directional type R |
| public static final int | RIGHT_TO_LEFT_ARABIC
Directional type AL |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static int | Returns: the numeric value represented by the code point in the specified radix, or -1 if the code point is not a decimal digit or if its value is too large for the radixthe code point to query ch, int the radix radix)Returns the numeric value of a decimal digit code point. |
| public static int | Returns: the numeric value represented by the code point, or -1 if the code point is not a decimal digit or if its value is too large for a decimal radixthe code point to query ch)Returns the numeric value of a decimal digit code point. |
| public static VersionInfo | Returns: the Unicode version numberThe code point. ch)Returns the "age" of the code point. |
| public static int | Returns: the paired bracket code point, or c itself if there is no such mapping (Bidi_Paired_Bracket_Type=None)the code point to be mapped c)Maps the specified character to its paired bracket character. |
| public static int | Returns: code point if surrogate characters are valid.the lead char lead, char the trail char trail)Returns a code point corresponding to the two UTF16 characters. |
| public static int | Returns: the combining class of the codepointcode point whose combining is to be retrieved ch)Returns the combining class of the argument codepoint |
| public static int | Returns: direction constant from UCharacterDirection.the code point to be determined its direction ch)Returns the Bidirection property of a code point. |
| public static int | Returns: numeric value that is directly the property value or, for enumerated properties, corresponds to the numeric value of the enumerated constant of the respective property value enumeration type (cast to enum type if necessary). Returns 0 or 1 (for false / true) for binary Unicode properties. Returns a bit-mask for mask properties. Returns 0 if 'type' is out of bounds or if the Unicode version does not have data for the property at all, or not for this code point.code point to test. ch, int UProperty selector constant, identifies which binary
property to check. Must be
UProperty.BINARY_START <= type < UProperty.BINARY_LIMIT or
UProperty.INT_START <= type < UProperty.INT_LIMIT or
UProperty.MASK_START <= type < UProperty.MASK_LIMIT. type)Returns the property value for an Unicode property type of a code point. |
| public static int | Returns: another code point that may serve as a mirror-image substitute, or ch itself if there is no such mapping or ch does not have the "mirrored" propertycode point whose mirror is to be retrieved ch)Maps the specified code point to a "mirror-image" code point. |
| public static int | Returns: category which is a value of UCharacterCategorycode point whose type is to be determined ch)Returns a value indicating a code point's Unicode category. |
| public static VersionInfo | Returns: the unicode version number usedReturns the version of Unicode data used. |
| CHAR_CATEGORY_COUNT | back to summary |
|---|---|
| public static final byte CHAR_CATEGORY_COUNT Character type count
| |
| COMBINING_SPACING_MARK | back to summary |
|---|---|
| public static final byte COMBINING_SPACING_MARK Character type Mc
| |
| ENCLOSING_MARK | back to summary |
|---|---|
| public static final byte ENCLOSING_MARK Character type Me
| |
| MAX_VALUE | back to summary |
|---|---|
| public static final int MAX_VALUE The highest Unicode code point value (scalar value) according to the
Unicode Standard.
This is a 21-bit value (21 bits, rounded up).
| |
| MIN_VALUE | back to summary |
|---|---|
| public static final int MIN_VALUE The lowest Unicode code point value.
| |
| NON_SPACING_MARK | back to summary |
|---|---|
| public static final byte NON_SPACING_MARK Character type Mn
| |
| RIGHT_TO_LEFT | back to summary |
|---|---|
| public static final int RIGHT_TO_LEFT Directional type R
| |
| RIGHT_TO_LEFT_ARABIC | back to summary |
|---|---|
| public static final int RIGHT_TO_LEFT_ARABIC Directional type AL
| |
| UCharacter | back to summary |
|---|---|
| private UCharacter() Private constructor to prevent instantiation | |
| digit | back to summary |
|---|---|
| public static int digit(int ch, int radix) Returns the numeric value of a decimal digit code point.
| |
| digit | back to summary |
|---|---|
| public static int digit(int ch) Returns the numeric value of a decimal digit code point.
| |
| getAge | back to summary |
|---|---|
| public static VersionInfo getAge(int ch) Returns the "age" of the code point. The "age" is the Unicode version when the code point was first designated (as a non-character or for Private Use) or assigned a character. This can be useful to avoid emitting code points to receiving processes that do not accept newer characters. The data is from the UCD file DerivedAge.txt.
| |
| getBidiPairedBracket | back to summary |
|---|---|
| public static int getBidiPairedBracket(int c) Maps the specified character to its paired bracket character. For Bidi_Paired_Bracket_Type!=None, this is the same as getMirror(int). Otherwise c itself is returned. See http://www.unicode.org/reports/tr9/
| |
| getCodePoint | back to summary |
|---|---|
| public static int getCodePoint(char lead, char trail) Returns a code point corresponding to the two UTF16 characters.
| |
| getCombiningClass | back to summary |
|---|---|
| public static int getCombiningClass(int ch) Returns the combining class of the argument codepoint
| |
| getDirection | back to summary |
|---|---|
| public static int getDirection(int ch) Returns the Bidirection property of a code point.
For example, 0x0041 (letter A) has the LEFT_TO_RIGHT directional
property.
| |
| getIntPropertyValue | back to summary |
|---|---|
| public static int getIntPropertyValue(int ch, int type) Returns the property value for an Unicode property type of a code point. Also returns binary and mask property values. Unicode, especially in version 3.2, defines many more properties than the original set in UnicodeData.txt. The properties APIs are intended to reflect Unicode properties as defined in the Unicode Character Database (UCD) and Unicode Technical Reports (UTR). For details about the properties see http://www.unicode.org/. For names of Unicode properties see the UCD file PropertyAliases.txt. Sample usage: int ea = UCharacter.getIntPropertyValue(c, UProperty.EAST_ASIAN_WIDTH); int ideo = UCharacter.getIntPropertyValue(c, UProperty.IDEOGRAPHIC); boolean b = (ideo == 1) ? true : false;
| |
| getMirror | back to summary |
|---|---|
| public static int getMirror(int ch) Maps the specified code point to a "mirror-image" code point.
For code points with the "mirrored" property, implementations sometimes
need a "poor man's" mapping to another code point such that the default
glyph may serve as the mirror-image of the default glyph of the
specified code point.
| |
| getType | back to summary |
|---|---|
| public static int getType(int ch) Returns a value indicating a code point's Unicode category.
Up-to-date Unicode implementation of java.lang.Character.getType()
except for the above mentioned code points that had their category
changed. Note the UCharacterCategory values are not compatible with those returned by java.lang.Character.getType. UCharacterCategory values match the ones used in ICU4C, while java.lang.Character type values, though similar, skip the value 17.
| |
| getUnicodeVersion | back to summary |
|---|---|
| public static VersionInfo getUnicodeVersion() Returns the version of Unicode data used.
| |
UProperty#HANGUL_SYLLABLE_TYPE
| Modifier and Type | Field and Description |
|---|---|
| public static final int | |
| public static final int | |
| public static final int | |
| public static final int | |
| public static final int | |
| public static final int | |
| public static final int |
| COUNT | back to summary |
|---|---|
public static final int COUNT
| |
| LEADING_JAMO | back to summary |
|---|---|
public static final int LEADING_JAMO
| |
| LV_SYLLABLE | back to summary |
|---|---|
public static final int LV_SYLLABLE
| |
| LVT_SYLLABLE | back to summary |
|---|---|
public static final int LVT_SYLLABLE
| |
| NOT_APPLICABLE | back to summary |
|---|---|
public static final int NOT_APPLICABLE
| |
| TRAILING_JAMO | back to summary |
|---|---|
public static final int TRAILING_JAMO
| |
| VOWEL_JAMO | back to summary |
|---|---|
public static final int VOWEL_JAMO
| |
UProperty#JOINING_GROUP
| Modifier and Type | Field and Description |
|---|---|
| public static final int |
| NO_JOINING_GROUP | back to summary |
|---|---|
public static final int NO_JOINING_GROUP
| |
UProperty#NUMERIC_TYPE
| Modifier and Type | Field and Description |
|---|---|
| public static final int | |
| public static final int | |
| public static final int | |
| public static final int | |
| public static final int |
| COUNT | back to summary |
|---|---|
public static final int COUNT
| |
| DECIMAL | back to summary |
|---|---|
public static final int DECIMAL
| |
| DIGIT | back to summary |
|---|---|
public static final int DIGIT
| |
| NONE | back to summary |
|---|---|
public static final int NONE
| |
| NUMERIC | back to summary |
|---|---|
public static final int NUMERIC
| |