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

Last change on this file since 323 was 309, checked in by alloc, 7 years ago

Fixes 14_16_21

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