| 151 | } |
| 152 | |
| 153 | const string = (quote: number) => { |
| 154 | const plain = quote === 0x27 ? json5Single : json5 ? json5Double : jsonDouble |
| 155 | let result = "" |
| 156 | for (i++;;) { |
| 157 | // Plain content runs until the quote, an escape, a line break, a control character |
| 158 | // JSON forbids, or the end of input, where `code` is NaN and fails the last test. |
| 159 | const start = i |
| 160 | let code = text.charCodeAt(i) |
| 161 | // Short runs are cheaper to scan by hand; long runs are handed to the pattern. |
| 162 | const handoff = i + 24 |
| 163 | while (code !== quote && code !== 0x5c && code !== 0x0a && code !== 0x0d && code >= plainFloor) { |
| 164 | if (++i === handoff) { |
| 165 | run(plain) |
| 166 | code = text.charCodeAt(i) |
| 167 | break |
| 168 | } |
| 169 | code = text.charCodeAt(i) |
| 170 | } |
| 171 | result += text.slice(start, i) |
| 172 | i++ |
| 173 | if (code === quote) return result |
| 174 | // Anything else that stops a plain run is an escape or a forbidden character. |
| 175 | if (code !== 0x5c) fail(i - 1) |
| 176 | const escape = text.charCodeAt(i++) |
| 177 | const simple = escapes[escape] |
| 178 | if (simple !== undefined) result += simple |
| 179 | else if (escape === 0x75) result += hex(4) |
| 180 | else if (!json5 || i > text.length || (escape >= 0x31 && escape <= 0x39)) fail(i - 1) |
| 181 | else if (escape === 0x76) result += "\v" |
| 182 | else if (escape === 0x78) result += hex(2) |
| 183 | else if (escape === 0x30) { |
| 184 | if (isDigit(text.charCodeAt(i))) fail(i) |
| 185 | result += "\0" |
| 186 | } else if (escape === 0x0d) { |
| 187 | // A CR LF line continuation contributes nothing, like a single line terminator. |
| 188 | if (text.charCodeAt(i) === 0x0a) i++ |
| 189 | } else if (escape !== 0x0a && escape !== 0x2028 && escape !== 0x2029) result += text[i - 1] |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | const identifier = () => { |
| 194 | const start = i |