summaryrefslogtreecommitdiffstats
path: root/host/include
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2010-08-13 12:20:11 -0700
committerJosh Blum <josh@joshknows.com>2010-08-13 12:20:11 -0700
commit6d2899d18661e4cec5ae90692e08404ea48bc112 (patch)
tree5029781c6408cb2d0bdd25ca92a5becd44183138 /host/include
parent8bdc6cda2b5cc33b3eaf7f51d21d51887b77f45b (diff)
parent805d4a0cff00fb4e0071bb300436bb7eefb8fb16 (diff)
downloaduhd-6d2899d18661e4cec5ae90692e08404ea48bc112.tar.gz
uhd-6d2899d18661e4cec5ae90692e08404ea48bc112.tar.bz2
uhd-6d2899d18661e4cec5ae90692e08404ea48bc112.zip
Merge branch 'split_string' into next
Diffstat (limited to 'host/include')
-rw-r--r--host/include/uhd/utils/algorithm.hpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/host/include/uhd/utils/algorithm.hpp b/host/include/uhd/utils/algorithm.hpp
index 1b5eacfa9..53c571e4e 100644
--- a/host/include/uhd/utils/algorithm.hpp
+++ b/host/include/uhd/utils/algorithm.hpp
@@ -22,6 +22,9 @@
#include <boost/range/begin.hpp>
#include <boost/range/end.hpp>
#include <boost/range/size.hpp>
+#include <boost/algorithm/string.hpp>
+#include <vector>
+#include <string>
/*! \file algorithm.hpp
* Useful templated functions and classes that I like to pretend are part of stl.
@@ -30,6 +33,24 @@
namespace std{
/*!
+ * Split a string at the separation characters.
+ * \param string the string to split
+ * \param sep the separator characters
+ * \return a range of strings
+ */
+ inline std::vector<std::string> split_string(
+ const std::string &string, const std::string &sep = "\t "
+ ){
+ std::vector<std::string> strings;
+ if (not string.empty()) boost::split(
+ // do not split an empty string:
+ // let me tell you about the time when boost::split segfaulted...
+ strings, string, boost::is_any_of(sep)
+ );
+ return strings;
+ }
+
+ /*!
* A wrapper around std::copy that takes ranges instead of iterators.
*
* Copy the elements of the source range into the destination range.