Simplify sc_str_truncate()
Use strcspn() to get the prefix length directly.
@@ -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;
}
