`a|b|(c|d)` split at its top-level bars.
(s: string)
| 199 | |
| 200 | /** `a|b|(c|d)` split at its top-level bars. */ |
| 201 | function topLevelBars(s: string): string[] { |
| 202 | const out: string[] = []; |
| 203 | let from = 0; |
| 204 | for (let i = 0; i < s.length; i++) { |
| 205 | const c = s[i]; |
| 206 | if (c === '\\') i++; |
| 207 | else if (c === '[') { |
| 208 | while (i < s.length && s[i] !== ']') i += s[i] === '\\' ? 2 : 1; |
| 209 | } else if (c === '(') { |
| 210 | const close = closingParen(s, i); |
| 211 | if (close < 0) return [s]; |
| 212 | i = close; |
| 213 | } else if (c === '|') { |
| 214 | out.push(s.slice(from, i)); |
| 215 | from = i + 1; |
| 216 | } |
| 217 | } |
| 218 | out.push(s.slice(from)); |
| 219 | return out; |
| 220 | } |
| 221 | |
| 222 | /** |
| 223 | * One branch of a negative lookahead, as a regex of our own: a literal path |
no test coverage detected