feat: add split function to utils for string splitting by delimiter
This commit is contained in:
parent
1994de27af
commit
f598fbc185
@ -4,6 +4,7 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace utils
|
namespace utils
|
||||||
{
|
{
|
||||||
@ -104,4 +105,17 @@ void removeComments(std::string &str)
|
|||||||
}
|
}
|
||||||
removeEmptyLines(str);
|
removeEmptyLines(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> split(const std::string &str, char delimiter)
|
||||||
|
{
|
||||||
|
std::vector<std::string> parts;
|
||||||
|
std::string part;
|
||||||
|
std::istringstream stream(str);
|
||||||
|
|
||||||
|
while (std::getline(stream, part, delimiter))
|
||||||
|
{
|
||||||
|
parts.push_back(part);
|
||||||
|
}
|
||||||
|
return parts;
|
||||||
|
}
|
||||||
} // namespace utils
|
} // namespace utils
|
||||||
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include <cstddef> // for size_t
|
#include <cstddef> // for size_t
|
||||||
#include <string> // for string
|
#include <string> // for string
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace utils
|
namespace utils
|
||||||
{
|
{
|
||||||
@ -11,4 +12,5 @@ std::string trim(const std::string &str);
|
|||||||
size_t findCorrespondingClosingBrace(const std::string &str, size_t openPos);
|
size_t findCorrespondingClosingBrace(const std::string &str, size_t openPos);
|
||||||
void removeEmptyLines(std::string &str);
|
void removeEmptyLines(std::string &str);
|
||||||
void removeComments(std::string &str);
|
void removeComments(std::string &str);
|
||||||
|
std::vector<std::string> split(const std::string &str, char delimiter);
|
||||||
} // namespace utils
|
} // namespace utils
|
||||||
Loading…
Reference in New Issue
Block a user