pub trait Char {
fn is_digit(&self, radix: u32) -> bool;
fn is_inline_whitespace(&self) -> bool;
fn is_newline(&self) -> bool;
fn is_whitespace(&self) -> bool;
fn to_ascii(&self) -> Option<u8>;
}
impl Char for u8 {
fn is_digit(&self, radix: u32) -> bool {
(*self as char).is_digit(radix)
}
fn is_whitespace(&self) -> bool {
(*self as char).is_ascii_whitespace()
}
fn to_ascii(&self) -> Option<u8> {
self.is_ascii().then_some(*self)
}
fn is_inline_whitespace(&self) -> bool {
self == &b' ' || self == &b'\t'
}
fn is_newline(&self) -> bool {
[
b'\n', b'\r', b'\x0B', b'\x0C', ]
.as_slice()
.contains(self)
}
}
impl Char for char {
fn is_digit(&self, radix: u32) -> bool {
char::is_digit(*self, radix)
}
fn is_whitespace(&self) -> bool {
char::is_whitespace(*self)
}
fn to_ascii(&self) -> Option<u8> {
self.is_ascii().then_some(*self as u8)
}
fn is_inline_whitespace(&self) -> bool {
self == &' ' || self == &'\t'
}
fn is_newline(&self) -> bool {
[
'\n', '\r', '\x0B', '\x0C', '\u{0085}', '\u{2028}', '\u{2029}', ]
.as_slice()
.contains(self)
}
}