diff options
author | John Wiegley <johnw@newartisans.com> | 2010-02-02 17:07:05 -0500 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2010-02-02 17:07:05 -0500 |
commit | 141308597784f77414032b00f239e0601f9d4d38 (patch) | |
tree | cfbe1311abbffc7fd05578f8cf0f8ffdf4120f84 /src/item.cc | |
parent | a56a1db66294c06c7b9d582f694538a0cb473abf (diff) | |
download | fork-ledger-141308597784f77414032b00f239e0601f9d4d38.tar.gz fork-ledger-141308597784f77414032b00f239e0601f9d4d38.tar.bz2 fork-ledger-141308597784f77414032b00f239e0601f9d4d38.zip |
Added a --pivot=TAG option
This is equivalent to the following:
--account='"TAG:" + tag(/TAG/)'
Diffstat (limited to 'src/item.cc')
-rw-r--r-- | src/item.cc | 38 |
1 files changed, 33 insertions, 5 deletions
diff --git a/src/item.cc b/src/item.cc index f86b8ec8..0e596f33 100644 --- a/src/item.cc +++ b/src/item.cc @@ -238,11 +238,39 @@ namespace { return false; } - value_t get_tag(call_scope_t& scope) { - in_context_t<item_t> env(scope, "s"); - if (optional<string> value = env->get_tag(env.get<string>(0))) - return string_value(*value); - return string_value(empty_string); + value_t get_tag(call_scope_t& args) { + item_t& item(find_scope<item_t>(args)); + optional<string> str; + + if (args.size() == 1) { + if (args[0].is_string()) + str = item.get_tag(args[0].as_string()); + else if (args[0].is_mask()) + str = item.get_tag(args[0].as_mask()); + else + throw_(std::runtime_error, + _("Expected string or mask for argument 1, but received %1") + << args[0].label()); + } + 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()); + else + throw_(std::runtime_error, + _("Expected masks for arguments 1 and 2, but received %1 and %2") + << args[0].label() << args[1].label()); + } + else if (args.size() == 0) { + throw_(std::runtime_error, _("Too few arguments to function")); + } + else { + throw_(std::runtime_error, _("Too many arguments to function")); + } + + if (str) + return string_value(*str); + else + return string_value(empty_string); } value_t get_pathname(item_t& item) { |