Add string-helpers.c

This commit is contained in:
Johan Malm 2020-10-09 19:46:59 +01:00
parent 51507df2e7
commit 7e55e2cd09
6 changed files with 47 additions and 54 deletions

View file

@ -8,6 +8,7 @@
#include "common/dir.h"
#include "common/log.h"
#include "common/spawn.h"
#include "common/string-helpers.h"
static bool
isfile(const char *path)
@ -22,30 +23,6 @@ string_empty(const char *s)
return !s || !*s;
}
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';
}
static char *
strstrip(char *s)
{
rtrim(&s);
while (isspace(*s)) {
s++;
}
return s;
}
static void
process_line(char *line)
{
@ -58,8 +35,8 @@ process_line(char *line)
return;
}
*p = '\0';
key = strstrip(line);
value = strstrip(++p);
key = string_strip(line);
value = string_strip(++p);
if (string_empty(key) || string_empty(value)) {
return;
}