labwc/src/common/string-helpers.c

28 lines
330 B
C
Raw Normal View History

2020-10-09 19:46:59 +01:00
#include <ctype.h>
#include <stdio.h>
#include <string.h>
static void
rtrim(char **s)
{
size_t len = strlen(*s);
if (!len) {
return;
}
char *end = *s + len - 1;
while (end >= *s && isspace(*end)) {
end--;
}
*(end + 1) = '\0';
}
char *
string_strip(char *s)
{
rtrim(&s);
while (isspace(*s)) {
s++;
}
return s;
}