From 70b1af0d3cb330ec01f3736eb8f514dc4064927e Mon Sep 17 00:00:00 2001 From: JustinAJ Date: Mon, 2 Jun 2014 19:37:43 -0400 Subject: [PATCH] Changed many input variables to Readable_String. Moved comparative operators to Readable_String. Moved getWord and gotoWord templates to Readable_String. --- Jupiter/CString.h | 30 +++++----- Jupiter/CString_Imp.h | 36 +++++------ Jupiter/Readable_String.h | 58 ++++++++++++++++++ Jupiter/Readable_String_Imp.h | 102 +++++++++++++++++++++++++++++++ Jupiter/String.h | 26 ++++---- Jupiter/String_Imp.h | 32 +++++----- Jupiter/String_Type.h | 65 +++----------------- Jupiter/String_Type_Imp.h | 110 ++-------------------------------- 8 files changed, 234 insertions(+), 225 deletions(-) diff --git a/Jupiter/CString.h b/Jupiter/CString.h index b9cfd6c..b562539 100644 --- a/Jupiter/CString.h +++ b/Jupiter/CString.h @@ -115,7 +115,7 @@ namespace Jupiter * @param pos Position in the string to start copying from. * @return String containing a partial copy of the original string. */ - static CString_Type substring(const Jupiter::String_Type &in, size_t pos); + static CString_Type substring(const Jupiter::Readable_String &in, size_t pos); static CString_Type substring(const T *in, size_t pos); /** @@ -126,7 +126,7 @@ namespace Jupiter * @param length Number of characters to copy. * @return String containing a partial copy of the original string. */ - static CString_Type substring(const Jupiter::String_Type &in, size_t pos, size_t length); + static CString_Type substring(const Jupiter::Readable_String &in, size_t pos, size_t length); static CString_Type 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. * @return String containing a partial copy of the original string. */ - static CString_Type getWord(const Jupiter::String_Type &in, size_t pos, const T *whitespace); + static CString_Type getWord(const Jupiter::Readable_String &in, size_t pos, const T *whitespace); /** * @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. * @return String containing a partial copy of the original string. */ - static CString_Type gotoWord(const Jupiter::String_Type &in, size_t pos, const T *whitespace); + static CString_Type gotoWord(const Jupiter::Readable_String &in, size_t pos, const T *whitespace); /** * @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. * @return New size of the CString. */ - size_t set(const String_Type &in); + size_t set(const Readable_String &in); size_t set(const std::basic_string &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. * @return New size of the CString. */ - size_t concat(const String_Type &in); + size_t concat(const Readable_String &in); size_t concat(const std::basic_string &in); size_t concat(const T *in); size_t concat(const T in); /** Assignment Operators */ inline CString_Type &operator=(const CString_Type &right) { this->set(right); return *this; }; - inline CString_Type &operator=(const String_Type &right) { this->set(right); return *this; }; + inline CString_Type &operator=(const Readable_String &right) { this->set(right); return *this; }; inline CString_Type &operator=(const std::basic_string &right) { this->set(right); return *this; }; inline CString_Type &operator=(const T *right) { this->set(right); return *this; }; inline CString_Type &operator=(const T right) { this->set(right); return *this; }; @@ -223,8 +223,8 @@ namespace Jupiter CString_Type(CString_Type &&source); /** Copy Constructors */ - CString_Type(const CString_Type &in) : CString_Type((String_Type &)in) {} - CString_Type(const String_Type &in); + CString_Type(const CString_Type &in) : CString_Type((Readable_String &)in) {} + CString_Type(const Readable_String &in); CString_Type(const std::basic_string &in); CString_Type(const T *in); @@ -297,7 +297,7 @@ namespace Jupiter * @param pos Position in the string to start copying from. * @return String containing a partial copy of the original string. */ - static CString_Loose substring(const Jupiter::String_Type &in, size_t pos); + static CString_Loose substring(const Jupiter::Readable_String &in, size_t pos); static CString_Loose substring(const T *in, size_t pos); /** @@ -308,7 +308,7 @@ namespace Jupiter * @param length Number of characters to copy. * @return String containing a partial copy of the original string. */ - static CString_Loose substring(const Jupiter::String_Type &in, size_t pos, size_t length); + static CString_Loose substring(const Jupiter::Readable_String &in, size_t pos, size_t length); static CString_Loose 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. * @return String containing a partial copy of the original string. */ - static CString_Loose getWord(const Jupiter::String_Type &in, size_t pos, const T *whitespace); + static CString_Loose getWord(const Jupiter::Readable_String &in, size_t pos, const T *whitespace); /** * @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. * @return String containing a partial copy of the original string. */ - static CString_Loose gotoWord(const Jupiter::String_Type &in, size_t pos, const T *whitespace); + static CString_Loose gotoWord(const Jupiter::Readable_String &in, size_t pos, const T *whitespace); /** Default constructor */ CString_Loose(); @@ -376,7 +376,7 @@ namespace Jupiter /** Copy Constructors */ CString_Loose(const CString_Loose &in); - CString_Loose(const String_Type &in); + CString_Loose(const Readable_String &in); CString_Loose(const std::basic_string &in); CString_Loose(const T *in); @@ -386,7 +386,7 @@ namespace Jupiter /** Assignment Operators */ inline CString_Loose &operator=(const CString_Loose &right) { this->set(right); return *this; }; inline CString_Loose &operator=(const CString_Type &right) { this->set(right); return *this; }; - inline CString_Loose &operator=(const String_Type &right) { this->set(right); return *this; }; + inline CString_Loose &operator=(const Readable_String &right) { this->set(right); return *this; }; inline CString_Loose &operator=(const std::basic_string &right) { this->set(right); return *this; }; inline CString_Loose &operator=(const T *right) { this->set(right); return *this; }; inline CString_Loose &operator=(const T right) { this->set(right); return *this; }; diff --git a/Jupiter/CString_Imp.h b/Jupiter/CString_Imp.h index ccb73dd..3e1e70c 100644 --- a/Jupiter/CString_Imp.h +++ b/Jupiter/CString_Imp.h @@ -59,7 +59,7 @@ template Jupiter::CString_Type::CString_Type(Jupiter::CString_Typ { } -template Jupiter::CString_Type::CString_Type(const Jupiter::String_Type &in) : Jupiter::CString_Type::CString_Type(in.size()) +template Jupiter::CString_Type::CString_Type(const Jupiter::Readable_String &in) : Jupiter::CString_Type::CString_Type(in.size()) { while (Jupiter::String_Type::length < in.size() && in.get(Jupiter::String_Type::length) != 0) { @@ -233,7 +233,7 @@ template Jupiter::CString_Type Jupiter::CString_Type::substrin return Jupiter::CString_Type::substring(*this, pos, len); } -template Jupiter::CString_Type Jupiter::CString_Type::substring(const Jupiter::String_Type &in, size_t pos) +template Jupiter::CString_Type Jupiter::CString_Type::substring(const Jupiter::Readable_String &in, size_t pos) { if (pos >= in.size()) return Jupiter::CString_Type(); Jupiter::CString_Type r = Jupiter::CString_Type(in.size() - pos); @@ -249,7 +249,7 @@ template Jupiter::CString_Type Jupiter::CString_Type::substrin return r; } -template Jupiter::CString_Type Jupiter::CString_Type::substring(const Jupiter::String_Type &in, size_t pos, size_t len) +template Jupiter::CString_Type Jupiter::CString_Type::substring(const Jupiter::Readable_String &in, size_t pos, size_t len) { if (pos + len >= in.size()) return Jupiter::CString_Type::substring(in, pos); Jupiter::CString_Type r = Jupiter::CString_Type(len); @@ -270,14 +270,14 @@ template Jupiter::CString_Type Jupiter::CString_Type::getWord( return Jupiter::CString_Type::getWord(*this, pos, whitespace); } -template Jupiter::CString_Type Jupiter::CString_Type::getWord(const Jupiter::String_Type &in, size_t pos, const T *whitespace) +template Jupiter::CString_Type Jupiter::CString_Type::getWord(const Jupiter::Readable_String &in, size_t pos, const T *whitespace) { - return Jupiter::String_Type::getWord(in, pos, whitespace); + return Jupiter::Readable_String::getWord(in, pos, whitespace); } template Jupiter::CString_Type Jupiter::CString_Type::getWord(const T *in, size_t pos, const T *whitespace) { - return Jupiter::String_Type::getWord(in, pos, whitespace); + return Jupiter::Readable_String::getWord(in, pos, whitespace); } template Jupiter::CString_Type Jupiter::CString_Type::gotoWord(size_t pos, const T *whitespace) const @@ -285,12 +285,12 @@ template Jupiter::CString_Type Jupiter::CString_Type::gotoWord return Jupiter::CString_Type::gotoWord(*this, pos, whitespace); } -template Jupiter::CString_Type Jupiter::CString_Type::gotoWord(const Jupiter::String_Type &in, size_t pos, const T *whitespace) +template Jupiter::CString_Type Jupiter::CString_Type::gotoWord(const Jupiter::Readable_String &in, size_t pos, const T *whitespace) { - return Jupiter::String_Type::gotoWord(in, pos, whitespace); + return Jupiter::Readable_String::gotoWord(in, pos, whitespace); } -template size_t Jupiter::CString_Type::set(const String_Type &in) +template size_t Jupiter::CString_Type::set(const Jupiter::Readable_String &in) { this->setBufferSizeNoCopy(in.size()); for (Jupiter::String_Type::length = 0; Jupiter::String_Type::length < in.size() && in.get(Jupiter::String_Type::length) != 0; Jupiter::String_Type::length++) @@ -326,7 +326,7 @@ template size_t Jupiter::CString_Type::set(const T in) return Jupiter::String_Type::length = 1; } -template size_t Jupiter::CString_Type::concat(const String_Type &in) +template size_t Jupiter::CString_Type::concat(const Jupiter::Readable_String &in) { size_t nSize = Jupiter::String_Type::length + in.size(); const T *inData = in.ptr(); @@ -408,7 +408,7 @@ template Jupiter::CString_Loose::CString_Loose(const Jupiter::CSt Jupiter::String_Type::length = in.length; } -template Jupiter::CString_Loose::CString_Loose(const Jupiter::String_Type &in) : Jupiter::CString_Loose::CString_Loose(in.size()) +template Jupiter::CString_Loose::CString_Loose(const Jupiter::Readable_String &in) : Jupiter::CString_Loose::CString_Loose(in.size()) { while (Jupiter::String_Type::length < in.size() && in.get(Jupiter::String_Type::length) != 0) { @@ -503,7 +503,7 @@ template Jupiter::CString_Loose Jupiter::CString_Loose::substr return Jupiter::CString_Loose::substring(*this, pos, length); } -template Jupiter::CString_Loose Jupiter::CString_Loose::substring(const Jupiter::String_Type &in, size_t pos) +template Jupiter::CString_Loose Jupiter::CString_Loose::substring(const Jupiter::Readable_String &in, size_t pos) { if (pos > in.size()) return Jupiter::CString_Loose(); Jupiter::CString_Loose r = Jupiter::CString_Loose(in.size() - pos); @@ -519,7 +519,7 @@ template Jupiter::CString_Loose Jupiter::CString_Loose::substr return r; } -template Jupiter::CString_Loose Jupiter::CString_Loose::substring(const Jupiter::String_Type &in, size_t pos, size_t len) +template Jupiter::CString_Loose Jupiter::CString_Loose::substring(const Jupiter::Readable_String &in, size_t pos, size_t len) { if (pos + len >= in.size()) return Jupiter::CString_Loose::substring(in, pos); Jupiter::CString_Loose r = Jupiter::CString_Loose(len); @@ -540,14 +540,14 @@ template Jupiter::CString_Loose Jupiter::CString_Loose::getWor return Jupiter::CString_Loose::getWord(*this, pos, whitespace); } -template Jupiter::CString_Loose Jupiter::CString_Loose::getWord(const Jupiter::String_Type &in, size_t pos, const T *whitespace) +template Jupiter::CString_Loose Jupiter::CString_Loose::getWord(const Jupiter::Readable_String &in, size_t pos, const T *whitespace) { - return Jupiter::String_Type::getWord(in, pos, whitespace); + return Jupiter::Readable_String::getWord(in, pos, whitespace); } template Jupiter::CString_Loose Jupiter::CString_Loose::getWord(const T *in, size_t pos, const T *whitespace) { - return Jupiter::String_Type::getWord(in, pos, whitespace); + return Jupiter::Readable_String::getWord(in, pos, whitespace); } template Jupiter::CString_Loose Jupiter::CString_Loose::gotoWord(size_t pos, const T *whitespace) const @@ -555,9 +555,9 @@ template Jupiter::CString_Loose Jupiter::CString_Loose::gotoWo return Jupiter::CString_Loose::gotoWord(*this, pos, whitespace); } -template Jupiter::CString_Loose Jupiter::CString_Loose::gotoWord(const Jupiter::String_Type &in, size_t pos, const T *whitespace) +template Jupiter::CString_Loose Jupiter::CString_Loose::gotoWord(const Jupiter::Readable_String &in, size_t pos, const T *whitespace) { - return Jupiter::String_Type::gotoWord(in, pos, whitespace); + return Jupiter::Readable_String::gotoWord(in, pos, whitespace); } template const Jupiter::CString_Loose Jupiter::CString_Loose::empty = Jupiter::CString_Loose(); diff --git a/Jupiter/Readable_String.h b/Jupiter/Readable_String.h index 104c7e0..5457c88 100644 --- a/Jupiter/Readable_String.h +++ b/Jupiter/Readable_String.h @@ -174,9 +174,67 @@ namespace Jupiter size_t println(FILE *out) const; size_t println(std::basic_ostream &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 class R> static R getWord(const Jupiter::Readable_String &in, size_t pos, const T *whitespace); + template class R> static R 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 class R> static R gotoWord(const Jupiter::Readable_String &in, size_t pos, const T *whitespace); + template class R> static R gotoWord(const T *in, size_t pos, const T *whitespace); + /** Access operator */ inline T &operator[](size_t index) const { return this->get(index); }; + + /** Comparative operators */ + inline bool operator==(const Readable_String &right)const{ return this->equals(right); } + inline bool operator==(const std::basic_string &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 &right)const{ return !operator==(right); } + inline bool operator!=(const std::basic_string &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 &right)const{ return this->compare(right) < 0; } + inline bool operator<(const std::basic_string &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 &right)const{ return this->compare(right) > 0; } + inline bool operator>(const std::basic_string &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 &right)const{ return !operator>(right); } + inline bool operator<=(const std::basic_string &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 &right)const{ return !operator<(right); } + inline bool operator>=(const std::basic_string &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 ReadableString; + + /** Generic Wide Readable String Type */ + typedef Readable_String ReadableWString; } #include "Readable_String_Imp.h" diff --git a/Jupiter/Readable_String_Imp.h b/Jupiter/Readable_String_Imp.h index e624e1a..0f4e227 100644 --- a/Jupiter/Readable_String_Imp.h +++ b/Jupiter/Readable_String_Imp.h @@ -743,4 +743,106 @@ template size_t Jupiter::Readable_String::println(std::basic_ostr return r; } +// getWord + +template template class R> R Jupiter::Readable_String::getWord(const Jupiter::Readable_String &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(); + if (Jupiter::strpbrk(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(whitespace, in.get(y)) == nullptr; y++); + return R::substring(in, x, y - x); +} + +template template class R> R Jupiter::Readable_String::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(); + if (Jupiter::strpbrk(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(whitespace, in[y]) == nullptr; y++); + return R::substring(in, x, y - x); +} + +// gotoWord + +template template class R> R Jupiter::Readable_String::gotoWord(const Jupiter::Readable_String &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(); + if (Jupiter::strpbrk(whitespace, in.get(x)) != nullptr) + { + if (y != true) + { + y = true; + i++; + } + } + else + { + if (i >= pos) break; + y = false; + } + } + return R::substring(in, x); +} + +template template class R> R Jupiter::Readable_String::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(); + if (Jupiter::strpbrk(whitespace, in[x]) != nullptr) + { + if (y != true) + { + y = true; + i++; + } + } + else + { + if (i >= pos) break; + y = false; + } + } + return R::substring(in, x); +} + #endif // _READABLE_STRING_IMP_H_HEADER \ No newline at end of file diff --git a/Jupiter/String.h b/Jupiter/String.h index 10d900e..0b82a60 100644 --- a/Jupiter/String.h +++ b/Jupiter/String.h @@ -100,7 +100,7 @@ namespace Jupiter * @param pos Position in the string to start copying from. * @return String containing a partial copy of the original string. */ - static String_Strict substring(const Jupiter::String_Type &in, size_t pos); + static String_Strict substring(const Jupiter::Readable_String &in, size_t pos); static String_Strict substring(const T *in, size_t pos); /** @@ -111,7 +111,7 @@ namespace Jupiter * @param length Number of characters to copy. * @return String containing a partial copy of the original string. */ - static String_Strict substring(const Jupiter::String_Type &in, size_t pos, size_t length); + static String_Strict substring(const Jupiter::Readable_String &in, size_t pos, size_t length); static String_Strict 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. * @return String containing a partial copy of the original string. */ - static String_Strict getWord(const Jupiter::String_Type &in, size_t pos, const T *whitespace); + static String_Strict getWord(const Jupiter::Readable_String &in, size_t pos, const T *whitespace); /** * @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. * @return String containing a partial copy of the original string. */ - static String_Strict gotoWord(const Jupiter::String_Type &in, size_t pos, const T *whitespace); + static String_Strict gotoWord(const Jupiter::Readable_String &in, size_t pos, const T *whitespace); /** Assignment Operators */ inline String_Strict &operator=(const String_Strict &right) { this->set(right); return *this; }; - inline String_Strict &operator=(const String_Type &right) { this->set(right); return *this; }; + inline String_Strict &operator=(const Readable_String &right) { this->set(right); return *this; }; inline String_Strict &operator=(const std::basic_string &right) { this->set(right); return *this; }; inline String_Strict &operator=(const T *right) { this->set(right); return *this; }; inline String_Strict &operator=(const T right) { this->set(right); return *this; }; @@ -186,8 +186,8 @@ namespace Jupiter String_Strict(String_Strict &&source); /** Copy Constructors */ - String_Strict(const String_Strict &in) : String_Strict((String_Type &)in) {} - String_Strict(const String_Type &in); + String_Strict(const String_Strict &in) : String_Strict((Readable_String &)in) {} + String_Strict(const Readable_String &in); String_Strict(const std::basic_string &in); String_Strict(const T *in); @@ -268,7 +268,7 @@ namespace Jupiter * @param pos Position in the string to start copying from. * @return String containing a partial copy of the original string. */ - static String_Loose substring(const Jupiter::String_Type &in, size_t pos); + static String_Loose substring(const Jupiter::Readable_String &in, size_t pos); static String_Loose substring(const T *in, size_t pos); /** @@ -279,7 +279,7 @@ namespace Jupiter * @param length Number of characters to copy. * @return String containing a partial copy of the original string. */ - static String_Loose substring(const Jupiter::String_Type &in, size_t pos, size_t length); + static String_Loose substring(const Jupiter::Readable_String &in, size_t pos, size_t length); static String_Loose 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. * @return String containing a partial copy of the original string. */ - static String_Loose getWord(const Jupiter::String_Type &in, size_t pos, const T *whitespace); + static String_Loose getWord(const Jupiter::Readable_String &in, size_t pos, const T *whitespace); /** * @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. * @return String containing a partial copy of the original string. */ - static String_Loose gotoWord(const Jupiter::String_Type &in, size_t pos, const T *whitespace); + static String_Loose gotoWord(const Jupiter::Readable_String &in, size_t pos, const T *whitespace); /** Default constructor */ String_Loose(); @@ -347,7 +347,7 @@ namespace Jupiter /** Copy Constructors */ String_Loose(const String_Loose &in); - String_Loose(const String_Type &in); + String_Loose(const Readable_String &in); String_Loose(const std::basic_string &in); String_Loose(const T *in); @@ -356,7 +356,7 @@ namespace Jupiter /** Assignment Operators */ inline String_Loose &operator=(const String_Loose &right) { this->set(right); return *this; }; - inline String_Loose &operator=(const String_Type &right) { this->set(right); return *this; }; + inline String_Loose &operator=(const Readable_String &right) { this->set(right); return *this; }; inline String_Loose &operator=(const std::basic_string &right) { this->set(right); return *this; }; inline String_Loose &operator=(const T *right) { this->set(right); return *this; }; inline String_Loose &operator=(const T right) { this->set(right); return *this; }; diff --git a/Jupiter/String_Imp.h b/Jupiter/String_Imp.h index 23299d4..0354a5b 100644 --- a/Jupiter/String_Imp.h +++ b/Jupiter/String_Imp.h @@ -57,7 +57,7 @@ template Jupiter::String_Strict::String_Strict(Jupiter::String_St { } -template Jupiter::String_Strict::String_Strict(const Jupiter::String_Type &in) : Jupiter::String_Strict::String_Strict(in.size()) +template Jupiter::String_Strict::String_Strict(const Jupiter::Readable_String &in) : Jupiter::String_Strict::String_Strict(in.size()) { while (Jupiter::String_Type::length < in.size()) { @@ -194,7 +194,7 @@ template Jupiter::String_Strict Jupiter::String_Strict::substr return Jupiter::String_Strict::substring(*this, pos, len); } -template Jupiter::String_Strict Jupiter::String_Strict::substring(const Jupiter::String_Type &in, size_t pos) +template Jupiter::String_Strict Jupiter::String_Strict::substring(const Jupiter::Readable_String &in, size_t pos) { return Jupiter::String_Type::substring(in, pos); } @@ -204,7 +204,7 @@ template Jupiter::String_Strict Jupiter::String_Strict::substr return Jupiter::String_Type::substring(in, pos); } -template Jupiter::String_Strict Jupiter::String_Strict::substring(const Jupiter::String_Type &in, size_t pos, size_t len) +template Jupiter::String_Strict Jupiter::String_Strict::substring(const Jupiter::Readable_String &in, size_t pos, size_t len) { return Jupiter::String_Type::substring(in, pos, len); } @@ -219,14 +219,14 @@ template Jupiter::String_Strict Jupiter::String_Strict::getWor return Jupiter::String_Strict::getWord(*this, pos, whitespace); } -template Jupiter::String_Strict Jupiter::String_Strict::getWord(const Jupiter::String_Type &in, size_t pos, const T *whitespace) +template Jupiter::String_Strict Jupiter::String_Strict::getWord(const Jupiter::Readable_String &in, size_t pos, const T *whitespace) { - return Jupiter::String_Type::getWord(in, pos, whitespace); + return Jupiter::Readable_String::getWord(in, pos, whitespace); } template Jupiter::String_Strict Jupiter::String_Strict::getWord(const T *in, size_t pos, const T *whitespace) { - return Jupiter::String_Type::getWord(in, pos, whitespace); + return Jupiter::Readable_String::getWord(in, pos, whitespace); } template Jupiter::String_Strict Jupiter::String_Strict::gotoWord(size_t pos, const T *whitespace) const @@ -234,9 +234,9 @@ template Jupiter::String_Strict Jupiter::String_Strict::gotoWo return Jupiter::String_Strict::gotoWord(*this, pos, whitespace); } -template Jupiter::String_Strict Jupiter::String_Strict::gotoWord(const Jupiter::String_Type &in, size_t pos, const T *whitespace) +template Jupiter::String_Strict Jupiter::String_Strict::gotoWord(const Jupiter::Readable_String &in, size_t pos, const T *whitespace) { - return Jupiter::String_Type::gotoWord(in, pos, whitespace); + return Jupiter::Readable_String::gotoWord(in, pos, whitespace); } template const Jupiter::String_Strict Jupiter::String_Strict::empty = Jupiter::String_Strict(); @@ -275,7 +275,7 @@ template Jupiter::String_Loose::String_Loose(const Jupiter::Strin Jupiter::String_Type::str[Jupiter::String_Type::length] = in.get(Jupiter::String_Type::length); } -template Jupiter::String_Loose::String_Loose(const Jupiter::String_Type &in) : Jupiter::String_Loose::String_Loose(in.size()) +template Jupiter::String_Loose::String_Loose(const Jupiter::Readable_String &in) : Jupiter::String_Loose::String_Loose(in.size()) { while (Jupiter::String_Type::length < in.size()) { @@ -434,7 +434,7 @@ template Jupiter::String_Loose Jupiter::String_Loose::substrin return Jupiter::String_Loose::substring(*this, pos, length); } -template Jupiter::String_Loose Jupiter::String_Loose::substring(const Jupiter::String_Type &in, size_t pos) +template Jupiter::String_Loose Jupiter::String_Loose::substring(const Jupiter::Readable_String &in, size_t pos) { return Jupiter::String_Type::substring(in, pos); } @@ -444,7 +444,7 @@ template Jupiter::String_Loose Jupiter::String_Loose::substrin return Jupiter::String_Type::substring(in, pos); } -template Jupiter::String_Loose Jupiter::String_Loose::substring(const Jupiter::String_Type &in, size_t pos, size_t len) +template Jupiter::String_Loose Jupiter::String_Loose::substring(const Jupiter::Readable_String &in, size_t pos, size_t len) { return Jupiter::String_Type::substring(in, pos, len); } @@ -459,14 +459,14 @@ template Jupiter::String_Loose Jupiter::String_Loose::getWord( return Jupiter::String_Loose::getWord(*this, pos, whitespace); } -template Jupiter::String_Loose Jupiter::String_Loose::getWord(const Jupiter::String_Type &in, size_t pos, const T *whitespace) +template Jupiter::String_Loose Jupiter::String_Loose::getWord(const Jupiter::Readable_String &in, size_t pos, const T *whitespace) { - return Jupiter::String_Type::getWord(in, pos, whitespace); + return Jupiter::Readable_String::getWord(in, pos, whitespace); } template Jupiter::String_Loose Jupiter::String_Loose::getWord(const T *in, size_t pos, const T *whitespace) { - return Jupiter::String_Type::getWord(in, pos, whitespace); + return Jupiter::Readable_String::getWord(in, pos, whitespace); } template Jupiter::String_Loose Jupiter::String_Loose::gotoWord(size_t pos, const T *whitespace) const @@ -474,9 +474,9 @@ template Jupiter::String_Loose Jupiter::String_Loose::gotoWord return Jupiter::String_Loose::gotoWord(*this, pos, whitespace); } -template Jupiter::String_Loose Jupiter::String_Loose::gotoWord(const Jupiter::String_Type &in, size_t pos, const T *whitespace) +template Jupiter::String_Loose Jupiter::String_Loose::gotoWord(const Jupiter::Readable_String &in, size_t pos, const T *whitespace) { - return Jupiter::String_Type::gotoWord(in, pos, whitespace); + return Jupiter::Readable_String::gotoWord(in, pos, whitespace); } template const Jupiter::String_Loose Jupiter::String_Loose::empty = Jupiter::String_Loose(); diff --git a/Jupiter/String_Type.h b/Jupiter/String_Type.h index a8a5a6b..23db529 100644 --- a/Jupiter/String_Type.h +++ b/Jupiter/String_Type.h @@ -117,7 +117,7 @@ namespace Jupiter * @param in String containing the data to be copied. * @return New size of the String. */ - virtual size_t set(const String_Type &in); + virtual size_t set(const Jupiter::Readable_String &in); virtual size_t set(const std::basic_string &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. * @return New size of the CString. */ - virtual size_t concat(const String_Type &in); + virtual size_t concat(const Jupiter::Readable_String &in); virtual size_t concat(const std::basic_string &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. * @return Partial copy of the input string. */ - template class R> static R substring(const Jupiter::String_Type &in, size_t pos); + template class R> static R substring(const Jupiter::Readable_String &in, size_t pos); template class R> static R substring(const T *in, size_t pos); /** @@ -155,72 +155,22 @@ namespace Jupiter * @param len Number of elements to copy. * @return Partial copy of the input string. */ - template class R> static R substring(const Jupiter::String_Type &in, size_t pos, size_t len); + template class R> static R substring(const Jupiter::Readable_String &in, size_t pos, size_t len); template class R> static R 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 class R> static R getWord(const Jupiter::String_Type &in, size_t pos, const T *whitespace); - template class R> static R 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 class R> static R gotoWord(const Jupiter::String_Type &in, size_t pos, const T *whitespace); - template class R> static R gotoWord(const T *in, size_t pos, const T *whitespace); - /** Mutative operators */ + inline String_Type &operator+=(const Readable_String &right) { this->concat(right); return *this; }; inline String_Type &operator+=(const String_Type &right) { this->concat(right); return *this; }; inline String_Type &operator+=(const std::basic_string &right) { this->concat(right); return *this; }; inline String_Type &operator+=(const T *right) { this->concat(right); return *this; }; inline String_Type &operator+=(const T right) { this->concat(right); return *this; }; inline String_Type &operator-=(size_t right) { this->truncate(right); return *this; }; + inline String_Type &operator=(const Readable_String &right) { this->set(right); return *this; }; inline String_Type &operator=(const String_Type &right) { this->set(right); return *this; }; inline String_Type &operator=(const std::basic_string &right) { this->set(right); return *this; }; inline String_Type &operator=(const T *right) { this->set(right); return *this; }; inline String_Type &operator=(const T right) { this->set(right); return *this; }; - /** Comparative operators */ - inline bool operator==(const String_Type &right)const{ return this->equals(right); } - inline bool operator==(const std::basic_string &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 &right)const{ return !operator==(right); } - inline bool operator!=(const std::basic_string &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 &right)const{ return this->compare(right) < 0; } - inline bool operator<(const std::basic_string &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 &right)const{ return this->compare(right) > 0; } - inline bool operator>(const std::basic_string &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 &right)const{ return !operator>(right); } - inline bool operator<=(const std::basic_string &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 &right)const{ return !operator<(right); } - inline bool operator>=(const std::basic_string &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. */ @@ -235,9 +185,10 @@ namespace Jupiter * The following constructors should exist: * A default constructor * 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. * A copy constructor for C-style strings. + * A copy constructor for memory array strings. */ protected: diff --git a/Jupiter/String_Type_Imp.h b/Jupiter/String_Type_Imp.h index 439ebd1..4c33ac3 100644 --- a/Jupiter/String_Type_Imp.h +++ b/Jupiter/String_Type_Imp.h @@ -152,7 +152,7 @@ template bool Jupiter::String_Type::remove(const T &value) return false; } -template size_t Jupiter::String_Type::set(const String_Type &in) +template size_t Jupiter::String_Type::set(const Jupiter::Readable_String &in) { this->setBufferSizeNoCopy(in.size()); for (Jupiter::String_Type::length = 0; Jupiter::String_Type::length < in.size() != 0; Jupiter::String_Type::length++) @@ -183,7 +183,7 @@ template size_t Jupiter::String_Type::set(const T in) return Jupiter::String_Type::length = 1; } -template size_t Jupiter::String_Type::concat(const String_Type &in) +template size_t Jupiter::String_Type::concat(const Jupiter::Readable_String &in) { size_t nSize = Jupiter::String_Type::length + in.size(); const T *inData = in.ptr(); @@ -238,7 +238,7 @@ template size_t Jupiter::String_Type::concat(const T c) // substring -template template class R> R Jupiter::String_Type::substring(const Jupiter::String_Type &in, size_t pos) +template template class R> R Jupiter::String_Type::substring(const Jupiter::Readable_String &in, size_t pos) { if (pos >= in.size()) return R(); R r = R(in.size() - pos); @@ -246,7 +246,7 @@ template template class R> R Jupiter::String_T return r; } -template template class R> R Jupiter::String_Type::substring(const Jupiter::String_Type &in, size_t pos, size_t len) +template template class R> R Jupiter::String_Type::substring(const Jupiter::Readable_String &in, size_t pos, size_t len) { if (pos + len >= in.size()) return R::substring(in, pos); R r = R(len); @@ -272,108 +272,6 @@ template template class R> R Jupiter::String_T return r; } -// getWord - -template template class R> R Jupiter::String_Type::getWord(const Jupiter::String_Type &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(); - if (Jupiter::strpbrk(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(whitespace, in.get(y)) == nullptr; y++); - return R::substring(in, x, y - x); -} - -template template class R> R Jupiter::String_Type::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(); - if (Jupiter::strpbrk(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(whitespace, in[y]) == nullptr; y++); - return R::substring(in, x, y - x); -} - -// gotoWord - -template template class R> R Jupiter::String_Type::gotoWord(const Jupiter::String_Type &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(); - if (Jupiter::strpbrk(whitespace, in.get(x)) != nullptr) - { - if (y != true) - { - y = true; - i++; - } - } - else - { - if (i >= pos) break; - y = false; - } - } - return R::substring(in, x); -} - -template template class R> R Jupiter::String_Type::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(); - if (Jupiter::strpbrk(whitespace, in[x]) != nullptr) - { - if (y != true) - { - y = true; - i++; - } - } - else - { - if (i >= pos) break; - y = false; - } - } - return R::substring(in, x); -} - namespace Jupiter { static struct String_Constructor_Base {} stringConstructorBase;