From b5e6f93fd70bf748a10be49394689d967ee247ea Mon Sep 17 00:00:00 2001 From: JustinAJ Date: Tue, 3 Jun 2014 01:05:16 -0400 Subject: [PATCH] Added empty static member and set() functions --- Jupiter/Reference_String.h | 13 +++++++++++++ Jupiter/Reference_String_Imp.h | 31 +++++++++++++++++++++++++++---- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/Jupiter/Reference_String.h b/Jupiter/Reference_String.h index 6d01b7f..a2a4e17 100644 --- a/Jupiter/Reference_String.h +++ b/Jupiter/Reference_String.h @@ -61,6 +61,17 @@ namespace Jupiter */ const T *ptr() const; + /** + * @brief Sets the reference to point to an input string. + * + * @param in String containing the data to be referenced. + * @return New size of the String. + */ + size_t set(const Jupiter::Readable_String &in); + size_t set(const std::basic_string &in); + size_t set(const T *in, size_t len); + size_t set(const T *in); + /** * @brief Creates a partial copy of the string. * @@ -192,6 +203,8 @@ namespace Jupiter */ Reference_String(const Jupiter::Reference_String &in); + static const Jupiter::Reference_String empty; /** Empty instantiation of Reference_String */ + protected: const T *str; /** Pointer for the underlying string of elements */ diff --git a/Jupiter/Reference_String_Imp.h b/Jupiter/Reference_String_Imp.h index 5ee158a..fcb04e1 100644 --- a/Jupiter/Reference_String_Imp.h +++ b/Jupiter/Reference_String_Imp.h @@ -32,16 +32,15 @@ * Reference_String */ -template Jupiter::Reference_String::Reference_String() +template Jupiter::Reference_String::Reference_String() : Reference_String(nullptr, 0) { - Jupiter::Reference_String::str = ""; - Jupiter::Reference_String::length = 0; } template Jupiter::Reference_String::Reference_String(const T *in) { Jupiter::Reference_String::str = in; - Jupiter::Reference_String::length = Jupiter::strlen(in); + if (in == nullptr) Jupiter::Reference_String::length = 0; + else Jupiter::Reference_String::length = Jupiter::strlen(in); } template Jupiter::Reference_String::Reference_String(const T *in, size_t len) @@ -81,6 +80,28 @@ template const T *Jupiter::Reference_String::ptr() const return Jupiter::Reference_String::str; } +template size_t Jupiter::Reference_String::set(const Jupiter::Readable_String &in) +{ + return this->set(in.ptr(), in.size()); +} + +template size_t Jupiter::Reference_String::set(const std::basic_string &in) +{ + return this->set(in.data(), in.size()); +} + +template size_t Jupiter::Reference_String::set(const T *in, size_t len) +{ + Jupiter::Reference_String::str = in; + return Jupiter::Reference_String::length = len; +} + +template size_t Jupiter::Reference_String::set(const T *in) +{ + if (in == nullptr) return this->set(in, 0); + return this->set(in, Jupiter::strlen(in)); +} + template Jupiter::Reference_String Jupiter::Reference_String::substring(size_t pos) const { return Jupiter::Reference_String::substring(*this, pos); @@ -143,4 +164,6 @@ template Jupiter::Reference_String Jupiter::Reference_String:: return Jupiter::Readable_String::gotoWord(in, pos, whitespace); } +template const Jupiter::Reference_String Jupiter::Reference_String::empty = Jupiter::Reference_String(); + #endif // _REFERENCE_STRING_IMP \ No newline at end of file