pub enum Utf8 {}
impl Utf8 {
pub const MAX_UNITS_PER_CHAR: usize = 4;
pub const MAX_BYTES_PER_CHAR: usize = Self::MAX_UNITS_PER_CHAR;
#[inline]
pub const fn is_single_byte(byte: u8) -> bool {
byte <= 0x7f
}
#[inline]
pub const fn is_leading_byte(byte: u8) -> bool {
byte >= 0xc2 && byte <= 0xf4
}
#[inline]
pub const fn is_continuation_byte(byte: u8) -> bool {
(byte & 0xc0) == 0x80
}
#[inline]
pub const fn byte_len_from_leading_byte(byte: u8) -> Option<usize> {
if byte <= 0x7f {
Some(1)
} else if byte >= 0xc2 && byte <= 0xdf {
Some(2)
} else if byte >= 0xe0 && byte <= 0xef {
Some(3)
} else if byte >= 0xf0 && byte <= 0xf4 {
Some(4)
} else {
None
}
}
#[inline]
pub const fn byte_len(ch: char) -> usize {
let code_point = ch as u32;
if code_point <= 0x7f {
1
} else if code_point <= 0x7ff {
2
} else if code_point <= 0xffff {
3
} else {
4
}
}
}