diff --git a/Jupiter/CString.h b/Jupiter/CString.h index 8f3ee00..b54bc63 100644 --- a/Jupiter/CString.h +++ b/Jupiter/CString.h @@ -1,5 +1,5 @@ /** - * Copyright (C) 2013-2014 Justin James. + * Copyright (C) 2013-2015 Justin James. * * This license must be preserved. * Any applications, libraries, or code which make any use of any @@ -205,15 +205,6 @@ namespace Jupiter 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 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; }; - - static const Jupiter::CString_Type empty; /** Empty instantation of CString_Type */ - /** Default Constructor */ CString_Type(); @@ -235,6 +226,22 @@ namespace Jupiter CString_Type(const T *in, size_t len); CString_Type(const T *in); + /** Concatenation Constructor */ + CString_Type(const Readable_String &lhs, const Readable_String &rhs); + + /** Addition Operators */ + inline CString_Type operator+(const CString_Type &rhs) const; + inline CString_Type operator+(const Readable_String &rhs) const; + + /** Assignment Operators */ + inline CString_Type &operator=(const CString_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; }; + + static const Jupiter::CString_Type empty; /** Empty instantiation of CString_Type */ + protected: /** @@ -260,6 +267,11 @@ namespace Jupiter }; template using CString_Strict = CString_Type; +#if defined JUPITER_CSTRING_TYPE_OPERATOR_PLUS + /** String_Loose Addition Operator */ + template static inline Jupiter::CString_Type operator+(const Jupiter::Readable_String &lhs, const Jupiter::Readable_String &rhs); +#endif // JUPITER_CSTRING_TYPE_OPERATOR_PLUS + /** * @brief Provides a "loose" CString implementation that's more optimized for repeated concatenations. * Note: The underlying C-style string will always have a size which is a power of 2, but no fewer than 8 elements. @@ -382,14 +394,18 @@ namespace Jupiter CString_Loose(CString_Loose &&source); /** Copy Constructors */ - CString_Loose(const CString_Loose &in); + CString_Loose(const CString_Loose &in); CString_Loose(const Readable_String &in); CString_Loose(const std::basic_string &in); CString_Loose(const T *in, size_t len); CString_Loose(const T *in); - static const Jupiter::CString_Loose empty; /** Empty instantation of CString_Loose */ - static const size_t start_size = 8; /** Starting size for loose CStrings. */ + /** Concatenation Constructor */ + CString_Loose(const Readable_String &lhs, const Readable_String &rhs); + + /** Addition Operators */ + inline CString_Loose operator+(const CString_Loose &rhs) const; + inline CString_Loose operator+(const Readable_String &rhs) const; /** Assignment Operators */ inline CString_Loose &operator=(const CString_Loose &right) { this->set(right); return *this; }; @@ -399,6 +415,9 @@ namespace Jupiter inline CString_Loose &operator=(const T *right) { this->set(right); return *this; }; inline CString_Loose &operator=(const T right) { this->set(right); return *this; }; + static const Jupiter::CString_Loose empty; /** Empty instantiation of CString_Loose */ + static const size_t start_size = 8; /** Starting size for loose CStrings. */ + protected: /** @@ -425,6 +444,11 @@ namespace Jupiter size_t strSize; /** Size of underlying C-string buffer */ }; +#if defined JUPITER_CSTRING_LOOSE_OPERATOR_PLUS + /** String_Loose Addition Operator */ + template static inline Jupiter::CString_LOOSE operator+(const Jupiter::Readable_String &lhs, const Jupiter::Readable_String &rhs); +#endif // JUPITER_CSTRING_LOOSE_OPERATOR_PLUS + /** Definition of a Loose CString. */ typedef CString_Loose CStringL; diff --git a/Jupiter/CString_Imp.h b/Jupiter/CString_Imp.h index b50f304..71a3c00 100644 --- a/Jupiter/CString_Imp.h +++ b/Jupiter/CString_Imp.h @@ -108,6 +108,36 @@ template Jupiter::CString_Type::CString_Type(const T *in) } } +template Jupiter::CString_Type::CString_Type(const Jupiter::Readable_String &lhs, const Jupiter::Readable_String &rhs) : CString_Type(lhs.size() + rhs.size()) +{ + const T *itr; + const T *end; + + if (lhs.isNotEmpty()) + { + itr = lhs.ptr(); + end = itr + lhs.size(); + *Jupiter::String_Type::str = *itr; + while (++itr != end) + *++Jupiter::String_Type::str = *itr; + ++Jupiter::String_Type::str; + } + + if (rhs.isNotEmpty()) + { + itr = rhs.ptr(); + end = itr + rhs.size(); + *Jupiter::String_Type::str = *itr; + while (++itr != end) + *++Jupiter::String_Type::str = *itr; + ++Jupiter::String_Type::str; + } + + *Jupiter::String_Type::str = 0; + Jupiter::String_Type::length = Jupiter::String_Type::str - Jupiter::Shift_String_Type::base; + Jupiter::String_Type::str = Jupiter::Shift_String_Type::base; +} + template bool Jupiter::CString_Type::setBufferSize(size_t len) { if (Jupiter::Shift_String_Type::setBufferSize(len + 1)) @@ -385,6 +415,24 @@ template size_t Jupiter::CString_Type::concat(const T c) return Jupiter::String_Type::length; } +// Operators +template inline Jupiter::CString_Type Jupiter::CString_Type::operator+(const Jupiter::CString_Type &rhs) const +{ + return Jupiter::CString_Type::operator+(reinterpret_cast &>(rhs)); +} + +template inline Jupiter::CString_Type Jupiter::CString_Type::operator+(const Jupiter::Readable_String &rhs) const +{ + return Jupiter::operator+(*this, rhs); +} + +#if defined JUPITER_CSTRING_TYPE_OPERATOR_PLUS +template static inline Jupiter::CString_Type Jupiter::operator+(const Jupiter::Readable_String &lhs, const Jupiter::Readable_String &rhs) +{ + return Jupiter::CString_Type(lhs, rhs); +} +#endif // JUPITER_CSTRING_TYPE_OPERATOR_PLUS + template const Jupiter::CString_Type Jupiter::CString_Type::empty = Jupiter::CString_Type(); // Jupiter::DataBuffer specialization @@ -479,6 +527,36 @@ template Jupiter::CString_Loose::CString_Loose(const T *in) : Jup } } +template Jupiter::CString_Loose::CString_Loose(const Jupiter::Readable_String &lhs, const Jupiter::Readable_String &rhs) : CString_Loose(lhs.size() + rhs.size()) +{ + const T *itr; + const T *end; + + if (lhs.isNotEmpty()) + { + itr = lhs.ptr(); + end = itr + lhs.size(); + *Jupiter::String_Type::str = *itr; + while (++itr != end) + *++Jupiter::String_Type::str = *itr; + ++Jupiter::String_Type::str; + } + + if (rhs.isNotEmpty()) + { + itr = rhs.ptr(); + end = itr + rhs.size(); + *Jupiter::String_Type::str = *itr; + while (++itr != end) + *++Jupiter::String_Type::str = *itr; + ++Jupiter::String_Type::str; + } + + *Jupiter::String_Type::str = 0; + Jupiter::String_Type::length = Jupiter::String_Type::str - Jupiter::Shift_String_Type::base; + Jupiter::String_Type::str = Jupiter::Shift_String_Type::base; +} + template bool Jupiter::CString_Loose::setBufferSize(size_t len) { len = getPowerTwo32(len + 1); @@ -590,6 +668,24 @@ template Jupiter::CString_Loose Jupiter::CString_Loose::gotoWo return Jupiter::Readable_String::gotoWord(in, pos, whitespace); } +// Operators +template inline Jupiter::CString_Loose Jupiter::CString_Loose::operator+(const Jupiter::CString_Loose &rhs) const +{ + return Jupiter::CString_Loose::operator+(reinterpret_cast &>(rhs)); +} + +template inline Jupiter::CString_Loose Jupiter::CString_Loose::operator+(const Jupiter::Readable_String &rhs) const +{ + return Jupiter::operator+(*this, rhs); +} + +#if defined JUPITER_CSTRING_LOOSE_OPERATOR_PLUS +template static inline Jupiter::CString_Loose Jupiter::operator+(const Jupiter::Readable_String &lhs, const Jupiter::Readable_String &rhs) +{ + return Jupiter::CString_Loose(lhs, rhs); +} +#endif // JUPITER_CSTRING_LOOSE_OPERATOR_PLUS + template const Jupiter::CString_Loose Jupiter::CString_Loose::empty = Jupiter::CString_Loose(); // Jupiter::DataBuffer specialization diff --git a/Jupiter/Shift_String.h b/Jupiter/Shift_String.h index 7ecf043..13a9e95 100644 --- a/Jupiter/Shift_String.h +++ b/Jupiter/Shift_String.h @@ -76,6 +76,11 @@ namespace Jupiter */ virtual void remove(size_t index, size_t length) override; + /** + * @brief Removes all elements from the string. + */ + virtual void erase(); + /** * @brief Default constructor for the Shift_String_Type class. */ diff --git a/Jupiter/Shift_String_Imp.h b/Jupiter/Shift_String_Imp.h index 7465128..f2fd40a 100644 --- a/Jupiter/Shift_String_Imp.h +++ b/Jupiter/Shift_String_Imp.h @@ -72,6 +72,12 @@ template void Jupiter::Shift_String_Type::remove(size_t index, si Jupiter::String_Type::remove(index, len); } +template void Jupiter::Shift_String_Type::erase() +{ + Jupiter::String_Type::erase(); + Jupiter::String_Type::str = Jupiter::Shift_String_Type::base; +} + template bool Jupiter::Shift_String_Type::setBufferSize(size_t len) { if (len > Jupiter::String_Type::length) diff --git a/Jupiter/String.h b/Jupiter/String.h index 6b842ec..fd3d147 100644 --- a/Jupiter/String.h +++ b/Jupiter/String.h @@ -203,15 +203,6 @@ namespace Jupiter static String_Strict gotoToken(const Jupiter::Readable_String &in, size_t pos, const T &token); static String_Strict gotoToken(const Jupiter::Readable_String &in, size_t pos, const Jupiter::Readable_String &token); - /** Assignment Operators */ - inline String_Strict &operator=(const String_Strict &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; }; - - static const Jupiter::String_Strict empty; /** Empty instantation of String_Strict */ - /** Default Constructor */ String_Strict(); @@ -234,12 +225,33 @@ namespace Jupiter String_Strict(const T *in); String_Strict(const Jupiter::DataBuffer &in); + /** Concatenation Constructor */ + String_Strict(const Readable_String &lhs, const Readable_String &rhs); + + /** Addition Operators */ + inline String_Strict operator+(const String_Strict &rhs) const; + inline String_Strict operator+(const Readable_String &rhs) const; + + /** Assignment Operators */ + inline String_Strict &operator=(const String_Strict &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; }; + + static const Jupiter::String_Strict empty; /** Empty instantiation of String_Strict */ + protected: /** Dummy constructor to prevent string initialization */ String_Strict(Jupiter::String_Constructor_Base &) {}; }; +#if defined JUPITER_STRING_STRICT_OPERATOR_PLUS + /** String_Loose Addition Operator */ + template static inline Jupiter::String_Strict operator+(const Jupiter::Readable_String &lhs, const Jupiter::Readable_String &rhs); +#endif // JUPITER_STRING_STRICT_OPERATOR_PLUS + /** * @brief Provides a "loose" String implementation that's more optimized for repeated concatenations. * Note: The underlying string will always have a size which is a power of 2, but no fewer than 8 elements. @@ -424,15 +436,19 @@ namespace Jupiter String_Loose(String_Loose &&source); /** Copy Constructors */ - String_Loose(const String_Loose &in); + String_Loose(const String_Loose &in); String_Loose(const Readable_String &in); String_Loose(const std::basic_string &in); String_Loose(const T *in, size_t len); String_Loose(const T *in); String_Loose(const Jupiter::DataBuffer &in); - static const Jupiter::String_Loose empty; /** Empty instantation of String_Loose */ - static const size_t start_size = 8; /** Starting size for loose Strings. */ + /** Concatenation Constructor */ + String_Loose(const Readable_String &lhs, const Readable_String &rhs); + + /** Addition Operators */ + inline String_Loose operator+(const String_Loose &rhs) const; + inline String_Loose operator+(const Readable_String &rhs) const; /** Assignment Operators */ inline String_Loose &operator=(const String_Loose &right) { this->set(right); return *this; }; @@ -441,6 +457,9 @@ namespace Jupiter inline String_Loose &operator=(const T *right) { this->set(right); return *this; }; inline String_Loose &operator=(const T right) { this->set(right); return *this; }; + static const Jupiter::String_Loose empty; /** Empty instantiation of String_Loose */ + static const size_t start_size = 8; /** Starting size for loose Strings. */ + protected: /** @@ -467,6 +486,13 @@ namespace Jupiter size_t strSize; /** Size of underlying string buffer */ }; +#if !defined JUPITER_STRING_STRICT_OPERATOR_PLUS +#if !defined DISABLE_DEFAULT_JUPITER_STRING_OPERATOR_PLUS + /** String_Loose Addition Operator */ + template static inline Jupiter::String_Loose operator+(const Jupiter::Readable_String &lhs, const Jupiter::Readable_String &rhs); +#endif // DISABLE_DEFAULT_JUPITER_STRING_OPERATOR_PLUS +#endif // JUPITER_STRING_STRICT_OPERATOR_PLUS + /** Definition of a Loose String. */ typedef String_Loose StringL; diff --git a/Jupiter/String_Imp.h b/Jupiter/String_Imp.h index 4f10b88..5b87dcd 100644 --- a/Jupiter/String_Imp.h +++ b/Jupiter/String_Imp.h @@ -105,6 +105,35 @@ template Jupiter::String_Strict::String_Strict(const Jupiter::Dat { } +template Jupiter::String_Strict::String_Strict(const Jupiter::Readable_String &lhs, const Jupiter::Readable_String &rhs) : String_Strict(lhs.size() + rhs.size()) +{ + const T *itr; + const T *end; + + if (lhs.isNotEmpty()) + { + itr = lhs.ptr(); + end = itr + lhs.size(); + *Jupiter::String_Type::str = *itr; + while (++itr != end) + *++Jupiter::String_Type::str = *itr; + ++Jupiter::String_Type::str; + } + + if (rhs.isNotEmpty()) + { + itr = rhs.ptr(); + end = itr + rhs.size(); + *Jupiter::String_Type::str = *itr; + while (++itr != end) + *++Jupiter::String_Type::str = *itr; + ++Jupiter::String_Type::str; + } + + Jupiter::String_Type::length = Jupiter::String_Type::str - Jupiter::Shift_String_Type::base; + Jupiter::String_Type::str = Jupiter::Shift_String_Type::base; +} + // vformat() template<> size_t inline Jupiter::String_Strict::vformat(const char *format, va_list args) @@ -286,6 +315,24 @@ template Jupiter::String_Strict Jupiter::String_Strict::gotoTo return Jupiter::Readable_String::gotoToken(in, pos, token); } +// Operators +template inline Jupiter::String_Strict Jupiter::String_Strict::operator+(const Jupiter::String_Strict &rhs) const +{ + return Jupiter::String_Strict::operator+(reinterpret_cast &>(rhs)); +} + +template inline Jupiter::String_Strict Jupiter::String_Strict::operator+(const Jupiter::Readable_String &rhs) const +{ + return Jupiter::operator+(*this, rhs); +} + +#if defined JUPITER_STRING_STRICT_OPERATOR_PLUS +template static inline Jupiter::String_Strict Jupiter::operator+(const Jupiter::Readable_String &lhs, const Jupiter::Readable_String &rhs) +{ + return Jupiter::String_Strict(lhs, rhs); +} +#endif // JUPITER_STRING_STRICT_OPERATOR_PLUS + template const Jupiter::String_Strict Jupiter::String_Strict::empty = Jupiter::String_Strict(); // Jupiter::DataBuffer specialization @@ -385,6 +432,35 @@ template Jupiter::String_Loose::String_Loose(const Jupiter::DataB { } +template Jupiter::String_Loose::String_Loose(const Jupiter::Readable_String &lhs, const Jupiter::Readable_String &rhs) : String_Loose(lhs.size() + rhs.size()) +{ + const T *itr; + const T *end; + + if (lhs.isNotEmpty()) + { + itr = lhs.ptr(); + end = itr + lhs.size(); + *Jupiter::String_Type::str = *itr; + while (++itr != end) + *++Jupiter::String_Type::str = *itr; + ++Jupiter::String_Type::str; + } + + if (rhs.isNotEmpty()) + { + itr = rhs.ptr(); + end = itr + rhs.size(); + *Jupiter::String_Type::str = *itr; + while (++itr != end) + *++Jupiter::String_Type::str = *itr; + ++Jupiter::String_Type::str; + } + + Jupiter::String_Type::length = Jupiter::String_Type::str - Jupiter::Shift_String_Type::base; + Jupiter::String_Type::str = Jupiter::Shift_String_Type::base; +} + template bool Jupiter::String_Loose::setBufferSize(size_t len) { return Jupiter::Shift_String_Type::setBufferSize(Jupiter::String_Loose::strSize = getPowerTwo32(len)); @@ -576,6 +652,26 @@ template Jupiter::String_Loose Jupiter::String_Loose::gotoToke return Jupiter::Readable_String::gotoToken(in, pos, token); } +// Operators +template inline Jupiter::String_Loose Jupiter::String_Loose::operator+(const Jupiter::String_Loose &rhs) const +{ + return Jupiter::String_Loose::operator+(reinterpret_cast &>(rhs)); +} + +template inline Jupiter::String_Loose Jupiter::String_Loose::operator+(const Jupiter::Readable_String &rhs) const +{ + return Jupiter::operator+(*this, rhs); +} + +#if !defined JUPITER_STRING_STRICT_OPERATOR_PLUS +#if !defined DISABLE_DEFAULT_JUPITER_STRING_OPERATOR_PLUS +template static inline Jupiter::String_Loose Jupiter::operator+(const Jupiter::Readable_String &lhs, const Jupiter::Readable_String &rhs) +{ + return Jupiter::String_Loose(lhs, rhs); +} +#endif // DISABLE_DEFAULT_JUPITER_STRING_OPERATOR_PLUS +#endif // JUPITER_STRING_STRICT_OPERATOR_PLUS + template const Jupiter::String_Loose Jupiter::String_Loose::empty = Jupiter::String_Loose(); // Jupiter::DataBuffer specialization diff --git a/Jupiter/String_Type.h b/Jupiter/String_Type.h index f7ae093..1634041 100644 --- a/Jupiter/String_Type.h +++ b/Jupiter/String_Type.h @@ -116,6 +116,11 @@ namespace Jupiter */ virtual void remove(size_t index, size_t length); + /** + * @brief Removes all elements from the string. + */ + virtual void erase(); + /** * @brief Processes escape sequences in a string. * Source reference: http://en.cppreference.com/w/cpp/language/escape diff --git a/Jupiter/String_Type_Imp.h b/Jupiter/String_Type_Imp.h index 788426d..fe018f7 100644 --- a/Jupiter/String_Type_Imp.h +++ b/Jupiter/String_Type_Imp.h @@ -152,6 +152,13 @@ template void Jupiter::String_Type::remove(size_t index, size_t l } } +// erase + +template void Jupiter::String_Type::erase() +{ + Jupiter::String_Type::length = 0; +} + // processEscapeSequences template void Jupiter::String_Type::processEscapeSequences() diff --git a/Release/Jupiter.lib b/Release/Jupiter.lib index df56c4a..8850119 100644 Binary files a/Release/Jupiter.lib and b/Release/Jupiter.lib differ