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 size_t
sc_str_truncate(char *data, size_t len, const char *endchars) { sc_str_truncate(char *data, size_t len, const char *endchars) {
data[len - 1] = '\0'; data[len - 1] = '\0';
char *eol = strpbrk(data, endchars); size_t idx = strcspn(data, endchars);
if (eol) { data[idx] = '\0';
*eol = '\0'; return idx;
len = eol - data;
}
return len;
} }