Tags were not being set properly on postings
This commit is contained in:
parent
0e34d08b8d
commit
d7b8095c3d
3 changed files with 32 additions and 23 deletions
37
src/item.cc
37
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 {
|
||||
|
|
|
|||
10
src/item.h
10
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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue