From f598fbc185e34fac3f9ffc44a0f198a3f7603615 Mon Sep 17 00:00:00 2001 From: Quinten Date: Tue, 7 Oct 2025 16:41:02 +0200 Subject: [PATCH] feat: add split function to utils for string splitting by delimiter --- webserv/utils/utils.cpp | 14 ++++++++++++++ webserv/utils/utils.hpp | 2 ++ 2 files changed, 16 insertions(+) diff --git a/webserv/utils/utils.cpp b/webserv/utils/utils.cpp index a902758..b0fc644 100644 --- a/webserv/utils/utils.cpp +++ b/webserv/utils/utils.cpp @@ -4,6 +4,7 @@ #include #include #include +#include namespace utils { @@ -104,4 +105,17 @@ void removeComments(std::string &str) } removeEmptyLines(str); } + +std::vector split(const std::string &str, char delimiter) +{ + std::vector parts; + std::string part; + std::istringstream stream(str); + + while (std::getline(stream, part, delimiter)) + { + parts.push_back(part); + } + return parts; +} } // namespace utils \ No newline at end of file diff --git a/webserv/utils/utils.hpp b/webserv/utils/utils.hpp index 002b5e3..0858735 100644 --- a/webserv/utils/utils.hpp +++ b/webserv/utils/utils.hpp @@ -2,6 +2,7 @@ #include // for size_t #include // for string +#include namespace utils { @@ -11,4 +12,5 @@ std::string trim(const std::string &str); size_t findCorrespondingClosingBrace(const std::string &str, size_t openPos); void removeEmptyLines(std::string &str); void removeComments(std::string &str); +std::vector split(const std::string &str, char delimiter); } // namespace utils \ No newline at end of file