source: binary-improvements/7dtd-server-fixes/src/JSON/Parser.cs@ 430

Last change on this file since 430 was 351, checked in by alloc, 6 years ago

Fixed game version compatibility of GamePrefs
Code style cleanup (mostly argument names)

File size: 1.2 KB
RevLine 
[325]1namespace AllocsFixes.JSON {
2 public class Parser {
[351]3 public static JSONNode Parse (string _json) {
[188]4 int offset = 0;
[351]5 return ParseInternal (_json, ref offset);
[188]6 }
7
[351]8 public static JSONNode ParseInternal (string _json, ref int _offset) {
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 '[':
[351]14 return JSONArray.Parse (_json, ref _offset);
[188]15 case '{':
[351]16 return JSONObject.Parse (_json, ref _offset);
[188]17 case '"':
[351]18 return JSONString.Parse (_json, ref _offset);
[188]19 case 't':
20 case 'f':
[351]21 return JSONBoolean.Parse (_json, ref _offset);
[188]22 case 'n':
[351]23 return JSONNull.Parse (_json, ref _offset);
[188]24 default:
[351]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
[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.