use utf_types::utf8::Ascii;
use utf_types::utf8::FourByteSequence;
use utf_types::utf8::ThreeByteSequence;
use utf_types::utf8::TwoByteSequence;
use crate::Utf8Handler;
#[derive(Debug, Clone)]
pub struct DefaultHandler;
impl DefaultHandler {
pub const fn new() -> Self {
Self {}
}
}
impl Default for DefaultHandler {
fn default() -> Self {
Self::new()
}
}
impl Utf8Handler for DefaultHandler {
type Output = char;
#[inline(always)]
fn single_byte(&self, ascii: Ascii) -> Self::Output {
ascii.to_char()
}
#[inline(always)]
fn two_byte(&self, sequence: TwoByteSequence) -> Self::Output {
sequence.to_char()
}
#[inline(always)]
fn three_byte(&self, sequence: ThreeByteSequence) -> Self::Output {
sequence.to_char()
}
#[inline(always)]
fn four_byte(&self, sequence: FourByteSequence) -> Self::Output {
sequence.to_char()
}
#[inline(always)]
fn error(&self) -> Self::Output {
char::REPLACEMENT_CHARACTER
}
}
crate::macros::named_iterators_from_no_argument_handler!(
DefaultHandler,
char,
,
Utf8Chars,
,
Utf8CharIndices,
);
pub trait Utf8CharsEx {
fn chars(&self) -> Utf8Chars<'_>;
fn char_indices(&self) -> Utf8CharIndices<'_>;
}
impl Utf8CharsEx for [u8] {
#[inline(always)]
fn chars(&self) -> Utf8Chars<'_> {
Utf8Chars::new(self)
}
#[inline(always)]
fn char_indices(&self) -> Utf8CharIndices<'_> {
Utf8CharIndices::new(self)
}
}