From dea2aed0b509734ec4e1cd163ac2a4f013000da2 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Fri, 11 Jun 2010 16:03:50 -0400 Subject: Untabified all source files --- src/csv.cc | 66 +++++++++++++++++++++++++++++++------------------------------- 1 file changed, 33 insertions(+), 33 deletions(-) (limited to 'src/csv.cc') diff --git a/src/csv.cc b/src/csv.cc index 5a74232f..53a1ad98 100644 --- a/src/csv.cc +++ b/src/csv.cc @@ -51,29 +51,29 @@ string csv_reader::read_field(std::istream& in) while (in.good() && ! in.eof()) { in.get(x); if (x == '\\') { - in.get(x); + in.get(x); } else if (x == '"' && in.peek() == '"') { - in.get(x); + in.get(x); } else if (x == c) { - if (x == '|') - in.unget(); - else if (in.peek() == ',') - in.get(c); - break; + if (x == '|') + in.unget(); + else if (in.peek() == ',') + in.get(c); + break; } if (x != '\0') - field += x; + field += x; } } else { while (in.good() && ! in.eof()) { in.get(c); if (c == ',') - break; + break; if (c != '\0') - field += c; + field += c; } } trim(field); @@ -144,7 +144,7 @@ xact_t * csv_reader::read_xact(journal_t& journal, account_t * bucket) xact->set_state(item_t::CLEARED); - xact->pos = position_t(); + xact->pos = position_t(); xact->pos->pathname = "jww (2010-03-05): unknown"; xact->pos->beg_pos = in.tellg(); xact->pos->beg_line = 0; @@ -153,7 +153,7 @@ xact_t * csv_reader::read_xact(journal_t& journal, account_t * bucket) post->xact = xact.get(); #if 0 - post->pos = position_t(); + post->pos = position_t(); post->pos->pathname = pathname; post->pos->beg_pos = line_beg_pos; post->pos->beg_line = linenum; @@ -163,7 +163,7 @@ xact_t * csv_reader::read_xact(journal_t& journal, account_t * bucket) post->set_state(item_t::CLEARED); post->account = NULL; - int n = 0; + int n = 0; amount_t amt; string total; @@ -173,12 +173,12 @@ xact_t * csv_reader::read_xact(journal_t& journal, account_t * bucket) switch (index[n]) { case FIELD_DATE: if (field.empty()) - goto restart; + goto restart; try { - xact->_date = parse_date(field); + xact->_date = parse_date(field); } catch (date_error&) { - goto restart; + goto restart; } break; @@ -188,21 +188,21 @@ xact_t * csv_reader::read_xact(journal_t& journal, account_t * bucket) case FIELD_CODE: if (! field.empty()) - xact->code = field; + xact->code = field; break; case FIELD_PAYEE: { bool found = false; foreach (payee_mapping_t& value, journal.payee_mappings) { - DEBUG("csv.mappings", "Looking for payee mapping: " << value.first); - if (value.first.match(field)) { - xact->payee = value.second; - found = true; - break; - } + DEBUG("csv.mappings", "Looking for payee mapping: " << value.first); + if (value.first.match(field)) { + xact->payee = value.second; + found = true; + break; + } } if (! found) - xact->payee = field; + xact->payee = field; break; } @@ -210,8 +210,8 @@ xact_t * csv_reader::read_xact(journal_t& journal, account_t * bucket) std::istringstream amount_str(field); amt.parse(amount_str, PARSE_NO_REDUCE); if (! amt.has_commodity() && - commodity_pool_t::current_pool->default_commodity) - amt.set_commodity(*commodity_pool_t::current_pool->default_commodity); + commodity_pool_t::current_pool->default_commodity) + amt.set_commodity(*commodity_pool_t::current_pool->default_commodity); post->amount = amt; break; } @@ -220,9 +220,9 @@ xact_t * csv_reader::read_xact(journal_t& journal, account_t * bucket) std::istringstream amount_str(field); amt.parse(amount_str, PARSE_NO_REDUCE); if (! amt.has_commodity() && - commodity_pool_t::current_pool->default_commodity) - amt.set_commodity - (*commodity_pool_t::current_pool->default_commodity); + commodity_pool_t::current_pool->default_commodity) + amt.set_commodity + (*commodity_pool_t::current_pool->default_commodity); post->cost = amt; break; } @@ -237,7 +237,7 @@ xact_t * csv_reader::read_xact(journal_t& journal, account_t * bucket) case FIELD_UNKNOWN: if (! names[n].empty() && ! field.empty()) - xact->set_tag(names[n], field); + xact->set_tag(names[n], field); break; } n++; @@ -245,7 +245,7 @@ xact_t * csv_reader::read_xact(journal_t& journal, account_t * bucket) #if 0 xact->set_tag(_("Imported"), - string(format_date(CURRENT_DATE(), FMT_WRITTEN))); + string(format_date(CURRENT_DATE(), FMT_WRITTEN))); xact->set_tag(_("Original"), string(line)); xact->set_tag(_("SHA1"), string(sha1sum(line))); #endif @@ -268,7 +268,7 @@ xact_t * csv_reader::read_xact(journal_t& journal, account_t * bucket) post->xact = xact.get(); #if 0 - post->pos = position_t(); + post->pos = position_t(); post->pos->pathname = pathname; post->pos->beg_pos = line_beg_pos; post->pos->beg_line = linenum; @@ -285,7 +285,7 @@ xact_t * csv_reader::read_xact(journal_t& journal, account_t * bucket) std::istringstream assigned_amount_str(total); amt.parse(assigned_amount_str, PARSE_NO_REDUCE); if (! amt.has_commodity() && - commodity_pool_t::current_pool->default_commodity) + commodity_pool_t::current_pool->default_commodity) amt.set_commodity(*commodity_pool_t::current_pool->default_commodity); post->assigned_amount = amt; } -- cgit v1.2.3 From 28c65cda512135bde36542351533941b019b6ee8 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Sat, 12 Jun 2010 14:55:18 -0400 Subject: Store metadata values as value_t instead of string --- src/csv.cc | 2 +- src/item.cc | 44 +++++++++++++++++++++++--------------------- src/item.h | 16 ++++++++-------- src/post.cc | 12 ++++++------ src/post.h | 6 +++--- src/py_item.cc | 8 ++++---- src/py_post.cc | 8 ++++---- src/xact.cc | 2 +- 8 files changed, 50 insertions(+), 48 deletions(-) (limited to 'src/csv.cc') diff --git a/src/csv.cc b/src/csv.cc index 53a1ad98..dd5ca935 100644 --- a/src/csv.cc +++ b/src/csv.cc @@ -237,7 +237,7 @@ xact_t * csv_reader::read_xact(journal_t& journal, account_t * bucket) case FIELD_UNKNOWN: if (! names[n].empty() && ! field.empty()) - xact->set_tag(names[n], field); + xact->set_tag(names[n], string_value(field)); break; } n++; diff --git a/src/item.cc b/src/item.cc index 8a056e6c..1f42510c 100644 --- a/src/item.cc +++ b/src/item.cc @@ -66,14 +66,14 @@ bool item_t::has_tag(const mask_t& tag_mask, if (! value_mask) return true; else if (data.second.first) - return value_mask->match(*data.second.first); + return value_mask->match(data.second.first->to_string()); } } } return false; } -optional item_t::get_tag(const string& tag) const +optional item_t::get_tag(const string& tag) const { DEBUG("item.meta", "Getting item tag: " << tag); if (metadata) { @@ -87,24 +87,26 @@ optional item_t::get_tag(const string& tag) const return none; } -optional item_t::get_tag(const mask_t& tag_mask, - const optional& value_mask) const +optional item_t::get_tag(const mask_t& tag_mask, + const optional& value_mask) const { if (metadata) { foreach (const string_map::value_type& data, *metadata) { if (tag_mask.match(data.first) && (! value_mask || - (data.second.first && value_mask->match(*data.second.first)))) + (data.second.first && + value_mask->match(data.second.first->to_string())))) { return data.second.first; + } } } return none; } item_t::string_map::iterator -item_t::set_tag(const string& tag, - const optional& value, - const bool overwrite_existing) +item_t::set_tag(const string& tag, + const optional& value, + const bool overwrite_existing) { assert(! tag.empty()); @@ -112,10 +114,12 @@ item_t::set_tag(const string& tag, metadata = string_map(); DEBUG("item.meta", "Setting tag '" << tag << "' to value '" - << (value ? *value : string("")) << "'"); + << (value ? *value : string_value("")) << "'"); - optional data = value; - if (data && data->empty()) + optional data = value; + if (data && + (data->is_null() || + (data->is_string() && data->as_string().empty()))) data = none; string_map::iterator i = metadata->find(tag); @@ -165,8 +169,9 @@ void item_t::parse_tags(const char * p, bool overwrite_existing, q = std::strtok(NULL, " \t")) { const string::size_type len = std::strlen(q); if (! tag.empty()) { - string_map::iterator i = set_tag(tag, string(p + (q - buf.get())), - overwrite_existing); + string_map::iterator i = + set_tag(tag, string_value(string(p + (q - buf.get()))), + overwrite_existing); (*i).second.second = true; break; } @@ -263,13 +268,13 @@ namespace { value_t get_tag(call_scope_t& args) { item_t& item(find_scope(args)); - optional str; + optional val; if (args.size() == 1) { if (args[0].is_string()) - str = item.get_tag(args[0].as_string()); + val = item.get_tag(args[0].as_string()); else if (args[0].is_mask()) - str = item.get_tag(args[0].as_mask()); + val = item.get_tag(args[0].as_mask()); else throw_(std::runtime_error, _("Expected string or mask for argument 1, but received %1") @@ -277,7 +282,7 @@ namespace { } else if (args.size() == 2) { if (args[0].is_mask() && args[1].is_mask()) - str = item.get_tag(args[0].to_mask(), args[1].to_mask()); + val = item.get_tag(args[0].to_mask(), args[1].to_mask()); else throw_(std::runtime_error, _("Expected masks for arguments 1 and 2, but received %1 and %2") @@ -290,10 +295,7 @@ namespace { throw_(std::runtime_error, _("Too many arguments to function")); } - if (str) - return string_value(*str); - else - return NULL_VALUE; + return val ? *val : NULL_VALUE; } value_t get_pathname(item_t& item) { diff --git a/src/item.h b/src/item.h index 25130d6d..61438593 100644 --- a/src/item.h +++ b/src/item.h @@ -106,8 +106,8 @@ public: enum state_t { UNCLEARED = 0, CLEARED, PENDING }; - typedef std::pair, bool> tag_data_t; - typedef std::map string_map; + typedef std::pair, bool> tag_data_t; + typedef std::map string_map; state_t _state; optional _date; @@ -153,14 +153,14 @@ public: virtual bool has_tag(const mask_t& tag_mask, const optional& value_mask = none) const; - virtual optional get_tag(const string& tag) const; - virtual optional get_tag(const mask_t& tag_mask, - const optional& value_mask = none) const; + virtual optional get_tag(const string& tag) const; + virtual optional get_tag(const mask_t& tag_mask, + const optional& value_mask = none) const; virtual string_map::iterator - set_tag(const string& tag, - const optional& value = none, - const bool overwrite_existing = true); + set_tag(const string& tag, + const optional& value = none, + const bool overwrite_existing = true); virtual void parse_tags(const char * p, bool overwrite_existing = true, optional current_year = none); diff --git a/src/post.cc b/src/post.cc index 3ef76f7f..2a8abddc 100644 --- a/src/post.cc +++ b/src/post.cc @@ -59,19 +59,19 @@ bool post_t::has_tag(const mask_t& tag_mask, return false; } -optional post_t::get_tag(const string& tag) const +optional post_t::get_tag(const string& tag) const { - if (optional value = item_t::get_tag(tag)) + if (optional value = item_t::get_tag(tag)) return value; if (xact) return xact->get_tag(tag); return none; } -optional post_t::get_tag(const mask_t& tag_mask, - const optional& value_mask) const +optional post_t::get_tag(const mask_t& tag_mask, + const optional& value_mask) const { - if (optional value = item_t::get_tag(tag_mask, value_mask)) + if (optional value = item_t::get_tag(tag_mask, value_mask)) return value; if (xact) return xact->get_tag(tag_mask, value_mask); @@ -715,7 +715,7 @@ void to_xml(std::ostream& out, const post_t& post) } { push_xml z(out, "value"); - out << y.guard(*pair.second.first); + to_xml(out, *pair.second.first); } } else { push_xml z(out, "tag"); diff --git a/src/post.h b/src/post.h index a43e6cd9..aec81e89 100644 --- a/src/post.h +++ b/src/post.h @@ -103,9 +103,9 @@ public: virtual bool has_tag(const mask_t& tag_mask, const optional& value_mask = none) const; - virtual optional get_tag(const string& tag) const; - virtual optional get_tag(const mask_t& tag_mask, - const optional& value_mask = none) const; + virtual optional get_tag(const string& tag) const; + virtual optional get_tag(const mask_t& tag_mask, + const optional& value_mask = none) const; virtual date_t value_date() const; virtual date_t date() const; diff --git a/src/py_item.cc b/src/py_item.cc index 65d89119..0e95f24f 100644 --- a/src/py_item.cc +++ b/src/py_item.cc @@ -53,14 +53,14 @@ namespace { return item.has_tag(tag_mask, value_mask); } - boost::optional py_get_tag_1s(item_t& item, const string& tag) { + boost::optional py_get_tag_1s(item_t& item, const string& tag) { return item.get_tag(tag); } - boost::optional py_get_tag_1m(item_t& item, const mask_t& tag_mask) { + boost::optional py_get_tag_1m(item_t& item, const mask_t& tag_mask) { return item.get_tag(tag_mask); } - boost::optional py_get_tag_2m(item_t& item, const mask_t& tag_mask, - const boost::optional& value_mask) { + boost::optional py_get_tag_2m(item_t& item, const mask_t& tag_mask, + const boost::optional& value_mask) { return item.get_tag(tag_mask, value_mask); } diff --git a/src/py_post.cc b/src/py_post.cc index 930a46c9..537289b3 100644 --- a/src/py_post.cc +++ b/src/py_post.cc @@ -52,14 +52,14 @@ namespace { return post.has_tag(tag_mask, value_mask); } - boost::optional py_get_tag_1s(post_t& post, const string& tag) { + boost::optional py_get_tag_1s(post_t& post, const string& tag) { return post.get_tag(tag); } - boost::optional py_get_tag_1m(post_t& post, const mask_t& tag_mask) { + boost::optional py_get_tag_1m(post_t& post, const mask_t& tag_mask) { return post.get_tag(tag_mask); } - boost::optional py_get_tag_2m(post_t& post, const mask_t& tag_mask, - const boost::optional& value_mask) { + boost::optional py_get_tag_2m(post_t& post, const mask_t& tag_mask, + const boost::optional& value_mask) { return post.get_tag(tag_mask, value_mask); } diff --git a/src/xact.cc b/src/xact.cc index b4438b48..3b66598c 100644 --- a/src/xact.cc +++ b/src/xact.cc @@ -823,7 +823,7 @@ void to_xml(std::ostream& out, const xact_t& xact) } { push_xml w(out, "value"); - out << y.guard(*pair.second.first); + to_xml(out, *pair.second.first); } } else { push_xml z(out, "tag"); -- cgit v1.2.3