diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/csv.cc | 2 | ||||
-rw-r--r-- | src/item.cc | 44 | ||||
-rw-r--r-- | src/item.h | 16 | ||||
-rw-r--r-- | src/post.cc | 12 | ||||
-rw-r--r-- | src/post.h | 6 | ||||
-rw-r--r-- | src/py_item.cc | 8 | ||||
-rw-r--r-- | src/py_post.cc | 8 | ||||
-rw-r--r-- | src/xact.cc | 2 |
8 files changed, 50 insertions, 48 deletions
@@ -237,7 +237,7 @@ xact_t * csv_reader::read_xact(journal_t& journal, account_t * bucket) case FIELD_UNKNOWN: if (! names[n].empty() && ! field.empty()) - xact->set_tag(names[n], field); + xact->set_tag(names[n], string_value(field)); break; } n++; diff --git a/src/item.cc b/src/item.cc index 8a056e6c..1f42510c 100644 --- a/src/item.cc +++ b/src/item.cc @@ -66,14 +66,14 @@ bool item_t::has_tag(const mask_t& tag_mask, if (! value_mask) return true; else if (data.second.first) - return value_mask->match(*data.second.first); + return value_mask->match(data.second.first->to_string()); } } } return false; } -optional<string> item_t::get_tag(const string& tag) const +optional<value_t> item_t::get_tag(const string& tag) const { DEBUG("item.meta", "Getting item tag: " << tag); if (metadata) { @@ -87,24 +87,26 @@ optional<string> item_t::get_tag(const string& tag) const return none; } -optional<string> item_t::get_tag(const mask_t& tag_mask, - const optional<mask_t>& value_mask) const +optional<value_t> item_t::get_tag(const mask_t& tag_mask, + const optional<mask_t>& value_mask) const { if (metadata) { foreach (const string_map::value_type& data, *metadata) { if (tag_mask.match(data.first) && (! value_mask || - (data.second.first && value_mask->match(*data.second.first)))) + (data.second.first && + value_mask->match(data.second.first->to_string())))) { return data.second.first; + } } } return none; } item_t::string_map::iterator -item_t::set_tag(const string& tag, - const optional<string>& value, - const bool overwrite_existing) +item_t::set_tag(const string& tag, + const optional<value_t>& value, + const bool overwrite_existing) { assert(! tag.empty()); @@ -112,10 +114,12 @@ item_t::set_tag(const string& tag, metadata = string_map(); DEBUG("item.meta", "Setting tag '" << tag << "' to value '" - << (value ? *value : string("<none>")) << "'"); + << (value ? *value : string_value("<none>")) << "'"); - optional<string> data = value; - if (data && data->empty()) + optional<value_t> data = value; + if (data && + (data->is_null() || + (data->is_string() && data->as_string().empty()))) data = none; string_map::iterator i = metadata->find(tag); @@ -165,8 +169,9 @@ void item_t::parse_tags(const char * p, bool overwrite_existing, q = std::strtok(NULL, " \t")) { const string::size_type len = std::strlen(q); if (! tag.empty()) { - string_map::iterator i = set_tag(tag, string(p + (q - buf.get())), - overwrite_existing); + string_map::iterator i = + set_tag(tag, string_value(string(p + (q - buf.get()))), + overwrite_existing); (*i).second.second = true; break; } @@ -263,13 +268,13 @@ namespace { value_t get_tag(call_scope_t& args) { item_t& item(find_scope<item_t>(args)); - optional<string> str; + optional<value_t> val; if (args.size() == 1) { if (args[0].is_string()) - str = item.get_tag(args[0].as_string()); + val = item.get_tag(args[0].as_string()); else if (args[0].is_mask()) - str = item.get_tag(args[0].as_mask()); + val = item.get_tag(args[0].as_mask()); else throw_(std::runtime_error, _("Expected string or mask for argument 1, but received %1") @@ -277,7 +282,7 @@ namespace { } else if (args.size() == 2) { if (args[0].is_mask() && args[1].is_mask()) - str = item.get_tag(args[0].to_mask(), args[1].to_mask()); + val = item.get_tag(args[0].to_mask(), args[1].to_mask()); else throw_(std::runtime_error, _("Expected masks for arguments 1 and 2, but received %1 and %2") @@ -290,10 +295,7 @@ namespace { throw_(std::runtime_error, _("Too many arguments to function")); } - if (str) - return string_value(*str); - else - return NULL_VALUE; + return val ? *val : NULL_VALUE; } value_t get_pathname(item_t& item) { @@ -106,8 +106,8 @@ public: enum state_t { UNCLEARED = 0, CLEARED, PENDING }; - typedef std::pair<optional<string>, bool> tag_data_t; - typedef std::map<string, tag_data_t> string_map; + typedef std::pair<optional<value_t>, bool> tag_data_t; + typedef std::map<string, tag_data_t> string_map; state_t _state; optional<date_t> _date; @@ -153,14 +153,14 @@ public: virtual bool has_tag(const mask_t& tag_mask, const optional<mask_t>& value_mask = none) const; - virtual optional<string> get_tag(const string& tag) const; - virtual optional<string> get_tag(const mask_t& tag_mask, - const optional<mask_t>& value_mask = none) const; + virtual optional<value_t> get_tag(const string& tag) const; + virtual optional<value_t> 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, - const bool overwrite_existing = true); + set_tag(const string& tag, + const optional<value_t>& value = none, + const bool overwrite_existing = true); virtual void parse_tags(const char * p, bool overwrite_existing = true, optional<date_t::year_type> current_year = none); diff --git a/src/post.cc b/src/post.cc index 3ef76f7f..2a8abddc 100644 --- a/src/post.cc +++ b/src/post.cc @@ -59,19 +59,19 @@ bool post_t::has_tag(const mask_t& tag_mask, return false; } -optional<string> post_t::get_tag(const string& tag) const +optional<value_t> post_t::get_tag(const string& tag) const { - if (optional<string> value = item_t::get_tag(tag)) + if (optional<value_t> value = item_t::get_tag(tag)) return value; if (xact) return xact->get_tag(tag); return none; } -optional<string> post_t::get_tag(const mask_t& tag_mask, - const optional<mask_t>& value_mask) const +optional<value_t> post_t::get_tag(const mask_t& tag_mask, + const optional<mask_t>& value_mask) const { - if (optional<string> value = item_t::get_tag(tag_mask, value_mask)) + if (optional<value_t> value = item_t::get_tag(tag_mask, value_mask)) return value; if (xact) return xact->get_tag(tag_mask, value_mask); @@ -715,7 +715,7 @@ void to_xml(std::ostream& out, const post_t& post) } { push_xml z(out, "value"); - out << y.guard(*pair.second.first); + to_xml(out, *pair.second.first); } } else { push_xml z(out, "tag"); @@ -103,9 +103,9 @@ public: virtual bool has_tag(const mask_t& tag_mask, const optional<mask_t>& value_mask = none) const; - virtual optional<string> get_tag(const string& tag) const; - virtual optional<string> get_tag(const mask_t& tag_mask, - const optional<mask_t>& value_mask = none) const; + virtual optional<value_t> get_tag(const string& tag) const; + virtual optional<value_t> get_tag(const mask_t& tag_mask, + const optional<mask_t>& value_mask = none) const; virtual date_t value_date() const; virtual date_t date() const; diff --git a/src/py_item.cc b/src/py_item.cc index 65d89119..0e95f24f 100644 --- a/src/py_item.cc +++ b/src/py_item.cc @@ -53,14 +53,14 @@ namespace { return item.has_tag(tag_mask, value_mask); } - boost::optional<string> py_get_tag_1s(item_t& item, const string& tag) { + boost::optional<value_t> py_get_tag_1s(item_t& item, const string& tag) { return item.get_tag(tag); } - boost::optional<string> py_get_tag_1m(item_t& item, const mask_t& tag_mask) { + boost::optional<value_t> py_get_tag_1m(item_t& item, const mask_t& tag_mask) { return item.get_tag(tag_mask); } - boost::optional<string> py_get_tag_2m(item_t& item, const mask_t& tag_mask, - const boost::optional<mask_t>& value_mask) { + boost::optional<value_t> py_get_tag_2m(item_t& item, const mask_t& tag_mask, + const boost::optional<mask_t>& value_mask) { return item.get_tag(tag_mask, value_mask); } diff --git a/src/py_post.cc b/src/py_post.cc index 930a46c9..537289b3 100644 --- a/src/py_post.cc +++ b/src/py_post.cc @@ -52,14 +52,14 @@ namespace { return post.has_tag(tag_mask, value_mask); } - boost::optional<string> py_get_tag_1s(post_t& post, const string& tag) { + boost::optional<value_t> py_get_tag_1s(post_t& post, const string& tag) { return post.get_tag(tag); } - boost::optional<string> py_get_tag_1m(post_t& post, const mask_t& tag_mask) { + boost::optional<value_t> py_get_tag_1m(post_t& post, const mask_t& tag_mask) { return post.get_tag(tag_mask); } - boost::optional<string> py_get_tag_2m(post_t& post, const mask_t& tag_mask, - const boost::optional<mask_t>& value_mask) { + boost::optional<value_t> py_get_tag_2m(post_t& post, const mask_t& tag_mask, + const boost::optional<mask_t>& value_mask) { return post.get_tag(tag_mask, value_mask); } diff --git a/src/xact.cc b/src/xact.cc index b4438b48..3b66598c 100644 --- a/src/xact.cc +++ b/src/xact.cc @@ -823,7 +823,7 @@ void to_xml(std::ostream& out, const xact_t& xact) } { push_xml w(out, "value"); - out << y.guard(*pair.second.first); + to_xml(out, *pair.second.first); } } else { push_xml z(out, "tag"); |