diff --git a/Jupiter/Readable_String.h b/Jupiter/Readable_String.h index ced8b70..f5db4eb 100644 --- a/Jupiter/Readable_String.h +++ b/Jupiter/Readable_String.h @@ -81,6 +81,15 @@ namespace Jupiter size_t find(const T &value, size_t index = 0) const; size_t find(const Readable_String &in) const; + /** + * @brief Returns the number of elements of the string which match the input string. + * + * @param in Character set to match against. + * @return Number of elements at the start of the string that match the character set. + */ + size_t span(const Readable_String &in) const; + size_t span(const T *str) const; + /** * @brief Compares another string against the String. * diff --git a/Jupiter/Readable_String_Imp.h b/Jupiter/Readable_String_Imp.h index 3dde809..1055b61 100644 --- a/Jupiter/Readable_String_Imp.h +++ b/Jupiter/Readable_String_Imp.h @@ -68,6 +68,22 @@ template size_t Jupiter::Readable_String::find(const Jupiter::Rea return Jupiter::INVALID_INDEX; } +// span() + +template size_t Jupiter::Readable_String::span(const Jupiter::Readable_String &in) const +{ + size_t index = 0; + while (in.contains(this->get(index))) index++; + return index; +} + +template size_t Jupiter::Readable_String::span(const T *in) const +{ + size_t index = 0; + while (containsSymbol(in, this->get(index))) index++; + return index; +} + // compare() template int Jupiter::Readable_String::compare(const Jupiter::Readable_String &in) const