mod hstring;
mod literals;
mod pcstr;
mod pcwstr;
mod pstr;
mod pwstr;
pub use hstring::*;
#[doc(hidden)]
pub use literals::*;
pub use pcstr::*;
pub use pcwstr::*;
pub use pstr::*;
pub use pwstr::*;
use super::*;
extern "C" {
#[doc(hidden)]
pub fn strlen(s: PCSTR) -> usize;
#[doc(hidden)]
pub fn wcslen(s: PCWSTR) -> usize;
}
#[doc(hidden)]
pub struct Decode<F>(pub F);
impl<F, R, E> core::fmt::Display for Decode<F>
where
F: Clone + FnOnce() -> R,
R: IntoIterator<Item = core::result::Result<char, E>>,
{
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
use core::fmt::Write;
let iter = self.0.clone();
for c in iter().into_iter() {
f.write_char(c.unwrap_or_else(|_| std::char::REPLACEMENT_CHARACTER))?
}
Ok(())
}
}
fn decode_utf8<'a>(mut buffer: &'a [u8]) -> impl Iterator<Item = core::result::Result<char, std::str::Utf8Error>> + 'a {
let mut current = "".chars();
let mut previous_error = None;
std::iter::from_fn(move || {
loop {
match (current.next(), previous_error) {
(Some(c), _) => return Some(Ok(c)),
(None, Some(e)) => {
previous_error = None;
return Some(Err(e));
}
(None, None) if buffer.is_empty() => return None,
(None, None) => {
match std::str::from_utf8(buffer) {
Ok(s) => {
current = s.chars();
buffer = &[];
}
Err(e) => {
let (valid, rest) = buffer.split_at(e.valid_up_to());
let invalid_sequence_length = e.error_len()?;
buffer = &rest[invalid_sequence_length..];
current = unsafe { std::str::from_utf8_unchecked(valid) }.chars();
previous_error = Some(e);
}
}
}
}
}
})
}