Skip to content

Commit

Permalink
uhd: Replace boost::regex with std::regex
Browse files Browse the repository at this point in the history
boost::regex was a requirement until the minimum version of gcc was
increased. Since it is at version 5.3 now, using Boost.Regex is no
longer necessary.
This change is a pure search-and-replace; Boost and std versions of
regex are compatible and use the same syntax.
  • Loading branch information
mbr0wn committed Nov 26, 2019
1 parent fcc2e9c commit f773cf9
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 37 deletions.
1 change: 0 additions & 1 deletion host/CMakeLists.txt
Expand Up @@ -287,7 +287,6 @@ set(UHD_BOOST_REQUIRED_COMPONENTS
date_time
filesystem
program_options
regex
system
unit_test_framework
serialization
Expand Down
1 change: 0 additions & 1 deletion host/cmake/debian/control
Expand Up @@ -10,7 +10,6 @@ Build-Depends: cmake,
libboost-dev,
libboost-filesystem-dev,
libboost-program-options-dev,
libboost-regex-dev,
libboost-serialization-dev,
libboost-system-dev,
libboost-test-dev,
Expand Down
18 changes: 9 additions & 9 deletions host/lib/rfnoc/block_id.cpp
Expand Up @@ -11,7 +11,7 @@
#include <uhd/rfnoc/constants.hpp>
#include <boost/format.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/regex.hpp>
#include <regex>
#include <iostream>

using namespace uhd::rfnoc;
Expand All @@ -38,12 +38,12 @@ block_id_t::block_id_t(

bool block_id_t::is_valid_blockname(const std::string& block_name)
{
return boost::regex_match(block_name, boost::regex(VALID_BLOCKNAME_REGEX));
return std::regex_match(block_name, std::regex(VALID_BLOCKNAME_REGEX));
}

bool block_id_t::is_valid_block_id(const std::string& block_name)
{
return boost::regex_match(block_name, boost::regex(VALID_BLOCKID_REGEX));
return std::regex_match(block_name, std::regex(VALID_BLOCKID_REGEX));
}

std::string block_id_t::to_string() const
Expand All @@ -63,9 +63,9 @@ uhd::fs_path block_id_t::get_tree_root() const

bool block_id_t::match(const std::string& block_str)
{
boost::cmatch matches;
if (not boost::regex_match(
block_str.c_str(), matches, boost::regex(VALID_BLOCKID_REGEX))) {
std::cmatch matches;
if (not std::regex_match(
block_str.c_str(), matches, std::regex(VALID_BLOCKID_REGEX))) {
return false;
}
try {
Expand All @@ -82,9 +82,9 @@ bool block_id_t::match(const std::string& block_str)

bool block_id_t::set(const std::string& new_name)
{
boost::cmatch matches;
if (not boost::regex_match(
new_name.c_str(), matches, boost::regex(VALID_BLOCKID_REGEX))) {
std::cmatch matches;
if (not std::regex_match(
new_name.c_str(), matches, std::regex(VALID_BLOCKID_REGEX))) {
return false;
}
if (not(matches[1] == "")) {
Expand Down
2 changes: 1 addition & 1 deletion host/lib/transport/nirio/lvbitx/template_lvbitx.cpp
Expand Up @@ -7,7 +7,7 @@
#include <streambuf>
#include <boost/filesystem/path.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/regex.hpp>
#include <regex>
#include <uhd/utils/paths.hpp>

namespace uhd {{ namespace niusrprio {{
Expand Down
10 changes: 5 additions & 5 deletions host/lib/transport/nirio/nifpga_lvbitx.cpp
Expand Up @@ -11,15 +11,15 @@
#include <fstream>
#include <streambuf>
#include <boost/algorithm/string.hpp>
#include <boost/regex.hpp>
#include <regex>

namespace uhd { namespace niusrprio {

std::string nifpga_lvbitx::_get_bitstream_checksum(const std::string& file_path)
{
const boost::regex md5_regex(
const std::regex md5_regex(
"<BitstreamMD5>([a-fA-F0-9]{32})<\\/BitstreamMD5>",
boost::regex::icase);
std::regex::icase);

std::ifstream lvbitx_stream(file_path.c_str());
if (!lvbitx_stream.is_open()) {
Expand All @@ -32,9 +32,9 @@ std::string nifpga_lvbitx::_get_bitstream_checksum(const std::string& file_path)
try {
// short-circuiting the regex search with a simple find is faster
// for cases where the tag doesn't exist
boost::smatch md5_match;
std::smatch md5_match;
if (line.find("<BitstreamMD5>") != std::string::npos &&
boost::regex_search(line, md5_match, md5_regex))
std::regex_search(line, md5_match, md5_regex))
{
checksum = std::string(md5_match[1].first, md5_match[1].second);
break;
Expand Down
6 changes: 3 additions & 3 deletions host/lib/types/device_addr.cpp
Expand Up @@ -9,7 +9,7 @@
#include <boost/algorithm/string.hpp>
#include <boost/tokenizer.hpp>
#include <boost/format.hpp>
#include <boost/regex.hpp>
#include <regex>
#include <stdexcept>
#include <sstream>

Expand Down Expand Up @@ -93,8 +93,8 @@ device_addrs_t uhd::separate_device_addr(const device_addr_t &dev_addr){
device_addrs_t dev_addrs(1); //must be at least one (obviously)
std::vector<std::string> global_keys; //keys that apply to all (no numerical suffix)
for(const std::string &key: dev_addr.keys()){
boost::cmatch matches;
if (not boost::regex_match(key.c_str(), matches, boost::regex("^(\\D+)(\\d*)$"))){
std::cmatch matches;
if (not std::regex_match(key.c_str(), matches, std::regex("^(\\D+)(\\d*)$"))){
throw std::runtime_error("unknown key format: " + key);
}
std::string key_part(matches[1].first, matches[1].second);
Expand Down
8 changes: 4 additions & 4 deletions host/lib/usrp/fe_connection.cpp
Expand Up @@ -7,7 +7,7 @@

#include <uhd/usrp/fe_connection.hpp>
#include <uhd/exception.hpp>
#include <boost/regex.hpp>
#include <regex>
#include <uhd/utils/math.hpp>

using namespace uhd::usrp;
Expand All @@ -21,9 +21,9 @@ fe_connection_t::fe_connection_t(
}

fe_connection_t::fe_connection_t(const std::string& conn_str, double if_freq) {
static const boost::regex conn_regex("([IQ])(b?)(([IQ])(b?))?");
boost::cmatch matches;
if (boost::regex_match(conn_str.c_str(), matches, conn_regex)) {
static const std::regex conn_regex("([IQ])(b?)(([IQ])(b?))?");
std::cmatch matches;
if (std::regex_match(conn_str.c_str(), matches, conn_regex)) {
if (matches[3].length() == 0) {
//Connection in {I, Q, Ib, Qb}
_sampling_mode = REAL;
Expand Down
10 changes: 5 additions & 5 deletions host/lib/usrp/gps_ctrl.cpp
Expand Up @@ -14,7 +14,7 @@
#include <boost/thread/thread.hpp>
#include <boost/tokenizer.hpp>
#include <boost/format.hpp>
#include <boost/regex.hpp>
#include <regex>
#include <boost/thread/mutex.hpp>
#include <boost/date_time.hpp>
#include <boost/tuple/tuple.hpp>
Expand Down Expand Up @@ -137,8 +137,8 @@ class gps_ctrl_impl : public gps_ctrl{
}

const std::list<std::string> keys{"GPGGA", "GPRMC", "SERVO"};
static const boost::regex servo_regex("^\\d\\d-\\d\\d-\\d\\d.*$");
static const boost::regex gp_msg_regex("^\\$GP.*,\\*[0-9A-F]{2}$");
static const std::regex servo_regex("^\\d\\d-\\d\\d-\\d\\d.*$");
static const std::regex gp_msg_regex("^\\$GP.*,\\*[0-9A-F]{2}$");
std::map<std::string,std::string> msgs;

// Get all GPSDO messages available
Expand All @@ -162,11 +162,11 @@ class gps_ctrl_impl : public gps_ctrl{
}

// Look for SERVO message
if (boost::regex_search(msg, servo_regex, boost::regex_constants::match_continuous))
if (std::regex_search(msg, servo_regex, std::regex_constants::match_continuous))
{
msgs["SERVO"] = msg;
}
else if (boost::regex_match(msg, gp_msg_regex) and is_nmea_checksum_ok(msg))
else if (std::regex_match(msg, gp_msg_regex) and is_nmea_checksum_ok(msg))
{
msgs[msg.substr(1,5)] = msg;
}
Expand Down
10 changes: 5 additions & 5 deletions host/lib/utils/paths.cpp
Expand Up @@ -14,7 +14,7 @@
#include <boost/bind.hpp>
#include <boost/filesystem.hpp>
#include <boost/format.hpp>
#include <boost/regex.hpp>
#include <regex>
#include <boost/tokenizer.hpp>

#include <cstdio>
Expand Down Expand Up @@ -200,16 +200,16 @@ std::vector<fs::path> uhd::get_module_paths(void){
* \return The images path, formatted for windows.
*/
std::string _get_images_path_from_registry(const std::string& registry_key_path) {
boost::smatch reg_key_match;
std::smatch reg_key_match;
//If a substring in the search path is enclosed in [] (square brackets) then it is interpreted as a registry path
if (not boost::regex_search(registry_key_path, reg_key_match, boost::regex("\\[(.+)\\](.*)", boost::regex::icase)))
if (not std::regex_search(registry_key_path, reg_key_match, std::regex("\\[(.+)\\](.*)", std::regex::icase)))
return std::string();
std::string reg_key_path = std::string(reg_key_match[1].first, reg_key_match[1].second);
std::string path_suffix = std::string(reg_key_match[2].first, reg_key_match[2].second);

//Split the registry path into parent, key-path and value.
boost::smatch reg_parent_match;
if (not boost::regex_search(reg_key_path, reg_parent_match, boost::regex("^(.+?)\\\\(.+)\\\\(.+)$", boost::regex::icase)))
std::smatch reg_parent_match;
if (not std::regex_search(reg_key_path, reg_parent_match, std::regex("^(.+?)\\\\(.+)\\\\(.+)$", std::regex::icase)))
return std::string();
std::string reg_parent = std::string(reg_parent_match[1].first, reg_parent_match[1].second);
std::string reg_path = std::string(reg_parent_match[2].first, reg_parent_match[2].second);
Expand Down
3 changes: 0 additions & 3 deletions host/tests/dpdk_test.cpp
Expand Up @@ -17,14 +17,11 @@
#include <sys/time.h>
#include <unistd.h>
#include <boost/program_options.hpp>
#include <boost/regex.hpp>
#include <cstdbool>
#include <cstdio>
#include <cstring>
#include <iostream>

static const boost::regex colons(":");

namespace po = boost::program_options;

namespace {
Expand Down

0 comments on commit f773cf9

Please sign in to comment.