* shifts until condition holds, reading `\` before the terminator as the * terminator and `\\` as escapeEscape followed by a backslash. Where * escapeEscape is "", as in a literal, the escapes JSON writes for a * control character are read as that character, so a literal's expression * parse
( condition: Scanner.UntilCondition, escapeEscape: typeof Backslash | "" = "" )
| 96 | * parses back to it |
| 97 | */ |
| 98 | shiftUntilEscapable( |
| 99 | condition: Scanner.UntilCondition, |
| 100 | escapeEscape: typeof Backslash | "" = "" |
| 101 | ): string { |
| 102 | let shifted = "" |
| 103 | while (this.peek) { |
| 104 | if (this.peek === Backslash) { |
| 105 | this.shift() |
| 106 | if (!this.peek) { |
| 107 | shifted += Backslash |
| 108 | break |
| 109 | } |
| 110 | if (condition(this, shifted)) shifted += this.shift() |
| 111 | else if (this.peek === Backslash) |
| 112 | shifted += `${escapeEscape}${this.shift()}` |
| 113 | else if (escapeEscape === "") shifted += this.shiftControlEscape() |
| 114 | else shifted += `${Backslash}${this.shift()}` |
| 115 | } else if (condition(this, shifted)) break |
| 116 | else shifted += this.shift() |
| 117 | } |
| 118 | return shifted |
| 119 | } |
| 120 | |
| 121 | /** the control character escaped after a backslash, or the backslash as written */ |
| 122 | private shiftControlEscape(): string { |
no test coverage detected