Browse Source

Added truncate() function to Reference_String.

release/0.19
JustinAJ 11 years ago
parent
commit
eb146710cf
  1. 8
      Jupiter/Reference_String.h
  2. 10
      Jupiter/Reference_String_Imp.h

8
Jupiter/Reference_String.h

@ -61,6 +61,14 @@ namespace Jupiter
*/ */
const T *ptr() const; const T *ptr() const;
/**
* @brief Truncates the string by a specified number of elements.
*
* @param n Number of elements to remove from the tail.
* @return New size of the String.
*/
virtual size_t truncate(size_t n);
/** /**
* @brief Sets the reference to point to an input string. * @brief Sets the reference to point to an input string.
* *

10
Jupiter/Reference_String_Imp.h

@ -80,6 +80,16 @@ template<typename T> const T *Jupiter::Reference_String<T>::ptr() const
return Jupiter::Reference_String<T>::str; return Jupiter::Reference_String<T>::str;
} }
// truncate
template<typename T> size_t Jupiter::Reference_String<T>::truncate(size_t n)
{
if (n >= Jupiter::Reference_String<T>::length) return (Jupiter::Reference_String<T>::length = 0);
return (Jupiter::Reference_String<T>::length -= n);
}
// set
template<typename T> size_t Jupiter::Reference_String<T>::set(const Jupiter::Readable_String<T> &in) template<typename T> size_t Jupiter::Reference_String<T>::set(const Jupiter::Readable_String<T> &in)
{ {
return this->set(in.ptr(), in.size()); return this->set(in.ptr(), in.size());

Loading…
Cancel
Save