diff options
Diffstat (limited to 'src/utilities/utilities.hpp')
-rw-r--r-- | src/utilities/utilities.hpp | 25 |
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[]); |