use crate::error::DogeError;
use crate::value::Value;
pub(crate) const MAX_DEPTH: usize = 128;
pub(crate) fn unsupported(module: &str, v: &Value) -> DogeError {
DogeError::type_error(format!("{module}.emit cannot serialize {}", v.describe()))
}
pub(crate) fn too_deep(module: &str, action: &str) -> DogeError {
DogeError::value_error(format!(
"{module}.{action}: much deep. nesting past {MAX_DEPTH} levels"
))
}
pub(crate) fn escape_str(s: &str, out: &mut String, unicode: impl Fn(&mut String, u32)) {
out.push('"');
for c in s.chars() {
match c {
'"' => out.push_str("\\\""),
'\\' => out.push_str("\\\\"),
'\n' => out.push_str("\\n"),
'\r' => out.push_str("\\r"),
'\t' => out.push_str("\\t"),
'\u{08}' => out.push_str("\\b"),
'\u{0c}' => out.push_str("\\f"),
c if (c as u32) < 0x20 => unicode(out, c as u32),
c => out.push(c),
}
}
out.push('"');
}