backported fixes for trim() from pacman 2.9.5
This commit is contained in:
parent
e010e1bba6
commit
6e63ccfd0f
1 changed files with 11 additions and 1 deletions
|
@ -145,6 +145,11 @@ char *_alpm_strtrim(char *str)
|
||||||
{
|
{
|
||||||
char *pch = str;
|
char *pch = str;
|
||||||
|
|
||||||
|
if(*str == '\0') {
|
||||||
|
/* string is empty, so we're done. */
|
||||||
|
return(str);
|
||||||
|
}
|
||||||
|
|
||||||
while(isspace(*pch)) {
|
while(isspace(*pch)) {
|
||||||
pch++;
|
pch++;
|
||||||
}
|
}
|
||||||
|
@ -152,13 +157,18 @@ char *_alpm_strtrim(char *str)
|
||||||
memmove(str, pch, (strlen(pch) + 1));
|
memmove(str, pch, (strlen(pch) + 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* check if there wasn't anything but whitespace in the string. */
|
||||||
|
if(*str == '\0') {
|
||||||
|
return(str);
|
||||||
|
}
|
||||||
|
|
||||||
pch = (char*)(str + (strlen(str) - 1));
|
pch = (char*)(str + (strlen(str) - 1));
|
||||||
while(isspace(*pch)) {
|
while(isspace(*pch)) {
|
||||||
pch--;
|
pch--;
|
||||||
}
|
}
|
||||||
*++pch = '\0';
|
*++pch = '\0';
|
||||||
|
|
||||||
return str;
|
return(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* A cheap grep for text files, returns 1 if a substring
|
/* A cheap grep for text files, returns 1 if a substring
|
||||||
|
|
Loading…
Add table
Reference in a new issue