Simplify sc_str_truncate()
Use strcspn() to get the prefix length directly.
This commit is contained in:
parent
9619ade706
commit
cb65531533
1 changed files with 3 additions and 6 deletions
|
@ -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;
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue