CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RegexMatch.cc
Go to the documentation of this file.
1 // functions used to assist with regular expression matching of strings
2 
3 #include <boost/regex.hpp>
4 #include <boost/algorithm/string.hpp>
5 
7 
8 namespace edm {
9 
10  bool is_glob(std::string const& pattern) {
11  return (pattern.find_first_of("*?") != pattern.npos);
12  }
13 
14  std::string glob2reg(std::string const& pattern) {
15  std::string regexp = pattern;
16  boost::replace_all(regexp, "*", ".*");
17  boost::replace_all(regexp, "?", ".");
18  return regexp;
19  }
20 
21  std::vector<std::vector<std::string>::const_iterator>
22  regexMatch(std::vector<std::string> const& strings, boost::regex const& regexp) {
23  std::vector< std::vector<std::string>::const_iterator> matches;
24  for (std::vector<std::string>::const_iterator i = strings.begin(), iEnd = strings.end(); i != iEnd; ++i) {
25  if (boost::regex_match((*i), regexp)) {
26  matches.push_back(i);
27  }
28  }
29  return matches;
30  }
31 
32  std::vector<std::vector<std::string>::const_iterator>
33  regexMatch(std::vector<std::string> const& strings, std::string const& pattern) {
34  boost::regex regexp(glob2reg(pattern));
35  return regexMatch(strings, regexp);
36  }
37 
38 }
int i
Definition: DBlmapReader.cc:9
bool is_glob(std::string const &pattern)
Definition: RegexMatch.cc:10
std::string glob2reg(std::string const &pattern)
Definition: RegexMatch.cc:14
std::vector< std::vector< std::string >::const_iterator > regexMatch(std::vector< std::string > const &strings, boost::regex const &regexp)
Definition: RegexMatch.cc:22