From a1873af50d31d892af75022e231b60f6756b1999 Mon Sep 17 00:00:00 2001 From: ala89 Date: Fri, 15 Dec 2023 15:00:39 +0100 Subject: [PATCH] Add string split util --- src/include/utils.h | 5 +++++ src/utils.cpp | 17 +++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/include/utils.h b/src/include/utils.h index b55702e..2778170 100644 --- a/src/include/utils.h +++ b/src/include/utils.h @@ -14,4 +14,9 @@ CodePosition get_node_pos(Node node); */ Type string_to_type(string type_name); +/** + * Splits a string using the provided delimiter +*/ +vector split_string(const string& input, char delimiter); + #endif \ No newline at end of file diff --git a/src/utils.cpp b/src/utils.cpp index db2a6de..ca5a909 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -1,3 +1,8 @@ +#include +#include +#include +#include + #include "include/utils.h" CodePosition get_node_pos(Node node) { @@ -13,4 +18,16 @@ Type string_to_type(string type_name) { return Type::Double; throw exception(); +} + +vector split_string(const string& input, char delimiter) { + vector tokens; + string token; + istringstream tokenStream(input); + + while (getline(tokenStream, token, delimiter)) { + tokens.push_back(token); + } + + return tokens; } \ No newline at end of file