diff --git a/src/StringView/StringView.c b/src/StringView/StringView.c index aace3d5..50fb023 100644 --- a/src/StringView/StringView.c +++ b/src/StringView/StringView.c @@ -132,6 +132,15 @@ StringView StringView_TakeWhile(StringView string, StringViewContinue function) return StringView_Take(string, length); } +StringView StringView_SpanWhile(StringView* source, StringViewContinue function) +{ + StringView result = StringView_TakeWhile(*source, function); + + *source = StringView_Slice(*source, result.length, source->length); + + return result; +} + StringView StringView_Take(StringView string, size_t length) { return StringView_Slice(string, 0, length); diff --git a/src/StringView/StringView.h b/src/StringView/StringView.h index 98e1f79..bee2e2c 100644 --- a/src/StringView/StringView.h +++ b/src/StringView/StringView.h @@ -50,6 +50,7 @@ StringView StringView_Slice(StringView string, size_t start, size_t end); // sta StringView StringView_Drop(StringView string, size_t length); StringView StringView_Take(StringView string, size_t length); StringView StringView_TakeWhile(StringView string, StringViewContinue function); +StringView StringView_SpanWhile(StringView* source, StringViewContinue function); bool StringView_Partition(StringView* left, StringView* right, StringView source, StringView delim); bool StringView_NextSplit(StringView* dest, StringView* source, StringView delim);