diff options
| author | Leonetienne <leonetienne@hotmail.de> | 2022-03-13 15:52:53 +0100 |
|---|---|---|
| committer | Leonetienne <leonetienne@hotmail.de> | 2022-03-13 15:52:53 +0100 |
| commit | 25bd26972945f956ad4c92ce8a61bb6126c0dedb (patch) | |
| tree | 9548e39ced9cd541586a8dd5c12638a0edb6a1ca /Src/StringTools.cpp | |
| parent | 5f791b8d9f66b53e1019abfe6a13b6e86fe5ca51 (diff) | |
Implementation Split
Diffstat (limited to 'Src/StringTools.cpp')
| -rw-r--r-- | Src/StringTools.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/Src/StringTools.cpp b/Src/StringTools.cpp index 931bd75..302fad9 100644 --- a/Src/StringTools.cpp +++ b/Src/StringTools.cpp @@ -92,3 +92,31 @@ std::string StringTools::Upper(const std::string& str) { return ss.str();
}
+
+std::vector<std::string> StringTools::Split(const std::string& str, const std::string& seperator) {
+ std::vector<std::string> toRet;
+
+ // Quick-accept: seperator length is 0
+ if (seperator.length() == 0) {
+ for (const char c : str)
+ toRet.push_back(std::string(&c, (&c) + 1));
+ }
+
+ else {
+ std::size_t idx = 0;
+ while (idx != std::string::npos) {
+ std::size_t lastIdx = idx;
+ idx = str.find(seperator, idx + seperator.length());
+
+ toRet.push_back(str.substr(
+ lastIdx,
+ idx - lastIdx
+ ));
+
+ if (idx != std::string::npos)
+ idx += seperator.length();
+ }
+ }
+
+ return toRet;
+}
|
