use std::fmt::Write;
#[must_use]
pub fn urlencode_query(input: &str) -> String {
let mut out = String::with_capacity(input.len() * 3);
for byte in input.bytes() {
match byte {
b'A'..=b'Z' | b'a'..=b'z' | b'0'..=b'9' | b'-' | b'_' | b'.' | b'~' => {
out.push(byte as char);
}
b' ' => out.push_str("%20"),
_ => {
let _ = write!(out, "%{byte:02X}");
}
}
}
out
}
#[must_use]
pub fn truncate(s: &str, max: usize) -> String {
if s.len() > max {
format!("{}...", &s[..max])
} else {
s.to_string()
}
}