Merge branch 'remove-html-comments'
[libi2ncommon] / src / stringfunc.cpp
index 043dda7..266b34f 100644 (file)
@@ -381,6 +381,27 @@ void split_string(
 } // 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.