Created
June 1, 2016 09:39
-
-
Save ju1ion/95731feb7251d9cd1bd391982cd795bc to your computer and use it in GitHub Desktop.
C++ String split without boost
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public: | |
static std::vector<std::string> splitStrA(const std::string &InputString, char delimiterChar) { | |
std::vector<std::string> ResultVec; | |
splitStrA(InputString, delimiterChar, ResultVec); | |
return ResultVec; | |
}; | |
static std::vector<std::wstring> splitStrW(const std::wstring &InputString, wchar_t delimiterChar) { | |
std::vector<std::wstring> ResultVec; | |
splitStrW(InputString, delimiterChar, ResultVec); | |
return ResultVec; | |
}; | |
#ifdef UNICODE | |
#define splitStr splitStrW | |
#else | |
#define splitStr splitStrA | |
#endif | |
private: | |
static std::vector<std::wstring> &splitStrW(const std::wstring &InputString, wchar_t delimiterChar, std::vector<std::wstring> &ResultVec) { | |
std::wstringstream sStream(InputString); | |
std::wstring item; | |
while (std::getline(sStream, item, delimiterChar)) { | |
ResultVec.push_back(item); | |
} | |
return ResultVec; | |
} | |
static std::vector<std::string> &splitStrA(const std::string &InputString, char delimiterChar, std::vector<std::string> &ResultVec) { | |
std::stringstream sStream(InputString); | |
std::string item; | |
while (std::getline(sStream, item, delimiterChar)) { | |
ResultVec.push_back(item); | |
} | |
return ResultVec; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment