1pub fn quoted(text: &str, delimiter: char, escape: impl Fn(char) -> Option<String>) -> String {
6 let mut out = String::with_capacity(text.len() + 2);
7 out.push(delimiter);
8 for c in text.chars() {
9 match escape(c) {
10 Some(escaped) => out.push_str(&escaped),
11 None => out.push(c),
12 }
13 }
14 out.push(delimiter);
15 out
16}
17
18pub fn utf16_units(c: char, prefix: &str) -> String {
20 let mut units = [0u16; 2];
21 c.encode_utf16(&mut units)
22 .iter()
23 .map(|unit| format!("{prefix}{unit:04x}"))
24 .collect()
25}
26
27#[cfg(test)]
28mod tests;