From a089c3e619091c26a0c67f2a610e42b50ed61218 Mon Sep 17 00:00:00 2001 From: Toni Wilen Date: Thu, 10 Sep 2015 18:43:35 +0300 Subject: [PATCH] Support true (1) and false (0). --- calc.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/calc.cpp b/calc.cpp index c2c1acde..da06292a 100644 --- a/calc.cpp +++ b/calc.cpp @@ -385,6 +385,13 @@ static bool execution_order(const TCHAR *input, double *outval) return ok; } +static bool is_separator(TCHAR c) +{ + if (is_operator(c)) + return true; + return c == 0 || c == ')' || c == ' '; +} + static bool parse_values(const TCHAR *ins, TCHAR *out) { int ident = 0; @@ -401,6 +408,18 @@ static bool parse_values(const TCHAR *ins, TCHAR *out) } while (*in) { TCHAR *instart = in; + if (!_tcsncmp(in, _T("true"), 4) && is_separator(in[4])) { + in[0] = '1'; + in[1] = ' '; + in[2] = ' '; + in[3] = ' '; + } else if (!_tcsncmp(in, _T("false"), 5) && is_separator(in[5])) { + in[0] = '0'; + in[1] = ' '; + in[2] = ' '; + in[3] = ' '; + in[4] = ' '; + } if (_istdigit (*in)) { if (ident >= MAX_VALUES) return false; -- 2.47.3