From 2c799aaf552425752df4436c975a6ba4fd43632d Mon Sep 17 00:00:00 2001 From: woegster Date: Sun, 17 Aug 2025 01:46:29 +0200 Subject: [PATCH 1/2] add support for utf8 expressions --- tinyexpr.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/tinyexpr.c b/tinyexpr.c index 176e8d0..efb2fdd 100755 --- a/tinyexpr.c +++ b/tinyexpr.c @@ -235,6 +235,26 @@ static double divide(double a, double b) {return a / b;} static double negate(double a) {return -a;} static double comma(double a, double b) {(void)a; return b;} +int is_not_special_token(char c) +{ + switch (c) { + case '+': + case '-': + case '*': + case '/': + case '^': + case '%': + case '(': + case ')': + case ',': + case ' ': + case '\t': + case '\n': + case '\r': + return 0; + } + return 1; +} void next_token(state *s) { s->type = TOK_NULL; @@ -252,10 +272,10 @@ void next_token(state *s) { s->type = TOK_NUMBER; } else { /* Look for a variable or builtin function call. */ - if (isalpha(s->next[0])) { + if (is_not_special_token(s->next[0])) { const char *start; start = s->next; - while (isalpha(s->next[0]) || isdigit(s->next[0]) || (s->next[0] == '_')) s->next++; + while (is_not_special_token(s->next[0]) || isdigit(s->next[0]) || (s->next[0] == '_')) s->next++; const te_variable *var = find_lookup(s, start, s->next - start); if (!var) var = find_builtin(start, s->next - start); From ce28672eaea51097be45ef73f9c603e95f7e11d2 Mon Sep 17 00:00:00 2001 From: woegster Date: Sun, 17 Aug 2025 04:25:10 +0200 Subject: [PATCH 2/2] correct null handling --- tinyexpr.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tinyexpr.c b/tinyexpr.c index efb2fdd..2074786 100755 --- a/tinyexpr.c +++ b/tinyexpr.c @@ -251,6 +251,7 @@ int is_not_special_token(char c) case '\t': case '\n': case '\r': + case '\0': return 0; } return 1;