#![forbid(unsafe_code)]
use std::io::{self, Write};
use simdutf8_cli::validate::{validate, Validity};
fn main() -> io::Result<()> {
let samples: [(&str, &[u8]); 4] = [
("valid UTF-8", "grüße 😊".as_bytes()),
("UTF-16LE w/ BOM", &[0xFF, 0xFE, 0x48, 0x00, 0x69, 0x00]),
("Latin-1 'é'", b"caf\xE9"),
("truncated UTF-8", b"abc\xF0"),
];
let stdout = io::stdout();
let mut out = stdout.lock();
for (label, bytes) in samples {
match validate(bytes) {
Validity::Valid => writeln!(out, "{label:18} -> valid")?,
Validity::Invalid {
valid_up_to,
error_len,
} => writeln!(
out,
"{label:18} -> invalid (valid_up_to={valid_up_to}, error_len={error_len:?})"
)?,
}
}
Ok(())
}