} // eo split_string(const std::string&,std::list< std::string >&,const std::string&,bool,const std::string&)
+/** call split_string with list<string>, converts result to vector; vector is clear()-ed first
+ *
+ * Note: Uses 3 O(n)-operations: list.size, vector.resize and std::swap_ranges;
+ * not sure whether there is a better way to do this
+ * */
+void split_string(
+ const std::string& str,
+ std::vector<std::string>& result,
+ const std::string& delimiter,
+ bool omit_empty,
+ const std::string& trim_list
+)
+{
+ std::list<std::string> tmp;
+ split_string(str, tmp, delimiter, omit_empty, trim_list);
+ std::size_t size = tmp.size(); // this is O(n)
+ result.clear();
+ result.resize(size); // also O(n)
+ std::swap_ranges(tmp.begin(), tmp.end(), result.begin()); // also O(n)
+}
+
/**
* splits a string by a given delimiter
* @param str the string which should be splitted.
const std::string& trim_list= std::string()
);
+void split_string(
+ const std::string& str,
+ std::vector< std::string >& result,
+ const std::string& delimiter= "\n",
+ bool omit_empty= false,
+ const std::string& trim_list= std::string()
+);
+
std::list< std::string > split_string(
const std::string& str,
const std::string& delimiter = "\n",
} // eo SplitStringDelimiterOnly
+BOOST_AUTO_TEST_CASE(SplitToVector)
+{
+ std::string line("0;1;2;3;4;5;6;7;8;9");
+ std::vector<std::string> result;
+ split_string(line, result, ";");
+ BOOST_REQUIRE_EQUAL(result.size(), 10);
+ BOOST_CHECK_EQUAL(result[0], "0");
+ BOOST_CHECK_EQUAL(result[4], "4");
+ BOOST_CHECK_EQUAL(result[9], "9");
+}
+
BOOST_AUTO_TEST_CASE(JoinString1)
{