From 46b35a015bc72a7ecf03a296f6dc20917c6ae7f0 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Mon, 2 Feb 2009 15:16:40 -0400 Subject: Don't allow implicit matching of strings against masks, =~ is needed. --- src/item.cc | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) (limited to 'src/item.cc') diff --git a/src/item.cc b/src/item.cc index 6e820b8d..2fe7601c 100644 --- a/src/item.cc +++ b/src/item.cc @@ -141,18 +141,29 @@ namespace { value_t& arg(args[0]); if (arg.is_string()) { - if (args.size() == 1) + if (args.size() == 1) { return item.has_tag(args[0].as_string()); - else if (optional tag = item.get_tag(args[0].as_string())) - return args[1] == string_value(*tag); + } + else if (optional tag = item.get_tag(args[0].as_string())) { + if (args[1].is_string()) { + return args[1].as_string() == *tag; + } + else if (args[1].is_mask()) { + return args[1].as_mask().match(*tag); + } + } } else if (arg.is_mask()) { foreach (const item_t::string_map::value_type& data, *item.metadata) { if (arg.as_mask().match(data.first)) { if (args.size() == 1) return true; - else if (data.second && args[1] == string_value(*data.second)) - return true; + else if (data.second) { + if (args[1].is_string()) + return args[1].as_string() == *data.second; + else if (args[1].is_mask()) + return args[1].as_mask().match(*data.second); + } } } } @@ -312,8 +323,13 @@ string item_context(const item_t& item) std::ostringstream out; out << "While balancing item from \"" << path.string() - << "\", line " << item.beg_line - << ", byte " << item.beg_pos << ":\n"; + << "\""; + + if (item.beg_line != (item.end_line - 1)) + out << ", lines " << item.beg_line << "-" + << (item.end_line - 1) << ":\n"; + else + out << ", line " << item.beg_line << ":\n"; bool first = true; for (char * p = std::strtok(buf.get(), "\n"); -- cgit v1.2.3