Go to the documentation of this file.00001
00002
00003 #include <boost/regex.hpp>
00004 #include <boost/algorithm/string.hpp>
00005
00006 #include "FWCore/Utilities/interface/RegexMatch.h"
00007
00008 namespace edm {
00009
00010 bool is_glob(std::string const& pattern) {
00011 return (pattern.find_first_of("*?") != pattern.npos);
00012 }
00013
00014 std::string glob2reg(std::string const& pattern) {
00015 std::string regexp = pattern;
00016 boost::replace_all(regexp, "*", ".*");
00017 boost::replace_all(regexp, "?", ".");
00018 return regexp;
00019 }
00020
00021 std::vector<std::vector<std::string>::const_iterator>
00022 regexMatch(std::vector<std::string> const& strings, boost::regex const& regexp) {
00023 std::vector< std::vector<std::string>::const_iterator> matches;
00024 for (std::vector<std::string>::const_iterator i = strings.begin(), iEnd = strings.end(); i != iEnd; ++i) {
00025 if (boost::regex_match((*i), regexp)) {
00026 matches.push_back(i);
00027 }
00028 }
00029 return matches;
00030 }
00031
00032 std::vector<std::vector<std::string>::const_iterator>
00033 regexMatch(std::vector<std::string> const& strings, std::string const& pattern) {
00034 boost::regex regexp(glob2reg(pattern));
00035 return regexMatch(strings, regexp);
00036 }
00037
00038 }