diff options
author | Florent Le Coz <louiz@louiz.org> | 2013-11-12 23:43:43 +0100 |
---|---|---|
committer | Florent Le Coz <louiz@louiz.org> | 2013-11-12 23:48:10 +0100 |
commit | 5817a95b5ee89480788832be35679dfcd2ed833b (patch) | |
tree | b4db0db18a195b11f820247b78bfc4df5dba8c14 /src/utils | |
parent | b60cbda4f93bb83e36b29f5cba975b94b833663d (diff) | |
download | biboumi-5817a95b5ee89480788832be35679dfcd2ed833b.tar.gz biboumi-5817a95b5ee89480788832be35679dfcd2ed833b.tar.bz2 biboumi-5817a95b5ee89480788832be35679dfcd2ed833b.tar.xz biboumi-5817a95b5ee89480788832be35679dfcd2ed833b.zip |
Basic handling of modes, both ways
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/split.cpp | 18 | ||||
-rw-r--r-- | src/utils/split.hpp | 10 |
2 files changed, 19 insertions, 9 deletions
diff --git a/src/utils/split.cpp b/src/utils/split.cpp new file mode 100644 index 0000000..82852ee --- /dev/null +++ b/src/utils/split.cpp @@ -0,0 +1,18 @@ +#include <utils/split.hpp> + +namespace utils +{ + std::vector<std::string> split(const std::string &s, const char delim, const bool allow_empty) + { + std::vector<std::string> ret; + std::stringstream ss(s); + std::string item; + while (std::getline(ss, item, delim)) + { + if (item.empty() && !allow_empty) + continue ; + ret.emplace_back(std::move(item)); + } + return ret; + } +} diff --git a/src/utils/split.hpp b/src/utils/split.hpp index 0067131..9fee90a 100644 --- a/src/utils/split.hpp +++ b/src/utils/split.hpp @@ -7,15 +7,7 @@ namespace utils { - std::vector<std::string> split(const std::string &s, const char delim) - { - std::vector<std::string> ret; - std::stringstream ss(s); - std::string item; - while (std::getline(ss, item, delim)) - ret.emplace_back(std::move(item)); - return ret; - } + std::vector<std::string> split(const std::string &s, const char delim, const bool allow_empty=true); } #endif // SPLIT_INCLUDED |