diff options
author | John Wiegley <johnw@newartisans.com> | 2007-05-14 11:08:50 +0000 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2008-04-13 03:38:49 -0400 |
commit | 766a16131aaa89a576ae63dcf12ab6ad467d6655 (patch) | |
tree | 2040e179524025c1d52d3f1d322425ffa2decd2e /src/commodity.cc | |
parent | 9044bf168ab0d8d6df03034898b1e5a4cb1559e8 (diff) | |
download | ledger-766a16131aaa89a576ae63dcf12ab6ad467d6655.tar.gz ledger-766a16131aaa89a576ae63dcf12ab6ad467d6655.tar.bz2 ledger-766a16131aaa89a576ae63dcf12ab6ad467d6655.zip |
Begin work on splitting parsing into parse and compile phases.
Diffstat (limited to 'src/commodity.cc')
-rw-r--r-- | src/commodity.cc | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/commodity.cc b/src/commodity.cc index b4302d67..9eaa3ad8 100644 --- a/src/commodity.cc +++ b/src/commodity.cc @@ -186,6 +186,26 @@ void commodity_t::parse_symbol(std::istream& in, string& symbol) symbol = buf; } +void commodity_t::parse_symbol(const char *& p, string& symbol) +{ + if (*p == '"') { + char * q = std::strchr(p + 1, '"'); + if (! q) + throw_(parse_error, "Quoted commodity symbol lacks closing quote"); + symbol = string(p + 1, 0, q - p - 1); + p = q + 2; + } else { + char * q = next_element(p); + symbol = p; + if (q) + p = q; + else + p += symbol.length(); + } + if (symbol.empty()) + throw_(parse_error, "Failed to parse commodity"); +} + bool commodity_t::valid() const { if (symbol().empty() && this != parent().null_commodity) { |