From 48a58231818b6c50bba2e8aa8ce2332217b98c2f Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Thu, 29 Jul 2010 03:40:03 -0400 Subject: [PATCH] Based symbol_needs_quotes an invalid_chars (#386) --- src/commodity.cc | 70 +++++++++++++++++++------------------- test/regress/A28CF697.test | 9 +++++ 2 files changed, 44 insertions(+), 35 deletions(-) create mode 100644 test/regress/A28CF697.test diff --git a/src/commodity.cc b/src/commodity.cc index 179bbc05..81183b25 100644 --- a/src/commodity.cc +++ b/src/commodity.cc @@ -490,42 +490,7 @@ commodity_t::operator bool() const return this != pool().null_commodity; } -bool commodity_t::symbol_needs_quotes(const string& symbol) -{ - foreach (char ch, symbol) - if (std::isspace(ch) || std::isdigit(ch) || ch == '-' || ch == '.') - return true; - - return false; -} - namespace { - bool is_reserved_token(const char * buf) - { - switch (buf[0]) { - case 'a': - return std::strcmp(buf, "and") == 0; - case 'd': - return std::strcmp(buf, "div") == 0; - case 'e': - return std::strcmp(buf, "else") == 0; - case 'f': - return std::strcmp(buf, "false") == 0; - case 'i': - return std::strcmp(buf, "if") == 0; - case 'o': - return std::strcmp(buf, "or") == 0; - case 'n': - return std::strcmp(buf, "not") == 0; - case 't': - return std::strcmp(buf, "true") == 0; - } - return false; - } -} - -void commodity_t::parse_symbol(std::istream& in, string& symbol) -{ // Invalid commodity characters: // SPACE, TAB, NEWLINE, RETURN // 0-9 . , ; : ? ! - + * / ^ & | = @@ -551,6 +516,41 @@ void commodity_t::parse_symbol(std::istream& in, string& symbol) /* f0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; + bool is_reserved_token(const char * buf) + { + switch (buf[0]) { + case 'a': + return std::strcmp(buf, "and") == 0; + case 'd': + return std::strcmp(buf, "div") == 0; + case 'e': + return std::strcmp(buf, "else") == 0; + case 'f': + return std::strcmp(buf, "false") == 0; + case 'i': + return std::strcmp(buf, "if") == 0; + case 'o': + return std::strcmp(buf, "or") == 0; + case 'n': + return std::strcmp(buf, "not") == 0; + case 't': + return std::strcmp(buf, "true") == 0; + } + return false; + } +} + +bool commodity_t::symbol_needs_quotes(const string& symbol) +{ + foreach (char ch, symbol) + if (invalid_chars[static_cast(ch)]) + return true; + + return false; +} + +void commodity_t::parse_symbol(std::istream& in, string& symbol) +{ istream_pos_type pos = in.tellg(); char buf[256]; diff --git a/test/regress/A28CF697.test b/test/regress/A28CF697.test new file mode 100644 index 00000000..513dbd97 --- /dev/null +++ b/test/regress/A28CF697.test @@ -0,0 +1,9 @@ +print +<<< +2010-02-05 * Flight SN2094 + Assets:Rewards:Airmiles 125 "M&M" + Income:Rewards +>>> +2010/02/05 * Flight SN2094 + Assets:Rewards:Airmiles 125 "M&M" + Income:Rewards