CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_1/src/FWCore/Utilities/src/RegexMatch.cc

Go to the documentation of this file.
00001 // functions used to assist with  regular expression matching of strings
00002 
00003 #include "FWCore/Utilities/interface/RegexMatch.h"
00004 
00005 #include <boost/algorithm/string.hpp>
00006 #include <boost/regex.hpp>
00007 
00008 namespace edm {
00009 
00010   // checks that a tainted string is valid.
00011   // Needed to satisfy Coverity.
00012   bool
00013   untaintString(char const* pattern, char const* regexp) {
00014     boost::regex rexp(regexp);
00015     return boost::regex_match(pattern, rexp);
00016   }
00017 
00018   bool is_glob(std::string const& pattern) {
00019     return (pattern.find_first_of("*?") != pattern.npos);
00020   }
00021 
00022   std::string glob2reg(std::string const& pattern) {
00023     std::string regexp = pattern;
00024     boost::replace_all(regexp, "*", ".*");
00025     boost::replace_all(regexp, "?", ".");
00026     return regexp;
00027   }
00028 
00029   std::vector<std::vector<std::string>::const_iterator>
00030   regexMatch(std::vector<std::string> const& strings, boost::regex const& regexp) {
00031     std::vector< std::vector<std::string>::const_iterator> matches;
00032     for (std::vector<std::string>::const_iterator i = strings.begin(), iEnd = strings.end(); i != iEnd; ++i) {
00033       if (boost::regex_match((*i), regexp)) {
00034         matches.push_back(i);
00035       }
00036     }
00037     return matches;
00038   }
00039 
00040   std::vector<std::vector<std::string>::const_iterator>
00041   regexMatch(std::vector<std::string> const& strings, std::string const& pattern) {
00042     boost::regex regexp(glob2reg(pattern));
00043     return regexMatch(strings, regexp);
00044   }
00045 
00046 }