diff --git a/Jupiter/Readable_String.h b/Jupiter/Readable_String.h index f258c89..fbc2d30 100644 --- a/Jupiter/Readable_String.h +++ b/Jupiter/Readable_String.h @@ -147,6 +147,13 @@ namespace Jupiter */ unsigned int wordCount(const T *whitespace) const; + /** + * @brief Interprets the string as a bool. + * + * @return Bool interpretation of the string. + */ + bool asBool() const; + /** * @brief Interprets the string as an integer. * Note: This returns 0 on any value string type other than char. diff --git a/Jupiter/Readable_String_Imp.h b/Jupiter/Readable_String_Imp.h index 520f2f5..876d439 100644 --- a/Jupiter/Readable_String_Imp.h +++ b/Jupiter/Readable_String_Imp.h @@ -690,6 +690,29 @@ template unsigned int Jupiter::Readable_String::wordCount(const T // as +template<> bool inline Jupiter::Readable_String::asBool() const +{ + if (this->equalsi("FALSE")) return false; + if (this->equalsi('0')) return false; + if (this->equalsi("OFF")) return false; + if (this->equalsi('-')) return false; + return true; +} + +template<> bool inline Jupiter::Readable_String::asBool() const +{ + if (this->equalsi(L"FALSE")) return false; + if (this->equalsi(L'0')) return false; + if (this->equalsi(L"OFF")) return false; + if (this->equalsi(L'-')) return false; + return true; +} + +template bool Jupiter::Readable_String::asBool() const +{ + return false; +} + template<> int inline Jupiter::Readable_String::asInt(int base) const { return strtoi_s(this->ptr(), this->size(), base);