From ec7dc3a28a5a6289595fab7140bd357c4cca8f3e Mon Sep 17 00:00:00 2001 From: Lewis Van Winkle Date: Mon, 22 Aug 2016 19:09:21 -0500 Subject: [PATCH] Allow whitespace at end of expression. --- test.c | 1 + tinyexpr.c | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/test.c b/test.c index e840525..59941f0 100644 --- a/test.c +++ b/test.c @@ -38,6 +38,7 @@ typedef struct { void test_results() { test_case cases[] = { {"1", 1}, + {"1 ", 1}, {"(1)", 1}, {"pi", 3.14159}, diff --git a/tinyexpr.c b/tinyexpr.c index 048436f..d544ad3 100644 --- a/tinyexpr.c +++ b/tinyexpr.c @@ -172,13 +172,13 @@ static double comma(double a, double b) {return b;} void next_token(state *s) { s->type = TOK_NULL; - if (!*s->next){ - s->type = TOK_END; - return; - } - do { + if (!*s->next){ + s->type = TOK_END; + return; + } + /* Try reading a number. */ if ((s->next[0] >= '0' && s->next[0] <= '9') || s->next[0] == '.') { s->value = strtod(s->next, (char**)&s->next);