From 70bdc1c91ec8f2d44804709dd3fe6e2d6d1fb78c Mon Sep 17 00:00:00 2001 From: WrinklyNinja Date: Wed, 16 Jul 2014 11:37:19 +0100 Subject: [PATCH] Removed Boost.Regex usage. I thought I'd already switched to using C++11 std::regex, but there were a lot of places it was missing. I also removed Boost.ProgramOptions since we're using CEF to handle that now. --- CMakeLists.txt | 3 +-- src/api/api.cpp | 16 ++++++++-------- src/backend/generators.cpp | 10 +++++++--- src/backend/helpers.cpp | 2 +- src/backend/metadata.cpp | 4 ++-- src/backend/parsers.h | 16 ++++++++++------ 6 files changed, 29 insertions(+), 22 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2c58a9bb..47f3ff18 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -65,7 +65,7 @@ set (LOOT_GUI_SRC ${LOOT_SRC} set (LOOT_API_SRC ${LOOT_SRC} "${CMAKE_SOURCE_DIR}/src/api/api.cpp") -find_package(Boost REQUIRED COMPONENTS log log_setup locale thread chrono date_time filesystem program_options system regex iostreams) +find_package(Boost REQUIRED COMPONENTS log log_setup locale thread chrono date_time filesystem system regex iostreams) # Include source and library directories. include_directories ("${CMAKE_SOURCE_DIR}/src" @@ -114,7 +114,6 @@ IF (MINGW) boost_chrono boost_date_time boost_filesystem - boost_program_options boost_system boost_regex version diff --git a/src/api/api.cpp b/src/api/api.cpp index 5325af0d..75acc6cd 100644 --- a/src/api/api.cpp +++ b/src/api/api.cpp @@ -363,16 +363,16 @@ LOOT_API unsigned int loot_eval_lists (loot_db db, const unsigned int language) for (auto it=temp.begin(); it != temp.end();) { it->EvalAllConditions(db->game, language); if (it->IsRegexPlugin()) { - boost::regex regex; + std::regex reg; try { - regex = boost::regex(it->Name(), boost::regex::perl|boost::regex::icase); - } catch (boost::regex_error& e) { + reg = std::regex(it->Name(), std::regex::ECMAScript | std::regex::icase); + } catch (std::exception& e) { return c_error(loot_error_regex_eval_fail, e.what()); } for (boost::filesystem::directory_iterator itr(db->game.DataPath()); itr != boost::filesystem::directory_iterator(); ++itr) { const std::string filename = itr->path().filename().string(); - if (boost::regex_match(filename, regex)) { + if (std::regex_match(filename, reg)) { loot::Plugin p = *it; p.Name(filename); temp.push_back(p); @@ -393,16 +393,16 @@ LOOT_API unsigned int loot_eval_lists (loot_db db, const unsigned int language) for (auto it=temp.begin(); it != temp.end();) { it->EvalAllConditions(db->game, language); if (it->IsRegexPlugin()) { - boost::regex regex; + std::regex reg; try { - regex = boost::regex(it->Name(), boost::regex::perl|boost::regex::icase); - } catch (boost::regex_error& e) { + reg = std::regex(it->Name(), std::regex::ECMAScript | std::regex::icase); + } catch (std::exception& e) { return c_error(loot_error_regex_eval_fail, e.what()); } for (boost::filesystem::directory_iterator itr(db->game.DataPath()); itr != boost::filesystem::directory_iterator(); ++itr) { const std::string filename = itr->path().filename().string(); - if (boost::regex_match(filename, regex)) { + if (std::regex_match(filename, reg)) { loot::Plugin p = *it; p.Name(filename); temp.push_back(p); diff --git a/src/backend/generators.cpp b/src/backend/generators.cpp index b66ca267..2b99a43a 100644 --- a/src/backend/generators.cpp +++ b/src/backend/generators.cpp @@ -31,6 +31,10 @@ along with LOOT. If not, see #include #include +#include + +using namespace std; + namespace loot { //LOOT Report generation stuff. void GetOldReportDetails(const boost::filesystem::path& filepath, YAML::Node& node) { @@ -87,16 +91,16 @@ namespace loot { void WriteMessage(YAML::Emitter& out, const Message& message) { //Look for Markdown URL syntax and convert any found. - boost::regex regex("(\\[([^\\]]+)\\]\\s?\\(|<)((file|https?)://\\S+)(\\)|>)", boost::regex::perl | boost::regex::icase); // \2 is the label, \3 is the URL. + regex reg("(\\[([^\\]]+)\\]\\s?\\(|<)((file|https?)://\\S+)(\\)|>)", regex::ECMAScript | regex::icase); // \2 is the label, \3 is the URL. - boost::match_results results; + std::match_results results; std::string content = message.Content().front().Str(); std::string converted; std::string::iterator start, end; start = content.begin(); end = content.end(); - while (boost::regex_search(start, end, results, regex)) { + while (regex_search(start, end, results, reg)) { //Get data from match. std::string url, label; diff --git a/src/backend/helpers.cpp b/src/backend/helpers.cpp index 04367d7a..d364cf00 100644 --- a/src/backend/helpers.cpp +++ b/src/backend/helpers.cpp @@ -377,7 +377,7 @@ namespace loot { regex reg1("(\\d+\\.?)+"); //a.b.c.d.e.f.... where the letters are all integers, and 'a' is the shortest possible match. - //boost::regex reg2("(\\d+\\.?)+([a-zA-Z\\-]+(\\d+\\.?)*)+"); //Matches a mix of letters and numbers - from "0.99.xx", "1.35Alpha2", "0.9.9MB8b1", "10.52EV-D", "1.62EV" to "10.0EV-D1.62EV". + //regex reg2("(\\d+\\.?)+([a-zA-Z\\-]+(\\d+\\.?)*)+"); //Matches a mix of letters and numbers - from "0.99.xx", "1.35Alpha2", "0.9.9MB8b1", "10.52EV-D", "1.62EV" to "10.0EV-D1.62EV". if (regex_match(verString, reg1) && regex_match(ver.AsString(), reg1)) { //First type: numbers separated by periods. If two versions have a different number of numbers, then the shorter should be padded diff --git a/src/backend/metadata.cpp b/src/backend/metadata.cpp index c6538d2d..a990ad67 100644 --- a/src/backend/metadata.cpp +++ b/src/backend/metadata.cpp @@ -645,8 +645,8 @@ namespace loot { bool Plugin::operator == (const Plugin& rhs) const { return (boost::iequals(name, rhs.Name()) - || (IsRegexPlugin() && boost::regex_match(rhs.Name(), boost::regex(name, boost::regex::perl|boost::regex::icase))) - || (rhs.IsRegexPlugin() && boost::regex_match(name, boost::regex(rhs.Name(), boost::regex::perl|boost::regex::icase)))); + || (IsRegexPlugin() && regex_match(rhs.Name(), regex(name, regex::ECMAScript | regex::icase))) + || (rhs.IsRegexPlugin() && regex_match(name, regex(rhs.Name(), regex::ECMAScript | regex::icase)))); } bool Plugin::operator != (const Plugin& rhs) const { diff --git a/src/backend/parsers.h b/src/backend/parsers.h index 3de48a72..33469128 100644 --- a/src/backend/parsers.h +++ b/src/backend/parsers.h @@ -498,10 +498,14 @@ namespace loot { BOOST_LOG_TRIVIAL(trace) << "Checking to see if any files matching the regex \"" << regexStr << "\" exist."; - boost::regex sepReg("/|(\\\\\\\\)", boost::regex::perl); + regex sepReg("/|(\\\\\\\\)", regex::ECMAScript | regex::icase); std::vector components; - boost::algorithm::split_regex(components, regexStr, sepReg); + std::sregex_token_iterator it(regexStr.begin(), regexStr.end(), sepReg, -1); + std::sregex_token_iterator itend; + for (; it != itend; ++it) { + components.push_back(*it); + } std::string filename = components.back(); components.pop_back(); @@ -528,16 +532,16 @@ namespace loot { return; } - boost::regex regex; + regex reg; try { - regex = boost::regex(filename, boost::regex::perl|boost::regex::icase); - } catch (boost::regex_error& /*e*/) { + reg = regex(filename, regex::ECMAScript | regex::icase); + } catch (exception& /*e*/) { BOOST_LOG_TRIVIAL(error) << "Invalid regex string:" << filename; throw loot::error(loot::error::invalid_args, boost::locale::translate("Invalid regex string:").str() + " " + filename); } for (boost::filesystem::directory_iterator itr(parent_path); itr != boost::filesystem::directory_iterator(); ++itr) { - if (boost::regex_match(itr->path().filename().string(), regex)) { + if (regex_match(itr->path().filename().string(), reg)) { result = true; BOOST_LOG_TRIVIAL(trace) << "Matching file found: " << itr->path(); return;