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
|
||||
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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue