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
mps_fire.i
i
Definition: mps_fire.py:355
edm::regexMatch
std::vector< std::vector< std::string >::const_iterator > regexMatch(std::vector< std::string > const &strings, std::regex const &regexp)
Definition: RegexMatch.cc:26
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::is_glob
bool is_glob(std::string const &pattern)
Definition: RegexMatch.cc:17
fetchall_from_DQM_v2.regexp
regexp
Definition: fetchall_from_DQM_v2.py:93
nano_cff.strings
strings
Definition: nano_cff.py:28
edm::glob2reg
std::string glob2reg(std::string const &pattern)
Definition: RegexMatch.cc:19
edm::untaintString
bool untaintString(char const *pattern, char const *regexp)
Definition: RegexMatch.cc:12
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
topSingleLeptonDQM_PU_cfi.pattern
pattern
Definition: topSingleLeptonDQM_PU_cfi.py:39
patCandidatesForDimuonsSequences_cff.matches
matches
Definition: patCandidatesForDimuonsSequences_cff.py:131
RegexMatch.h