Browse Source

Added asDouble and find()

release/0.19
JustinAJ 10 years ago
parent
commit
e4f3dc8e26
  1. 14
      Jupiter/Readable_String.h
  2. 24
      Jupiter/Readable_String_Imp.h

14
Jupiter/Readable_String.h

@ -26,6 +26,7 @@
#include <cwchar> // wchar_t
#include <cstdio> // FILE
#include <string> // std::basic_string<T> 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.

24
Jupiter/Readable_String_Imp.h

@ -40,6 +40,14 @@ template<typename T> bool Jupiter::Readable_String<T>::contains(const T &value)
return false;
}
// find
template<typename T> size_t Jupiter::Readable_String<T>::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<typename T> int Jupiter::Readable_String<T>::compare(const Jupiter::Readable_String<T> &in) const
@ -682,6 +690,16 @@ template<typename T> unsigned int Jupiter::Readable_String<T>::wordCount(const T
// as<type>
template<> int inline Jupiter::Readable_String<char>::asInt(int base) const
{
return strtoi_s(this->ptr(), this->size(), base);
}
template<typename T> int Jupiter::Readable_String<T>::asInt(int base) const
{
return 0;
}
template<> unsigned int inline Jupiter::Readable_String<char>::asUnsignedInt(int base) const
{
return strtoui_s(this->ptr(), this->size(), base);
@ -692,12 +710,12 @@ template<typename T> unsigned int Jupiter::Readable_String<T>::asUnsignedInt(int
return 0;
}
template<> int inline Jupiter::Readable_String<char>::asInt(int base) const
template<> double inline Jupiter::Readable_String<char>::asDouble() const
{
return strtoi_s(this->ptr(), this->size(), base);
return Jupiter_strtod_s(this->ptr(), this->size());
}
template<typename T> int Jupiter::Readable_String<T>::asInt(int base) const
template<typename T> double Jupiter::Readable_String<T>::asDouble() const
{
return 0;
}

Loading…
Cancel
Save