CMS 3D CMS Logo

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 untaintString(char const* pattern, char const* regexp) {
13  std::regex rexp(regexp);
14  return std::regex_match(pattern, rexp);
15  }
16 
17  bool is_glob(std::string const& pattern) { return (pattern.find_first_of("*?") != pattern.npos); }
18 
21  boost::replace_all(regexp, "*", ".*");
22  boost::replace_all(regexp, "?", ".");
23  return regexp;
24  }
25 
26  std::vector<std::vector<std::string>::const_iterator> regexMatch(std::vector<std::string> const& strings,
27  std::regex const& regexp) {
28  std::vector<std::vector<std::string>::const_iterator> matches;
29  for (std::vector<std::string>::const_iterator i = strings.begin(), iEnd = strings.end(); i != iEnd; ++i) {
30  if (std::regex_match((*i), regexp)) {
31  matches.push_back(i);
32  }
33  }
34  return matches;
35  }
36 
37  std::vector<std::vector<std::string>::const_iterator> regexMatch(std::vector<std::string> const& strings,
38  std::string const& pattern) {
39  std::regex regexp(glob2reg(pattern));
40  return regexMatch(strings, regexp);
41  }
42 
43 } // namespace edm
bool is_glob(std::string const &pattern)
Definition: RegexMatch.cc:17
std::string glob2reg(std::string const &pattern)
Definition: RegexMatch.cc:19
bool untaintString(char const *pattern, char const *regexp)
Definition: RegexMatch.cc:12
std::vector< std::vector< std::string >::const_iterator > regexMatch(std::vector< std::string > const &strings, std::regex const &regexp)
Definition: RegexMatch.cc:26
HLT enums.