diff options
author | John Wiegley <johnw@newartisans.com> | 2010-05-30 02:55:02 -0600 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2010-05-30 03:01:11 -0600 |
commit | 4f3b39e22c7a7743132ead79b1e092929679de44 (patch) | |
tree | b49eeb433c03f71318b64a0dc4d0d0d5ebea2d4f /src | |
parent | 647d4aac2fa474085d01f7ea1cebdc34fafd64a6 (diff) | |
download | fork-ledger-4f3b39e22c7a7743132ead79b1e092929679de44.tar.gz fork-ledger-4f3b39e22c7a7743132ead79b1e092929679de44.tar.bz2 fork-ledger-4f3b39e22c7a7743132ead79b1e092929679de44.zip |
Empty notes and tags now return null values
Diffstat (limited to 'src')
-rw-r--r-- | src/filters.cc | 84 | ||||
-rw-r--r-- | src/item.cc | 9 | ||||
-rw-r--r-- | src/post.cc | 12 | ||||
-rw-r--r-- | src/xact.cc | 2 |
4 files changed, 58 insertions, 49 deletions
diff --git a/src/filters.cc b/src/filters.cc index 6915144d..6e4aeee3 100644 --- a/src/filters.cc +++ b/src/filters.cc @@ -69,14 +69,16 @@ void post_splitter::operator()(post_t& post) bind_scope_t bound_scope(report, post); value_t result(group_by_expr.calc(bound_scope)); - value_to_posts_map::iterator i = posts_map.find(result); - if (i != posts_map.end()) { - (*i).second.push_back(&post); - } else { - std::pair<value_to_posts_map::iterator, bool> inserted - = posts_map.insert(value_to_posts_map::value_type(result, posts_list())); - assert(inserted.second); - (*inserted.first).second.push_back(&post); + if (! result.is_null()) { + value_to_posts_map::iterator i = posts_map.find(result); + if (i != posts_map.end()) { + (*i).second.push_back(&post); + } else { + std::pair<value_to_posts_map::iterator, bool> inserted + = posts_map.insert(value_to_posts_map::value_type(result, posts_list())); + 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); value_t substitute(expr.calc(bound_scope)); - switch (which_element) { - case SET_DATE: - temp.xdata().date = substitute.to_date(); - break; - - case SET_ACCOUNT: { - string account_name = substitute.to_string(); - if (! account_name.empty() && - account_name[account_name.length() - 1] != ':') { - account_t * prev_account = temp.account; - temp.account->remove_post(&temp); - - account_name += ':'; - account_name += prev_account->fullname(); - - std::list<string> account_names; - split_string(account_name, ':', account_names); - temp.account = create_temp_account_from_path(account_names, temps, - xact.journal->master); - temp.account->add_post(&temp); - - temp.account->add_flags(prev_account->flags()); - if (prev_account->has_xdata()) - temp.account->xdata().add_flags(prev_account->xdata().flags()); + if (! substitute.is_null()) { + switch (which_element) { + case SET_DATE: + temp.xdata().date = substitute.to_date(); + break; + + case SET_ACCOUNT: { + string account_name = substitute.to_string(); + if (! account_name.empty() && + account_name[account_name.length() - 1] != ':') { + account_t * prev_account = temp.account; + temp.account->remove_post(&temp); + + account_name += ':'; + account_name += prev_account->fullname(); + + std::list<string> account_names; + split_string(account_name, ':', account_names); + temp.account = create_temp_account_from_path(account_names, temps, + xact.journal->master); + temp.account->add_post(&temp); + + temp.account->add_flags(prev_account->flags()); + if (prev_account->has_xdata()) + temp.account->xdata().add_flags(prev_account->xdata().flags()); + } + break; } - break; - } - case SET_PAYEE: - xact.payee = substitute.to_string(); - break; + case SET_PAYEE: + xact.payee = substitute.to_string(); + break; - default: - assert(false); - break; + default: + assert(false); + break; + } } item_handler<post_t>::operator()(temp); diff --git a/src/item.cc b/src/item.cc index 14a0896f..0a22b260 100644 --- a/src/item.cc +++ b/src/item.cc @@ -227,7 +227,7 @@ namespace { return NULL_VALUE; } 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) { @@ -260,7 +260,8 @@ namespace { 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)); optional<string> str; @@ -292,14 +293,14 @@ namespace { if (str) return string_value(*str); else - return string_value(empty_string); + return NULL_VALUE; } value_t get_pathname(item_t& item) { if (item.pos) return string_value(item.pos->pathname.string()); else - return string_value(empty_string); + return NULL_VALUE; } value_t get_beg_pos(item_t& item) { diff --git a/src/post.cc b/src/post.cc index f1f3e96a..7dc15830 100644 --- a/src/post.cc +++ b/src/post.cc @@ -150,7 +150,7 @@ namespace { if (post.xact->code) return string_value(*post.xact->code); else - return string_value(empty_string); + return NULL_VALUE; } value_t get_payee(post_t& post) { @@ -158,9 +158,13 @@ namespace { } value_t get_note(post_t& post) { - string note = post.note ? *post.note : empty_string; - note += post.xact->note ? *post.xact->note : empty_string; - return string_value(note); + if (post.note || post.xact->note) { + string note = post.note ? *post.note : empty_string; + note += post.xact->note ? *post.xact->note : empty_string; + return string_value(note); + } else { + return NULL_VALUE; + } } value_t get_magnitude(post_t& post) { diff --git a/src/xact.cc b/src/xact.cc index f63835c9..569e5869 100644 --- a/src/xact.cc +++ b/src/xact.cc @@ -468,7 +468,7 @@ namespace { if (xact.code) return string_value(*xact.code); else - return string_value(empty_string); + return NULL_VALUE; } value_t get_payee(xact_t& xact) { |