diff options
author | John Wiegley <johnw@newartisans.com> | 2009-01-31 01:22:04 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2009-01-31 01:22:04 -0400 |
commit | 02ac444374b04233f2dde7d10a430df0846d309b (patch) | |
tree | 70976c7cd70340af7b9854d13f187e652e540eb4 /src/commodity.cc | |
parent | 6423e44c115fea89eb567bb20f65a6370131b04b (diff) | |
download | fork-ledger-02ac444374b04233f2dde7d10a430df0846d309b.tar.gz fork-ledger-02ac444374b04233f2dde7d10a430df0846d309b.tar.bz2 fork-ledger-02ac444374b04233f2dde7d10a430df0846d309b.zip |
Don't parse reserved word (such as "and" or "true") as commodity names.
Diffstat (limited to 'src/commodity.cc')
-rw-r--r-- | src/commodity.cc | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/commodity.cc b/src/commodity.cc index 5d993d9e..60ddaec6 100644 --- a/src/commodity.cc +++ b/src/commodity.cc @@ -40,6 +40,7 @@ */ #include "amount.h" +#include "token.h" namespace ledger { @@ -521,6 +522,27 @@ bool commodity_t::symbol_needs_quotes(const string& symbol) 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 'f': + return std::strcmp(buf, "false") == 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: @@ -561,6 +583,8 @@ void commodity_t::parse_symbol(std::istream& in, string& symbol) throw_(amount_error, "Quoted commodity symbol lacks closing quote"); } else { READ_INTO(in, buf, 255, c, ! invalid_chars[static_cast<unsigned char>(c)]); + if (is_reserved_token(buf)) + buf[0] = '\0'; } symbol = buf; |