Last active
June 30, 2024 14:24
-
-
Save trikitrok/559226aab65efc5cadbd to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#include <regex> | |
#include <sstream> | |
std::vector<std::string> StringUtils::split( | |
const std::string & str, | |
const std::vector<std::string> & delimiters) { | |
std::regex rgx(join(escapeStrings(delimiters), "|")); | |
std::sregex_token_iterator | |
first{begin(str), end(str), rgx, -1}, | |
last; | |
return{first, last}; | |
} | |
std::vector<std::string> StringUtils::split(const std::string & str, | |
const std::string & delimiter) { | |
std::vector<std::string> delimiters = {delimiter}; | |
return split(str, delimiters); | |
} | |
std::string StringUtils::join( | |
const std::vector<std::string> & tokens, | |
const std::string & delimiter) { | |
std::stringstream stream; | |
stream << tokens.front(); | |
std::for_each( | |
begin(tokens) + 1, | |
end(tokens), | |
[&](const std::string &elem) { | |
stream << delimiter << elem;} | |
); | |
return stream.str(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment