(text: string, ignoreTrivia: boolean = false)
| 199 | * If ignoreTrivia is set, whitespaces or comments are ignored. |
| 200 | */ |
| 201 | export function createScanner(text: string, ignoreTrivia: boolean = false): JSONScanner { |
| 202 | |
| 203 | let pos = 0; |
| 204 | const len = text.length; |
| 205 | let value: string = ''; |
| 206 | let tokenOffset = 0; |
| 207 | let token: SyntaxKind = SyntaxKind.Unknown; |
| 208 | let scanError: ScanError = ScanError.None; |
| 209 | |
| 210 | function scanHexDigits(count: number): number { |
| 211 | let digits = 0; |
| 212 | let hexValue = 0; |
| 213 | while (digits < count) { |
| 214 | const ch = text.charCodeAt(pos); |
| 215 | if (ch >= CharacterCodes._0 && ch <= CharacterCodes._9) { |
| 216 | hexValue = hexValue * 16 + ch - CharacterCodes._0; |
| 217 | } |
| 218 | else if (ch >= CharacterCodes.A && ch <= CharacterCodes.F) { |
| 219 | hexValue = hexValue * 16 + ch - CharacterCodes.A + 10; |
| 220 | } |
| 221 | else if (ch >= CharacterCodes.a && ch <= CharacterCodes.f) { |
| 222 | hexValue = hexValue * 16 + ch - CharacterCodes.a + 10; |
| 223 | } |
| 224 | else { |
| 225 | break; |
| 226 | } |
| 227 | pos++; |
| 228 | digits++; |
| 229 | } |
| 230 | if (digits < count) { |
| 231 | hexValue = -1; |
| 232 | } |
| 233 | return hexValue; |
| 234 | } |
| 235 | |
| 236 | function setPosition(newPosition: number) { |
| 237 | pos = newPosition; |
| 238 | value = ''; |
| 239 | tokenOffset = 0; |
| 240 | token = SyntaxKind.Unknown; |
| 241 | scanError = ScanError.None; |
| 242 | } |
| 243 | |
| 244 | function scanNumber(): string { |
| 245 | const start = pos; |
| 246 | if (text.charCodeAt(pos) === CharacterCodes._0) { |
| 247 | pos++; |
| 248 | } else { |
| 249 | pos++; |
| 250 | while (pos < text.length && isDigit(text.charCodeAt(pos))) { |
| 251 | pos++; |
| 252 | } |
| 253 | } |
| 254 | if (pos < text.length && text.charCodeAt(pos) === CharacterCodes.dot) { |
| 255 | pos++; |
| 256 | if (pos < text.length && isDigit(text.charCodeAt(pos))) { |
| 257 | pos++; |
| 258 | while (pos < text.length && isDigit(text.charCodeAt(pos))) { |
no outgoing calls
searching dependent graphs…