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