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/include/uhd/utils/algorithm.hpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'host/include') 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 #include #include +#include +#include +#include /*! \file algorithm.hpp * Useful templated functions and classes that I like to pretend are part of stl. @@ -29,6 +32,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 split_string( + const std::string &string, const std::string &sep = "\t " + ){ + std::vector 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. * -- cgit v1.2.3