summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2011-11-03 19:28:43 -0700
committerJosh Blum <josh@joshknows.com>2011-12-16 10:53:26 -0800
commitc490cdda00ebd7733c1633939b258225f3834e8e (patch)
treefb751c35c1578485f1891503be53fb56c4782f21
parent4d2c1e06a96604e54b99c1871dbfecba1286bd8b (diff)
downloaduhd-c490cdda00ebd7733c1633939b258225f3834e8e.tar.gz
uhd-c490cdda00ebd7733c1633939b258225f3834e8e.tar.bz2
uhd-c490cdda00ebd7733c1633939b258225f3834e8e.zip
uhd: allow device addr (from string) to parse empty values
-rw-r--r--host/lib/types/device_addr.cpp15
-rw-r--r--host/tests/addr_test.cpp3
2 files changed, 9 insertions, 9 deletions
diff --git a/host/lib/types/device_addr.cpp b/host/lib/types/device_addr.cpp
index e329bd390..1554c3e4e 100644
--- a/host/lib/types/device_addr.cpp
+++ b/host/lib/types/device_addr.cpp
@@ -40,16 +40,15 @@ static std::string trim(const std::string &in){
device_addr_t::device_addr_t(const std::string &args){
BOOST_FOREACH(const std::string &pair, tokenizer(args, arg_delim)){
if (trim(pair) == "") continue;
- std::string key;
+ std::vector<std::string> toks;
BOOST_FOREACH(const std::string &tok, tokenizer(pair, pair_delim)){
- if (key.empty()) key = tok;
- else{
- this->set(trim(key), trim(tok));
- goto continue_next_arg;
- }
+ toks.push_back(tok);
+ }
+ if (toks.size() == 1) toks.push_back(""); //pad empty value
+ if (toks.size() == 2 and not trim(toks[0]).empty()){ //only valid combination
+ this->set(trim(toks[0]), trim(toks[1]));
}
- throw uhd::value_error("invalid args string: "+args);
- continue_next_arg: continue;
+ else throw uhd::value_error("invalid args string: "+args); //otherwise error
}
}
diff --git a/host/tests/addr_test.cpp b/host/tests/addr_test.cpp
index 01a7ab607..cea2f224c 100644
--- a/host/tests/addr_test.cpp
+++ b/host/tests/addr_test.cpp
@@ -39,7 +39,8 @@ BOOST_AUTO_TEST_CASE(test_device_addr){
//load the device address with something
uhd::device_addr_t dev_addr;
dev_addr["key1"] = "val1";
- dev_addr["key2"] = "val2";
+ dev_addr["key1"] = "val1";
+ dev_addr["key3"] = "";
//convert to and from args string
std::cout << "Pretty Print: " << std::endl << dev_addr.to_pp_string();