summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2010-03-17 02:18:46 -0400
committerJohn Wiegley <johnw@newartisans.com>2010-03-17 02:18:46 -0400
commitd7b8095c3db345329cf89b8c00d51817ae4ce4c9 (patch)
tree5cdd04a952eb43d2a65d1b59c9808f38a115f805 /src
parent0e34d08b8d9100a59e8d457cbe7343462a4d8739 (diff)
downloadfork-ledger-d7b8095c3db345329cf89b8c00d51817ae4ce4c9.tar.gz
fork-ledger-d7b8095c3db345329cf89b8c00d51817ae4ce4c9.tar.bz2
fork-ledger-d7b8095c3db345329cf89b8c00d51817ae4ce4c9.zip
Tags were not being set properly on postings
Diffstat (limited to 'src')
-rw-r--r--src/item.cc37
-rw-r--r--src/item.h10
-rw-r--r--src/textual.cc8
3 files changed, 32 insertions, 23 deletions
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<string> 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<string>& value)
+item_t::string_map::iterator
+item_t::set_tag(const string& tag,
+ const optional<string>& 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<string_map::iterator, bool> 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<string_map::iterator, bool> 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<date_t::year_type> 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<date_t::year_type> 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 {
diff --git a/src/item.h b/src/item.h
index f82e8da6..7045c875 100644
--- a/src/item.h
+++ b/src/item.h
@@ -157,12 +157,14 @@ public:
virtual optional<string> get_tag(const mask_t& tag_mask,
const optional<mask_t>& value_mask = none) const;
- virtual string_map::iterator set_tag(const string& tag,
- const optional<string>& value = none);
+ virtual string_map::iterator
+ set_tag(const string& tag,
+ const optional<string>& value = none,
+ const bool overwrite_existing = true);
- virtual void parse_tags(const char * p,
+ virtual void parse_tags(const char * p, bool overwrite_existing = true,
optional<date_t::year_type> current_year = none);
- virtual void append_note(const char * p,
+ virtual void append_note(const char * p, bool overwrite_existing = true,
optional<date_t::year_type> current_year = none);
static bool use_effective_date;
diff --git a/src/textual.cc b/src/textual.cc
index 6a8ea62e..0a2166f8 100644
--- a/src/textual.cc
+++ b/src/textual.cc
@@ -1199,7 +1199,7 @@ post_t * instance_t::parse_post(char * line,
// Parse the optional note
if (next && *next == ';') {
- post->append_note(++next, current_year);
+ post->append_note(++next, true, current_year);
next = line + len;
DEBUG("textual.parse", "line " << linenum << ": "
<< "Parsed a posting note");
@@ -1218,7 +1218,7 @@ post_t * instance_t::parse_post(char * line,
if (! context.state_stack.empty()) {
foreach (const state_t& state, context.state_stack)
if (state.type() == typeid(string))
- post->parse_tags(boost::get<string>(state).c_str());
+ post->parse_tags(boost::get<string>(state).c_str(), true);
}
TRACE_STOP(post_details, 1);
@@ -1355,7 +1355,7 @@ xact_t * instance_t::parse_xact(char * line,
item = xact.get();
// This is a trailing note, and possibly a metadata info tag
- item->append_note(p + 1, current_year);
+ item->append_note(p + 1, true, current_year);
item->pos->end_pos = curr_pos;
item->pos->end_line++;
} else {
@@ -1389,7 +1389,7 @@ xact_t * instance_t::parse_xact(char * line,
if (! context.state_stack.empty()) {
foreach (const state_t& state, context.state_stack)
if (state.type() == typeid(string))
- xact->parse_tags(boost::get<string>(state).c_str());
+ xact->parse_tags(boost::get<string>(state).c_str(), false);
}
TRACE_STOP(xact_details, 1);