uhd: Replace boost::regex with std::regex

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.
This commit is contained in:
Martin Braun 2019-09-28 13:13:41 +02:00
parent fcc2e9c602
commit f773cf9fb9
10 changed files with 32 additions and 37 deletions

View File

@ -287,7 +287,6 @@ set(UHD_BOOST_REQUIRED_COMPONENTS
date_time
filesystem
program_options
regex
system
unit_test_framework
serialization

View File

@ -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,

View File

@ -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;
@ -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
@ -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 {
@ -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] == "")) {

View File

@ -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 {{

View File

@ -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()) {
@ -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;

View File

@ -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>
@ -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);

View File

@ -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;
@ -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;

View File

@ -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>
@ -137,8 +137,8 @@ private:
}
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
@ -162,11 +162,11 @@ private:
}
// 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;
}

View File

@ -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>
@ -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);

View File

@ -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 {