Line | |
---|
1 | namespace AllocsFixes.JSON {
|
---|
2 | public static class Parser {
|
---|
3 | public static JsonNode Parse (string _json) {
|
---|
4 | int offset = 0;
|
---|
5 | return ParseInternal (_json, ref offset);
|
---|
6 | }
|
---|
7 |
|
---|
8 | public static JsonNode ParseInternal (string _json, ref int _offset) {
|
---|
9 | SkipWhitespace (_json, ref _offset);
|
---|
10 |
|
---|
11 | //Log.Out ("ParseInternal (" + offset + "): Decide on: '" + json [offset] + "'");
|
---|
12 | switch (_json [_offset]) {
|
---|
13 | case '[':
|
---|
14 | return JsonArray.Parse (_json, ref _offset);
|
---|
15 | case '{':
|
---|
16 | return JsonObject.Parse (_json, ref _offset);
|
---|
17 | case '"':
|
---|
18 | return JsonString.Parse (_json, ref _offset);
|
---|
19 | case 't':
|
---|
20 | case 'f':
|
---|
21 | return JsonBoolean.Parse (_json, ref _offset);
|
---|
22 | case 'n':
|
---|
23 | return JsonNull.Parse (_json, ref _offset);
|
---|
24 | default:
|
---|
25 | return JsonNumber.Parse (_json, ref _offset);
|
---|
26 | }
|
---|
27 | }
|
---|
28 |
|
---|
29 | public static void SkipWhitespace (string _json, ref int _offset) {
|
---|
30 | //Log.Out ("SkipWhitespace (" + offset + "): '" + json [offset] + "'");
|
---|
31 | while (_offset < _json.Length) {
|
---|
32 | switch (_json [_offset]) {
|
---|
33 | case ' ':
|
---|
34 | case '\t':
|
---|
35 | case '\r':
|
---|
36 | case '\n':
|
---|
37 | _offset++;
|
---|
38 | break;
|
---|
39 | default:
|
---|
40 | return;
|
---|
41 | }
|
---|
42 | }
|
---|
43 |
|
---|
44 | throw new MalformedJsonException ("End of JSON reached before parsing finished");
|
---|
45 | }
|
---|
46 | }
|
---|
47 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.