Simplify sc_str_truncate()

Use strcspn() to get the prefix length directly.
This commit is contained in:
Romain Vimont 2021-11-18 09:34:54 +01:00
parent 9619ade706
commit cb65531533

View file

@ -295,10 +295,7 @@ error:
size_t
sc_str_truncate(char *data, size_t len, const char *endchars) {
data[len - 1] = '\0';
char *eol = strpbrk(data, endchars);
if (eol) {
*eol = '\0';
len = eol - data;
}
return len;
size_t idx = strcspn(data, endchars);
data[idx] = '\0';
return idx;
}