diff --git a/sv.h b/sv.h index 09c6321..f7d0bf9 100644 --- a/sv.h +++ b/sv.h @@ -179,19 +179,11 @@ SVDEF bool sv_try_chop_by_delim(String_View *sv, char delim, String_View *chunk) SVDEF String_View sv_chop_by_delim(String_View *sv, char delim) { - size_t i = 0; - while (i < sv->count && sv->data[i] != delim) { - i += 1; - } - - String_View result = sv_from_parts(sv->data, i); + String_View result; - if (i < sv->count) { - sv->count -= i + 1; - sv->data += i + 1; - } else { - sv->count -= i; - sv->data += i; + if (!sv_try_chop_by_delim(sv, delim, &result)) { + result = *sv; + *sv = SV_NULL; } return result;