Char

The {@code Character} class wraps a value of the primitive type {@code char} in an object. An object of type {@code Character} contains a single field whose type is {@code char}. <p> In addition, this class provides several methods for determining a character's category (lowercase letter, digit, etc.) and for converting characters from uppercase to lowercase and vice versa. <p> Character information is based on the Unicode Standard, version 8.0.0. <p> The methods and data of class {@code Character} are defined by the information in the <i>UnicodeData</i> file that is part of the Unicode Character Database maintained by the Unicode Consortium. This file specifies various properties including name and general category for every defined Unicode code point or character range. <p> The file and its description are available from the Unicode Consortium at: <ul> <li><a href="http://www.unicode.org">http://www.unicode.org</a> </ul>

<h3><a id="unicode">Unicode Character Representations</a></h3>

<p>The {@code char} data type (and therefore the value that a {@code Character} object encapsulates) are based on the original Unicode specification, which defined characters as fixed-width 16-bit entities. The Unicode Standard has since been changed to allow for characters whose representation requires more than 16 bits. The range of legal <em>code point</em>s is now U+0000 to U+10FFFF, known as <em>Unicode scalar value</em>. (Refer to the <a href="http://www.unicode.org/reports/tr27/#notation"><i> definition</i></a> of the U+<i>n</i> notation in the Unicode Standard.)

<p><a id="BMP">The set of characters from U+0000 to U+FFFF</a> is sometimes referred to as the <em>Basic Multilingual Plane (BMP)</em>. <a id="supplementary">Characters</a> whose code points are greater than U+FFFF are called <em>supplementary character</em>s. The Java platform uses the UTF-16 representation in {@code char} arrays and in the {@code string} and {@code StringBuffer} classes. In this representation, supplementary characters are represented as a pair of {@code char} values, the first from the <em>high-surrogates</em> range, (&#92;uD800-&#92;uDBFF), the second from the <em>low-surrogates</em> range (&#92;uDC00-&#92;uDFFF).

<p>A {@code char} value, therefore, represents Basic Multilingual Plane (BMP) code points, including the surrogate code points, or code units of the UTF-16 encoding. An {@code int} value represents all Unicode code points, including supplementary code points. The lower (least significant) 21 bits of {@code int} are used to represent Unicode code points and the upper (most significant) 11 bits must be zero. Unless otherwise specified, the behavior with respect to supplementary characters and surrogate {@code char} values is as follows:

<ul> <li>The methods that only accept a {@code char} value cannot support supplementary characters. They treat {@code char} values from the surrogate ranges as undefined characters. For example, {@code Character.isLetter('\u005CuD840')} returns {@code false}, even though this specific value if followed by any low-surrogate value in a string would represent a letter.

<li>The methods that accept an {@code int} value support all Unicode characters, including supplementary characters. For example, {@code Character.isLetter(0x2F81A)} returns {@code true} because the code point value represents a letter (a CJK ideograph). </ul>

<p>In the Java SE API documentation, <em>Unicode code point</em> is used for character values in the range between U+0000 and U+10FFFF, and <em>Unicode code unit</em> is used for 16-bit {@code char} values that are code units of the <em>UTF-16</em> encoding. For more information on Unicode terminology, refer to the <a href="http://www.unicode.org/glossary/">Unicode Glossary</a>.

@author Lee Boynton @author Guy Steele @author Akira Tanaka @author Martin Buchholz @author Ulf Zibis

class Char : Nullable!char {}

Constructors

this
this(char value)
Undocumented in source.

Members

Functions

charValue
char charValue()

Returns the value of this {@code Character} object. @return the primitive {@code char} value represented by this object.

toHash
size_t toHash()
Undocumented in source. Be warned that the author may not have intended to support it.

Static functions

charCount
int charCount(int codePoint)

Determines the number of {@code char} values needed to represent the specified character (Unicode code point). If the specified character is equal to or greater than 0x10000, then the method returns 2. Otherwise, the method returns 1.

codePointAt
int codePointAt(string seq, int index)

Returns the code point at the given index of the {@code CharSequence}. If the {@code char} value at the given index in the {@code CharSequence} is in the high-surrogate range, the following index is less than the length of the {@code CharSequence}, and the {@code char} value at the following index is in the low-surrogate range, then the supplementary code point corresponding to this surrogate pair is returned. Otherwise, the {@code char} value at the given index is returned.

highSurrogate
char highSurrogate(int codePoint)

Returns the leading surrogate (a <a href="http://www.unicode.org/glossary/#high_surrogate_code_unit"> high surrogate code unit</a>) of the <a href="http://www.unicode.org/glossary/#surrogate_pair"> surrogate pair</a> representing the specified supplementary character (Unicode code point) in the UTF-16 encoding. If the specified character is not a <a href="Character.html#supplementary">supplementary character</a>, an unspecified {@code char} is returned.

isBmpCodePoint
bool isBmpCodePoint(int codePoint)

Determines whether the specified character (Unicode code point) is in the <a href="#BMP">Basic Multilingual Plane (BMP)</a>. Such code points can be represented using a single {@code char}.

isHighSurrogate
bool isHighSurrogate(char ch)

Determines if the given {@code char} value is a <a href="http://www.unicode.org/glossary/#high_surrogate_code_unit"> Unicode high-surrogate code unit</a> (also known as <i>leading-surrogate code unit</i>).

isISOControl
bool isISOControl(char ch)

Determines if the specified character is an ISO control character. A character is considered to be an ISO control character if its code is in the range {@code '\u005Cu0000'} through {@code '\u005Cu001F'} or in the range {@code '\u005Cu007F'} through {@code '\u005Cu009F'}.

isISOControl
bool isISOControl(int codePoint)

Determines if the referenced character (Unicode code point) is an ISO control character. A character is considered to be an ISO control character if its code is in the range {@code '\u005Cu0000'} through {@code '\u005Cu001F'} or in the range {@code '\u005Cu007F'} through {@code '\u005Cu009F'}.

isLetter
bool isLetter(char ch)

Determines if the specified character is a letter. <p> A character is considered to be a letter if its general category type, provided by {@code Character.getType(ch)}, is any of the following: <ul> <li> {@code UPPERCASE_LETTER} <li> {@code LOWERCASE_LETTER} <li> {@code TITLECASE_LETTER} <li> {@code MODIFIER_LETTER} <li> {@code OTHER_LETTER} </ul>

isLowSurrogate
bool isLowSurrogate(char ch)

Determines if the given {@code char} value is a <a href="http://www.unicode.org/glossary/#low_surrogate_code_unit"> Unicode low-surrogate code unit</a> (also known as <i>trailing-surrogate code unit</i>).

isValidCodePoint
bool isValidCodePoint(int codePoint)

Determines whether the specified code point is a valid <a href="http://www.unicode.org/glossary/#code_point"> Unicode code point value</a>.

lowSurrogate
char lowSurrogate(int codePoint)

Returns the trailing surrogate (a <a href="http://www.unicode.org/glossary/#low_surrogate_code_unit"> low surrogate code unit</a>) of the <a href="http://www.unicode.org/glossary/#surrogate_pair"> surrogate pair</a> representing the specified supplementary character (Unicode code point) in the UTF-16 encoding. If the specified character is not a <a href="Character.html#supplementary">supplementary character</a>, an unspecified {@code char} is returned.

toChars
char[] toChars(int codePoint)

Converts the specified character (Unicode code point) to its UTF-16 representation stored in a {@code char} array. If the specified code point is a BMP (Basic Multilingual Plane or Plane 0) value, the resulting {@code char} array has the same value as {@code codePoint}. If the specified code point is a supplementary code point, the resulting {@code char} array has the corresponding surrogate pair.

toCodePoint
int toCodePoint(char high, char low)

Converts the specified surrogate pair to its supplementary code point value. This method does not validate the specified surrogate pair. The caller must validate it using {@link #isSurrogatePair(char, char) isSurrogatePair} if necessary.

toSurrogates
void toSurrogates(int codePoint, char[] dst, int index)
Undocumented in source. Be warned that the author may not have intended to support it.
valueOf
Char valueOf(char c)

Returns a {@code Character} instance representing the specified {@code char} value. If a new {@code Character} instance is not required, this method should generally be used in preference to the constructor {@link #Character(char)}, as this method is likely to yield significantly better space and time performance by caching frequently requested values.

Variables

COMBINING_SPACING_MARK
enum byte COMBINING_SPACING_MARK;

General category "Mc" in the Unicode specification.

CONNECTOR_PUNCTUATION
enum byte CONNECTOR_PUNCTUATION;

General category "Pc" in the Unicode specification.

CONTROL
enum byte CONTROL;

General category "Cc" in the Unicode specification.

CURRENCY_SYMBOL
enum byte CURRENCY_SYMBOL;

General category "Sc" in the Unicode specification.

DASH_PUNCTUATION
enum byte DASH_PUNCTUATION;

General category "Pd" in the Unicode specification.

DECIMAL_DIGIT_NUMBER
enum byte DECIMAL_DIGIT_NUMBER;

General category "Nd" in the Unicode specification.

DIRECTIONALITY_ARABIC_NUMBER
enum byte DIRECTIONALITY_ARABIC_NUMBER;

Weak bidirectional character type "AN" in the Unicode specification.

DIRECTIONALITY_BOUNDARY_NEUTRAL
enum byte DIRECTIONALITY_BOUNDARY_NEUTRAL;

Weak bidirectional character type "BN" in the Unicode specification.

DIRECTIONALITY_COMMON_NUMBER_SEPARATOR
enum byte DIRECTIONALITY_COMMON_NUMBER_SEPARATOR;

Weak bidirectional character type "CS" in the Unicode specification.

DIRECTIONALITY_EUROPEAN_NUMBER
enum byte DIRECTIONALITY_EUROPEAN_NUMBER;

Weak bidirectional character type "EN" in the Unicode specification.

DIRECTIONALITY_EUROPEAN_NUMBER_SEPARATOR
enum byte DIRECTIONALITY_EUROPEAN_NUMBER_SEPARATOR;

Weak bidirectional character type "ES" in the Unicode specification.

DIRECTIONALITY_EUROPEAN_NUMBER_TERMINATOR
enum byte DIRECTIONALITY_EUROPEAN_NUMBER_TERMINATOR;

Weak bidirectional character type "ET" in the Unicode specification.

DIRECTIONALITY_LEFT_TO_RIGHT
enum byte DIRECTIONALITY_LEFT_TO_RIGHT;

Strong bidirectional character type "L" in the Unicode specification.

DIRECTIONALITY_LEFT_TO_RIGHT_EMBEDDING
enum byte DIRECTIONALITY_LEFT_TO_RIGHT_EMBEDDING;

Strong bidirectional character type "LRE" in the Unicode specification.

DIRECTIONALITY_LEFT_TO_RIGHT_OVERRIDE
enum byte DIRECTIONALITY_LEFT_TO_RIGHT_OVERRIDE;

Strong bidirectional character type "LRO" in the Unicode specification.

DIRECTIONALITY_NONSPACING_MARK
enum byte DIRECTIONALITY_NONSPACING_MARK;

Weak bidirectional character type "NSM" in the Unicode specification.

DIRECTIONALITY_OTHER_NEUTRALS
enum byte DIRECTIONALITY_OTHER_NEUTRALS;

Neutral bidirectional character type "ON" in the Unicode specification.

DIRECTIONALITY_PARAGRAPH_SEPARATOR
enum byte DIRECTIONALITY_PARAGRAPH_SEPARATOR;

Neutral bidirectional character type "B" in the Unicode specification.

DIRECTIONALITY_POP_DIRECTIONAL_FORMAT
enum byte DIRECTIONALITY_POP_DIRECTIONAL_FORMAT;

Weak bidirectional character type "PDF" in the Unicode specification.

DIRECTIONALITY_RIGHT_TO_LEFT
enum byte DIRECTIONALITY_RIGHT_TO_LEFT;

Strong bidirectional character type "R" in the Unicode specification.

DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC
enum byte DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC;

* Strong bidirectional character type "AL" in the Unicode specification.

DIRECTIONALITY_RIGHT_TO_LEFT_EMBEDDING
enum byte DIRECTIONALITY_RIGHT_TO_LEFT_EMBEDDING;

Strong bidirectional character type "RLE" in the Unicode specification.

DIRECTIONALITY_RIGHT_TO_LEFT_OVERRIDE
enum byte DIRECTIONALITY_RIGHT_TO_LEFT_OVERRIDE;

Strong bidirectional character type "RLO" in the Unicode specification.

DIRECTIONALITY_SEGMENT_SEPARATOR
enum byte DIRECTIONALITY_SEGMENT_SEPARATOR;

Neutral bidirectional character type "S" in the Unicode specification.

DIRECTIONALITY_UNDEFINED
enum byte DIRECTIONALITY_UNDEFINED;

Undefined bidirectional character type. Undefined {@code char} values have undefined directionality in the Unicode specification.

DIRECTIONALITY_WHITESPACE
enum byte DIRECTIONALITY_WHITESPACE;

Neutral bidirectional character type "WS" in the Unicode specification.

ENCLOSING_MARK
enum byte ENCLOSING_MARK;

General category "Me" in the Unicode specification.

END_PUNCTUATION
enum byte END_PUNCTUATION;

General category "Pe" in the Unicode specification.

ERROR
enum int ERROR;

Error flag. Use int (code point) to avoid confusion with U+FFFF.

FINAL_QUOTE_PUNCTUATION
enum byte FINAL_QUOTE_PUNCTUATION;

General category "Pf" in the Unicode specification.

FORMAT
enum byte FORMAT;

General category "Cf" in the Unicode specification.

INITIAL_QUOTE_PUNCTUATION
enum byte INITIAL_QUOTE_PUNCTUATION;

General category "Pi" in the Unicode specification.

LETTER_NUMBER
enum byte LETTER_NUMBER;

General category "Nl" in the Unicode specification.

LINE_SEPARATOR
enum byte LINE_SEPARATOR;

General category "Zl" in the Unicode specification.

LOWERCASE_LETTER
enum byte LOWERCASE_LETTER;

General category "Ll" in the Unicode specification.

MATH_SYMBOL
enum byte MATH_SYMBOL;

General category "Sm" in the Unicode specification.

MAX_CODE_POINT
enum int MAX_CODE_POINT;

The maximum value of a <a href="http://www.unicode.org/glossary/#code_point"> Unicode code point</a>, constant {@code U+10FFFF}.

MAX_HIGH_SURROGATE
enum wchar MAX_HIGH_SURROGATE;

The maximum value of a <a href="http://www.unicode.org/glossary/#high_surrogate_code_unit"> Unicode high-surrogate code unit</a> in the UTF-16 encoding, constant {@code '\u005CuDBFF'}. A high-surrogate is also known as a <i>leading-surrogate</i>.

MAX_LOW_SURROGATE
enum wchar MAX_LOW_SURROGATE;

The maximum value of a <a href="http://www.unicode.org/glossary/#low_surrogate_code_unit"> Unicode low-surrogate code unit</a> in the UTF-16 encoding, constant {@code '\u005CuDFFF'}. A low-surrogate is also known as a <i>trailing-surrogate</i>.

MAX_RADIX
enum int MAX_RADIX;

The maximum radix available for conversion to and from strings. The constant value of this field is the largest value permitted for the radix argument in radix-conversion methods such as the {@code digit} method, the {@code forDigit} method, and the {@code toString} method of class {@code Integer}.

MAX_SURROGATE
enum wchar MAX_SURROGATE;

The maximum value of a Unicode surrogate code unit in the UTF-16 encoding, constant {@code '\u005CuDFFF'}.

MIN_CODE_POINT
enum int MIN_CODE_POINT;

The minimum value of a <a href="http://www.unicode.org/glossary/#code_point"> Unicode code point</a>, constant {@code U+0000}.

MIN_HIGH_SURROGATE
enum wchar MIN_HIGH_SURROGATE;

The minimum value of a <a href="http://www.unicode.org/glossary/#high_surrogate_code_unit"> Unicode high-surrogate code unit</a> in the UTF-16 encoding, constant {@code '\u005CuD800'}. A high-surrogate is also known as a <i>leading-surrogate</i>.

MIN_LOW_SURROGATE
enum wchar MIN_LOW_SURROGATE;

The minimum value of a <a href="http://www.unicode.org/glossary/#low_surrogate_code_unit"> Unicode low-surrogate code unit</a> in the UTF-16 encoding, constant {@code '\u005CuDC00'}. A low-surrogate is also known as a <i>trailing-surrogate</i>.

MIN_RADIX
enum int MIN_RADIX;

The minimum radix available for conversion to and from strings. The constant value of this field is the smallest value permitted for the radix argument in radix-conversion methods such as the {@code digit} method, the {@code forDigit} method, and the {@code toString} method of class {@code Integer}.

MIN_SUPPLEMENTARY_CODE_POINT
enum int MIN_SUPPLEMENTARY_CODE_POINT;

The minimum value of a <a href="http://www.unicode.org/glossary/#supplementary_code_point"> Unicode supplementary code point</a>, constant {@code U+10000}.

MIN_SURROGATE
enum wchar MIN_SURROGATE;

The minimum value of a Unicode surrogate code unit in the UTF-16 encoding, constant {@code '\u005CuD800'}.

MIN_VALUE
enum char MIN_VALUE;

The constant value of this field is the smallest value of type {@code char}, {@code '\u005Cu0000'}.

MODIFIER_LETTER
enum byte MODIFIER_LETTER;

General category "Lm" in the Unicode specification.

MODIFIER_SYMBOL
enum byte MODIFIER_SYMBOL;

General category "Sk" in the Unicode specification.

NON_SPACING_MARK
enum byte NON_SPACING_MARK;

General category "Mn" in the Unicode specification.

OTHER_LETTER
enum byte OTHER_LETTER;

General category "Lo" in the Unicode specification.

OTHER_NUMBER
enum byte OTHER_NUMBER;

General category "No" in the Unicode specification.

OTHER_PUNCTUATION
enum byte OTHER_PUNCTUATION;

General category "Po" in the Unicode specification.

OTHER_SYMBOL
enum byte OTHER_SYMBOL;

General category "So" in the Unicode specification.

PARAGRAPH_SEPARATOR
enum byte PARAGRAPH_SEPARATOR;

General category "Zp" in the Unicode specification.

PRIVATE_USE
enum byte PRIVATE_USE;

General category "Co" in the Unicode specification.

SPACE_SEPARATOR
enum byte SPACE_SEPARATOR;

General category "Zs" in the Unicode specification.

START_PUNCTUATION
enum byte START_PUNCTUATION;

General category "Ps" in the Unicode specification.

SURROGATE
enum byte SURROGATE;

General category "Cs" in the Unicode specification.

TITLECASE_LETTER
enum byte TITLECASE_LETTER;

General category "Lt" in the Unicode specification.

UNASSIGNED
enum byte UNASSIGNED;

General category "Cn" in the Unicode specification.

UPPERCASE_LETTER
enum byte UPPERCASE_LETTER;

General category "Lu" in the Unicode specification.

Meta