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