From f773cf9fb96e25d064f43cffdc893ac905d91f15 Mon Sep 17 00:00:00 2001
From: Martin Braun <martin.braun@ettus.com>
Date: Sat, 28 Sep 2019 13:13:41 +0200
Subject: 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.
---
 host/lib/rfnoc/block_id.cpp                         | 18 +++++++++---------
 host/lib/transport/nirio/lvbitx/template_lvbitx.cpp |  2 +-
 host/lib/transport/nirio/nifpga_lvbitx.cpp          | 10 +++++-----
 host/lib/types/device_addr.cpp                      |  6 +++---
 host/lib/usrp/fe_connection.cpp                     |  8 ++++----
 host/lib/usrp/gps_ctrl.cpp                          | 10 +++++-----
 host/lib/utils/paths.cpp                            | 10 +++++-----
 7 files changed, 32 insertions(+), 32 deletions(-)

(limited to 'host/lib')

diff --git a/host/lib/rfnoc/block_id.cpp b/host/lib/rfnoc/block_id.cpp
index 573b393e5..db7ddb032 100644
--- a/host/lib/rfnoc/block_id.cpp
+++ b/host/lib/rfnoc/block_id.cpp
@@ -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] == "")) {
diff --git a/host/lib/transport/nirio/lvbitx/template_lvbitx.cpp b/host/lib/transport/nirio/lvbitx/template_lvbitx.cpp
index 8f1fb6b36..4cae73f9c 100644
--- a/host/lib/transport/nirio/lvbitx/template_lvbitx.cpp
+++ b/host/lib/transport/nirio/lvbitx/template_lvbitx.cpp
@@ -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 {{
diff --git a/host/lib/transport/nirio/nifpga_lvbitx.cpp b/host/lib/transport/nirio/nifpga_lvbitx.cpp
index ef4a02aff..015344710 100644
--- a/host/lib/transport/nirio/nifpga_lvbitx.cpp
+++ b/host/lib/transport/nirio/nifpga_lvbitx.cpp
@@ -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;
diff --git a/host/lib/types/device_addr.cpp b/host/lib/types/device_addr.cpp
index 65d265857..3e2fac94d 100644
--- a/host/lib/types/device_addr.cpp
+++ b/host/lib/types/device_addr.cpp
@@ -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);
diff --git a/host/lib/usrp/fe_connection.cpp b/host/lib/usrp/fe_connection.cpp
index 0c2574ed3..8e3c0c88b 100644
--- a/host/lib/usrp/fe_connection.cpp
+++ b/host/lib/usrp/fe_connection.cpp
@@ -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;
diff --git a/host/lib/usrp/gps_ctrl.cpp b/host/lib/usrp/gps_ctrl.cpp
index 717654151..f9e03b16a 100644
--- a/host/lib/usrp/gps_ctrl.cpp
+++ b/host/lib/usrp/gps_ctrl.cpp
@@ -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;
         }
diff --git a/host/lib/utils/paths.cpp b/host/lib/utils/paths.cpp
index 8a7ba001f..7fd64e6f5 100644
--- a/host/lib/utils/paths.cpp
+++ b/host/lib/utils/paths.cpp
@@ -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);
-- 
cgit v1.2.3