From 141308597784f77414032b00f239e0601f9d4d38 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Tue, 2 Feb 2010 17:07:05 -0500 Subject: Added a --pivot=TAG option This is equivalent to the following: --account='"TAG:" + tag(/TAG/)' --- src/item.cc | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) (limited to 'src/item.cc') 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 env(scope, "s"); - if (optional value = env->get_tag(env.get(0))) - return string_value(*value); - return string_value(empty_string); + value_t get_tag(call_scope_t& args) { + item_t& item(find_scope(args)); + optional 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) { -- cgit v1.2.3