The primitive character type.
Methods
Returns true
if this char
has the Alphabetic
property.
Alphabetic
is described in Chapter 4 (Character Properties) of the Unicode Standard and specified in the Unicode Character Database DerivedCoreProperties.txt
.
Examples
assert!;
assert!;
let c = '💝';
// love is many things, but it is not alphabetic
assert!;
Returns true
if this char
satisfies either is_alphabetic()
or is_numeric()
.
Examples
Basic usage:
assert!;
assert!;
assert!;
assert!;
assert!;
assert!;
assert!;
assert!;
Returns true
if this char
has the general category for control codes.
Control codes (code points with the general category of Cc
) are described in Chapter 4 (Character Properties) of the Unicode Standard and specified in the Unicode Character Database UnicodeData.txt
.
Examples
Basic usage:
// U+009C, STRING TERMINATOR
assert!;
assert!;
Returns true
if this char
has the Lowercase
property.
Lowercase
is described in Chapter 4 (Character Properties) of the Unicode Standard and specified in the Unicode Character Database DerivedCoreProperties.txt
.
Examples
Basic usage:
assert!;
assert!;
assert!;
assert!;
// The various Chinese scripts and punctuation do not have case, and so:
assert!;
assert!;
Returns true
if this char
has one of the general categories for numbers.
The general categories for numbers (Nd
for decimal digits, Nl
for letter-like numeric characters, and No
for other numeric characters) are specified in the Unicode Character Database UnicodeData.txt
.
This method doesn't cover everything that could be considered a number, e.g. ideographic numbers like '三'. If you want everything including characters with overlapping purposes then you might want to use a unicode or language-processing library that exposes the appropriate character properties instead of looking at the unicode categories.
If you want to parse ASCII decimal digits (0-9) or ASCII base-N, use is_ascii_digit
or is_digit
instead.
Examples
Basic usage:
assert!;
assert!;
assert!;
assert!;
assert!;
assert!;
assert!;
assert!;
assert!;
Returns true
if this char
has the Uppercase
property.
Uppercase
is described in Chapter 4 (Character Properties) of the Unicode Standard and specified in the Unicode Character Database DerivedCoreProperties.txt
.
Examples
Basic usage:
assert!;
assert!;
assert!;
assert!;
// The various Chinese scripts and punctuation do not have case, and so:
assert!;
assert!;
Returns true
if this char
has the White_Space
property.
White_Space
is specified in the Unicode Character Database PropList.txt
.
Examples
Basic usage:
assert!;
// line break
assert!;
// a non-breaking space
assert!;
assert!;
Converts a char
to a digit in the given radix.
A 'radix' here is sometimes also called a 'base'. A radix of two indicates a binary number, a radix of ten, decimal, and a radix of sixteen, hexadecimal, to give some common values. Arbitrary radices are supported.
'Digit' is defined to be only the following characters:
0-9
a-z
A-Z
Errors
Returns None
if the char
does not refer to a digit in the given radix.
Panics
Panics if given a radix larger than 36.
Examples
Basic usage:
assert_eq!;
assert_eq!;
Passing a non-digit results in failure:
assert_eq!;
assert_eq!;
Passing a large radix, causing a panic:
// this panics
let _ = '1'.to_digit;