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

Last change on this file since 291 was 188, checked in by alloc, 10 years ago

fixes

File size: 1.2 KB
RevLine 
[188]1using System;
2using System.Text;
3
4namespace AllocsFixes.JSON
5{
6 public class Parser
7 {
8
9 public static JSONNode Parse (string json)
10 {
11 int offset = 0;
12 return ParseInternal (json, ref offset);
13 }
14
15 public static JSONNode ParseInternal (string json, ref int offset)
16 {
17 SkipWhitespace (json, ref offset);
18 //Log.Out ("ParseInternal (" + offset + "): Decide on: '" + json [offset] + "'");
19 switch (json [offset]) {
20 case '[':
21 return JSONArray.Parse (json, ref offset);
22 case '{':
23 return JSONObject.Parse (json, ref offset);
24 case '"':
25 return JSONString.Parse (json, ref offset);
26 case 't':
27 case 'f':
28 return JSONBoolean.Parse (json, ref offset);
29 case 'n':
30 return JSONNull.Parse (json, ref offset);
31 default:
32 return JSONNumber.Parse (json, ref offset);
33 }
34 }
35
36 public static void SkipWhitespace (string json, ref int offset)
37 {
38 //Log.Out ("SkipWhitespace (" + offset + "): '" + json [offset] + "'");
39 while (offset < json.Length) {
40 switch (json [offset]) {
41 case ' ':
42 case '\t':
43 case '\r':
44 case '\n':
45 offset++;
46 break;
47 default:
48 return;
49 }
50 }
51 throw new MalformedJSONException ("End of JSON reached before parsing finished");
52 }
53
54
55 }
56}
57
Note: See TracBrowser for help on using the repository browser.