Browse Source

Changed many input variables to Readable_String. Moved comparative operators to Readable_String. Moved getWord and gotoWord templates to Readable_String.

release/0.19
JustinAJ 11 years ago
parent
commit
70b1af0d3c
  1. 30
      Jupiter/CString.h
  2. 36
      Jupiter/CString_Imp.h
  3. 58
      Jupiter/Readable_String.h
  4. 102
      Jupiter/Readable_String_Imp.h
  5. 26
      Jupiter/String.h
  6. 32
      Jupiter/String_Imp.h
  7. 65
      Jupiter/String_Type.h
  8. 110
      Jupiter/String_Type_Imp.h

30
Jupiter/CString.h

@ -115,7 +115,7 @@ namespace Jupiter
* @param pos Position in the string to start copying from. * @param pos Position in the string to start copying from.
* @return String containing a partial copy of the original string. * @return String containing a partial copy of the original string.
*/ */
static CString_Type<T> substring(const Jupiter::String_Type<T> &in, size_t pos); static CString_Type<T> substring(const Jupiter::Readable_String<T> &in, size_t pos);
static CString_Type<T> substring(const T *in, size_t pos); static CString_Type<T> substring(const T *in, size_t pos);
/** /**
@ -126,7 +126,7 @@ namespace Jupiter
* @param length Number of characters to copy. * @param length Number of characters to copy.
* @return String containing a partial copy of the original string. * @return String containing a partial copy of the original string.
*/ */
static CString_Type<T> substring(const Jupiter::String_Type<T> &in, size_t pos, size_t length); static CString_Type<T> substring(const Jupiter::Readable_String<T> &in, size_t pos, size_t length);
static CString_Type<T> substring(const T *in, size_t pos, size_t length); static CString_Type<T> substring(const T *in, size_t pos, size_t length);
/** /**
@ -146,7 +146,7 @@ namespace Jupiter
* @param whitespace A string of tokens used to deliminate words. * @param whitespace A string of tokens used to deliminate words.
* @return String containing a partial copy of the original string. * @return String containing a partial copy of the original string.
*/ */
static CString_Type<T> getWord(const Jupiter::String_Type<T> &in, size_t pos, const T *whitespace); static CString_Type<T> getWord(const Jupiter::Readable_String<T> &in, size_t pos, const T *whitespace);
/** /**
* @brief Creates a partial copy of an input string, based on a set of tokens. * @brief Creates a partial copy of an input string, based on a set of tokens.
@ -175,7 +175,7 @@ namespace Jupiter
* @param whitespace A string of tokens used to deliminate words. * @param whitespace A string of tokens used to deliminate words.
* @return String containing a partial copy of the original string. * @return String containing a partial copy of the original string.
*/ */
static CString_Type<T> gotoWord(const Jupiter::String_Type<T> &in, size_t pos, const T *whitespace); static CString_Type<T> gotoWord(const Jupiter::Readable_String<T> &in, size_t pos, const T *whitespace);
/** /**
* @brief Copies the data from the input string to the CString. * @brief Copies the data from the input string to the CString.
@ -183,7 +183,7 @@ namespace Jupiter
* @param in String containing the data to be copied. * @param in String containing the data to be copied.
* @return New size of the CString. * @return New size of the CString.
*/ */
size_t set(const String_Type<T> &in); size_t set(const Readable_String<T> &in);
size_t set(const std::basic_string<T> &in); size_t set(const std::basic_string<T> &in);
size_t set(const T *in); size_t set(const T *in);
size_t set(const T in); size_t set(const T in);
@ -194,14 +194,14 @@ namespace Jupiter
* @param in String containing the data to be concatenated. * @param in String containing the data to be concatenated.
* @return New size of the CString. * @return New size of the CString.
*/ */
size_t concat(const String_Type<T> &in); size_t concat(const Readable_String<T> &in);
size_t concat(const std::basic_string<T> &in); size_t concat(const std::basic_string<T> &in);
size_t concat(const T *in); size_t concat(const T *in);
size_t concat(const T in); size_t concat(const T in);
/** Assignment Operators */ /** Assignment Operators */
inline CString_Type<T> &operator=(const CString_Type<T> &right) { this->set(right); return *this; }; inline CString_Type<T> &operator=(const CString_Type<T> &right) { this->set(right); return *this; };
inline CString_Type<T> &operator=(const String_Type<T> &right) { this->set(right); return *this; }; inline CString_Type<T> &operator=(const Readable_String<T> &right) { this->set(right); return *this; };
inline CString_Type<T> &operator=(const std::basic_string<T> &right) { this->set(right); return *this; }; inline CString_Type<T> &operator=(const std::basic_string<T> &right) { this->set(right); return *this; };
inline CString_Type<T> &operator=(const T *right) { this->set(right); return *this; }; inline CString_Type<T> &operator=(const T *right) { this->set(right); return *this; };
inline CString_Type<T> &operator=(const T right) { this->set(right); return *this; }; inline CString_Type<T> &operator=(const T right) { this->set(right); return *this; };
@ -223,8 +223,8 @@ namespace Jupiter
CString_Type(CString_Type<T> &&source); CString_Type(CString_Type<T> &&source);
/** Copy Constructors */ /** Copy Constructors */
CString_Type(const CString_Type<T> &in) : CString_Type((String_Type<T> &)in) {} CString_Type(const CString_Type<T> &in) : CString_Type((Readable_String<T> &)in) {}
CString_Type(const String_Type<T> &in); CString_Type(const Readable_String<T> &in);
CString_Type(const std::basic_string<T> &in); CString_Type(const std::basic_string<T> &in);
CString_Type(const T *in); CString_Type(const T *in);
@ -297,7 +297,7 @@ namespace Jupiter
* @param pos Position in the string to start copying from. * @param pos Position in the string to start copying from.
* @return String containing a partial copy of the original string. * @return String containing a partial copy of the original string.
*/ */
static CString_Loose<T> substring(const Jupiter::String_Type<T> &in, size_t pos); static CString_Loose<T> substring(const Jupiter::Readable_String<T> &in, size_t pos);
static CString_Loose<T> substring(const T *in, size_t pos); static CString_Loose<T> substring(const T *in, size_t pos);
/** /**
@ -308,7 +308,7 @@ namespace Jupiter
* @param length Number of characters to copy. * @param length Number of characters to copy.
* @return String containing a partial copy of the original string. * @return String containing a partial copy of the original string.
*/ */
static CString_Loose<T> substring(const Jupiter::String_Type<T> &in, size_t pos, size_t length); static CString_Loose<T> substring(const Jupiter::Readable_String<T> &in, size_t pos, size_t length);
static CString_Loose<T> substring(const T *in, size_t pos, size_t length); static CString_Loose<T> substring(const T *in, size_t pos, size_t length);
/** /**
@ -329,7 +329,7 @@ namespace Jupiter
* @param whitespace A string of tokens used to deliminate words. * @param whitespace A string of tokens used to deliminate words.
* @return String containing a partial copy of the original string. * @return String containing a partial copy of the original string.
*/ */
static CString_Loose<T> getWord(const Jupiter::String_Type<T> &in, size_t pos, const T *whitespace); static CString_Loose<T> getWord(const Jupiter::Readable_String<T> &in, size_t pos, const T *whitespace);
/** /**
* @brief Creates a partial copy of an input string, based on a set of tokens. * @brief Creates a partial copy of an input string, based on a set of tokens.
@ -359,7 +359,7 @@ namespace Jupiter
* @param whitespace A string of tokens used to deliminate words. * @param whitespace A string of tokens used to deliminate words.
* @return String containing a partial copy of the original string. * @return String containing a partial copy of the original string.
*/ */
static CString_Loose<T> gotoWord(const Jupiter::String_Type<T> &in, size_t pos, const T *whitespace); static CString_Loose<T> gotoWord(const Jupiter::Readable_String<T> &in, size_t pos, const T *whitespace);
/** Default constructor */ /** Default constructor */
CString_Loose(); CString_Loose();
@ -376,7 +376,7 @@ namespace Jupiter
/** Copy Constructors */ /** Copy Constructors */
CString_Loose(const CString_Loose &in); CString_Loose(const CString_Loose &in);
CString_Loose(const String_Type<T> &in); CString_Loose(const Readable_String<T> &in);
CString_Loose(const std::basic_string<T> &in); CString_Loose(const std::basic_string<T> &in);
CString_Loose(const T *in); CString_Loose(const T *in);
@ -386,7 +386,7 @@ namespace Jupiter
/** Assignment Operators */ /** Assignment Operators */
inline CString_Loose<T> &operator=(const CString_Loose<T> &right) { this->set(right); return *this; }; inline CString_Loose<T> &operator=(const CString_Loose<T> &right) { this->set(right); return *this; };
inline CString_Loose<T> &operator=(const CString_Type<T> &right) { this->set(right); return *this; }; inline CString_Loose<T> &operator=(const CString_Type<T> &right) { this->set(right); return *this; };
inline CString_Loose<T> &operator=(const String_Type<T> &right) { this->set(right); return *this; }; inline CString_Loose<T> &operator=(const Readable_String<T> &right) { this->set(right); return *this; };
inline CString_Loose<T> &operator=(const std::basic_string<T> &right) { this->set(right); return *this; }; inline CString_Loose<T> &operator=(const std::basic_string<T> &right) { this->set(right); return *this; };
inline CString_Loose<T> &operator=(const T *right) { this->set(right); return *this; }; inline CString_Loose<T> &operator=(const T *right) { this->set(right); return *this; };
inline CString_Loose<T> &operator=(const T right) { this->set(right); return *this; }; inline CString_Loose<T> &operator=(const T right) { this->set(right); return *this; };

36
Jupiter/CString_Imp.h

@ -59,7 +59,7 @@ template<typename T> Jupiter::CString_Type<T>::CString_Type(Jupiter::CString_Typ
{ {
} }
template<typename T> Jupiter::CString_Type<T>::CString_Type(const Jupiter::String_Type<T> &in) : Jupiter::CString_Type<T>::CString_Type(in.size()) template<typename T> Jupiter::CString_Type<T>::CString_Type(const Jupiter::Readable_String<T> &in) : Jupiter::CString_Type<T>::CString_Type(in.size())
{ {
while (Jupiter::String_Type<T>::length < in.size() && in.get(Jupiter::String_Type<T>::length) != 0) while (Jupiter::String_Type<T>::length < in.size() && in.get(Jupiter::String_Type<T>::length) != 0)
{ {
@ -233,7 +233,7 @@ template<typename T> Jupiter::CString_Type<T> Jupiter::CString_Type<T>::substrin
return Jupiter::CString_Type<T>::substring(*this, pos, len); return Jupiter::CString_Type<T>::substring(*this, pos, len);
} }
template<typename T> Jupiter::CString_Type<T> Jupiter::CString_Type<T>::substring(const Jupiter::String_Type<T> &in, size_t pos) template<typename T> Jupiter::CString_Type<T> Jupiter::CString_Type<T>::substring(const Jupiter::Readable_String<T> &in, size_t pos)
{ {
if (pos >= in.size()) return Jupiter::CString_Type<T>(); if (pos >= in.size()) return Jupiter::CString_Type<T>();
Jupiter::CString_Type<T> r = Jupiter::CString_Type<T>(in.size() - pos); Jupiter::CString_Type<T> r = Jupiter::CString_Type<T>(in.size() - pos);
@ -249,7 +249,7 @@ template<typename T> Jupiter::CString_Type<T> Jupiter::CString_Type<T>::substrin
return r; return r;
} }
template<typename T> Jupiter::CString_Type<T> Jupiter::CString_Type<T>::substring(const Jupiter::String_Type<T> &in, size_t pos, size_t len) template<typename T> Jupiter::CString_Type<T> Jupiter::CString_Type<T>::substring(const Jupiter::Readable_String<T> &in, size_t pos, size_t len)
{ {
if (pos + len >= in.size()) return Jupiter::CString_Type<T>::substring(in, pos); if (pos + len >= in.size()) return Jupiter::CString_Type<T>::substring(in, pos);
Jupiter::CString_Type<T> r = Jupiter::CString_Type<T>(len); Jupiter::CString_Type<T> r = Jupiter::CString_Type<T>(len);
@ -270,14 +270,14 @@ template<typename T> Jupiter::CString_Type<T> Jupiter::CString_Type<T>::getWord(
return Jupiter::CString_Type<T>::getWord(*this, pos, whitespace); return Jupiter::CString_Type<T>::getWord(*this, pos, whitespace);
} }
template<typename T> Jupiter::CString_Type<T> Jupiter::CString_Type<T>::getWord(const Jupiter::String_Type<T> &in, size_t pos, const T *whitespace) template<typename T> Jupiter::CString_Type<T> Jupiter::CString_Type<T>::getWord(const Jupiter::Readable_String<T> &in, size_t pos, const T *whitespace)
{ {
return Jupiter::String_Type<T>::getWord<Jupiter::CString_Type>(in, pos, whitespace); return Jupiter::Readable_String<T>::getWord<Jupiter::CString_Type>(in, pos, whitespace);
} }
template<typename T> Jupiter::CString_Type<T> Jupiter::CString_Type<T>::getWord(const T *in, size_t pos, const T *whitespace) template<typename T> Jupiter::CString_Type<T> Jupiter::CString_Type<T>::getWord(const T *in, size_t pos, const T *whitespace)
{ {
return Jupiter::String_Type<T>::getWord<Jupiter::CString_Type>(in, pos, whitespace); return Jupiter::Readable_String<T>::getWord<Jupiter::CString_Type>(in, pos, whitespace);
} }
template<typename T> Jupiter::CString_Type<T> Jupiter::CString_Type<T>::gotoWord(size_t pos, const T *whitespace) const template<typename T> Jupiter::CString_Type<T> Jupiter::CString_Type<T>::gotoWord(size_t pos, const T *whitespace) const
@ -285,12 +285,12 @@ template<typename T> Jupiter::CString_Type<T> Jupiter::CString_Type<T>::gotoWord
return Jupiter::CString_Type<T>::gotoWord(*this, pos, whitespace); return Jupiter::CString_Type<T>::gotoWord(*this, pos, whitespace);
} }
template<typename T> Jupiter::CString_Type<T> Jupiter::CString_Type<T>::gotoWord(const Jupiter::String_Type<T> &in, size_t pos, const T *whitespace) template<typename T> Jupiter::CString_Type<T> Jupiter::CString_Type<T>::gotoWord(const Jupiter::Readable_String<T> &in, size_t pos, const T *whitespace)
{ {
return Jupiter::String_Type<T>::gotoWord<Jupiter::CString_Type>(in, pos, whitespace); return Jupiter::Readable_String<T>::gotoWord<Jupiter::CString_Type>(in, pos, whitespace);
} }
template<typename T> size_t Jupiter::CString_Type<T>::set(const String_Type<T> &in) template<typename T> size_t Jupiter::CString_Type<T>::set(const Jupiter::Readable_String<T> &in)
{ {
this->setBufferSizeNoCopy(in.size()); this->setBufferSizeNoCopy(in.size());
for (Jupiter::String_Type<T>::length = 0; Jupiter::String_Type<T>::length < in.size() && in.get(Jupiter::String_Type<T>::length) != 0; Jupiter::String_Type<T>::length++) for (Jupiter::String_Type<T>::length = 0; Jupiter::String_Type<T>::length < in.size() && in.get(Jupiter::String_Type<T>::length) != 0; Jupiter::String_Type<T>::length++)
@ -326,7 +326,7 @@ template<typename T> size_t Jupiter::CString_Type<T>::set(const T in)
return Jupiter::String_Type<T>::length = 1; return Jupiter::String_Type<T>::length = 1;
} }
template<typename T> size_t Jupiter::CString_Type<T>::concat(const String_Type<T> &in) template<typename T> size_t Jupiter::CString_Type<T>::concat(const Jupiter::Readable_String<T> &in)
{ {
size_t nSize = Jupiter::String_Type<T>::length + in.size(); size_t nSize = Jupiter::String_Type<T>::length + in.size();
const T *inData = in.ptr(); const T *inData = in.ptr();
@ -408,7 +408,7 @@ template<typename T> Jupiter::CString_Loose<T>::CString_Loose(const Jupiter::CSt
Jupiter::String_Type<T>::length = in.length; Jupiter::String_Type<T>::length = in.length;
} }
template<typename T> Jupiter::CString_Loose<T>::CString_Loose(const Jupiter::String_Type<T> &in) : Jupiter::CString_Loose<T>::CString_Loose(in.size()) template<typename T> Jupiter::CString_Loose<T>::CString_Loose(const Jupiter::Readable_String<T> &in) : Jupiter::CString_Loose<T>::CString_Loose(in.size())
{ {
while (Jupiter::String_Type<T>::length < in.size() && in.get(Jupiter::String_Type<T>::length) != 0) while (Jupiter::String_Type<T>::length < in.size() && in.get(Jupiter::String_Type<T>::length) != 0)
{ {
@ -503,7 +503,7 @@ template<typename T> Jupiter::CString_Loose<T> Jupiter::CString_Loose<T>::substr
return Jupiter::CString_Loose<T>::substring(*this, pos, length); return Jupiter::CString_Loose<T>::substring(*this, pos, length);
} }
template<typename T> Jupiter::CString_Loose<T> Jupiter::CString_Loose<T>::substring(const Jupiter::String_Type<T> &in, size_t pos) template<typename T> Jupiter::CString_Loose<T> Jupiter::CString_Loose<T>::substring(const Jupiter::Readable_String<T> &in, size_t pos)
{ {
if (pos > in.size()) return Jupiter::CString_Loose<T>(); if (pos > in.size()) return Jupiter::CString_Loose<T>();
Jupiter::CString_Loose<T> r = Jupiter::CString_Loose<T>(in.size() - pos); Jupiter::CString_Loose<T> r = Jupiter::CString_Loose<T>(in.size() - pos);
@ -519,7 +519,7 @@ template<typename T> Jupiter::CString_Loose<T> Jupiter::CString_Loose<T>::substr
return r; return r;
} }
template<typename T> Jupiter::CString_Loose<T> Jupiter::CString_Loose<T>::substring(const Jupiter::String_Type<T> &in, size_t pos, size_t len) template<typename T> Jupiter::CString_Loose<T> Jupiter::CString_Loose<T>::substring(const Jupiter::Readable_String<T> &in, size_t pos, size_t len)
{ {
if (pos + len >= in.size()) return Jupiter::CString_Loose<T>::substring(in, pos); if (pos + len >= in.size()) return Jupiter::CString_Loose<T>::substring(in, pos);
Jupiter::CString_Loose<T> r = Jupiter::CString_Loose<T>(len); Jupiter::CString_Loose<T> r = Jupiter::CString_Loose<T>(len);
@ -540,14 +540,14 @@ template<typename T> Jupiter::CString_Loose<T> Jupiter::CString_Loose<T>::getWor
return Jupiter::CString_Loose<T>::getWord(*this, pos, whitespace); return Jupiter::CString_Loose<T>::getWord(*this, pos, whitespace);
} }
template<typename T> Jupiter::CString_Loose<T> Jupiter::CString_Loose<T>::getWord(const Jupiter::String_Type<T> &in, size_t pos, const T *whitespace) template<typename T> Jupiter::CString_Loose<T> Jupiter::CString_Loose<T>::getWord(const Jupiter::Readable_String<T> &in, size_t pos, const T *whitespace)
{ {
return Jupiter::String_Type<T>::getWord<Jupiter::CString_Loose>(in, pos, whitespace); return Jupiter::Readable_String<T>::getWord<Jupiter::CString_Loose>(in, pos, whitespace);
} }
template<typename T> Jupiter::CString_Loose<T> Jupiter::CString_Loose<T>::getWord(const T *in, size_t pos, const T *whitespace) template<typename T> Jupiter::CString_Loose<T> Jupiter::CString_Loose<T>::getWord(const T *in, size_t pos, const T *whitespace)
{ {
return Jupiter::String_Type<T>::getWord<Jupiter::CString_Loose>(in, pos, whitespace); return Jupiter::Readable_String<T>::getWord<Jupiter::CString_Loose>(in, pos, whitespace);
} }
template<typename T> Jupiter::CString_Loose<T> Jupiter::CString_Loose<T>::gotoWord(size_t pos, const T *whitespace) const template<typename T> Jupiter::CString_Loose<T> Jupiter::CString_Loose<T>::gotoWord(size_t pos, const T *whitespace) const
@ -555,9 +555,9 @@ template<typename T> Jupiter::CString_Loose<T> Jupiter::CString_Loose<T>::gotoWo
return Jupiter::CString_Loose<T>::gotoWord(*this, pos, whitespace); return Jupiter::CString_Loose<T>::gotoWord(*this, pos, whitespace);
} }
template<typename T> Jupiter::CString_Loose<T> Jupiter::CString_Loose<T>::gotoWord(const Jupiter::String_Type<T> &in, size_t pos, const T *whitespace) template<typename T> Jupiter::CString_Loose<T> Jupiter::CString_Loose<T>::gotoWord(const Jupiter::Readable_String<T> &in, size_t pos, const T *whitespace)
{ {
return Jupiter::String_Type<T>::gotoWord<Jupiter::CString_Loose>(in, pos, whitespace); return Jupiter::Readable_String<T>::gotoWord<Jupiter::CString_Loose>(in, pos, whitespace);
} }
template<typename T> const Jupiter::CString_Loose<T> Jupiter::CString_Loose<T>::empty = Jupiter::CString_Loose<T>(); template<typename T> const Jupiter::CString_Loose<T> Jupiter::CString_Loose<T>::empty = Jupiter::CString_Loose<T>();

58
Jupiter/Readable_String.h

@ -174,9 +174,67 @@ namespace Jupiter
size_t println(FILE *out) const; size_t println(FILE *out) const;
size_t println(std::basic_ostream<T> &out) const; size_t println(std::basic_ostream<T> &out) const;
/**
* @brief Copies a "word" from an input string and returns it in an output type.
*
* @param R Type to return. Must be a subclass of String_Type.
*
* @param in String to get a partial copy of.
* @param pos Index of the word to copy.
* @param whitespace String of characters that are to be considered whitespace.
* @return Copy of the word at the specified index on success, an empty string otherwise.
*/
template<template<typename> class R> static R<T> getWord(const Jupiter::Readable_String<T> &in, size_t pos, const T *whitespace);
template<template<typename> class R> static R<T> getWord(const T *in, size_t pos, const T *whitespace);
/**
* @brief Copies a part of an input string starting at a specified "word" and returns it in an output type.
*
* @param R Type to return. Must be a subclass of String_Type.
*
* @param in String to get a partial copy of.
* @param pos Index of the word to start copying from.
* @param whitespace String of characters that are to be considered whitespace.
* @return Copy of the string starting at the specified word on success, an empty string otherwise.
*/
template<template<typename> class R> static R<T> gotoWord(const Jupiter::Readable_String<T> &in, size_t pos, const T *whitespace);
template<template<typename> class R> static R<T> gotoWord(const T *in, size_t pos, const T *whitespace);
/** Access operator */ /** Access operator */
inline T &operator[](size_t index) const { return this->get(index); }; inline T &operator[](size_t index) const { return this->get(index); };
/** Comparative operators */
inline bool operator==(const Readable_String<T> &right)const{ return this->equals(right); }
inline bool operator==(const std::basic_string<T> &right)const{ return this->equals(right); }
inline bool operator==(const T *right)const{ return this->equals(right); }
inline bool operator==(const T right)const{ return this->equals(right); }
inline bool operator!=(const Readable_String<T> &right)const{ return !operator==(right); }
inline bool operator!=(const std::basic_string<T> &right)const{ return !operator==(right); }
inline bool operator!=(const T *right)const{ return !operator==(right); }
inline bool operator!=(const T right)const{ return !operator==(right); }
inline bool operator<(const Readable_String<T> &right)const{ return this->compare(right) < 0; }
inline bool operator<(const std::basic_string<T> &right)const{ return this->compare(right) < 0; }
inline bool operator<(const T *right)const{ return this->compare(right) < 0; }
inline bool operator<(const T right)const{ return this->compare(right) < 0; }
inline bool operator>(const Readable_String<T> &right)const{ return this->compare(right) > 0; }
inline bool operator>(const std::basic_string<T> &right)const{ return this->compare(right) > 0; }
inline bool operator>(const T *right)const{ return this->compare(right) > 0; }
inline bool operator>(const T right)const{ return this->compare(right) > 0; }
inline bool operator<=(const Readable_String<T> &right)const{ return !operator>(right); }
inline bool operator<=(const std::basic_string<T> &right)const{ return !operator>(right); }
inline bool operator<=(const T *right)const{ return !operator>(right); }
inline bool operator<=(const T right)const{ return !operator>(right); }
inline bool operator>=(const Readable_String<T> &right)const{ return !operator<(right); }
inline bool operator>=(const std::basic_string<T> &right)const{ return !operator<(right); }
inline bool operator>=(const T *right)const{ return !operator<(right); }
inline bool operator>=(const T right)const{ return !operator<(right); }
}; };
/** Generic Readable String Type */
typedef Readable_String<char> ReadableString;
/** Generic Wide Readable String Type */
typedef Readable_String<wchar_t> ReadableWString;
} }
#include "Readable_String_Imp.h" #include "Readable_String_Imp.h"

102
Jupiter/Readable_String_Imp.h

@ -743,4 +743,106 @@ template<typename T> size_t Jupiter::Readable_String<T>::println(std::basic_ostr
return r; return r;
} }
// getWord
template<typename T> template<template<typename> class R> R<T> Jupiter::Readable_String<T>::getWord(const Jupiter::Readable_String<T> &in, size_t pos, const T *whitespace)
{
unsigned int x = 0;
unsigned int y = 1;
for (unsigned int i = 0; i < pos || y == 1; x++)
{
if (x == in.size()) return R<T>();
if (Jupiter::strpbrk<T>(whitespace, in.get(x)) != nullptr)
{
if (y != 1)
{
y = 1;
i++;
}
}
else
{
if (i >= pos) break;
y = 0;
}
}
for (y = x; y != in.size() && Jupiter::strpbrk<T>(whitespace, in.get(y)) == nullptr; y++);
return R<T>::substring(in, x, y - x);
}
template<typename T> template<template<typename> class R> R<T> Jupiter::Readable_String<T>::getWord(const T *in, size_t pos, const T *whitespace)
{
unsigned int x = 0;
unsigned int y = 1;
for (unsigned int i = 0; i < pos || y == 1; x++)
{
if (in[x] == 0) return R<T>();
if (Jupiter::strpbrk<T>(whitespace, in[x]) != nullptr)
{
if (y != 1)
{
y = 1;
i++;
}
}
else
{
if (i >= pos) break;
y = 0;
}
}
for (y = x; in[y] != 0 && Jupiter::strpbrk<T>(whitespace, in[y]) == nullptr; y++);
return R<T>::substring(in, x, y - x);
}
// gotoWord
template<typename T> template<template<typename> class R> R<T> Jupiter::Readable_String<T>::gotoWord(const Jupiter::Readable_String<T> &in, size_t pos, const T *whitespace)
{
unsigned int x = 0;
bool y = true;
for (unsigned int i = 0; i < pos || y == true; x++)
{
if (x == in.size()) return R<T>();
if (Jupiter::strpbrk<T>(whitespace, in.get(x)) != nullptr)
{
if (y != true)
{
y = true;
i++;
}
}
else
{
if (i >= pos) break;
y = false;
}
}
return R<T>::substring(in, x);
}
template<typename T> template<template<typename> class R> R<T> Jupiter::Readable_String<T>::gotoWord(const T *in, size_t pos, const T *whitespace)
{
unsigned int x = 0;
bool y = true;
for (unsigned int i = 0; i < pos || y == true; x++)
{
if (in[x] == 0) return R<T>();
if (Jupiter::strpbrk<T>(whitespace, in[x]) != nullptr)
{
if (y != true)
{
y = true;
i++;
}
}
else
{
if (i >= pos) break;
y = false;
}
}
return R<T>::substring(in, x);
}
#endif // _READABLE_STRING_IMP_H_HEADER #endif // _READABLE_STRING_IMP_H_HEADER

26
Jupiter/String.h

@ -100,7 +100,7 @@ namespace Jupiter
* @param pos Position in the string to start copying from. * @param pos Position in the string to start copying from.
* @return String containing a partial copy of the original string. * @return String containing a partial copy of the original string.
*/ */
static String_Strict<T> substring(const Jupiter::String_Type<T> &in, size_t pos); static String_Strict<T> substring(const Jupiter::Readable_String<T> &in, size_t pos);
static String_Strict<T> substring(const T *in, size_t pos); static String_Strict<T> substring(const T *in, size_t pos);
/** /**
@ -111,7 +111,7 @@ namespace Jupiter
* @param length Number of characters to copy. * @param length Number of characters to copy.
* @return String containing a partial copy of the original string. * @return String containing a partial copy of the original string.
*/ */
static String_Strict<T> substring(const Jupiter::String_Type<T> &in, size_t pos, size_t length); static String_Strict<T> substring(const Jupiter::Readable_String<T> &in, size_t pos, size_t length);
static String_Strict<T> substring(const T *in, size_t pos, size_t length); static String_Strict<T> substring(const T *in, size_t pos, size_t length);
/** /**
@ -131,7 +131,7 @@ namespace Jupiter
* @param whitespace A string of tokens used to deliminate words. * @param whitespace A string of tokens used to deliminate words.
* @return String containing a partial copy of the original string. * @return String containing a partial copy of the original string.
*/ */
static String_Strict<T> getWord(const Jupiter::String_Type<T> &in, size_t pos, const T *whitespace); static String_Strict<T> getWord(const Jupiter::Readable_String<T> &in, size_t pos, const T *whitespace);
/** /**
* @brief Creates a partial copy of an input string, based on a set of tokens. * @brief Creates a partial copy of an input string, based on a set of tokens.
@ -160,11 +160,11 @@ namespace Jupiter
* @param whitespace A string of tokens used to deliminate words. * @param whitespace A string of tokens used to deliminate words.
* @return String containing a partial copy of the original string. * @return String containing a partial copy of the original string.
*/ */
static String_Strict<T> gotoWord(const Jupiter::String_Type<T> &in, size_t pos, const T *whitespace); static String_Strict<T> gotoWord(const Jupiter::Readable_String<T> &in, size_t pos, const T *whitespace);
/** Assignment Operators */ /** Assignment Operators */
inline String_Strict<T> &operator=(const String_Strict<T> &right) { this->set(right); return *this; }; inline String_Strict<T> &operator=(const String_Strict<T> &right) { this->set(right); return *this; };
inline String_Strict<T> &operator=(const String_Type<T> &right) { this->set(right); return *this; }; inline String_Strict<T> &operator=(const Readable_String<T> &right) { this->set(right); return *this; };
inline String_Strict<T> &operator=(const std::basic_string<T> &right) { this->set(right); return *this; }; inline String_Strict<T> &operator=(const std::basic_string<T> &right) { this->set(right); return *this; };
inline String_Strict<T> &operator=(const T *right) { this->set(right); return *this; }; inline String_Strict<T> &operator=(const T *right) { this->set(right); return *this; };
inline String_Strict<T> &operator=(const T right) { this->set(right); return *this; }; inline String_Strict<T> &operator=(const T right) { this->set(right); return *this; };
@ -186,8 +186,8 @@ namespace Jupiter
String_Strict(String_Strict<T> &&source); String_Strict(String_Strict<T> &&source);
/** Copy Constructors */ /** Copy Constructors */
String_Strict(const String_Strict<T> &in) : String_Strict((String_Type<T> &)in) {} String_Strict(const String_Strict<T> &in) : String_Strict((Readable_String<T> &)in) {}
String_Strict(const String_Type<T> &in); String_Strict(const Readable_String<T> &in);
String_Strict(const std::basic_string<T> &in); String_Strict(const std::basic_string<T> &in);
String_Strict(const T *in); String_Strict(const T *in);
@ -268,7 +268,7 @@ namespace Jupiter
* @param pos Position in the string to start copying from. * @param pos Position in the string to start copying from.
* @return String containing a partial copy of the original string. * @return String containing a partial copy of the original string.
*/ */
static String_Loose<T> substring(const Jupiter::String_Type<T> &in, size_t pos); static String_Loose<T> substring(const Jupiter::Readable_String<T> &in, size_t pos);
static String_Loose<T> substring(const T *in, size_t pos); static String_Loose<T> substring(const T *in, size_t pos);
/** /**
@ -279,7 +279,7 @@ namespace Jupiter
* @param length Number of characters to copy. * @param length Number of characters to copy.
* @return String containing a partial copy of the original string. * @return String containing a partial copy of the original string.
*/ */
static String_Loose<T> substring(const Jupiter::String_Type<T> &in, size_t pos, size_t length); static String_Loose<T> substring(const Jupiter::Readable_String<T> &in, size_t pos, size_t length);
static String_Loose<T> substring(const T *in, size_t pos, size_t length); static String_Loose<T> substring(const T *in, size_t pos, size_t length);
/** /**
@ -300,7 +300,7 @@ namespace Jupiter
* @param whitespace A string of tokens used to deliminate words. * @param whitespace A string of tokens used to deliminate words.
* @return String containing a partial copy of the original string. * @return String containing a partial copy of the original string.
*/ */
static String_Loose<T> getWord(const Jupiter::String_Type<T> &in, size_t pos, const T *whitespace); static String_Loose<T> getWord(const Jupiter::Readable_String<T> &in, size_t pos, const T *whitespace);
/** /**
* @brief Creates a partial copy of an input string, based on a set of tokens. * @brief Creates a partial copy of an input string, based on a set of tokens.
@ -330,7 +330,7 @@ namespace Jupiter
* @param whitespace A string of tokens used to deliminate words. * @param whitespace A string of tokens used to deliminate words.
* @return String containing a partial copy of the original string. * @return String containing a partial copy of the original string.
*/ */
static String_Loose<T> gotoWord(const Jupiter::String_Type<T> &in, size_t pos, const T *whitespace); static String_Loose<T> gotoWord(const Jupiter::Readable_String<T> &in, size_t pos, const T *whitespace);
/** Default constructor */ /** Default constructor */
String_Loose(); String_Loose();
@ -347,7 +347,7 @@ namespace Jupiter
/** Copy Constructors */ /** Copy Constructors */
String_Loose(const String_Loose &in); String_Loose(const String_Loose &in);
String_Loose(const String_Type<T> &in); String_Loose(const Readable_String<T> &in);
String_Loose(const std::basic_string<T> &in); String_Loose(const std::basic_string<T> &in);
String_Loose(const T *in); String_Loose(const T *in);
@ -356,7 +356,7 @@ namespace Jupiter
/** Assignment Operators */ /** Assignment Operators */
inline String_Loose<T> &operator=(const String_Loose<T> &right) { this->set(right); return *this; }; inline String_Loose<T> &operator=(const String_Loose<T> &right) { this->set(right); return *this; };
inline String_Loose<T> &operator=(const String_Type<T> &right) { this->set(right); return *this; }; inline String_Loose<T> &operator=(const Readable_String<T> &right) { this->set(right); return *this; };
inline String_Loose<T> &operator=(const std::basic_string<T> &right) { this->set(right); return *this; }; inline String_Loose<T> &operator=(const std::basic_string<T> &right) { this->set(right); return *this; };
inline String_Loose<T> &operator=(const T *right) { this->set(right); return *this; }; inline String_Loose<T> &operator=(const T *right) { this->set(right); return *this; };
inline String_Loose<T> &operator=(const T right) { this->set(right); return *this; }; inline String_Loose<T> &operator=(const T right) { this->set(right); return *this; };

32
Jupiter/String_Imp.h

@ -57,7 +57,7 @@ template<typename T> Jupiter::String_Strict<T>::String_Strict(Jupiter::String_St
{ {
} }
template<typename T> Jupiter::String_Strict<T>::String_Strict(const Jupiter::String_Type<T> &in) : Jupiter::String_Strict<T>::String_Strict(in.size()) template<typename T> Jupiter::String_Strict<T>::String_Strict(const Jupiter::Readable_String<T> &in) : Jupiter::String_Strict<T>::String_Strict(in.size())
{ {
while (Jupiter::String_Type<T>::length < in.size()) while (Jupiter::String_Type<T>::length < in.size())
{ {
@ -194,7 +194,7 @@ template<typename T> Jupiter::String_Strict<T> Jupiter::String_Strict<T>::substr
return Jupiter::String_Strict<T>::substring(*this, pos, len); return Jupiter::String_Strict<T>::substring(*this, pos, len);
} }
template<typename T> Jupiter::String_Strict<T> Jupiter::String_Strict<T>::substring(const Jupiter::String_Type<T> &in, size_t pos) template<typename T> Jupiter::String_Strict<T> Jupiter::String_Strict<T>::substring(const Jupiter::Readable_String<T> &in, size_t pos)
{ {
return Jupiter::String_Type<T>::substring<Jupiter::String_Strict>(in, pos); return Jupiter::String_Type<T>::substring<Jupiter::String_Strict>(in, pos);
} }
@ -204,7 +204,7 @@ template<typename T> Jupiter::String_Strict<T> Jupiter::String_Strict<T>::substr
return Jupiter::String_Type<T>::substring<Jupiter::String_Strict>(in, pos); return Jupiter::String_Type<T>::substring<Jupiter::String_Strict>(in, pos);
} }
template<typename T> Jupiter::String_Strict<T> Jupiter::String_Strict<T>::substring(const Jupiter::String_Type<T> &in, size_t pos, size_t len) template<typename T> Jupiter::String_Strict<T> Jupiter::String_Strict<T>::substring(const Jupiter::Readable_String<T> &in, size_t pos, size_t len)
{ {
return Jupiter::String_Type<T>::substring<Jupiter::String_Strict>(in, pos, len); return Jupiter::String_Type<T>::substring<Jupiter::String_Strict>(in, pos, len);
} }
@ -219,14 +219,14 @@ template<typename T> Jupiter::String_Strict<T> Jupiter::String_Strict<T>::getWor
return Jupiter::String_Strict<T>::getWord(*this, pos, whitespace); return Jupiter::String_Strict<T>::getWord(*this, pos, whitespace);
} }
template<typename T> Jupiter::String_Strict<T> Jupiter::String_Strict<T>::getWord(const Jupiter::String_Type<T> &in, size_t pos, const T *whitespace) template<typename T> Jupiter::String_Strict<T> Jupiter::String_Strict<T>::getWord(const Jupiter::Readable_String<T> &in, size_t pos, const T *whitespace)
{ {
return Jupiter::String_Type<T>::getWord<Jupiter::String_Strict>(in, pos, whitespace); return Jupiter::Readable_String<T>::getWord<Jupiter::String_Strict>(in, pos, whitespace);
} }
template<typename T> Jupiter::String_Strict<T> Jupiter::String_Strict<T>::getWord(const T *in, size_t pos, const T *whitespace) template<typename T> Jupiter::String_Strict<T> Jupiter::String_Strict<T>::getWord(const T *in, size_t pos, const T *whitespace)
{ {
return Jupiter::String_Type<T>::getWord<Jupiter::String_Strict>(in, pos, whitespace); return Jupiter::Readable_String<T>::getWord<Jupiter::String_Strict>(in, pos, whitespace);
} }
template<typename T> Jupiter::String_Strict<T> Jupiter::String_Strict<T>::gotoWord(size_t pos, const T *whitespace) const template<typename T> Jupiter::String_Strict<T> Jupiter::String_Strict<T>::gotoWord(size_t pos, const T *whitespace) const
@ -234,9 +234,9 @@ template<typename T> Jupiter::String_Strict<T> Jupiter::String_Strict<T>::gotoWo
return Jupiter::String_Strict<T>::gotoWord(*this, pos, whitespace); return Jupiter::String_Strict<T>::gotoWord(*this, pos, whitespace);
} }
template<typename T> Jupiter::String_Strict<T> Jupiter::String_Strict<T>::gotoWord(const Jupiter::String_Type<T> &in, size_t pos, const T *whitespace) template<typename T> Jupiter::String_Strict<T> Jupiter::String_Strict<T>::gotoWord(const Jupiter::Readable_String<T> &in, size_t pos, const T *whitespace)
{ {
return Jupiter::String_Type<T>::gotoWord<Jupiter::String_Strict>(in, pos, whitespace); return Jupiter::Readable_String<T>::gotoWord<Jupiter::String_Strict>(in, pos, whitespace);
} }
template<typename T> const Jupiter::String_Strict<T> Jupiter::String_Strict<T>::empty = Jupiter::String_Strict<T>(); template<typename T> const Jupiter::String_Strict<T> Jupiter::String_Strict<T>::empty = Jupiter::String_Strict<T>();
@ -275,7 +275,7 @@ template<typename T> Jupiter::String_Loose<T>::String_Loose(const Jupiter::Strin
Jupiter::String_Type<T>::str[Jupiter::String_Type<T>::length] = in.get(Jupiter::String_Type<T>::length); Jupiter::String_Type<T>::str[Jupiter::String_Type<T>::length] = in.get(Jupiter::String_Type<T>::length);
} }
template<typename T> Jupiter::String_Loose<T>::String_Loose(const Jupiter::String_Type<T> &in) : Jupiter::String_Loose<T>::String_Loose(in.size()) template<typename T> Jupiter::String_Loose<T>::String_Loose(const Jupiter::Readable_String<T> &in) : Jupiter::String_Loose<T>::String_Loose(in.size())
{ {
while (Jupiter::String_Type<T>::length < in.size()) while (Jupiter::String_Type<T>::length < in.size())
{ {
@ -434,7 +434,7 @@ template<typename T> Jupiter::String_Loose<T> Jupiter::String_Loose<T>::substrin
return Jupiter::String_Loose<T>::substring(*this, pos, length); return Jupiter::String_Loose<T>::substring(*this, pos, length);
} }
template<typename T> Jupiter::String_Loose<T> Jupiter::String_Loose<T>::substring(const Jupiter::String_Type<T> &in, size_t pos) template<typename T> Jupiter::String_Loose<T> Jupiter::String_Loose<T>::substring(const Jupiter::Readable_String<T> &in, size_t pos)
{ {
return Jupiter::String_Type<T>::substring<Jupiter::String_Loose>(in, pos); return Jupiter::String_Type<T>::substring<Jupiter::String_Loose>(in, pos);
} }
@ -444,7 +444,7 @@ template<typename T> Jupiter::String_Loose<T> Jupiter::String_Loose<T>::substrin
return Jupiter::String_Type<T>::substring<Jupiter::String_Loose>(in, pos); return Jupiter::String_Type<T>::substring<Jupiter::String_Loose>(in, pos);
} }
template<typename T> Jupiter::String_Loose<T> Jupiter::String_Loose<T>::substring(const Jupiter::String_Type<T> &in, size_t pos, size_t len) template<typename T> Jupiter::String_Loose<T> Jupiter::String_Loose<T>::substring(const Jupiter::Readable_String<T> &in, size_t pos, size_t len)
{ {
return Jupiter::String_Type<T>::substring<Jupiter::String_Loose>(in, pos, len); return Jupiter::String_Type<T>::substring<Jupiter::String_Loose>(in, pos, len);
} }
@ -459,14 +459,14 @@ template<typename T> Jupiter::String_Loose<T> Jupiter::String_Loose<T>::getWord(
return Jupiter::String_Loose<T>::getWord(*this, pos, whitespace); return Jupiter::String_Loose<T>::getWord(*this, pos, whitespace);
} }
template<typename T> Jupiter::String_Loose<T> Jupiter::String_Loose<T>::getWord(const Jupiter::String_Type<T> &in, size_t pos, const T *whitespace) template<typename T> Jupiter::String_Loose<T> Jupiter::String_Loose<T>::getWord(const Jupiter::Readable_String<T> &in, size_t pos, const T *whitespace)
{ {
return Jupiter::String_Type<T>::getWord<Jupiter::String_Loose>(in, pos, whitespace); return Jupiter::Readable_String<T>::getWord<Jupiter::String_Loose>(in, pos, whitespace);
} }
template<typename T> Jupiter::String_Loose<T> Jupiter::String_Loose<T>::getWord(const T *in, size_t pos, const T *whitespace) template<typename T> Jupiter::String_Loose<T> Jupiter::String_Loose<T>::getWord(const T *in, size_t pos, const T *whitespace)
{ {
return Jupiter::String_Type<T>::getWord<Jupiter::String_Loose>(in, pos, whitespace); return Jupiter::Readable_String<T>::getWord<Jupiter::String_Loose>(in, pos, whitespace);
} }
template<typename T> Jupiter::String_Loose<T> Jupiter::String_Loose<T>::gotoWord(size_t pos, const T *whitespace) const template<typename T> Jupiter::String_Loose<T> Jupiter::String_Loose<T>::gotoWord(size_t pos, const T *whitespace) const
@ -474,9 +474,9 @@ template<typename T> Jupiter::String_Loose<T> Jupiter::String_Loose<T>::gotoWord
return Jupiter::String_Loose<T>::gotoWord(*this, pos, whitespace); return Jupiter::String_Loose<T>::gotoWord(*this, pos, whitespace);
} }
template<typename T> Jupiter::String_Loose<T> Jupiter::String_Loose<T>::gotoWord(const Jupiter::String_Type<T> &in, size_t pos, const T *whitespace) template<typename T> Jupiter::String_Loose<T> Jupiter::String_Loose<T>::gotoWord(const Jupiter::Readable_String<T> &in, size_t pos, const T *whitespace)
{ {
return Jupiter::String_Type<T>::gotoWord<Jupiter::String_Loose>(in, pos, whitespace); return Jupiter::Readable_String<T>::gotoWord<Jupiter::String_Loose>(in, pos, whitespace);
} }
template<typename T> const Jupiter::String_Loose<T> Jupiter::String_Loose<T>::empty = Jupiter::String_Loose<T>(); template<typename T> const Jupiter::String_Loose<T> Jupiter::String_Loose<T>::empty = Jupiter::String_Loose<T>();

65
Jupiter/String_Type.h

@ -117,7 +117,7 @@ namespace Jupiter
* @param in String containing the data to be copied. * @param in String containing the data to be copied.
* @return New size of the String. * @return New size of the String.
*/ */
virtual size_t set(const String_Type<T> &in); virtual size_t set(const Jupiter::Readable_String<T> &in);
virtual size_t set(const std::basic_string<T> &in); virtual size_t set(const std::basic_string<T> &in);
virtual size_t set(const T *in); virtual size_t set(const T *in);
virtual size_t set(const T in); virtual size_t set(const T in);
@ -128,7 +128,7 @@ namespace Jupiter
* @param in String containing the data to be concatenated. * @param in String containing the data to be concatenated.
* @return New size of the CString. * @return New size of the CString.
*/ */
virtual size_t concat(const String_Type<T> &in); virtual size_t concat(const Jupiter::Readable_String<T> &in);
virtual size_t concat(const std::basic_string<T> &in); virtual size_t concat(const std::basic_string<T> &in);
virtual size_t concat(const T *in); virtual size_t concat(const T *in);
virtual size_t concat(const T in); virtual size_t concat(const T in);
@ -142,7 +142,7 @@ namespace Jupiter
* @param pos Position to start copying from. * @param pos Position to start copying from.
* @return Partial copy of the input string. * @return Partial copy of the input string.
*/ */
template<template<typename> class R> static R<T> substring(const Jupiter::String_Type<T> &in, size_t pos); template<template<typename> class R> static R<T> substring(const Jupiter::Readable_String<T> &in, size_t pos);
template<template<typename> class R> static R<T> substring(const T *in, size_t pos); template<template<typename> class R> static R<T> substring(const T *in, size_t pos);
/** /**
@ -155,72 +155,22 @@ namespace Jupiter
* @param len Number of elements to copy. * @param len Number of elements to copy.
* @return Partial copy of the input string. * @return Partial copy of the input string.
*/ */
template<template<typename> class R> static R<T> substring(const Jupiter::String_Type<T> &in, size_t pos, size_t len); template<template<typename> class R> static R<T> substring(const Jupiter::Readable_String<T> &in, size_t pos, size_t len);
template<template<typename> class R> static R<T> substring(const T *in, size_t pos, size_t len); template<template<typename> class R> static R<T> substring(const T *in, size_t pos, size_t len);
/**
* @brief Copies a "word" from an input string and returns it in an output type.
*
* @param R Type to return. Must be a subclass of String_Type.
*
* @param in String to get a partial copy of.
* @param pos Index of the word to copy.
* @param whitespace String of characters that are to be considered whitespace.
* @return Copy of the word at the specified index on success, an empty string otherwise.
*/
template<template<typename> class R> static R<T> getWord(const Jupiter::String_Type<T> &in, size_t pos, const T *whitespace);
template<template<typename> class R> static R<T> getWord(const T *in, size_t pos, const T *whitespace);
/**
* @brief Copies a part of an input string starting at a specified "word" and returns it in an output type.
*
* @param R Type to return. Must be a subclass of String_Type.
*
* @param in String to get a partial copy of.
* @param pos Index of the word to start copying from.
* @param whitespace String of characters that are to be considered whitespace.
* @return Copy of the string starting at the specified word on success, an empty string otherwise.
*/
template<template<typename> class R> static R<T> gotoWord(const Jupiter::String_Type<T> &in, size_t pos, const T *whitespace);
template<template<typename> class R> static R<T> gotoWord(const T *in, size_t pos, const T *whitespace);
/** Mutative operators */ /** Mutative operators */
inline String_Type<T> &operator+=(const Readable_String<T> &right) { this->concat(right); return *this; };
inline String_Type<T> &operator+=(const String_Type<T> &right) { this->concat(right); return *this; }; inline String_Type<T> &operator+=(const String_Type<T> &right) { this->concat(right); return *this; };
inline String_Type<T> &operator+=(const std::basic_string<T> &right) { this->concat(right); return *this; }; inline String_Type<T> &operator+=(const std::basic_string<T> &right) { this->concat(right); return *this; };
inline String_Type<T> &operator+=(const T *right) { this->concat(right); return *this; }; inline String_Type<T> &operator+=(const T *right) { this->concat(right); return *this; };
inline String_Type<T> &operator+=(const T right) { this->concat(right); return *this; }; inline String_Type<T> &operator+=(const T right) { this->concat(right); return *this; };
inline String_Type<T> &operator-=(size_t right) { this->truncate(right); return *this; }; inline String_Type<T> &operator-=(size_t right) { this->truncate(right); return *this; };
inline String_Type<T> &operator=(const Readable_String<T> &right) { this->set(right); return *this; };
inline String_Type<T> &operator=(const String_Type<T> &right) { this->set(right); return *this; }; inline String_Type<T> &operator=(const String_Type<T> &right) { this->set(right); return *this; };
inline String_Type<T> &operator=(const std::basic_string<T> &right) { this->set(right); return *this; }; inline String_Type<T> &operator=(const std::basic_string<T> &right) { this->set(right); return *this; };
inline String_Type<T> &operator=(const T *right) { this->set(right); return *this; }; inline String_Type<T> &operator=(const T *right) { this->set(right); return *this; };
inline String_Type<T> &operator=(const T right) { this->set(right); return *this; }; inline String_Type<T> &operator=(const T right) { this->set(right); return *this; };
/** Comparative operators */
inline bool operator==(const String_Type<T> &right)const{ return this->equals(right); }
inline bool operator==(const std::basic_string<T> &right)const{ return this->equals(right); }
inline bool operator==(const T *right)const{ return this->equals(right); }
inline bool operator==(const T right)const{ return this->equals(right); }
inline bool operator!=(const String_Type<T> &right)const{ return !operator==(right); }
inline bool operator!=(const std::basic_string<T> &right)const{ return !operator==(right); }
inline bool operator!=(const T *right)const{ return !operator==(right); }
inline bool operator!=(const T right)const{ return !operator==(right); }
inline bool operator<(const String_Type<T> &right)const{ return this->compare(right) < 0; }
inline bool operator<(const std::basic_string<T> &right)const{ return this->compare(right) < 0; }
inline bool operator<(const T *right)const{ return this->compare(right) < 0; }
inline bool operator<(const T right)const{ return this->compare(right) < 0; }
inline bool operator>(const String_Type<T> &right)const{ return this->compare(right) > 0; }
inline bool operator>(const std::basic_string<T> &right)const{ return this->compare(right) > 0; }
inline bool operator>(const T *right)const{ return this->compare(right) > 0; }
inline bool operator>(const T right)const{ return this->compare(right) > 0; }
inline bool operator<=(const String_Type<T> &right)const{ return !operator>(right); }
inline bool operator<=(const std::basic_string<T> &right)const{ return !operator>(right); }
inline bool operator<=(const T *right)const{ return !operator>(right); }
inline bool operator<=(const T right)const{ return !operator>(right); }
inline bool operator>=(const String_Type<T> &right)const{ return !operator<(right); }
inline bool operator>=(const std::basic_string<T> &right)const{ return !operator<(right); }
inline bool operator>=(const T *right)const{ return !operator<(right); }
inline bool operator>=(const T right)const{ return !operator<(right); }
/** /**
* @brief Default constructor for the String_Type class. * @brief Default constructor for the String_Type class.
*/ */
@ -235,9 +185,10 @@ namespace Jupiter
* The following constructors should exist: * The following constructors should exist:
* A default constructor * A default constructor
* A copy constructor for the same class. * A copy constructor for the same class.
* A copy constructor for String_Type. * A copy constructor for Readable_String.
* A copy constructor for std::basic_string<T>. * A copy constructor for std::basic_string<T>.
* A copy constructor for C-style strings. * A copy constructor for C-style strings.
* A copy constructor for memory array strings.
*/ */
protected: protected:

110
Jupiter/String_Type_Imp.h

@ -152,7 +152,7 @@ template<typename T> bool Jupiter::String_Type<T>::remove(const T &value)
return false; return false;
} }
template<typename T> size_t Jupiter::String_Type<T>::set(const String_Type<T> &in) template<typename T> size_t Jupiter::String_Type<T>::set(const Jupiter::Readable_String<T> &in)
{ {
this->setBufferSizeNoCopy(in.size()); this->setBufferSizeNoCopy(in.size());
for (Jupiter::String_Type<T>::length = 0; Jupiter::String_Type<T>::length < in.size() != 0; Jupiter::String_Type<T>::length++) for (Jupiter::String_Type<T>::length = 0; Jupiter::String_Type<T>::length < in.size() != 0; Jupiter::String_Type<T>::length++)
@ -183,7 +183,7 @@ template<typename T> size_t Jupiter::String_Type<T>::set(const T in)
return Jupiter::String_Type<T>::length = 1; return Jupiter::String_Type<T>::length = 1;
} }
template<typename T> size_t Jupiter::String_Type<T>::concat(const String_Type<T> &in) template<typename T> size_t Jupiter::String_Type<T>::concat(const Jupiter::Readable_String<T> &in)
{ {
size_t nSize = Jupiter::String_Type<T>::length + in.size(); size_t nSize = Jupiter::String_Type<T>::length + in.size();
const T *inData = in.ptr(); const T *inData = in.ptr();
@ -238,7 +238,7 @@ template<typename T> size_t Jupiter::String_Type<T>::concat(const T c)
// substring // substring
template<typename T> template<template<typename> class R> R<T> Jupiter::String_Type<T>::substring(const Jupiter::String_Type<T> &in, size_t pos) template<typename T> template<template<typename> class R> R<T> Jupiter::String_Type<T>::substring(const Jupiter::Readable_String<T> &in, size_t pos)
{ {
if (pos >= in.size()) return R<T>(); if (pos >= in.size()) return R<T>();
R<T> r = R<T>(in.size() - pos); R<T> r = R<T>(in.size() - pos);
@ -246,7 +246,7 @@ template<typename T> template<template<typename> class R> R<T> Jupiter::String_T
return r; return r;
} }
template<typename T> template<template<typename> class R> R<T> Jupiter::String_Type<T>::substring(const Jupiter::String_Type<T> &in, size_t pos, size_t len) template<typename T> template<template<typename> class R> R<T> Jupiter::String_Type<T>::substring(const Jupiter::Readable_String<T> &in, size_t pos, size_t len)
{ {
if (pos + len >= in.size()) return R<T>::substring(in, pos); if (pos + len >= in.size()) return R<T>::substring(in, pos);
R<T> r = R<T>(len); R<T> r = R<T>(len);
@ -272,108 +272,6 @@ template<typename T> template<template<typename> class R> R<T> Jupiter::String_T
return r; return r;
} }
// getWord
template<typename T> template<template<typename> class R> R<T> Jupiter::String_Type<T>::getWord(const Jupiter::String_Type<T> &in, size_t pos, const T *whitespace)
{
unsigned int x = 0;
unsigned int y = 1;
for (unsigned int i = 0; i < pos || y == 1; x++)
{
if (x == in.size()) return R<T>();
if (Jupiter::strpbrk<T>(whitespace, in.get(x)) != nullptr)
{
if (y != 1)
{
y = 1;
i++;
}
}
else
{
if (i >= pos) break;
y = 0;
}
}
for (y = x; y != in.size() && Jupiter::strpbrk<T>(whitespace, in.get(y)) == nullptr; y++);
return R<T>::substring(in, x, y - x);
}
template<typename T> template<template<typename> class R> R<T> Jupiter::String_Type<T>::getWord(const T *in, size_t pos, const T *whitespace)
{
unsigned int x = 0;
unsigned int y = 1;
for (unsigned int i = 0; i < pos || y == 1; x++)
{
if (in[x] == 0) return R<T>();
if (Jupiter::strpbrk<T>(whitespace, in[x]) != nullptr)
{
if (y != 1)
{
y = 1;
i++;
}
}
else
{
if (i >= pos) break;
y = 0;
}
}
for (y = x; in[y] != 0 && Jupiter::strpbrk<T>(whitespace, in[y]) == nullptr; y++);
return R<T>::substring(in, x, y - x);
}
// gotoWord
template<typename T> template<template<typename> class R> R<T> Jupiter::String_Type<T>::gotoWord(const Jupiter::String_Type<T> &in, size_t pos, const T *whitespace)
{
unsigned int x = 0;
bool y = true;
for (unsigned int i = 0; i < pos || y == true; x++)
{
if (x == in.size()) return R<T>();
if (Jupiter::strpbrk<T>(whitespace, in.get(x)) != nullptr)
{
if (y != true)
{
y = true;
i++;
}
}
else
{
if (i >= pos) break;
y = false;
}
}
return R<T>::substring(in, x);
}
template<typename T> template<template<typename> class R> R<T> Jupiter::String_Type<T>::gotoWord(const T *in, size_t pos, const T *whitespace)
{
unsigned int x = 0;
bool y = true;
for (unsigned int i = 0; i < pos || y == true; x++)
{
if (in[x] == 0) return R<T>();
if (Jupiter::strpbrk<T>(whitespace, in[x]) != nullptr)
{
if (y != true)
{
y = true;
i++;
}
}
else
{
if (i >= pos) break;
y = false;
}
}
return R<T>::substring(in, x);
}
namespace Jupiter namespace Jupiter
{ {
static struct String_Constructor_Base {} stringConstructorBase; static struct String_Constructor_Base {} stringConstructorBase;

Loading…
Cancel
Save