Created
July 31, 2020 22:37
-
-
Save jonwis/3d7a0b7989da59d144fa8236ac2e432b to your computer and use it in GitHub Desktop.
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
std::pair<std::wstring_view, std::wstring_view> SplitAt(std::wstring_view const& source, wchar_t split) | |
{ | |
auto splitpoint = source.find(split); | |
if (splitpoint != std::wstring_view::npos) | |
{ | |
return { source.substr(0, splitpoint), source.substr(splitpoint + 1) }; | |
} | |
else | |
{ | |
return { source, { } }; | |
} | |
} | |
std::vector<std::wstring_view> SplitMulti(std::wstring_view source, wchar_t split) | |
{ | |
std::vector<std::wstring_view> returned; | |
while (source.empty()) | |
{ | |
auto splitpoint = source.find(split); | |
if (splitpoint == source.npos) | |
{ | |
returned.emplace_back(source); | |
break; | |
} | |
else | |
{ | |
returned.emplace_back(source.substr(0, splitpoint)); | |
source = source.substr(splitpoint + 1); | |
} | |
} | |
return returned; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment