Index just past the bracket closing the one at `open`, or -1. Strings and comments hold no brackets.
(s: string, open: number)
| 39 | |
| 40 | /** Index just past the bracket closing the one at `open`, or -1. Strings and comments hold no brackets. */ |
| 41 | function pastBracket(s: string, open: number): number { |
| 42 | const stack = [CLOSER[s[open]!]!]; |
| 43 | for (let i = open + 1; i < s.length; i++) { |
| 44 | const c = s[i]!; |
| 45 | if (c === '"' || c === "'") { |
| 46 | i = skipString(s, i) - 1; |
| 47 | } else if (c === '/' && s[i + 1] === '/') { |
| 48 | while (i < s.length && s[i] !== '\n') i++; |
| 49 | } else if (c === '/' && s[i + 1] === '*') { |
| 50 | const end = s.indexOf('*/', i + 2); |
| 51 | if (end < 0) return -1; |
| 52 | i = end + 1; |
| 53 | } else if (CLOSER[c]) { |
| 54 | stack.push(CLOSER[c]!); |
| 55 | } else if (c === stack[stack.length - 1]) { |
| 56 | stack.pop(); |
| 57 | if (stack.length === 0) return i + 1; |
| 58 | } |
| 59 | } |
| 60 | return -1; |
| 61 | } |
| 62 | |
| 63 | function blank(out: string[], from: number, to: number): void { |
| 64 | for (let i = from; i < to; i++) if (out[i] !== '\n' && out[i] !== '\r') out[i] = ' '; |
no test coverage detected