10 std::vector<std::string>
split(
const std::string&
str,
const std::string& delim) {
11 assert_msg(!delim.empty(),
"Delimiter must not be empty.");
12 std::vector<std::string> tokens;
13 size_t prev = 0, pos = 0;
15 pos =
str.find(delim, prev);
16 if (pos == std::string::npos) pos =
str.length();
17 tokens.emplace_back(
str.substr(prev, pos-prev));
18 prev = pos + delim.length();
19 }
while (pos <
str.length() && prev <
str.length());
20 if (prev ==
str.length()) tokens.emplace_back(
"");
24 std::vector<std::string>
split(
const std::string&
str,
char delim) {
25 return split(
str, std::string(1, delim));
29 std::string
join(
const std::vector<std::string>& parts,
const std::string& joiner) {
30 if (parts.empty())
return "";
31 std::string result = parts[0];
33 for (
int i = 1; i < n; ++i) {
34 result += joiner + parts[i];
39 std::string
join(
const std::vector<std::string>& parts,
char joiner) {
40 return join(parts, std::string(1, joiner));