From 3ac6af88a3275de294fed1864e8fc2e6442197d5 Mon Sep 17 00:00:00 2001 From: Damian Day Date: Tue, 26 May 2020 20:56:19 +0100 Subject: [PATCH] Bool Parse Implemented parsing boolean strings. This implementation does not trim whitespace and nulls and check strings if the string does not match at first like C#. --- BeefLibs/corlib/src/Boolean.bf | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/BeefLibs/corlib/src/Boolean.bf b/BeefLibs/corlib/src/Boolean.bf index eea5a28c..57b6be83 100644 --- a/BeefLibs/corlib/src/Boolean.bf +++ b/BeefLibs/corlib/src/Boolean.bf @@ -2,14 +2,38 @@ namespace System { struct Boolean : bool, IHashable { + // + // Public Constants + // + + // The public string representation of true. + public const String TrueString = "True"; + + // The public string representation of false. + public const String FalseString = "False"; + public override void ToString(String strBuffer) { - strBuffer.Append(((bool)this) ? "true" : "false"); + strBuffer.Append(((bool)this) ? TrueString : FalseString); } public int GetHashCode() { return ((bool)this) ? 1 : 0; } + + public static Result Parse(StringView val) + { + if (val.IsEmpty) + return .Err; + + if (val.Equals(TrueString, true)) + return true; + + if (val.Equals(FalseString, true)) + return false; + + return .Err; + } } }