MCPcopy
hub / github.com/microsoft/vscode / createScanner

Function createScanner

src/vs/base/common/json.ts:201–559  ·  view source on GitHub ↗
(text: string, ignoreTrivia: boolean = false)

Source from the content-addressed store, hash-verified

199 * If ignoreTrivia is set, whitespaces or comments are ignored.
200 */
201export 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))) {

Callers 6

openInEditorFunction · 0.90
assertKindsFunction · 0.90
assertScanErrorFunction · 0.90
formatFunction · 0.90
visitFunction · 0.70

Calls

no outgoing calls

Tested by 2

assertKindsFunction · 0.72
assertScanErrorFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…