From e4f3dc8e268e6b515feed1b1467d67c6516d4ca6 Mon Sep 17 00:00:00 2001 From: JustinAJ Date: Tue, 3 Jun 2014 02:28:09 -0400 Subject: [PATCH] Added asDouble and find() --- Jupiter/Readable_String.h | 14 ++++++++++++-- Jupiter/Readable_String_Imp.h | 24 +++++++++++++++++++++--- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/Jupiter/Readable_String.h b/Jupiter/Readable_String.h index d3cce64..f258c89 100644 --- a/Jupiter/Readable_String.h +++ b/Jupiter/Readable_String.h @@ -26,6 +26,7 @@ #include // wchar_t #include // FILE #include // std::basic_string type +#include "InvalidIndex.h" namespace Jupiter { @@ -70,6 +71,14 @@ namespace Jupiter */ bool contains(const T &value) const; + /** + * @brief Returns the index of the first element in the string with the specified value. + * + * @param value Value of the element to search for. + * @return The index of an element if one is found, INVALID_INDEX otherwise. + */ + size_t find(const T &value) const; + /** * @brief Compares another string against the String. * @@ -146,15 +155,16 @@ namespace Jupiter * @return Integer representation of the string. */ int asInt(int base = 0) const; + unsigned int asUnsignedInt(int base = 0) const; /** - * @brief Interprets the string as an integer. + * @brief Interprets the string as a floating-point decimal number. * Note: This returns 0 on any value string type other than char. * * @param base Base of the string representation. * @return Integer representation of the string. */ - unsigned int asUnsignedInt(int base = 0) const; + double asDouble() const; /** * @brief Outputs the string to a FILE stream. diff --git a/Jupiter/Readable_String_Imp.h b/Jupiter/Readable_String_Imp.h index 0f4e227..520f2f5 100644 --- a/Jupiter/Readable_String_Imp.h +++ b/Jupiter/Readable_String_Imp.h @@ -40,6 +40,14 @@ template bool Jupiter::Readable_String::contains(const T &value) return false; } +// find + +template size_t Jupiter::Readable_String::find(const T &value) const +{ + for (size_t i = 0; i != this->size(); i++) if (this->get(i) == value) return i; + return Jupiter::INVALID_INDEX; +} + // compare() template int Jupiter::Readable_String::compare(const Jupiter::Readable_String &in) const @@ -682,6 +690,16 @@ template unsigned int Jupiter::Readable_String::wordCount(const T // as +template<> int inline Jupiter::Readable_String::asInt(int base) const +{ + return strtoi_s(this->ptr(), this->size(), base); +} + +template int Jupiter::Readable_String::asInt(int base) const +{ + return 0; +} + template<> unsigned int inline Jupiter::Readable_String::asUnsignedInt(int base) const { return strtoui_s(this->ptr(), this->size(), base); @@ -692,12 +710,12 @@ template unsigned int Jupiter::Readable_String::asUnsignedInt(int return 0; } -template<> int inline Jupiter::Readable_String::asInt(int base) const +template<> double inline Jupiter::Readable_String::asDouble() const { - return strtoi_s(this->ptr(), this->size(), base); + return Jupiter_strtod_s(this->ptr(), this->size()); } -template int Jupiter::Readable_String::asInt(int base) const +template double Jupiter::Readable_String::asDouble() const { return 0; }