Add string split util

This commit is contained in:
ala89 2023-12-15 15:00:39 +01:00
parent 5fed47367d
commit a1873af50d
2 changed files with 22 additions and 0 deletions

View File

@ -14,4 +14,9 @@ CodePosition get_node_pos(Node node);
*/ */
Type string_to_type(string type_name); Type string_to_type(string type_name);
/**
* Splits a string using the provided delimiter
*/
vector<string> split_string(const string& input, char delimiter);
#endif #endif

View File

@ -1,3 +1,8 @@
#include <string>
#include <iostream>
#include <vector>
#include <sstream>
#include "include/utils.h" #include "include/utils.h"
CodePosition get_node_pos(Node node) { CodePosition get_node_pos(Node node) {
@ -13,4 +18,16 @@ Type string_to_type(string type_name) {
return Type::Double; return Type::Double;
throw exception(); throw exception();
}
vector<string> split_string(const string& input, char delimiter) {
vector<string> tokens;
string token;
istringstream tokenStream(input);
while (getline(tokenStream, token, delimiter)) {
tokens.push_back(token);
}
return tokens;
} }