///|
/// Bound traversal before delegating syntax and Unicode handling to core.
fn check_document_depth(text : String) -> Unit raise InputError {
let mut depth = 0
let mut quoted = false
let mut escaped = false
for c in text {
if quoted {
if escaped {
escaped = false
} else if c == '\\' {
escaped = true
} else if c == '"' {
quoted = false
}
} else {
match c {
'"' => quoted = true
'{' | '[' => {
depth += 1
if depth > 16 {
raise Invalid("JSON nesting exceeds 16 containers")
}
}
'}' | ']' => {
if depth == 0 {
raise Invalid("unexpected JSON closing delimiter")
}
depth -= 1
}
_ => ()
}
}
}
}