scanCppBraceScopes: `src` as the parser saw it (after preParse). None when the braces don't balance.
(src: &str)
| 249 | /// scanCppBraceScopes: `src` as the parser saw it (after preParse). None when |
| 250 | /// the braces don't balance. |
| 251 | pub fn scan(src: &str) -> Option<BraceScopes> { |
| 252 | let s = src.as_bytes(); |
| 253 | let n = s.len(); |
| 254 | let mut closes: HashMap<usize, usize> = HashMap::new(); |
| 255 | let mut open: Vec<usize> = Vec::new(); |
| 256 | let mut branches: Vec<Branch> = Vec::new(); |
| 257 | let mut namespace_at: Vec<(usize, String)> = Vec::new(); |
| 258 | let mut pending_namespace: Option<(String, usize)> = None; |
| 259 | let mut balanced = true; |
| 260 | let mut line_start = true; |
| 261 | let mut word_start: usize = 0; |
| 262 | let mut word_end_at: Option<usize> = None; |
| 263 | // Past a byte-order mark, so line 1 can be a directive. |
| 264 | let mut i = if src.starts_with('\u{feff}') { 3 } else { 0 }; |
| 265 | while i < n { |
| 266 | let c = s[i]; |
| 267 | if c == b'\n' { |
| 268 | line_start = true; |
| 269 | i += 1; |
| 270 | continue; |
| 271 | } |
| 272 | if is_blank(c) { |
| 273 | i += 1; |
| 274 | continue; |
| 275 | } |
| 276 | if c == b'/' && at(s, i + 1) == b'/' { |
| 277 | i = line_comment_end(src, i + 2); |
| 278 | continue; |
| 279 | } |
| 280 | if c == b'/' && at(s, i + 1) == b'*' { |
| 281 | i = find(src, i + 2, "*/").map_or(n, |e| e + 2); |
| 282 | continue; |
| 283 | } |
| 284 | if c == b'#' && line_start { |
| 285 | let mut j = i + 1; |
| 286 | while j < n && is_blank(s[j]) { |
| 287 | j += 1; |
| 288 | } |
| 289 | let directive: &[u8] = match word_end(s, j) { |
| 290 | Some(e) => &s[j..e], |
| 291 | None => b"", |
| 292 | }; |
| 293 | while j < n { |
| 294 | let d = s[j]; |
| 295 | if d == b'\n' { |
| 296 | let mut k = j as isize - 1; |
| 297 | if k >= 0 && s[k as usize] == b'\r' { |
| 298 | k -= 1; |
| 299 | } |
| 300 | if k < 0 || s[k as usize] != b'\\' { |
| 301 | break; |
| 302 | } |
| 303 | j += 1; |
| 304 | } else if d == b'/' && at(s, j + 1) == b'/' { |
| 305 | j = line_comment_end(src, j + 2); |
| 306 | } else if d == b'/' && at(s, j + 1) == b'*' { |
| 307 | j = find(src, j + 2, "*/").map_or(n, |e| e + 2); |
| 308 | } else if d == b'"' { |
no test coverage detected