use kowito_json::serialize::write_str_escape;
fn show(label: &str, s: &str) {
let mut buf = Vec::new();
write_str_escape(&mut buf, s.as_bytes());
println!("{label:<30} → {}", std::str::from_utf8(&buf).unwrap());
}
fn main() {
show("Plain ASCII", "Hello, World!");
show("Embedded quotes", r#"She said "hello""#);
show("Backslash", r"C:\Users\Alice\Documents");
show("Newline", "line one\nline two");
show("Tab", "col1\tcol2\tcol3");
show("Carriage return", "before\rafter");
show("Backspace", "ab\x08c");
show("Form feed", "page\x0Cbreak");
show("Null byte", "\x00");
show("STX control", "\x02");
show("Unit separator", "\x1F");
show("Mixed mid-escape", "aaaaaaaaaaaaaaaa\"end");
let long_safe = "a".repeat(1024);
let mut buf = Vec::new();
write_str_escape(&mut buf, long_safe.as_bytes());
println!(
"{:<30} → {} bytes (starts: {}, ends: {})",
"1024-char safe string",
buf.len(),
std::str::from_utf8(&buf[..3]).unwrap(),
std::str::from_utf8(&buf[buf.len() - 3..]).unwrap(),
);
let long_with_trailing_quote = format!("{}\"", "b".repeat(1024));
buf.clear();
write_str_escape(&mut buf, long_with_trailing_quote.as_bytes());
println!(
"{:<30} → {} bytes (tail: {})",
"1024-char + trailing quote",
buf.len(),
std::str::from_utf8(&buf[buf.len() - 4..]).unwrap(),
);
}