tokenizer: split out equals-as-delimiter tokenizer to its own function

This commit is contained in:
Ariadne Conill 2020-09-14 17:34:44 -06:00
parent 4b30dc4573
commit 27a383cfa7
2 changed files with 21 additions and 3 deletions

View file

@ -40,8 +40,8 @@ lif_config_parse_file(FILE *fd, const char *filename, struct lif_config_handler
while (lif_fgetline(linebuf, sizeof linebuf, fd)) while (lif_fgetline(linebuf, sizeof linebuf, fd))
{ {
char *bufp = linebuf; char *bufp = linebuf;
char *key = lif_next_token(&bufp); char *key = lif_next_token_eq(&bufp);
char *value = lif_next_token(&bufp); char *value = lif_next_token_eq(&bufp);
lineno++; lineno++;

View file

@ -19,7 +19,7 @@
#include <ctype.h> #include <ctype.h>
static inline char * static inline char *
lif_next_token(char **buf) lif_next_token_eq(char **buf)
{ {
char *out = *buf; char *out = *buf;
@ -36,4 +36,22 @@ lif_next_token(char **buf)
return out; return out;
} }
static inline char *
lif_next_token(char **buf)
{
char *out = *buf;
while (*out && isspace(*out))
out++;
char *end = out;
while (*end && !isspace(*end))
end++;
*end++ = '\0';
*buf = end;
return out;
}
#endif #endif