splitTopLevel(body, sep): split on `sep` at brace/paren/bracket depth 0.
(body: &[u8], sep: u8)
| 985 | // ---------- struct field parsing ---------- |
| 986 | |
| 987 | /// splitTopLevel(body, sep): split on `sep` at brace/paren/bracket depth 0. |
| 988 | fn split_top_level(body: &[u8], sep: u8) -> Vec<Range> { |
| 989 | let mut out = Vec::new(); |
| 990 | let mut depth = 0i64; |
| 991 | let mut start = 0usize; |
| 992 | for (i, &c) in body.iter().enumerate() { |
| 993 | match c { |
| 994 | b'{' | b'(' | b'[' => depth += 1, |
| 995 | b'}' | b')' | b']' => depth -= 1, |
| 996 | _ if c == sep && depth == 0 => { |
| 997 | out.push((start, i)); |
| 998 | start = i + 1; |
| 999 | } |
| 1000 | _ => {} |
| 1001 | } |
| 1002 | } |
| 1003 | out.push((start, body.len())); |
| 1004 | out |
| 1005 | } |
| 1006 | |
| 1007 | /// JS String.prototype.trim over bytes (the JS set == our jsws set). |
no test coverage detected