Last change
on this file since 344 was 325, checked in by alloc, 6 years ago |
Code style cleanup (mostly whitespace changes, enforcing braces, using cleanup)
|
File size:
902 bytes
|
Line | |
---|
1 | using System.Text;
|
---|
2 |
|
---|
3 | namespace AllocsFixes.JSON {
|
---|
4 | public class JSONBoolean : JSONValue {
|
---|
5 | private readonly bool value;
|
---|
6 |
|
---|
7 | public JSONBoolean (bool value) {
|
---|
8 | this.value = value;
|
---|
9 | }
|
---|
10 |
|
---|
11 | public bool GetBool () {
|
---|
12 | return value;
|
---|
13 | }
|
---|
14 |
|
---|
15 | public override void ToString (StringBuilder stringBuilder, bool prettyPrint = false, int currentLevel = 0) {
|
---|
16 | stringBuilder.Append (value ? "true" : "false");
|
---|
17 | }
|
---|
18 |
|
---|
19 | public static JSONBoolean Parse (string json, ref int offset) {
|
---|
20 | //Log.Out ("ParseBool enter (" + offset + ")");
|
---|
21 |
|
---|
22 | if (json.Substring (offset, 4).Equals ("true")) {
|
---|
23 | //Log.Out ("JSON:Parsed Bool: true");
|
---|
24 | offset += 4;
|
---|
25 | return new JSONBoolean (true);
|
---|
26 | }
|
---|
27 |
|
---|
28 | if (json.Substring (offset, 5).Equals ("false")) {
|
---|
29 | //Log.Out ("JSON:Parsed Bool: false");
|
---|
30 | offset += 5;
|
---|
31 | return new JSONBoolean (false);
|
---|
32 | }
|
---|
33 |
|
---|
34 | throw new MalformedJSONException ("No valid boolean found");
|
---|
35 | }
|
---|
36 | }
|
---|
37 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.