📄 character.java
字号:
/** * Undefined bidirectional character type. Undefined char values have * undefined directionality in the Unicode specification. * * @since 1.4 */ public static final byte DIRECTIONALITY_UNDEFINED = -1; /** * Strong bidirectional character type "L". * * @since 1.4 */ public static final byte DIRECTIONALITY_LEFT_TO_RIGHT = 0; /** * Strong bidirectional character type "R". * * @since 1.4 */ public static final byte DIRECTIONALITY_RIGHT_TO_LEFT = 1; /** * Strong bidirectional character type "AL". * * @since 1.4 */ public static final byte DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC = 2; /** * Weak bidirectional character type "EN". * * @since 1.4 */ public static final byte DIRECTIONALITY_EUROPEAN_NUMBER = 3; /** * Weak bidirectional character type "ES". * * @since 1.4 */ public static final byte DIRECTIONALITY_EUROPEAN_NUMBER_SEPARATOR = 4; /** * Weak bidirectional character type "ET". * * @since 1.4 */ public static final byte DIRECTIONALITY_EUROPEAN_NUMBER_TERMINATOR = 5; /** * Weak bidirectional character type "AN". * * @since 1.4 */ public static final byte DIRECTIONALITY_ARABIC_NUMBER = 6; /** * Weak bidirectional character type "CS". * * @since 1.4 */ public static final byte DIRECTIONALITY_COMMON_NUMBER_SEPARATOR = 7; /** * Weak bidirectional character type "NSM". * * @since 1.4 */ public static final byte DIRECTIONALITY_NONSPACING_MARK = 8; /** * Weak bidirectional character type "BN". * * @since 1.4 */ public static final byte DIRECTIONALITY_BOUNDARY_NEUTRAL = 9; /** * Neutral bidirectional character type "B". * * @since 1.4 */ public static final byte DIRECTIONALITY_PARAGRAPH_SEPARATOR = 10; /** * Neutral bidirectional character type "S". * * @since 1.4 */ public static final byte DIRECTIONALITY_SEGMENT_SEPARATOR = 11; /** * Strong bidirectional character type "WS". * * @since 1.4 */ public static final byte DIRECTIONALITY_WHITESPACE = 12; /** * Neutral bidirectional character type "ON". * * @since 1.4 */ public static final byte DIRECTIONALITY_OTHER_NEUTRALS = 13; /** * Strong bidirectional character type "LRE". * * @since 1.4 */ public static final byte DIRECTIONALITY_LEFT_TO_RIGHT_EMBEDDING = 14; /** * Strong bidirectional character type "LRO". * * @since 1.4 */ public static final byte DIRECTIONALITY_LEFT_TO_RIGHT_OVERRIDE = 15; /** * Strong bidirectional character type "RLE". * * @since 1.4 */ public static final byte DIRECTIONALITY_RIGHT_TO_LEFT_EMBEDDING = 16; /** * Strong bidirectional character type "RLO". * * @since 1.4 */ public static final byte DIRECTIONALITY_RIGHT_TO_LEFT_OVERRIDE = 17; /** * Weak bidirectional character type "PDF". * * @since 1.4 */ public static final byte DIRECTIONALITY_POP_DIRECTIONAL_FORMAT = 18; /** * Mask for grabbing the type out of the result of readChar. * @see #readChar(char) */ private static final int TYPE_MASK = 0x1F; /** * Mask for grabbing the non-breaking space flag out of the result of * readChar. * @see #readChar(char) */ private static final int NO_BREAK_MASK = 0x20; /** * Mask for grabbing the mirrored directionality flag out of the result * of readChar. * @see #readChar(char) */ private static final int MIRROR_MASK = 0x40; /** * Min value for supplementary code point. * * @since 1.5 */ public static final int MIN_SUPPLEMENTARY_CODE_POINT = 0x10000; /** * Min value for code point. * * @since 1.5 */ public static final int MIN_CODE_POINT = 0; /** * Max value for code point. * * @since 1.5 */ public static final int MAX_CODE_POINT = 0x010ffff; /** * Minimum high surrogate code in UTF-16 encoding. * * @since 1.5 */ public static final char MIN_HIGH_SURROGATE = '\ud800'; /** * Maximum high surrogate code in UTF-16 encoding. * * @since 1.5 */ public static final char MAX_HIGH_SURROGATE = '\udbff'; /** * Minimum low surrogate code in UTF-16 encoding. * * @since 1.5 */ public static final char MIN_LOW_SURROGATE = '\udc00'; /** * Maximum low surrogate code in UTF-16 encoding. * * @since 1.5 */ public static final char MAX_LOW_SURROGATE = '\udfff'; /** * Minimum surrogate code in UTF-16 encoding. * * @since 1.5 */ public static final char MIN_SURROGATE = MIN_HIGH_SURROGATE; /** * Maximum low surrogate code in UTF-16 encoding. * * @since 1.5 */ public static final char MAX_SURROGATE = MAX_LOW_SURROGATE; /** * 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 ch 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 readChar(char ch); /** * Wraps up a character. * * @param value the character to wrap */ public Character(char value) { this.value = value; } /** * Returns the character which has been wrapped by this class. * * @return the character wrapped */ public char charValue() { return value; } /** * Returns the numerical value (unsigned) of the wrapped character. * Range of returned values: 0x0000-0xFFFF. * * @return the value of the wrapped character */ public int hashCode() { return value; } /** * Determines if an object is equal to this object. This is only true for * another Character object wrapping the same value. * * @param o object to compare * @return true if o is a Character with the same value */ public boolean equals(Object o) { return o instanceof Character && value == ((Character) o).value; } /** * Converts the wrapped character into a String. * * @return a String containing one character -- the wrapped character * of this instance */ public String toString() { // This assumes that String.valueOf(char) can create a single-character // String more efficiently than through the public API. return String.valueOf(value); } /** * Returns a String of length 1 representing the specified character. * * @param ch the character to convert * @return a String containing the character * @since 1.4 */ public static String toString(char ch) { // This assumes that String.valueOf(char) can create a single-character // String more efficiently than through the public API. return String.valueOf(ch); } /** * Determines if a character is a Unicode lowercase letter. For example, * <code>'a'</code> is lowercase. * <br> * lowercase = [Ll] * * @param ch character to test * @return true if ch is a Unicode lowercase letter, else false * @see #isUpperCase(char) * @see #isTitleCase(char) * @see #toLowerCase(char) * @see #getType(char) */ public static boolean isLowerCase(char ch) { return getType(ch) == LOWERCASE_LETTER; } /** * Determines if a character is a Unicode uppercase letter. For example, * <code>'A'</code> is uppercase. * <br> * uppercase = [Lu] * * @param ch character to test * @return true if ch is a Unicode uppercase letter, else false * @see #isLowerCase(char) * @see #isTitleCase(char) * @see #toUpperCase(char) * @see #getType(char) */ public static boolean isUpperCase(char ch) { return getType(ch) == 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. * <br> * titlecase = [Lt] * * @param ch character to test * @return true if ch is a Unicode titlecase letter, else false * @see #isLowerCase(char) * @see #isUpperCase(char) * @see #toTitleCase(char) * @see #getType(char) */ public static boolean isTitleCase(char ch) { return getType(ch) == TITLECASE_LETTER; } /** * Determines if a character is a Unicode decimal digit. For example, * <code>'0'</code> is a digit. * <br> * Unicode decimal digit = [Nd] * * @param ch character to test * @return true if ch is a Unicode decimal digit, else false * @see #digit(char, int) * @see #forDigit(int, int) * @see #getType(char) */ public static boolean isDigit(char ch) { return getType(ch) == 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. * <br> * defined = not [Cn] * * @param ch character to test * @return true if ch is a Unicode character, else false * @see #isDigit(char) * @see #isLetter(char) * @see #isLetterOrDigit(char) * @see #isLowerCase(char) * @see #isTitleCase(char) * @see #isUpperCase(char) */ public static boolean isDefined(char ch) { return getType(ch) != 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. * <br> * letter = [Lu]|[Ll]|[Lt]|[Lm]|[Lo] * * @param ch character to test * @return true if ch is a Unicode letter, else false * @see #isDigit(char) * @see #isJavaIdentifierStart(char) * @see #isJavaLetter(char) * @see #isJavaLetterOrDigit(char) * @see #isLetterOrDigit(char) * @see #isLowerCase(char) * @see #isTitleCase(char) * @see #isUnicodeIdentifierStart(char) * @see #isUpperCase(char) */ public static boolean isLetter(char ch) { return ((1 << getType(ch)) & ((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. * <br> * letter or digit = [Lu]|[Ll]|[Lt]|[Lm]|[Lo]|[Nd] * * @param ch character to test * @return true if ch is a Unicode letter or a Unicode digit, else false * @see #isDigit(char) * @see #isJavaIdentifierPart(char) * @see #isJavaLetter(char) * @see #isJavaLetterOrDigit(char) * @see #isLetter(char) * @see #isUnicodeIdentifierPart(char) */ public static boolean isLetterOrDigit(char ch) { return ((1 << getType(ch)) & ((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 * LETTER_NUMBER, currency symbols (like '$'), and connecting punctuation * (like '_'). * * @param ch character to test * @return true if ch can start a Java identifier, else false * @deprecated Replaced by {@link #isJavaIdentifierStart(char)} * @see #isJavaLetterOrDigit(char) * @see #isJavaIdentifierStart(char) * @see #isJavaIdentifierPart(char) * @see #isLetter(char) * @see #isLetterOrDigit(char) * @see #isUnicodeIdentifierStart(char) */ public static boolean isJavaLetter(char ch) { return isJavaIdentifierStart(ch); } /** * Determines if a character can follow the firs
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -