Last change
on this file since 336 was 325, checked in by alloc, 6 years ago |
Code style cleanup (mostly whitespace changes, enforcing braces, using cleanup)
|
File size:
1.2 KB
|
Line | |
---|
1 | namespace AllocsFixes.JSON {
|
---|
2 | public 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.