pub(super) const INDENT: &str = " ";
pub(super) fn needs_raw_marker(s: &str) -> bool {
match s.as_bytes().first() {
None => false,
Some(&b' ') | Some(&b'\t') => needs_raw_marker_slow(s.trim_start()),
Some(&b'{') | Some(&b'[') => true,
Some(_) => {
matches!(s, "null" | "true" | "false" | "(" | "((" | "()" | "(())")
}
}
}
#[cold]
#[inline(never)]
fn needs_raw_marker_slow(t: &str) -> bool {
t.starts_with('{')
|| t.starts_with('[')
|| matches!(t, "null" | "true" | "false" | "(" | "((" | "()" | "(())")
}
pub(super) fn push_indent(out: &mut String, level: usize) {
const SPACES: &str = " "; let mut remaining = level * INDENT.len();
if remaining == 0 {
return;
}
out.reserve(remaining);
while remaining > 0 {
let chunk = remaining.min(SPACES.len());
out.push_str(&SPACES[..chunk]);
remaining -= chunk;
}
}