From 805d4a0cff00fb4e0071bb300436bb7eefb8fb16 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 12 Aug 2010 10:08:17 -0700 Subject: uhd: made split string utility function --- host/lib/types.cpp | 19 ++++++------------- host/lib/usrp/subdev_spec.cpp | 9 +++------ host/lib/usrp/usrp2/usrp2_impl.cpp | 12 +++--------- host/lib/utils/paths.cpp | 10 ++-------- host/lib/utils/warning.cpp | 8 ++------ 5 files changed, 16 insertions(+), 42 deletions(-) (limited to 'host/lib') diff --git a/host/lib/types.cpp b/host/lib/types.cpp index 5c0fb1f42..f957cd83f 100644 --- a/host/lib/types.cpp +++ b/host/lib/types.cpp @@ -27,7 +27,6 @@ #include #include #include -#include #include #include #include @@ -181,15 +180,10 @@ static std::string trim(const std::string &in){ } device_addr_t::device_addr_t(const std::string &args){ - //split the args at the semi-colons - std::vector pairs; - boost::split(pairs, args, boost::is_any_of(arg_delim)); - BOOST_FOREACH(const std::string &pair, pairs){ + BOOST_FOREACH(const std::string &pair, std::split_string(args, arg_delim)){ if (trim(pair) == "") continue; - //split the key value pairs at the equals - std::vector key_val; - boost::split(key_val, pair, boost::is_any_of(pair_delim)); + std::vector key_val = std::split_string(pair, pair_delim); if (key_val.size() != 2) throw std::runtime_error("invalid args string: "+args); (*this)[trim(key_val.front())] = trim(key_val.back()); } @@ -238,13 +232,12 @@ mac_addr_t mac_addr_t::from_string(const std::string &mac_addr_str){ throw std::runtime_error("expected exactly 5 or 17 characters"); //split the mac addr hex string at the colons - std::vector hex_strs; - boost::split(hex_strs, mac_addr_str, boost::is_any_of(":")); - for (size_t i = 0; i < hex_strs.size(); i++){ + size_t i = 0; + BOOST_FOREACH(const std::string &hex_str, std::split_string(mac_addr_str, ":")){ int hex_num; - std::istringstream iss(hex_strs[i]); + std::istringstream iss(hex_str); iss >> std::hex >> hex_num; - bytes[i] = boost::uint8_t(hex_num); + bytes[i++] = boost::uint8_t(hex_num); } } diff --git a/host/lib/usrp/subdev_spec.cpp b/host/lib/usrp/subdev_spec.cpp index 0f00e2f74..765eecb3d 100644 --- a/host/lib/usrp/subdev_spec.cpp +++ b/host/lib/usrp/subdev_spec.cpp @@ -16,7 +16,7 @@ // #include -#include +#include #include #include #include @@ -35,12 +35,9 @@ subdev_spec_pair_t::subdev_spec_pair_t( } subdev_spec_t::subdev_spec_t(const std::string &markup){ - std::vector pairs; - boost::split(pairs, markup, boost::is_any_of("\t ")); - BOOST_FOREACH(const std::string &pair, pairs){ + BOOST_FOREACH(const std::string &pair, std::split_string(markup)){ if (pair == "") continue; - std::vector db_sd; - boost::split(db_sd, pair, boost::is_any_of(":")); + std::vector db_sd = std::split_string(pair, ":"); switch(db_sd.size()){ case 1: this->push_back(subdev_spec_pair_t("", db_sd.front())); break; case 2: this->push_back(subdev_spec_pair_t(db_sd.front(), db_sd.back())); break; diff --git a/host/lib/usrp/usrp2/usrp2_impl.cpp b/host/lib/usrp/usrp2/usrp2_impl.cpp index 21f411afe..45362c20f 100644 --- a/host/lib/usrp/usrp2/usrp2_impl.cpp +++ b/host/lib/usrp/usrp2/usrp2_impl.cpp @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include #include #include @@ -41,12 +41,6 @@ static const size_t DISCOVERY_TIMEOUT_MS = 100; /*********************************************************************** * Helper Functions **********************************************************************/ -std::vector split_addrs(const std::string &addrs_str){ - std::vector addrs; - boost::split(addrs, addrs_str, boost::is_any_of("\t ")); - return addrs; -} - template std::string num2str(T num){ return boost::lexical_cast(num); } @@ -80,7 +74,7 @@ static uhd::device_addrs_t usrp2_find(const device_addr_t &hint){ } //if there are multiple addresses, just return good, dont test - std::vector addrs = split_addrs(hint["addr"]); + std::vector addrs = std::split_string(hint["addr"]); if (addrs.size() > 1){ device_addr_t new_addr; new_addr["type"] = "usrp2"; @@ -155,7 +149,7 @@ static device::sptr usrp2_make(const device_addr_t &device_addr){ std::vector ctrl_transports; std::vector data_transports; - BOOST_FOREACH(const std::string &addr, split_addrs(device_addr["addr"])){ + BOOST_FOREACH(const std::string &addr, std::split_string(device_addr["addr"])){ ctrl_transports.push_back(udp_simple::make_connected( addr, num2str(USRP2_UDP_CTRL_PORT) )); diff --git a/host/lib/utils/paths.cpp b/host/lib/utils/paths.cpp index 4029bd989..9ac20d855 100644 --- a/host/lib/utils/paths.cpp +++ b/host/lib/utils/paths.cpp @@ -17,7 +17,7 @@ #include "constants.hpp" #include -#include +#include #include #include #include @@ -58,15 +58,9 @@ static std::vector get_env_paths(const std::string &var_name){ po::store(po::parse_environment(desc, boost::bind(&name_mapper, var_name, _1)), vm); po::notify(vm); - //split the path at the path separators - std::vector path_strings; - if (not var_value.empty()) boost::split(//dont split empty strings - path_strings, var_value, boost::is_any_of(env_path_sep) - ); - //convert to filesystem path, filter blank paths std::vector paths; - BOOST_FOREACH(std::string &path_string, path_strings){ + BOOST_FOREACH(const std::string &path_string, std::split_string(var_value, env_path_sep)){ if (path_string.empty()) continue; paths.push_back(fs::system_complete(path_string)); } diff --git a/host/lib/utils/warning.cpp b/host/lib/utils/warning.cpp index ae4d4c7aa..8a7d35a23 100644 --- a/host/lib/utils/warning.cpp +++ b/host/lib/utils/warning.cpp @@ -16,7 +16,7 @@ // #include -#include +#include #include #include #include @@ -24,13 +24,9 @@ using namespace uhd; void uhd::print_warning(const std::string &msg){ - //extract the message lines - std::vector lines; - boost::split(lines, msg, boost::is_any_of("\n")); - //print the warning message std::cerr << std::endl << "Warning:" << std::endl; - BOOST_FOREACH(const std::string &line, lines){ + BOOST_FOREACH(const std::string &line, std::split_string(msg, "\n")){ std::cerr << " " << line << std::endl; } } -- cgit v1.2.3