From 952ac5c00a1f566cf2b7a5a1ce082827dc4c57fd Mon Sep 17 00:00:00 2001 From: JustinAJ Date: Tue, 3 Jun 2014 22:08:00 -0400 Subject: [PATCH] Added shiftLeft() and shiftRight() --- Jupiter/Reference_String.h | 16 ++++++++++++++++ Jupiter/Reference_String_Imp.h | 17 +++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/Jupiter/Reference_String.h b/Jupiter/Reference_String.h index 9a1bd4e..ca5ad17 100644 --- a/Jupiter/Reference_String.h +++ b/Jupiter/Reference_String.h @@ -69,6 +69,22 @@ namespace Jupiter */ virtual size_t truncate(size_t n); + /** + * @brief Shifts the string pointer to the left. + * + * @param length Number of elements to shift + * @return Number of elements shifted to the left. + */ + size_t shiftLeft(size_t length); + + /** + * @brief Shifts the string pointer to the right. + * + * @param length Number of elements to shift + * @return Number of elements shifted. + */ + size_t shiftRight(size_t length); + /** * @brief Sets the reference to point to an input string. * diff --git a/Jupiter/Reference_String_Imp.h b/Jupiter/Reference_String_Imp.h index df33adc..4e31f49 100644 --- a/Jupiter/Reference_String_Imp.h +++ b/Jupiter/Reference_String_Imp.h @@ -88,6 +88,23 @@ template size_t Jupiter::Reference_String::truncate(size_t n) return (Jupiter::Reference_String::length -= n); } +// shift + +template size_t Jupiter::Reference_String::shiftLeft(size_t len) +{ + Jupiter::String_Type::str -= len; + Jupiter::String_Type::length += len; + return len; +} + +template size_t Jupiter::Reference_String::shiftRight(size_t len) +{ + if (len > Jupiter::String_Type::length) len = Jupiter::String_Type::length; + Jupiter::String_Type::str += len; + Jupiter::String_Type::length -= len; + return len; +} + // set template size_t Jupiter::Reference_String::set(const Jupiter::Readable_String &in)