From d7b8095c3db345329cf89b8c00d51817ae4ce4c9 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Wed, 17 Mar 2010 02:18:46 -0400 Subject: Tags were not being set properly on postings --- src/item.cc | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) (limited to 'src/item.cc') diff --git a/src/item.cc b/src/item.cc index cb92c003..14a0896f 100644 --- a/src/item.cc +++ b/src/item.cc @@ -101,8 +101,10 @@ optional item_t::get_tag(const mask_t& tag_mask, return none; } -item_t::string_map::iterator item_t::set_tag(const string& tag, - const optional& value) +item_t::string_map::iterator +item_t::set_tag(const string& tag, + const optional& value, + const bool overwrite_existing) { assert(! tag.empty()); @@ -116,14 +118,20 @@ item_t::string_map::iterator item_t::set_tag(const string& tag, if (data && data->empty()) data = none; - std::pair result - = metadata->insert(string_map::value_type(tag, tag_data_t(data, false))); - assert(result.second); - - return result.first; + string_map::iterator i = metadata->find(tag); + if (i == metadata->end()) { + std::pair result + = metadata->insert(string_map::value_type(tag, tag_data_t(data, false))); + assert(result.second); + return result.first; + } else { + if (overwrite_existing) + (*i).second = tag_data_t(data, false); + return i; + } } -void item_t::parse_tags(const char * p, +void item_t::parse_tags(const char * p, bool overwrite_existing, optional current_year) { if (const char * b = std::strchr(p, '[')) { @@ -157,17 +165,16 @@ void item_t::parse_tags(const char * p, q = std::strtok(NULL, " \t")) { const string::size_type len = std::strlen(q); if (! tag.empty()) { - if (! has_tag(tag)) { - string_map::iterator i = set_tag(tag, string(p + (q - buf.get()))); - (*i).second.second = true; - } + string_map::iterator i = set_tag(tag, string(p + (q - buf.get())), + overwrite_existing); + (*i).second.second = true; break; } else if (q[0] == ':' && q[len - 1] == ':') { // a series of tags for (char * r = std::strtok(q + 1, ":"); r; r = std::strtok(NULL, ":")) { - string_map::iterator i = set_tag(r); + string_map::iterator i = set_tag(r, none, overwrite_existing); (*i).second.second = true; } } @@ -177,7 +184,7 @@ void item_t::parse_tags(const char * p, } } -void item_t::append_note(const char * p, +void item_t::append_note(const char * p, bool overwrite_existing, optional current_year) { if (note) { @@ -187,7 +194,7 @@ void item_t::append_note(const char * p, note = p; } - parse_tags(p, current_year); + parse_tags(p, overwrite_existing, current_year); } namespace { -- cgit v1.2.3