Last change
on this file since 390 was 389, checked in by alloc, 2 years ago |
Finished up REST API base
Made API handler look for APIs in all loaded mods
|
File size:
1.0 KB
|
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 |
|
---|
[351] | 7 | public JSONBoolean (bool _value) {
|
---|
| 8 | value = _value;
|
---|
[154] | 9 | }
|
---|
| 10 |
|
---|
[325] | 11 | public bool GetBool () {
|
---|
[187] | 12 | return value;
|
---|
| 13 | }
|
---|
| 14 |
|
---|
[351] | 15 | public override void ToString (StringBuilder _stringBuilder, bool _prettyPrint = false, int _currentLevel = 0) {
|
---|
| 16 | _stringBuilder.Append (value ? "true" : "false");
|
---|
[154] | 17 | }
|
---|
| 18 |
|
---|
[351] | 19 | public static JSONBoolean Parse (string _json, ref int _offset) {
|
---|
[187] | 20 | //Log.Out ("ParseBool enter (" + offset + ")");
|
---|
| 21 |
|
---|
[351] | 22 | if (_json.Substring (_offset, 4).Equals ("true")) {
|
---|
[187] | 23 | //Log.Out ("JSON:Parsed Bool: true");
|
---|
[351] | 24 | _offset += 4;
|
---|
[187] | 25 | return new JSONBoolean (true);
|
---|
[325] | 26 | }
|
---|
| 27 |
|
---|
[351] | 28 | if (_json.Substring (_offset, 5).Equals ("false")) {
|
---|
[187] | 29 | //Log.Out ("JSON:Parsed Bool: false");
|
---|
[351] | 30 | _offset += 5;
|
---|
[187] | 31 | return new JSONBoolean (false);
|
---|
| 32 | }
|
---|
[325] | 33 |
|
---|
| 34 | throw new MalformedJSONException ("No valid boolean found");
|
---|
[187] | 35 | }
|
---|
[389] | 36 |
|
---|
| 37 | public override string AsString => value ? "true" : "false";
|
---|
| 38 | public override int AsInt => value ? 1 : 0;
|
---|
| 39 | public override double AsDouble => AsInt;
|
---|
[154] | 40 | }
|
---|
[325] | 41 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.