Simplified regex split

Instead of building the result vector with push_back, I now use
the vector c'tor with iterators directly.
This commit is contained in:
Bob Polis 2022-01-28 09:40:18 +01:00
parent 90d46ea7fa
commit 879eefb39e

View File

@ -32,12 +32,7 @@ vector<string> sc::split(const string& str, const string& sep)
} }
vector<string> sc::split(const string& str, const regex& sep) { vector<string> sc::split(const string& str, const regex& sep) {
vector<string> components; return {sregex_token_iterator {str.begin(), str.end(), sep, -1}, sregex_token_iterator {}};
sregex_token_iterator end {};
for (sregex_token_iterator p {str.begin(), str.end(), sep, -1}; p != end; ++p) {
components.push_back(*p);
}
return components;
} }
string sc::join(const vector<string>& components, const string& join) string sc::join(const vector<string>& components, const string& join)