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) { ...@@ -41,10 +41,13 @@ void cppa_unexpected_timeout(const char* fname, size_t line_num) {
CPPA_PRINTERRC(fname, line_num, "unexpected timeout"); CPPA_PRINTERRC(fname, line_num, "unexpected timeout");
} }
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) {
std::vector<std::string> result; using namespace std;
std::stringstream strs{str}; vector<string> result;
std::string tmp; stringstream strs{str};
while (std::getline(strs, tmp, delim)) result.push_back(tmp); string tmp;
while (getline(strs, tmp, delim)) {
if (!tmp.empty() || keep_empties) result.push_back(std::move(tmp));
}
return result; return result;
} }
...@@ -147,6 +147,6 @@ inline void cppa_check_value(V1 v1, ...@@ -147,6 +147,6 @@ inline void cppa_check_value(V1 v1,
#define CPPA_UNEXPECTED_MSG_CB() [] { CPPA_UNEXPECTED_MSG(); } #define CPPA_UNEXPECTED_MSG_CB() [] { CPPA_UNEXPECTED_MSG(); }
#define CPPA_UNEXPECTED_TOUT_CB() [] { CPPA_UNEXPECTED_TOUT(); } #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 #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