Refactor strtrim function
Signed-off-by: Silvan Jegen <s.jegen@gmail.com> Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
parent
9e22e75fa1
commit
947dfda515
1 changed files with 5 additions and 9 deletions
|
@ -144,17 +144,13 @@ size_t strtrim(char *str)
|
||||||
}
|
}
|
||||||
if(pch != str) {
|
if(pch != str) {
|
||||||
size_t len = strlen(pch);
|
size_t len = strlen(pch);
|
||||||
if(len) {
|
/* check if there wasn't anything but whitespace in the string. */
|
||||||
memmove(str, pch, len + 1);
|
if(len == 0) {
|
||||||
pch = str;
|
|
||||||
} else {
|
|
||||||
*str = '\0';
|
*str = '\0';
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
memmove(str, pch, len + 1);
|
||||||
|
pch = str;
|
||||||
/* check if there wasn't anything but whitespace in the string. */
|
|
||||||
if(*str == '\0') {
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
end = (str + strlen(str) - 1);
|
end = (str + strlen(str) - 1);
|
||||||
|
|
Loading…
Add table
Reference in a new issue