pub(crate) mod complete;
pub(crate) mod incomplete;
#[cfg(feature = "alloc")]
use alloc::string::String;
#[cfg(feature = "alloc")]
use alloc::vec::Vec;
#[cfg(feature = "alloc")]
use core::mem;
pub(crate) use complete::Entry as CompleteEntry;
pub(crate) use incomplete::{Entry as IncompleteEntry, Len as IncompleteLen};
#[cfg(not(feature = "alloc"))]
pub(crate) const fn entry_to_char(buf: [u8; 3], len: u32) -> char {
let cp = match len {
1 => buf[0] as u32,
2 => ((buf[0] as u32 & 0x1F) << 6) | (buf[1] as u32 & 0x3F),
_ => {
((buf[0] as u32 & 0x0F) << 12) | ((buf[1] as u32 & 0x3F) << 6) | (buf[2] as u32 & 0x3F)
}
};
unsafe { char::from_u32_unchecked(cp) }
}
#[cfg(feature = "alloc")]
const USIZE_SIZE: usize = mem::size_of::<usize>();
#[cfg(feature = "alloc")]
#[inline]
unsafe fn finalize_string(mut buffer: Vec<u8>, dst: *const u8) -> String {
let length = dst.offset_from(buffer.as_ptr()) as usize;
buffer.set_len(length);
buffer.shrink_to_fit();
String::from_utf8_unchecked(buffer)
}
#[cfg(feature = "alloc")]
#[inline]
fn contains_nonascii(v: usize) -> bool {
const NONASCII_MASK: usize = 0x8080_8080_8080_8080_u64 as usize;
(NONASCII_MASK & v) != 0
}