(s: string, pos: number)
| 110 | const CODE_0: number = "0".charCodeAt(0) |
| 111 | |
| 112 | export function parseJsonString(s: string, pos: number): string | undefined { |
| 113 | let str = "" |
| 114 | let c: string | undefined |
| 115 | parseJsonString.message = undefined |
| 116 | // eslint-disable-next-line no-constant-condition, @typescript-eslint/no-unnecessary-condition |
| 117 | while (true) { |
| 118 | c = s[pos++] |
| 119 | if (c === '"') break |
| 120 | if (c === "\\") { |
| 121 | c = s[pos] |
| 122 | if (c in escapedChars) { |
| 123 | str += escapedChars[c] |
| 124 | pos++ |
| 125 | } else if (c === "u") { |
| 126 | pos++ |
| 127 | let count = 4 |
| 128 | let code = 0 |
| 129 | while (count--) { |
| 130 | code <<= 4 |
| 131 | c = s[pos] |
| 132 | // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition |
| 133 | if (c === undefined) { |
| 134 | errorMessage("unexpected end") |
| 135 | return undefined |
| 136 | } |
| 137 | c = c.toLowerCase() |
| 138 | if (c >= "a" && c <= "f") { |
| 139 | code += c.charCodeAt(0) - CODE_A + 10 |
| 140 | } else if (c >= "0" && c <= "9") { |
| 141 | code += c.charCodeAt(0) - CODE_0 |
| 142 | } else { |
| 143 | errorMessage(`unexpected token ${c}`) |
| 144 | return undefined |
| 145 | } |
| 146 | pos++ |
| 147 | } |
| 148 | str += String.fromCharCode(code) |
| 149 | } else { |
| 150 | errorMessage(`unexpected token ${c}`) |
| 151 | return undefined |
| 152 | } |
| 153 | // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition |
| 154 | } else if (c === undefined) { |
| 155 | errorMessage("unexpected end") |
| 156 | return undefined |
| 157 | } else { |
| 158 | if (c.charCodeAt(0) >= 0x20) { |
| 159 | str += c |
| 160 | } else { |
| 161 | errorMessage(`unexpected token ${c}`) |
| 162 | return undefined |
| 163 | } |
| 164 | } |
| 165 | } |
| 166 | parseJsonString.position = pos |
| 167 | return str |
| 168 | |
| 169 | function errorMessage(msg: string): void { |
nothing calls this directly
no test coverage detected