Trait core::char::CharExtStable [-]  [+] [src]

pub trait CharExt {
    fn is_digit(self, radix: usize) -> bool;
    fn to_digit(self, radix: usize) -> Option<usize>;
    fn escape_unicode(self) -> EscapeUnicode;
    fn escape_default(self) -> EscapeDefault;
    fn len_utf8(self) -> usize;
    fn len_utf16(self) -> usize;
    fn encode_utf8(self, dst: &mut [u8]) -> Option<usize>;
    fn encode_utf16(self, dst: &mut [u16]) -> Option<usize>;
}

Basic char manipulations.

Required Methods

fn is_digit(self, radix: usize) -> bool

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

Compared to is_numeric(), 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: usize) -> Option<usize>

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 escape_unicode(self) -> EscapeUnicode

Returns an iterator that yields the hexadecimal Unicode escape of a character, as chars.

All characters are escaped with Rust syntax of the form \\u{NNNN} where NNNN is the shortest hexadecimal representation of the code point.

fn escape_default(self) -> EscapeDefault

Returns an iterator that yields the 'default' ASCII and C++11-like literal escape of a character, as chars.

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(self) -> usize

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

fn len_utf16(self) -> usize

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

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

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<usize>

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