New StringView function: SpanWhile

This commit is contained in:
VegOwOtenks 2024-10-10 15:57:56 +02:00
parent 10be4dfbbf
commit a30f259121
2 changed files with 10 additions and 0 deletions

View file

@ -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);

View file

@ -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);