source: binary-improvements/7dtd-server-fixes/src/JSON/JSONBoolean.cs@ 269

Last change on this file since 269 was 187, checked in by alloc, 10 years ago

fixes

File size: 922 bytes
Line 
1using System;
2
3namespace AllocsFixes.JSON
4{
5 public class JSONBoolean : JSONNode
6 {
7 private bool value;
8
9 public JSONBoolean (bool value)
10 {
11 this.value = value;
12 }
13
14 public bool GetBool ()
15 {
16 return value;
17 }
18
19 public override string ToString (bool prettyPrint = false, int currentLevel = 0)
20 {
21 return value.ToString (System.Globalization.CultureInfo.InvariantCulture).ToLower ();
22 }
23
24 public static JSONBoolean Parse (string json, ref int offset)
25 {
26 //Log.Out ("ParseBool enter (" + offset + ")");
27
28 if (json.Substring (offset, 4).Equals ("true")) {
29 //Log.Out ("JSON:Parsed Bool: true");
30 offset += 4;
31 return new JSONBoolean (true);
32 } else if (json.Substring (offset, 5).Equals ("false")) {
33 //Log.Out ("JSON:Parsed Bool: false");
34 offset += 5;
35 return new JSONBoolean (false);
36 } else {
37 throw new MalformedJSONException ("No valid boolean found");
38 }
39 }
40
41 }
42}
43
Note: See TracBrowser for help on using the repository browser.