Skip to content

Commit

Permalink
Merge pull request cms-sw#10000 from wmtan/UseCplusplusRegex
Browse files Browse the repository at this point in the history
Use C++ regex, not boost regex, in the framework where feasible.
  • Loading branch information
cmsbuild committed Jul 15, 2015
2 parents 383a7ba + 2227cd1 commit 1b05465
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 25 deletions.
6 changes: 3 additions & 3 deletions FWCore/Catalog/interface/FileLocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <list>
#include <map>
#include <utility>
#include <boost/regex.hpp>
#include <regex>
#include <xercesc/dom/DOM.hpp>

namespace edm {
Expand All @@ -26,8 +26,8 @@ namespace edm {
static int s_numberOfInstances;

struct Rule {
boost::regex pathMatch;
boost::regex destinationMatch;
std::regex pathMatch;
std::regex destinationMatch;
std::string result;
std::string chain;
};
Expand Down
12 changes: 6 additions & 6 deletions FWCore/Catalog/src/FileLocator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace {
}

std::string
replaceWithRegexp(boost::smatch const& matches,
replaceWithRegexp(std::smatch const& matches,
std::string const& outputFormat) {
std::string result = outputFormat;
std::stringstream str;
Expand Down Expand Up @@ -258,17 +258,17 @@ namespace edm {

Rules const& rules = (*(rulesIterator)).second;

boost::smatch destinationMatches;
boost::smatch nameMatches;
std::smatch destinationMatches;
std::smatch nameMatches;

/* Look up for a matching rule*/
for (Rules::const_iterator i = rules.begin(); i != rules.end(); ++i) {

if (!boost::regex_match(destination, destinationMatches, i->destinationMatch)) {
if (!std::regex_match(destination, destinationMatches, i->destinationMatch)) {
continue;
}

if (!boost::regex_match(name, i->pathMatch)) {
if (!std::regex_match(name, i->pathMatch)) {
continue;
}

Expand All @@ -282,7 +282,7 @@ namespace edm {
}
}

boost::regex_match(name, nameMatches, i->pathMatch);
std::regex_match(name, nameMatches, i->pathMatch);
name = replaceWithRegexp(nameMatches, i->result);

if ((direct == false) && (chain != "")) {
Expand Down
6 changes: 3 additions & 3 deletions FWCore/Framework/test/eventprocessor_t.cppunit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Test of the EventProcessor class.

#include "cppunit/extensions/HelperMacros.h"

#include "boost/regex.hpp"
#include <regex>

#include <exception>
#include <iostream>
Expand Down Expand Up @@ -454,7 +454,7 @@ testeventprocessor::activityRegistryTest() {
static
bool
findModuleName(std::string const& iMessage) {
static boost::regex const expr("TestFailuresAnalyzer");
static std::regex const expr("TestFailuresAnalyzer");
return regex_search(iMessage, expr);
}

Expand Down Expand Up @@ -556,7 +556,7 @@ testeventprocessor::moduleFailureTest() {

threw = false;
} catch(cms::Exception const& iException) {
static boost::regex const expr("m1");
static std::regex const expr("m1");
if(!regex_search(iException.explainSelf(), expr)) {
std::cout << iException.explainSelf() << std::endl;
CPPUNIT_ASSERT(0 == "module name not in exception message");
Expand Down
5 changes: 2 additions & 3 deletions FWCore/Utilities/interface/RegexMatch.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#ifndef FWCore_Utilities_RegexMatch_h
#define FWCore_Utilities_RegexMatch_h

#include <boost/regex_fwd.hpp>

#include <regex>
#include <string>
#include <vector>

Expand All @@ -18,7 +17,7 @@ namespace edm {
glob2reg(std::string const& pattern);

std::vector<std::vector<std::string>::const_iterator>
regexMatch(std::vector<std::string> const& strings, boost::regex const& regexp);
regexMatch(std::vector<std::string> const& strings, std::regex const& regexp);

std::vector<std::vector<std::string>::const_iterator>
regexMatch(std::vector<std::string> const& strings, std::string const& pattern);
Expand Down
12 changes: 6 additions & 6 deletions FWCore/Utilities/src/RegexMatch.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
#include "FWCore/Utilities/interface/RegexMatch.h"

#include <boost/algorithm/string.hpp>
#include <boost/regex.hpp>
#include <regex>

namespace edm {

// checks that a tainted string is valid.
// Needed to satisfy Coverity.
bool
untaintString(char const* pattern, char const* regexp) {
boost::regex rexp(regexp);
return boost::regex_match(pattern, rexp);
std::regex rexp(regexp);
return std::regex_match(pattern, rexp);
}

bool is_glob(std::string const& pattern) {
Expand All @@ -27,10 +27,10 @@ namespace edm {
}

std::vector<std::vector<std::string>::const_iterator>
regexMatch(std::vector<std::string> const& strings, boost::regex const& regexp) {
regexMatch(std::vector<std::string> const& strings, std::regex const& regexp) {
std::vector< std::vector<std::string>::const_iterator> matches;
for (std::vector<std::string>::const_iterator i = strings.begin(), iEnd = strings.end(); i != iEnd; ++i) {
if (boost::regex_match((*i), regexp)) {
if (std::regex_match((*i), regexp)) {
matches.push_back(i);
}
}
Expand All @@ -39,7 +39,7 @@ namespace edm {

std::vector<std::vector<std::string>::const_iterator>
regexMatch(std::vector<std::string> const& strings, std::string const& pattern) {
boost::regex regexp(glob2reg(pattern));
std::regex regexp(glob2reg(pattern));
return regexMatch(strings, regexp);
}

Expand Down
8 changes: 4 additions & 4 deletions FWCore/Utilities/src/TypeDemangler.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <cxxabi.h>
#include <cctype>
#include <string>
#include "boost/regex.hpp"
#include <regex>
#include "FWCore/Utilities/interface/Exception.h"

/********************************************************************
Expand All @@ -27,9 +27,9 @@
namespace {
void
reformatter(std::string& input, char const* exp, char const* format) {
boost::regex regexp(exp, boost::regex::egrep);
while(boost::regex_match(input, regexp)) {
std::string newstring = boost::regex_replace(input, regexp, format);
std::regex regexp(exp, std::regex::egrep);
while(std::regex_match(input, regexp)) {
std::string newstring = std::regex_replace(input, regexp, format);
input.swap(newstring);
}
}
Expand Down

0 comments on commit 1b05465

Please sign in to comment.