Empty notes and tags now return null values

This commit is contained in:
John Wiegley 2010-05-30 02:55:02 -06:00
parent 647d4aac2f
commit 4f3b39e22c
5 changed files with 56 additions and 47 deletions

View file

@ -69,14 +69,16 @@ void post_splitter::operator()(post_t& post)
bind_scope_t bound_scope(report, post); bind_scope_t bound_scope(report, post);
value_t result(group_by_expr.calc(bound_scope)); value_t result(group_by_expr.calc(bound_scope));
value_to_posts_map::iterator i = posts_map.find(result); if (! result.is_null()) {
if (i != posts_map.end()) { value_to_posts_map::iterator i = posts_map.find(result);
(*i).second.push_back(&post); if (i != posts_map.end()) {
} else { (*i).second.push_back(&post);
std::pair<value_to_posts_map::iterator, bool> inserted } else {
= posts_map.insert(value_to_posts_map::value_type(result, posts_list())); std::pair<value_to_posts_map::iterator, bool> inserted
assert(inserted.second); = posts_map.insert(value_to_posts_map::value_type(result, posts_list()));
(*inserted.first).second.push_back(&post); assert(inserted.second);
(*inserted.first).second.push_back(&post);
}
} }
} }
@ -837,41 +839,43 @@ void transfer_details::operator()(post_t& post)
bind_scope_t bound_scope(scope, temp); bind_scope_t bound_scope(scope, temp);
value_t substitute(expr.calc(bound_scope)); value_t substitute(expr.calc(bound_scope));
switch (which_element) { if (! substitute.is_null()) {
case SET_DATE: switch (which_element) {
temp.xdata().date = substitute.to_date(); case SET_DATE:
break; temp.xdata().date = substitute.to_date();
break;
case SET_ACCOUNT: { case SET_ACCOUNT: {
string account_name = substitute.to_string(); string account_name = substitute.to_string();
if (! account_name.empty() && if (! account_name.empty() &&
account_name[account_name.length() - 1] != ':') { account_name[account_name.length() - 1] != ':') {
account_t * prev_account = temp.account; account_t * prev_account = temp.account;
temp.account->remove_post(&temp); temp.account->remove_post(&temp);
account_name += ':'; account_name += ':';
account_name += prev_account->fullname(); account_name += prev_account->fullname();
std::list<string> account_names; std::list<string> account_names;
split_string(account_name, ':', account_names); split_string(account_name, ':', account_names);
temp.account = create_temp_account_from_path(account_names, temps, temp.account = create_temp_account_from_path(account_names, temps,
xact.journal->master); xact.journal->master);
temp.account->add_post(&temp); temp.account->add_post(&temp);
temp.account->add_flags(prev_account->flags()); temp.account->add_flags(prev_account->flags());
if (prev_account->has_xdata()) if (prev_account->has_xdata())
temp.account->xdata().add_flags(prev_account->xdata().flags()); temp.account->xdata().add_flags(prev_account->xdata().flags());
}
break;
} }
break;
}
case SET_PAYEE: case SET_PAYEE:
xact.payee = substitute.to_string(); xact.payee = substitute.to_string();
break; break;
default: default:
assert(false); assert(false);
break; break;
}
} }
item_handler<post_t>::operator()(temp); item_handler<post_t>::operator()(temp);

View file

@ -227,7 +227,7 @@ namespace {
return NULL_VALUE; return NULL_VALUE;
} }
value_t get_note(item_t& item) { value_t get_note(item_t& item) {
return string_value(item.note ? *item.note : empty_string); return item.note ? string_value(*item.note) : NULL_VALUE;
} }
value_t has_tag(call_scope_t& args) { value_t has_tag(call_scope_t& args) {
@ -260,7 +260,8 @@ namespace {
return false; return false;
} }
value_t get_tag(call_scope_t& args) { value_t get_tag(call_scope_t& args)
{
item_t& item(find_scope<item_t>(args)); item_t& item(find_scope<item_t>(args));
optional<string> str; optional<string> str;
@ -292,14 +293,14 @@ namespace {
if (str) if (str)
return string_value(*str); return string_value(*str);
else else
return string_value(empty_string); return NULL_VALUE;
} }
value_t get_pathname(item_t& item) { value_t get_pathname(item_t& item) {
if (item.pos) if (item.pos)
return string_value(item.pos->pathname.string()); return string_value(item.pos->pathname.string());
else else
return string_value(empty_string); return NULL_VALUE;
} }
value_t get_beg_pos(item_t& item) { value_t get_beg_pos(item_t& item) {

View file

@ -150,7 +150,7 @@ namespace {
if (post.xact->code) if (post.xact->code)
return string_value(*post.xact->code); return string_value(*post.xact->code);
else else
return string_value(empty_string); return NULL_VALUE;
} }
value_t get_payee(post_t& post) { value_t get_payee(post_t& post) {
@ -158,9 +158,13 @@ namespace {
} }
value_t get_note(post_t& post) { value_t get_note(post_t& post) {
string note = post.note ? *post.note : empty_string; if (post.note || post.xact->note) {
note += post.xact->note ? *post.xact->note : empty_string; string note = post.note ? *post.note : empty_string;
return string_value(note); note += post.xact->note ? *post.xact->note : empty_string;
return string_value(note);
} else {
return NULL_VALUE;
}
} }
value_t get_magnitude(post_t& post) { value_t get_magnitude(post_t& post) {

View file

@ -468,7 +468,7 @@ namespace {
if (xact.code) if (xact.code)
return string_value(*xact.code); return string_value(*xact.code);
else else
return string_value(empty_string); return NULL_VALUE;
} }
value_t get_payee(xact_t& xact) { value_t get_payee(xact_t& xact) {

View file

@ -28,7 +28,7 @@ reg --payee=code
08-Feb-01 102 Assets:Cash $-20.00 0 08-Feb-01 102 Assets:Cash $-20.00 0
08-Feb-28 103 Expenses:Books $20.00 $20.00 08-Feb-28 103 Expenses:Books $20.00 $20.00
08-Feb-28 103 Assets:Cash $-20.00 0 08-Feb-28 103 Assets:Cash $-20.00 0
08-Mar-01 Expenses:Books $30.00 $30.00 08-Mar-01 March Expenses:Books $30.00 $30.00
08-Mar-01 Assets:Cash $-30.00 0 08-Mar-01 March Assets:Cash $-30.00 0
>>>2 >>>2
=== 0 === 0