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
|
Rev | Line | |
---|
[325] | 1 | namespace AllocsFixes.JSON {
|
---|
| 2 | public class Parser {
|
---|
| 3 | public static JSONNode Parse (string json) {
|
---|
[188] | 4 | int offset = 0;
|
---|
| 5 | return ParseInternal (json, ref offset);
|
---|
| 6 | }
|
---|
| 7 |
|
---|
[325] | 8 | public static JSONNode ParseInternal (string json, ref int offset) {
|
---|
[188] | 9 | SkipWhitespace (json, ref offset);
|
---|
[325] | 10 |
|
---|
[188] | 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 |
|
---|
[325] | 29 | public static void SkipWhitespace (string json, ref int offset) {
|
---|
[188] | 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 | }
|
---|
[325] | 43 |
|
---|
[188] | 44 | throw new MalformedJSONException ("End of JSON reached before parsing finished");
|
---|
| 45 | }
|
---|
| 46 | }
|
---|
[325] | 47 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.