Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce boost regex dependencies #30333

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions CommonTools/Utils/src/TFileDirectory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include "CommonTools/Utils/interface/TFileDirectory.h"

#include "boost/regex.hpp"
#include <regex>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you move this header with the other standard headers above ?


using namespace std;

Expand Down Expand Up @@ -75,11 +75,11 @@ TDirectory *TFileDirectory::_mkdir(TDirectory *dirPtr, const string &subdirName,
}
// if we're here, then this directory doesn't exist. Is this
// directory a subdirectory?
const boost::regex subdirRE("(.+?)/([^/]+)");
boost::smatch matches;
const std::regex subdirRE("(.+?)/([^/]+)");
std::smatch matches;
TDirectory *parentDir = nullptr;
string useName = subdirName;
if (boost::regex_match(subdirName, matches, subdirRE)) {
if (std::regex_match(subdirName, matches, subdirRE)) {
parentDir = _mkdir(dirPtr, matches[1], description);
useName = matches[2];
} else {
Expand Down
20 changes: 10 additions & 10 deletions CondCore/CondDB/interface/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include <pwd.h>
#include <climits>
//
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
//

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

namespace cond {

Expand Down Expand Up @@ -123,10 +123,10 @@ namespace cond {
if (input.find("sqlite") == 0 || input.find("oracle") == 0)
return input;

//static const boost::regex trivial("oracle://(cms_orcon_adg|cms_orcoff_prep)/([_[:alnum:]]+?)");
static const boost::regex short_frontier("frontier://([[:alnum:]]+?)/([_[:alnum:]]+?)");
static const boost::regex long_frontier("frontier://((\\([-[:alnum:]]+?=[^\\)]+?\\))+)/([_[:alnum:]]+?)");
static const boost::regex long_frontier_serverurl("\\(serverurl=[^\\)]+?/([[:alnum:]]+?)\\)");
//static const std::regex trivial("oracle://(cms_orcon_adg|cms_orcoff_prep)/([_[:alnum:]]+?)");
static const std::regex short_frontier("frontier://([[:alnum:]]+?)/([_[:alnum:]]+?)");
static const std::regex long_frontier("frontier://((\\([-[:alnum:]]+?=[^\\)]+?\\))+)/([_[:alnum:]]+?)");
static const std::regex long_frontier_serverurl("\\(serverurl=[^\\)]+?/([[:alnum:]]+?)\\)");

static const std::map<std::string, std::string> frontierMap = {
{"PromptProd", "cms_orcon_adg"},
Expand All @@ -136,23 +136,23 @@ namespace cond {
{"FrontierPrep", "cms_orcoff_prep"},
};

boost::smatch matches;
std::smatch matches;

static const std::string technology("oracle://");
std::string service("");
std::string account("");

bool match = false;
if (boost::regex_match(input, matches, short_frontier)) {
if (std::regex_match(input, matches, short_frontier)) {
service = matches[1];
account = matches[2];
match = true;
}

if (boost::regex_match(input, matches, long_frontier)) {
if (std::regex_match(input, matches, long_frontier)) {
std::string frontier_config(matches[1]);
boost::smatch matches2;
if (not boost::regex_search(frontier_config, matches2, long_frontier_serverurl))
std::smatch matches2;
if (not std::regex_search(frontier_config, matches2, long_frontier_serverurl))
throwException("No serverurl in matched long frontier", "convertoToOracleConnection");
service = matches2[1];
account = matches[3];
Expand Down
8 changes: 4 additions & 4 deletions DQMOffline/Trigger/plugins/HLTMuonRefMethod.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include <cmath>
#include <climits>
#include <boost/tokenizer.hpp>
#include <boost/regex.hpp>
#include <regex>

#include <TH1.h>
#include <TEfficiency.h>
Expand Down Expand Up @@ -70,8 +70,8 @@ void HLTMuonRefMethod::beginJob() {}

void HLTMuonRefMethod::dqmEndJob(DQMStore::IBooker& ibooker, DQMStore::IGetter& igetter) {
using vstring = std::vector<std::string>;
boost::regex metacharacters{"[\\^\\$\\.\\*\\+\\?\\|\\(\\)\\{\\}\\[\\]]"};
boost::smatch what;
std::regex metacharacters{"[\\^\\$\\.\\*\\+\\?\\|\\(\\)\\{\\}\\[\\]]"};
std::smatch what;

// theDQM = 0;
// theDQM = Service<DQMStore>().operator->();
Expand All @@ -85,7 +85,7 @@ void HLTMuonRefMethod::dqmEndJob(DQMStore::IBooker& ibooker, DQMStore::IGetter&
if (subDir[subDir.size() - 1] == '/')
subDir.erase(subDir.size() - 1);

if (boost::regex_search(subDir, what, metacharacters)) {
if (std::regex_search(subDir, what, metacharacters)) {
const string::size_type shiftPos = subDir.rfind('/');
const string searchPath = subDir.substr(0, shiftPos);
const string pattern = subDir.substr(shiftPos + 1, subDir.length());
Expand Down
8 changes: 4 additions & 4 deletions DQMServices/StreamerIO/plugins/DQMFileIterator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/Utilities/interface/TimeOfDay.h"

#include <boost/regex.hpp>
#include <regex>
#include <boost/format.hpp>
#include <boost/range.hpp>
#include <boost/filesystem.hpp>
Expand Down Expand Up @@ -231,7 +231,7 @@ namespace dqmservices {

directory_iterator dend;
for (directory_iterator di(runPath); di != dend; ++di) {
const boost::regex fn_re("run(\\d+)_ls(\\d+)_([a-zA-Z0-9]+)(_.*)?\\.jsn");
const std::regex fn_re("run(\\d+)_ls(\\d+)_([a-zA-Z0-9]+)(_.*)?\\.jsn");

const std::string filename = di->path().filename().string();
const std::string fn = di->path().string();
Expand All @@ -240,8 +240,8 @@ namespace dqmservices {
continue;
}

boost::smatch result;
if (boost::regex_match(filename, result, fn_re)) {
std::smatch result;
if (std::regex_match(filename, result, fn_re)) {
unsigned int run = std::stoi(result[1]);
unsigned int lumi = std::stoi(result[2]);
std::string label = result[3];
Expand Down
8 changes: 4 additions & 4 deletions DQMServices/StreamerIO/plugins/RamdiskMonitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include <map>
#include <sys/stat.h>

#include <boost/regex.hpp>
#include <regex>
#include <boost/format.hpp>
#include <boost/range.hpp>
#include <boost/filesystem.hpp>
Expand Down Expand Up @@ -181,7 +181,7 @@ namespace dqm {

directory_iterator dend;
for (directory_iterator di(runPath_); di != dend; ++di) {
const boost::regex fn_re("run(\\d+)_ls(\\d+)_([a-zA-Z0-9]+)(_.*)?\\.jsn");
const std::regex fn_re("run(\\d+)_ls(\\d+)_([a-zA-Z0-9]+)(_.*)?\\.jsn");

const std::string filename = di->path().filename().string();
const std::string fn = di->path().string();
Expand All @@ -190,8 +190,8 @@ namespace dqm {
continue;
}

boost::smatch result;
if (boost::regex_match(filename, result, fn_re)) {
std::smatch result;
if (std::regex_match(filename, result, fn_re)) {
unsigned int run = std::stoi(result[1]);
unsigned int lumi = std::stoi(result[2]);
std::string label = result[3];
Expand Down
6 changes: 3 additions & 3 deletions DataFormats/PatCandidates/interface/EventHypothesis.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include "DataFormats/Candidate/interface/CandidateFwd.h"
#include "DataFormats/Candidate/interface/Candidate.h"
#include <boost/regex.hpp>
#include <regex>

#include <typeinfo>
#include <iostream>
Expand Down Expand Up @@ -131,11 +131,11 @@ namespace pat {
public:
explicit RoleRegexpFilter(const std::string &roleRegexp) : re_(roleRegexp) {}
bool operator()(const CandRefType &cand, const std::string &role) const override {
return boost::regex_match(role, re_);
return std::regex_match(role, re_);
}

private:
boost::regex re_;
std::regex re_;
};
} // namespace eventhypothesis

Expand Down
12 changes: 6 additions & 6 deletions EventFilter/L1TRawToDigi/interface/MP7FileReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include <vector>

// Boost Headers
#include <boost/regex.hpp>
#include <regex>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you move this header with the other standard headers above ?


class FileData {
public:
Expand Down Expand Up @@ -89,11 +89,11 @@ class MP7FileReader {
std::vector<FileData> buffers_;

private:
static boost::regex reBoard_;
static boost::regex reLink_;
static boost::regex reQuadChan_;
static boost::regex reFrame_;
static boost::regex reValid_;
static std::regex reBoard_;
static std::regex reLink_;
static std::regex reQuadChan_;
static std::regex reFrame_;
static std::regex reValid_;
};

#endif /* READER_H */
32 changes: 16 additions & 16 deletions EventFilter/L1TRawToDigi/src/MP7FileReader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "EventFilter/L1TRawToDigi/interface/MP7FileReader.h"

#include <boost/algorithm/string.hpp>
#include <boost/regex.hpp>
#include <regex>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you move this header with the other standard headers below ?

#include <boost/lexical_cast.hpp>

#include <iostream>
Expand All @@ -15,11 +15,11 @@ using std::cout;
using std::endl;

// Constants initialization
boost::regex MP7FileReader::reBoard_("^Board (.+)");
boost::regex MP7FileReader::reLink_("^Link : (.*)");
boost::regex MP7FileReader::reQuadChan_("^Quad/Chan : (.*)");
boost::regex MP7FileReader::reFrame_("^Frame (\\d{4}) : (.*)");
boost::regex MP7FileReader::reValid_("([01])v([0-9a-fA-F]{8})");
std::regex MP7FileReader::reBoard_("^Board (.+)");
std::regex MP7FileReader::reLink_("^Link : (.*)");
std::regex MP7FileReader::reQuadChan_("^Quad/Chan : (.*)");
std::regex MP7FileReader::reFrame_("^Frame (\\d{4}) : (.*)");
std::regex MP7FileReader::reValid_("([01])v([0-9a-fA-F]{8})");

//____________________________________________________________________________//
const std::vector<uint64_t>& FileData::link(uint32_t i) const {
Expand Down Expand Up @@ -116,7 +116,7 @@ void MP7FileReader::load() {
std::string MP7FileReader::searchBoard() {
std::string line;
std::string id;
boost::smatch what;
std::smatch what;

while (getline(file_, line)) {
// Trim and skip empties and comments
Expand All @@ -126,7 +126,7 @@ std::string MP7FileReader::searchBoard() {
if (line[0] == '#')
continue;

if (boost::regex_match(line, what, reBoard_)) {
if (std::regex_match(line, what, reBoard_)) {
// Create a new buffer snapshot
id = what[1];
return id;
Expand All @@ -142,7 +142,7 @@ std::string MP7FileReader::searchBoard() {
//____________________________________________________________________________//
std::vector<uint32_t> MP7FileReader::searchLinks() {
std::string line;
boost::smatch what;
std::smatch what;

while (getline(file_, line)) {
boost::trim(line);
Expand All @@ -151,12 +151,12 @@ std::vector<uint32_t> MP7FileReader::searchLinks() {
if (line[0] == '#')
continue;

if (boost::regex_match(line, what, reQuadChan_)) {
if (std::regex_match(line, what, reQuadChan_)) {
// Not used
continue;
}

if (boost::regex_match(line, what, reLink_)) {
if (std::regex_match(line, what, reLink_)) {
std::vector<std::string> tokens;
std::string tmp = what[1].str();
// Trim the line
Expand All @@ -176,8 +176,8 @@ std::vector<uint32_t> MP7FileReader::searchLinks() {
}

uint64_t MP7FileReader::validStrToUint64(const std::string& token) {
boost::smatch what;
if (!boost::regex_match(token, what, reValid_)) {
std::smatch what;
if (!std::regex_match(token, what, reValid_)) {
throw std::logic_error("Token '" + token + "' doesn't match the valid format");
}

Expand All @@ -189,17 +189,17 @@ uint64_t MP7FileReader::validStrToUint64(const std::string& token) {
//____________________________________________________________________________//
std::vector<std::vector<uint64_t> > MP7FileReader::readRows() {
std::string line;
boost::smatch what;
std::smatch what;
std::vector<std::vector<uint64_t> > data;
int place = file_.tellg();
while (getline(file_, line)) {
if (boost::regex_match(line, what, reBoard_)) {
if (std::regex_match(line, what, reBoard_)) {
// Upos, next board found. Go back by one line
file_.seekg(place);
return data;
}

if (boost::regex_match(line, what, reFrame_)) {
if (std::regex_match(line, what, reFrame_)) {
// check frame number
uint32_t n = boost::lexical_cast<uint32_t>(what[1].str());

Expand Down
1 change: 1 addition & 0 deletions EventFilter/L1TRawToDigi/src/MP7PacketReader.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "EventFilter/L1TRawToDigi/interface/MP7PacketReader.h"

#include <iostream>
#include <set>

using std::cout;
using std::endl;
Expand Down
6 changes: 3 additions & 3 deletions FWCore/Framework/doc/EventSelector.cc-with-cerr-traces
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "FWCore/Utilities/interface/Algorithms.h"

#include "boost/algorithm/string.hpp"
#include "boost/regex.hpp"
#include <regex>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is obsolete. I suggest we let this change go in and then I remove the file (among others). Unless this PR needs to be modified for other reasons, in which case I'd ask to leave this file untouched (but only in that case).


#include <algorithm>
#include <iostream> // ###
Expand Down Expand Up @@ -350,10 +350,10 @@ namespace edm
EventSelector::matching_triggers(Strings const& trigs, std::string const& s)
{
std::vector< Strings::const_iterator > m;
boost::regex r ( glob2reg(s) );
std::regex r ( glob2reg(s) );
for (Strings::const_iterator i = trigs.begin(); i != trigs.end(); ++i)
{
if (boost::regex_match((*i),r))
if (std::regex_match((*i),r))
{
m.push_back(i);
}
Expand Down
18 changes: 9 additions & 9 deletions Fireworks/Core/src/FWFileEntry.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <boost/regex.hpp>
#include <regex>

#include "TFile.h"
#include "TEveTreeTools.h"
Expand Down Expand Up @@ -346,17 +346,17 @@ void FWFileEntry::runFilter(Filter* filter, const FWEventItemsManager* eiMng) {
item->setEvent(nullptr);
}

boost::regex re(std::string("\\$") + (*i)->name());
std::regex re(std::string("\\$") + (*i)->name());

if (boost::regex_search(interpretedSelection, re)) {
if (std::regex_search(interpretedSelection, re)) {
const edm::TypeWithDict elementType(const_cast<TClass*>(item->type()));
const edm::TypeWithDict wrapperType = edm::TypeWithDict::byName(edm::wrappedClassName(elementType.name()));
std::string fullBranchName = m_event->getBranchNameFor(wrapperType.typeInfo(),
item->moduleLabel().c_str(),
item->productInstanceLabel().c_str(),
item->processName().c_str());

interpretedSelection = boost::regex_replace(interpretedSelection, re, fullBranchName + ".obj");
interpretedSelection = std::regex_replace(interpretedSelection, re, fullBranchName + ".obj");

branch_names.push_back(fullBranchName);

Expand Down Expand Up @@ -456,8 +456,8 @@ void FWFileEntry::runFilter(Filter* filter, const FWEventItemsManager* eiMng) {
bool FWFileEntry::filterEventsWithCustomParser(Filter* filterEntry) {
std::string selection(filterEntry->m_selector->m_expression);

boost::regex re_spaces("\\s+");
selection = boost::regex_replace(selection, re_spaces, "");
std::regex re_spaces("\\s+");
selection = std::regex_replace(selection, re_spaces, "");
if (selection.find("&&") != std::string::npos && selection.find("||") != std::string::npos) {
// Combination of && and || operators not supported.
return false;
Expand All @@ -483,10 +483,10 @@ bool FWFileEntry::filterEventsWithCustomParser(Filter* filterEntry) {
if (selection.find("||") != std::string::npos)
junction_mode = false; // OR

boost::regex re("\\&\\&|\\|\\|");
std::regex re("\\&\\&|\\|\\|");

boost::sregex_token_iterator i(selection.begin(), selection.end(), re, -1);
boost::sregex_token_iterator j;
std::sregex_token_iterator i(selection.begin(), selection.end(), re, -1);
std::sregex_token_iterator j;

// filters and how they enter in the logical expression
std::vector<std::pair<unsigned int, bool>> filters;
Expand Down
Loading