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
Line 
1using System;
2using System.Text;
3
4namespace AllocsFixes.JSON
5{
6 public class JSONBoolean : JSONValue
7 {
8 private bool value;
9
10 public JSONBoolean (bool value)
11 {
12 this.value = value;
13 }
14
15 public bool GetBool ()
16 {
17 return value;
18 }
19
20 public override void ToString (StringBuilder stringBuilder, bool prettyPrint = false, int currentLevel = 0)
21 {
22 stringBuilder.Append (value ? "true" : "false");
23 }
24
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
42 }
43}
44
Note: See TracBrowser for help on using the repository browser.