test
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 
4 
5 #include <boost/algorithm/string.hpp>
6 #include <regex>
7 
8 namespace edm {
9 
10  // checks that a tainted string is valid.
11  // Needed to satisfy Coverity.
12  bool
13  untaintString(char const* pattern, char const* regexp) {
14  std::regex rexp(regexp);
15  return std::regex_match(pattern, rexp);
16  }
17 
18  bool is_glob(std::string const& pattern) {
19  return (pattern.find_first_of("*?") != pattern.npos);
20  }
21 
23  std::string regexp = pattern;
24  boost::replace_all(regexp, "*", ".*");
25  boost::replace_all(regexp, "?", ".");
26  return regexp;
27  }
28 
29  std::vector<std::vector<std::string>::const_iterator>
30  regexMatch(std::vector<std::string> const& strings, std::regex const& regexp) {
31  std::vector< std::vector<std::string>::const_iterator> matches;
32  for (std::vector<std::string>::const_iterator i = strings.begin(), iEnd = strings.end(); i != iEnd; ++i) {
33  if (std::regex_match((*i), regexp)) {
34  matches.push_back(i);
35  }
36  }
37  return matches;
38  }
39 
40  std::vector<std::vector<std::string>::const_iterator>
41  regexMatch(std::vector<std::string> const& strings, std::string const& pattern) {
42  std::regex regexp(glob2reg(pattern));
43  return regexMatch(strings, regexp);
44  }
45 
46 }
int i
Definition: DBlmapReader.cc:9
bool is_glob(std::string const &pattern)
Definition: RegexMatch.cc:18
std::string glob2reg(std::string const &pattern)
Definition: RegexMatch.cc:22
bool untaintString(char const *pattern, char const *regexp)
Definition: RegexMatch.cc:13
std::vector< std::vector< std::string >::const_iterator > regexMatch(std::vector< std::string > const &strings, std::regex const &regexp)
Definition: RegexMatch.cc:30