MCPcopy Index your code
hub / github.com/RustPython/RustPython / _scan_once

Function _scan_once

Lib/json/scanner.py:28–63  ·  view source on GitHub ↗
(string, idx)

Source from the content-addressed store, hash-verified

26 memo = context.memo
27
28 def _scan_once(string, idx):
29 try:
30 nextchar = string[idx]
31 except IndexError:
32 raise StopIteration(idx) from None
33
34 if nextchar == '"':
35 return parse_string(string, idx + 1, strict)
36 elif nextchar == '{':
37 return parse_object((string, idx + 1), strict,
38 _scan_once, object_hook, object_pairs_hook, memo)
39 elif nextchar == '[':
40 return parse_array((string, idx + 1), _scan_once)
41 elif nextchar == 'n' and string[idx:idx + 4] == 'null':
42 return None, idx + 4
43 elif nextchar == 't' and string[idx:idx + 4] == 'true':
44 return True, idx + 4
45 elif nextchar == 'f' and string[idx:idx + 5] == 'false':
46 return False, idx + 5
47
48 m = match_number(string, idx)
49 if m is not None:
50 integer, frac, exp = m.groups()
51 if frac or exp:
52 res = parse_float(integer + (frac or '') + (exp or ''))
53 else:
54 res = parse_int(integer)
55 return res, m.end()
56 elif nextchar == 'N' and string[idx:idx + 3] == 'NaN':
57 return parse_constant('NaN'), idx + 3
58 elif nextchar == 'I' and string[idx:idx + 8] == 'Infinity':
59 return parse_constant('Infinity'), idx + 8
60 elif nextchar == '-' and string[idx:idx + 9] == '-Infinity':
61 return parse_constant('-Infinity'), idx + 9
62 else:
63 raise StopIteration(idx)
64
65 def scan_once(string, idx):
66 try:

Callers 1

scan_onceFunction · 0.85

Calls 4

parse_arrayFunction · 0.85
parse_intFunction · 0.85
groupsMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected