Browse Source

Added empty static member and set() functions

release/0.19
JustinAJ 11 years ago
parent
commit
b5e6f93fd7
  1. 13
      Jupiter/Reference_String.h
  2. 31
      Jupiter/Reference_String_Imp.h

13
Jupiter/Reference_String.h

@ -61,6 +61,17 @@ namespace Jupiter
*/ */
const T *ptr() const; 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<T> &in);
size_t set(const std::basic_string<T> &in);
size_t set(const T *in, size_t len);
size_t set(const T *in);
/** /**
* @brief Creates a partial copy of the string. * @brief Creates a partial copy of the string.
* *
@ -192,6 +203,8 @@ namespace Jupiter
*/ */
Reference_String(const Jupiter::Reference_String<T> &in); Reference_String(const Jupiter::Reference_String<T> &in);
static const Jupiter::Reference_String<T> empty; /** Empty instantiation of Reference_String */
protected: protected:
const T *str; /** Pointer for the underlying string of elements */ const T *str; /** Pointer for the underlying string of elements */

31
Jupiter/Reference_String_Imp.h

@ -32,16 +32,15 @@
* Reference_String * Reference_String
*/ */
template<typename T> Jupiter::Reference_String<T>::Reference_String() template<typename T> Jupiter::Reference_String<T>::Reference_String() : Reference_String(nullptr, 0)
{ {
Jupiter::Reference_String<T>::str = "";
Jupiter::Reference_String<T>::length = 0;
} }
template<typename T> Jupiter::Reference_String<T>::Reference_String(const T *in) template<typename T> Jupiter::Reference_String<T>::Reference_String(const T *in)
{ {
Jupiter::Reference_String<T>::str = in; Jupiter::Reference_String<T>::str = in;
Jupiter::Reference_String<T>::length = Jupiter::strlen<T>(in); if (in == nullptr) Jupiter::Reference_String<T>::length = 0;
else Jupiter::Reference_String<T>::length = Jupiter::strlen<T>(in);
} }
template<typename T> Jupiter::Reference_String<T>::Reference_String(const T *in, size_t len) template<typename T> Jupiter::Reference_String<T>::Reference_String(const T *in, size_t len)
@ -81,6 +80,28 @@ template<typename T> const T *Jupiter::Reference_String<T>::ptr() const
return Jupiter::Reference_String<T>::str; return Jupiter::Reference_String<T>::str;
} }
template<typename T> size_t Jupiter::Reference_String<T>::set(const Jupiter::Readable_String<T> &in)
{
return this->set(in.ptr(), in.size());
}
template<typename T> size_t Jupiter::Reference_String<T>::set(const std::basic_string<T> &in)
{
return this->set(in.data(), in.size());
}
template<typename T> size_t Jupiter::Reference_String<T>::set(const T *in, size_t len)
{
Jupiter::Reference_String<T>::str = in;
return Jupiter::Reference_String<T>::length = len;
}
template<typename T> size_t Jupiter::Reference_String<T>::set(const T *in)
{
if (in == nullptr) return this->set(in, 0);
return this->set(in, Jupiter::strlen<T>(in));
}
template<typename T> Jupiter::Reference_String<T> Jupiter::Reference_String<T>::substring(size_t pos) const template<typename T> Jupiter::Reference_String<T> Jupiter::Reference_String<T>::substring(size_t pos) const
{ {
return Jupiter::Reference_String<T>::substring(*this, pos); return Jupiter::Reference_String<T>::substring(*this, pos);
@ -143,4 +164,6 @@ template<typename T> Jupiter::Reference_String<T> Jupiter::Reference_String<T>::
return Jupiter::Readable_String<T>::gotoWord<Jupiter::Reference_String>(in, pos, whitespace); return Jupiter::Readable_String<T>::gotoWord<Jupiter::Reference_String>(in, pos, whitespace);
} }
template<typename T> const Jupiter::Reference_String<T> Jupiter::Reference_String<T>::empty = Jupiter::Reference_String<T>();
#endif // _REFERENCE_STRING_IMP #endif // _REFERENCE_STRING_IMP
Loading…
Cancel
Save