Trait unicode::char::CharExperimental [-]  [+] [src]

pub trait Char {
    fn is_digit_radix(&self, radix: uint) -> bool;
    fn to_digit(&self, radix: uint) -> Option<uint>;
    fn from_digit(num: uint, radix: uint) -> Option<Self>;
    fn escape_unicode(&self, f: |char|);
    fn escape_default(&self, f: |char|);
    fn len_utf8_bytes(&self) -> uint;
    fn encode_utf8(&self, dst: &mut [u8]) -> Option<uint>;
    fn encode_utf16(&self, dst: &mut [u16]) -> Option<uint>;
}

Basic char manipulations.

Required Methods

fn is_digit_radix(&self, radix: uint) -> bool

Checks if a char parses as a numeric digit in the given radix.

Compared to is_digit(), this function only recognizes the characters 0-9, a-z and A-Z.

Return value

Returns true if c is a valid digit under radix, and false otherwise.

Panics

Panics if given a radix > 36.

fn to_digit(&self, radix: uint) -> Option<uint>

Converts a character to the corresponding digit.

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 character does not refer to a digit in the given radix.

Panics

Panics if given a radix outside the range [0..36].

fn from_digit(num: uint, radix: uint) -> Option<Self>

Converts a number to the character representing it.

Return value

Returns Some(char) if num represents one digit under radix, using one character of 0-9 or a-z, or None if it doesn't.

Panics

Panics if given a radix > 36.

fn escape_unicode(&self, f: |char|)

Returns the hexadecimal Unicode escape of a character.

The rules are as follows:

  • Characters in [0,0xff] get 2-digit escapes: \\xNN
  • Characters in [0x100,0xffff] get 4-digit escapes: \\uNNNN.
  • Characters above 0x10000 get 8-digit escapes: \\UNNNNNNNN.

fn escape_default(&self, f: |char|)

Returns a 'default' ASCII and C++11-like literal escape of a character.

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:

  • Tab, CR and LF are escaped as '\t', '\r' and '\n' respectively.
  • Single-quote, double-quote and backslash chars are backslash- escaped.
  • Any other chars in the range [0x20,0x7e] are not escaped.
  • Any other chars are given hex Unicode escapes; see escape_unicode.

fn len_utf8_bytes(&self) -> uint

Returns the amount of bytes this character would need if encoded in UTF-8.

fn encode_utf8(&self, dst: &mut [u8]) -> Option<uint>

Encodes this character as UTF-8 into the provided byte buffer, and then returns the number of bytes written.

If the buffer is not large enough, nothing will be written into it and a None will be returned.

fn encode_utf16(&self, dst: &mut [u16]) -> Option<uint>

Encodes this character as UTF-16 into the provided u16 buffer, and then returns the number of u16s written.

If the buffer is not large enough, nothing will be written into it and a None will be returned.

Implementors