splitTopLevel(body, sep): split on `sep` at brace/paren/bracket depth 0.
(body: &[u8], sep: u8)
| 967 | // ---------- struct field parsing ---------- |
| 968 | |
| 969 | /// splitTopLevel(body, sep): split on `sep` at brace/paren/bracket depth 0. |
| 970 | fn split_top_level(body: &[u8], sep: u8) -> Vec<Range> { |
| 971 | let mut out = Vec::new(); |
| 972 | let mut depth = 0i64; |
| 973 | let mut start = 0usize; |
| 974 | for (i, &c) in body.iter().enumerate() { |
| 975 | match c { |
| 976 | b'{' | b'(' | b'[' => depth += 1, |
| 977 | b'}' | b')' | b']' => depth -= 1, |
| 978 | _ if c == sep && depth == 0 => { |
| 979 | out.push((start, i)); |
| 980 | start = i + 1; |
| 981 | } |
| 982 | _ => {} |
| 983 | } |
| 984 | } |
| 985 | out.push((start, body.len())); |
| 986 | out |
| 987 | } |
| 988 | |
| 989 | /// JS String.prototype.trim over bytes (the JS set == our jsws set). |
no test coverage detected