mirror of
https://github.com/moparisthebest/pacman
synced 2024-12-23 00:08:50 -05:00
pacman/util: return size_t from strtrim
Instead of returning the same value as the parameter to this function, return the length of the string, which can be useful to the caller when its non-zero (e.g. to find the end of the string). Signed-off-by: Dave Reisner <dreisner@archlinux.org>
This commit is contained in:
parent
7b2f68cc21
commit
92216c5864
@ -325,13 +325,13 @@ char *strtoupper(char *str)
|
|||||||
|
|
||||||
/* Trim whitespace and newlines from a string
|
/* Trim whitespace and newlines from a string
|
||||||
*/
|
*/
|
||||||
char *strtrim(char *str)
|
size_t strtrim(char *str)
|
||||||
{
|
{
|
||||||
char *pch = str;
|
char *end, *pch = str;
|
||||||
|
|
||||||
if(str == NULL || *str == '\0') {
|
if(str == NULL || *str == '\0') {
|
||||||
/* string is empty, so we're done. */
|
/* string is empty, so we're done. */
|
||||||
return str;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
while(isspace((unsigned char)*pch)) {
|
while(isspace((unsigned char)*pch)) {
|
||||||
@ -348,16 +348,16 @@ char *strtrim(char *str)
|
|||||||
|
|
||||||
/* check if there wasn't anything but whitespace in the string. */
|
/* check if there wasn't anything but whitespace in the string. */
|
||||||
if(*str == '\0') {
|
if(*str == '\0') {
|
||||||
return str;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
pch = (str + (strlen(str) - 1));
|
end = (str + strlen(str) - 1);
|
||||||
while(isspace((unsigned char)*pch)) {
|
while(isspace((unsigned char)*end)) {
|
||||||
pch--;
|
end--;
|
||||||
}
|
}
|
||||||
*++pch = '\0';
|
*++end = '\0';
|
||||||
|
|
||||||
return str;
|
return end - pch;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Replace all occurances of 'needle' with 'replace' in 'str', returning
|
/* Replace all occurances of 'needle' with 'replace' in 'str', returning
|
||||||
|
@ -56,7 +56,7 @@ const char *mbasename(const char *path);
|
|||||||
char *mdirname(const char *path);
|
char *mdirname(const char *path);
|
||||||
void indentprint(const char *str, size_t indent);
|
void indentprint(const char *str, size_t indent);
|
||||||
char *strtoupper(char *str);
|
char *strtoupper(char *str);
|
||||||
char *strtrim(char *str);
|
size_t strtrim(char *str);
|
||||||
char *strreplace(const char *str, const char *needle, const char *replace);
|
char *strreplace(const char *str, const char *needle, const char *replace);
|
||||||
alpm_list_t *strsplit(const char *str, const char splitchar);
|
alpm_list_t *strsplit(const char *str, const char splitchar);
|
||||||
void string_display(const char *title, const char *string);
|
void string_display(const char *title, const char *string);
|
||||||
|
Loading…
Reference in New Issue
Block a user