trim anything that is not visible, not just spaces.
This commit is contained in:
Enno Rehling 2021-06-01 18:25:44 +02:00
parent 97655a52b8
commit 2f05f12e10

View file

@ -24,7 +24,7 @@ typedef struct parse_state {
static parse_state *states; static parse_state *states;
static int eatwhitespace_c(const char **str_p) static int ltrim(const char **str_p)
{ {
int ret = 0; int ret = 0;
wint_t wc; wint_t wc;
@ -32,11 +32,10 @@ static int eatwhitespace_c(const char **str_p)
const char *str = *str_p; const char *str = *str_p;
/* skip over potential whitespace */ /* skip over potential whitespace */
for (;;) { while (*str) {
unsigned char utf8_character = (unsigned char)*str; unsigned char uc = *(unsigned char *)str;
if (~utf8_character & 0x80) { if (~uc & 0x80) {
if (!iswspace(utf8_character)) if (!iswspace(uc)) break;
break;
++str; ++str;
} }
else { else {
@ -45,8 +44,8 @@ static int eatwhitespace_c(const char **str_p)
log_warning("illegal character sequence in UTF8 string: %s\n", str); log_warning("illegal character sequence in UTF8 string: %s\n", str);
break; break;
} }
if (!iswspace(wc)) if (iswgraph(wc)) break;
break; if (iswalnum(wc)) break;
str += len; str += len;
} }
} }
@ -94,7 +93,7 @@ void parser_popstate(void)
bool parser_end(void) bool parser_end(void)
{ {
if (states->current_token) { if (states->current_token) {
eatwhitespace_c(&states->current_token); ltrim(&states->current_token);
return *states->current_token == 0; return *states->current_token == 0;
} }
return true; return true;
@ -103,7 +102,7 @@ bool parser_end(void)
void skip_token(void) void skip_token(void)
{ {
char quotechar = 0; char quotechar = 0;
eatwhitespace_c(&states->current_token); ltrim(&states->current_token);
while (*states->current_token) { while (*states->current_token) {
wint_t wc; wint_t wc;
@ -152,7 +151,7 @@ char *parse_token(const char **str, char *lbuf, size_t buflen)
if (!ctoken) { if (!ctoken) {
return 0; return 0;
} }
eatwhitespace_c(&ctoken); ltrim(&ctoken);
if (!*ctoken) { if (!*ctoken) {
if (buflen > 0) { if (buflen > 0) {
*cursor = 0; *cursor = 0;