Skip to content

Commit

Permalink
Replace boost::regex with C++11 <regex>
Browse files Browse the repository at this point in the history
  • Loading branch information
K-ballo committed Sep 8, 2017
1 parent 60a0111 commit ea5a8df
Show file tree
Hide file tree
Showing 26 changed files with 124 additions and 93 deletions.
7 changes: 7 additions & 0 deletions cmake/HPX_AddConfigTest.cmake
Expand Up @@ -467,6 +467,13 @@ macro(hpx_check_for_cxx11_std_reference_wrapper)
FILE ${ARGN})
endmacro()

###############################################################################
macro(hpx_check_for_cxx11_std_regex)
add_hpx_config_test(HPX_WITH_CXX11_REGEX
SOURCE cmake/tests/cxx11_std_regex.cpp
FILE ${ARGN})
endmacro()

###############################################################################
macro(hpx_check_for_cxx11_std_shared_ptr)
add_hpx_config_test(HPX_WITH_CXX11_SHARED_PTR
Expand Down
3 changes: 3 additions & 0 deletions cmake/HPX_PerformCxxFeatureTests.cmake
Expand Up @@ -116,6 +116,9 @@ macro(hpx_perform_cxx_feature_tests)
hpx_check_for_cxx11_std_reference_wrapper(
REQUIRED "HPX needs support for C++11 std::ref and std::reference_wrapper")

hpx_check_for_cxx11_std_regex(
REQUIRED "HPX needs support for C++11 std::regex")

hpx_check_for_cxx11_std_shared_ptr(
REQUIRED "HPX needs support for C++11 std::shared_ptr")

Expand Down
1 change: 0 additions & 1 deletion cmake/HPX_SetupBoost.cmake
Expand Up @@ -66,7 +66,6 @@ set(__boost_libraries
atomic
filesystem
program_options
regex
system)

find_package(Boost 1.55 REQUIRED COMPONENTS ${__boost_libraries})
Expand Down
20 changes: 20 additions & 0 deletions cmake/tests/cxx11_std_regex.cpp
@@ -0,0 +1,20 @@
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2017 Agustin Berge
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
////////////////////////////////////////////////////////////////////////////////

#include <regex>

int main()
{
std::string text = "Lorem ipsum dolor sit amet";

std::regex re("[a-z]+");
std::smatch match;
if (std::regex_match(text, match, re))
{
std::ssub_match smatch = match[0];
}
}
6 changes: 3 additions & 3 deletions examples/quickstart/pipeline1.cpp
Expand Up @@ -8,12 +8,12 @@

#include <iostream>
#include <iterator>
#include <regex>
#include <string>
#include <utility>
#include <vector>

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

struct pipeline
{
Expand All @@ -22,8 +22,8 @@ struct pipeline
// job for first stage
auto grep = [](std::string const& re, std::string const& item)
{
boost::regex regex(re);
if (boost::regex_match(item, regex))
std::regex regex(re);
if (std::regex_match(item, regex))
{
auto trim = [](std::string const& s)
{
Expand Down
6 changes: 3 additions & 3 deletions plugins/parcel/coalescing/coalescing_counter_registry.cpp
Expand Up @@ -11,10 +11,10 @@
#include <hpx/plugins/parcel/coalescing_counter_registry.hpp>

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

#include <cstdint>
#include <mutex>
#include <regex>
#include <string>
#include <utility>
#include <vector>
Expand Down Expand Up @@ -262,15 +262,15 @@ namespace hpx { namespace plugins { namespace parcel
if (ec) return false;

bool found_one = false;
boost::regex rx(str_rx, boost::regex::perl);
std::regex rx(str_rx, std::regex_constants::extended);

std::unique_lock<mutex_type> l(mtx_);

{
map_type::const_iterator end = map_.end();
for (map_type::const_iterator it = map_.begin(); it != end; ++it)
{
if (!boost::regex_match((*it).first, rx))
if (!std::regex_match((*it).first, rx))
continue;
found_one = true;

Expand Down
6 changes: 3 additions & 3 deletions src/performance_counters/registry.cpp
Expand Up @@ -21,7 +21,6 @@
#include <hpx/util/rolling_min.hpp>

#include <boost/format.hpp>
#include <boost/regex.hpp>
#include <boost/accumulators/statistics_fwd.hpp>
#if BOOST_VERSION >= 105600
#include <boost/accumulators/statistics/rolling_variance.hpp>
Expand All @@ -30,6 +29,7 @@
#include <cstddef>
#include <cstdint>
#include <functional>
#include <regex>
#include <string>
#include <utility>
#include <vector>
Expand Down Expand Up @@ -255,13 +255,13 @@ namespace hpx { namespace performance_counters
if (ec) return status_invalid_data;

bool found_one = false;
boost::regex rx(str_rx, boost::regex::perl);
std::regex rx(str_rx, std::regex_constants::extended);

counter_type_map_type::const_iterator end = countertypes_.end();
for (counter_type_map_type::const_iterator it = countertypes_.begin();
it != end; ++it)
{
if (!boost::regex_match((*it).first, rx))
if (!std::regex_match((*it).first, rx))
continue;
found_one = true;

Expand Down
6 changes: 3 additions & 3 deletions src/runtime/actions/detail/invocation_count_registry.cpp
Expand Up @@ -8,10 +8,10 @@
#include <hpx/runtime/actions/detail/invocation_count_registry.hpp>
#include <hpx/performance_counters/registry.hpp>

#include <regex>
#include <string>

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

namespace hpx { namespace actions { namespace detail
{
Expand Down Expand Up @@ -105,12 +105,12 @@ namespace hpx { namespace actions { namespace detail
if (ec) return false;

bool found_one = false;
boost::regex rx(str_rx, boost::regex::perl);
std::regex rx(str_rx, std::regex_constants::extended);

map_type::const_iterator end = map_.end();
for (map_type::const_iterator it = map_.begin(); it != end; ++it)
{
if (!boost::regex_match((*it).first, rx))
if (!std::regex_match((*it).first, rx))
continue;
found_one = true;

Expand Down
Expand Up @@ -12,12 +12,12 @@
#include <hpx/performance_counters/registry.hpp>

#include <cstdint>
#include <regex>
#include <string>
#include <unordered_set>
#include <utility>

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

namespace hpx { namespace parcelset { namespace detail
{
Expand Down Expand Up @@ -99,12 +99,12 @@ namespace hpx { namespace parcelset { namespace detail
if (ec) return false;

bool found_one = false;
boost::regex rx(str_rx, boost::regex::perl);
std::regex rx(str_rx, std::regex_constants::extended);

map_type::const_iterator end = map_.end();
for (map_type::const_iterator it = map_.begin(); it != end; ++it)
{
if (!boost::regex_match(*it, rx))
if (!std::regex_match(*it, rx))
continue;
found_one = true;

Expand Down
30 changes: 16 additions & 14 deletions src/util/ini.cpp
Expand Up @@ -19,6 +19,7 @@
#include <iostream>
#include <list>
#include <mutex>
#include <regex>
#include <string>
#include <vector>
#include <utility>
Expand All @@ -34,7 +35,6 @@
#include <boost/algorithm/string/classification.hpp>
#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/replace.hpp>
#include <boost/regex.hpp>

#ifdef __APPLE__
#include <crt_externs.h>
Expand Down Expand Up @@ -204,13 +204,15 @@ void section::parse (std::string const& sourcename,
int linenum = 0;
section* current = this;

boost::regex regex_comment (pattern_comment, boost::regex::perl
| boost::regex::icase);
boost::regex regex_section (pattern_section, boost::regex::perl
| boost::regex::icase);
boost::regex regex_qualified_entry
(pattern_qualified_entry, boost::regex::perl | boost::regex::icase);
boost::regex regex_entry (pattern_entry, boost::regex::perl | boost::regex::icase);
std::regex regex_comment (pattern_comment, std::regex_constants::extended
| std::regex_constants::icase);
std::regex regex_section (pattern_section, std::regex_constants::extended
| std::regex_constants::icase);
std::regex regex_qualified_entry
(pattern_qualified_entry, std::regex_constants::extended
| std::regex_constants::icase);
std::regex regex_entry (pattern_entry, std::regex_constants::extended
| std::regex_constants::icase);

std::vector<std::string>::const_iterator end = lines.end();
for (std::vector<std::string>::const_iterator it = lines.begin();
Expand All @@ -228,8 +230,8 @@ void section::parse (std::string const& sourcename,
// weed out comments
if (weed_out_comments)
{
boost::smatch what_comment;
if (boost::regex_match (line, what_comment, regex_comment))
std::smatch what_comment;
if (std::regex_match (line, what_comment, regex_comment))
{
HPX_ASSERT(3 == what_comment.size());

Expand All @@ -241,8 +243,8 @@ void section::parse (std::string const& sourcename,

// no comments anymore: line is either section, key=val,
// or garbage/empty
boost::smatch what;
if (boost::regex_match(line, what, regex_qualified_entry))
std::smatch what;
if (std::regex_match(line, what, regex_qualified_entry))
{
// found a entry line
if (4 != what.size()) //-V112
Expand Down Expand Up @@ -283,7 +285,7 @@ void section::parse (std::string const& sourcename,
current = s;
}

else if (boost::regex_match(line, what, regex_section))
else if (std::regex_match(line, what, regex_section))
{
// found a section line
if (2 != what.size())
Expand All @@ -309,7 +311,7 @@ void section::parse (std::string const& sourcename,
}

// did not match section, so might be key/val entry
else if ( boost::regex_match (line, what, regex_entry) )
else if ( std::regex_match (line, what, regex_entry) )
{
// found a entry line
if (3 != what.size())
Expand Down
9 changes: 5 additions & 4 deletions src/util/sed_transform.cpp
Expand Up @@ -7,9 +7,9 @@

#include <hpx/exception.hpp>
#include <hpx/util/sed_transform.hpp>
#include <boost/regex.hpp>

#include <memory>
#include <regex>
#include <string>

namespace hpx { namespace util
Expand Down Expand Up @@ -84,7 +84,7 @@ struct sed_transform::command
, replace_(replace)
{}

boost::regex search_;
std::regex search_;
std::string replace_;
};

Expand Down Expand Up @@ -112,10 +112,11 @@ std::string sed_transform::operator()(
if (!command_)
return input;

return boost::regex_replace(input
return std::regex_replace(input
, command_->search_
, command_->replace_
, boost::match_default | boost::format_sed);
, std::regex_constants::match_default
| std::regex_constants::format_sed);
}

}}
Expand Down
6 changes: 3 additions & 3 deletions tools/inspect/apple_macro_check.cpp
Expand Up @@ -10,15 +10,15 @@
#include "apple_macro_check.hpp"
#include "function_hyper.hpp"
#include <functional>
#include <regex>
#include <string>
#include "boost/regex.hpp"
#include "boost/filesystem/operations.hpp"

namespace fs = boost::filesystem;

namespace
{
boost::regex apple_macro_regex(
std::regex apple_macro_regex(
"("
"^\\s*#\\s*undef\\s*" // # undef
"\\b(check|verify|require|check_error)\\b"
Expand All @@ -37,7 +37,7 @@ namespace
"\\b(check|verify|require|check_error)\\b" // apple macro name, whole word
"\\s*\\(" // followed by 0 or more spaces and an opening paren
")"
, boost::regex::normal);
, std::regex_constants::normal);

} // unnamed namespace

Expand Down
6 changes: 3 additions & 3 deletions tools/inspect/assert_macro_check.cpp
Expand Up @@ -9,16 +9,16 @@

#include "assert_macro_check.hpp"
#include <functional>
#include <regex>
#include "function_hyper.hpp"
#include "boost/regex.hpp"
#include "boost/lexical_cast.hpp"
#include "boost/filesystem/operations.hpp"

namespace fs = boost::filesystem;

namespace
{
boost::regex assert_macro_regex(
std::regex assert_macro_regex(
"("
"^\\s*#\\s*undef\\s*" // # undef
"\\b(assert)\\b" // followed by assert macro, whole word
Expand All @@ -36,7 +36,7 @@ namespace
"\\b(assert)\\b" // assert macro, whole word
"\\s*\\(" // followed by 0 or more spaces and an opening paren
")"
, boost::regex::normal);
, std::regex_constants::normal);

} // unnamed namespace

Expand Down
2 changes: 1 addition & 1 deletion tools/inspect/deprecated_include_check.cpp
Expand Up @@ -9,9 +9,9 @@
// http://www.boost.org/LICENSE_1_0.txt)

#include <algorithm>
#include <regex>

#include "deprecated_include_check.hpp"
#include "boost/regex.hpp"
#include "boost/lexical_cast.hpp"
#include "function_hyper.hpp"

Expand Down
7 changes: 3 additions & 4 deletions tools/inspect/deprecated_include_check.hpp
Expand Up @@ -14,8 +14,7 @@

#include "inspector.hpp"

#include "boost/regex.hpp"

#include <regex>
#include <vector>

namespace boost
Expand All @@ -33,11 +32,11 @@ namespace boost
{
deprecated_includes_regex_data(deprecated_includes const* d,
std::string const& rx)
: data(d), pattern(rx, boost::regex::normal)
: data(d), pattern(rx, std::regex_constants::normal)
{}

deprecated_includes const* data;
boost::regex pattern;
std::regex pattern;
};

class deprecated_include_check : public inspector
Expand Down

0 comments on commit ea5a8df

Please sign in to comment.