aboutsummaryrefslogtreecommitdiffstats
path: root/src/util.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/util.cpp')
-rw-r--r--src/util.cpp32
1 files changed, 31 insertions, 1 deletions
diff --git a/src/util.cpp b/src/util.cpp
index 37977f2..b22a704 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -16,6 +16,7 @@
#include "util.hpp"
+#include <sstream>
#include <time.h>
#include <stdio.h>
#include <stdarg.h>
@@ -139,4 +140,33 @@ void _DUMP(enum LOG_LEVEL level, const char *log, ...)
fprintf(stderr, "%s \n", message);
va_end(args);
free(message);
-} \ No newline at end of file
+}
+
+std::vector<std::string> parseString(std::string str, char delimiter)
+{
+ // Parse string by delimiter
+ std::vector<std::string> vct;
+ std::stringstream ss{str};
+ std::string buf;
+ while (std::getline(ss, buf, delimiter))
+ {
+ if (!buf.empty())
+ {
+ // Delete space and push back to vector
+ vct.push_back(deleteSpace(buf));
+ }
+ }
+ return vct;
+}
+
+std::string deleteSpace(std::string str)
+{
+ std::string ret = str;
+ size_t pos;
+ while ((pos = ret.find_first_of(" ")) != std::string::npos)
+ {
+ ret.erase(pos, 1);
+ }
+ return ret;
+}
+