mirror of
https://github.com/labwc/labwc.git
synced 2025-11-07 13:30:06 -05:00
Add string-helpers.c
This commit is contained in:
parent
51507df2e7
commit
7e55e2cd09
6 changed files with 47 additions and 54 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue