summaryrefslogtreecommitdiff
path: root/src/utilities/utilities.hpp
diff options
context:
space:
mode:
authorCedric Nugteren <web@cedricnugteren.nl>2017-11-25 17:44:21 +0100
committerCedric Nugteren <web@cedricnugteren.nl>2017-11-25 17:44:21 +0100
commitf01bcded1e34e3b031e78cee357d1c1e0f1aa5be (patch)
tree0c1db9e2961cba592cab88f63b8b30176199a753 /src/utilities/utilities.hpp
parentc0c6d00b1238b3d0aec7d3669fb7287f5939c8b7 (diff)
Moved string splitting functions; added string character removal function
Diffstat (limited to 'src/utilities/utilities.hpp')
-rw-r--r--src/utilities/utilities.hpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/utilities/utilities.hpp b/src/utilities/utilities.hpp
index a4f4fab0..08b165b9 100644
--- a/src/utilities/utilities.hpp
+++ b/src/utilities/utilities.hpp
@@ -20,6 +20,7 @@
#include <functional>
#include <complex>
#include <random>
+#include <algorithm>
#ifdef OPENCL_API
#include "clpp11.hpp"
@@ -258,6 +259,30 @@ std::string ToString(T value);
// =================================================================================================
+// String splitting by a delimiter
+template<typename Out>
+void split(const std::string &s, char delimiter, Out result) {
+ std::stringstream ss(s);
+ std::string item;
+ while (std::getline(ss, item, delimiter)) {
+ *(result++) = item;
+ }
+}
+
+// See above
+inline std::vector<std::string> split(const std::string &s, char delimiter) {
+ std::vector<std::string> elements;
+ split(s, delimiter, std::back_inserter(elements));
+ return elements;
+}
+
+// String character removal
+inline void remove_character(std::string &str, char to_be_removed) {
+ str.erase(std::remove(str.begin(), str.end(), to_be_removed), str.end());
+}
+
+// =================================================================================================
+
// Parses command-line and environmental-variable arguments into a std::vector of strings
std::vector<std::string> RetrieveCommandLineArguments(int argc, char *argv[]);