Commit 554bf7bd authored by Dominik Charousset's avatar Dominik Charousset

added `keep_empties` option to `split`

parent 5a8a755b
......@@ -41,10 +41,13 @@ void cppa_unexpected_timeout(const char* fname, size_t line_num) {
CPPA_PRINTERRC(fname, line_num, "unexpected timeout");
}
std::vector<std::string> split(const std::string& str, char delim) {
std::vector<std::string> result;
std::stringstream strs{str};
std::string tmp;
while (std::getline(strs, tmp, delim)) result.push_back(tmp);
std::vector<std::string> split(const std::string& str, char delim, bool keep_empties) {
using namespace std;
vector<string> result;
stringstream strs{str};
string tmp;
while (getline(strs, tmp, delim)) {
if (!tmp.empty() || keep_empties) result.push_back(std::move(tmp));
}
return result;
}
......@@ -147,6 +147,6 @@ inline void cppa_check_value(V1 v1,
#define CPPA_UNEXPECTED_MSG_CB() [] { CPPA_UNEXPECTED_MSG(); }
#define CPPA_UNEXPECTED_TOUT_CB() [] { CPPA_UNEXPECTED_TOUT(); }
std::vector<std::string> split(const std::string& str, char delim);
std::vector<std::string> split(const std::string& str, char delim = ' ', bool keep_empties = true);
#endif // TEST_HPP
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment