Utilities for manipulating the char type

Function cmp

pure fn cmp(a: char, b: char) -> int

Compare two chars

Return value

-1 if a < b, 0 if a == b, +1 if a > b

Function escape_default

fn escape_default(c: char) -> str

Return a 'default' ASCII and C++11-like char-literal escape of a char.

The default is chosen with a bias toward producing literals that are legal in a variety of languages, including C++11 and similar C-family languages. The exact rules are:

Function escape_unicode

fn escape_unicode(c: char) -> str

Return the hexadecimal unicode escape of a char.

The rules are as follows:

Function is_XID_continue

pure fn XID_Continue(c: char) -> bool

Function is_XID_start

pure fn XID_Start(c: char) -> bool

Function is_alphabetic

pure fn Alphabetic(c: char) -> bool

Check if a character has the alphabetic unicode property

Function is_alphanumeric

pure fn is_alphanumeric(c: char) -> bool

Indicates whether a character is alphanumeric, defined in terms of the Unicode General Categories 'Nd', 'Nl', 'No' and the Derived Core Property 'Alphabetic'.

Function is_ascii

pure fn is_ascii(c: char) -> bool

Indicates whether the character is an ASCII character

Function is_digit

pure fn is_digit(c: char) -> bool

Indicates whether the character is numeric (Nd, Nl, or No)

Function is_lowercase

pure fn is_lowercase(c: char) -> bool

Indicates whether a character is in lower case, defined in terms of the Unicode General Category 'Ll'

Function is_uppercase

pure fn is_uppercase(c: char) -> bool

Indicates whether a character is in upper case, defined in terms of the Unicode General Category 'Lu'.

Function is_whitespace

pure fn is_whitespace(c: char) -> bool

Indicates whether a character is whitespace, defined in terms of the Unicode General Categories 'Zs', 'Zl', 'Zp' additional 'Cc'-category control codes in the range [0x09, 0x0d]

Function to_digit

pure fn to_digit(c: char, radix: uint) -> option<uint>

Convert a char to the corresponding digit.

Safety note

This function fails if c is not a valid char

Return value

If c is between '0' and '9', the corresponding value between 0 and 9. If c is 'a' or 'A', 10. If c is 'b' or 'B', 11, etc. Returns none if the char does not refer to a digit in the given radix.