blob: cdbb42c33ed4abf458b6222fc9f6af72b2b37964 [file] [log] [blame]
#ifndef THIRD_PARTY_GBMCWEB_INCLUDE_STR_UTILITY_H_
#define THIRD_PARTY_GBMCWEB_INCLUDE_STR_UTILITY_H_
#include <cstddef>
#include <string>
#include <string_view>
#include <vector>
namespace bmcweb {
// This is a naive replacement for boost::split until
// https://github.com/llvm/llvm-project/issues/40486
// is resolved
inline void split(std::vector<std::string>& strings, std::string_view str,
char delim) {
size_t start = 0;
size_t end = 0;
while (end <= str.size()) {
end = str.find(delim, start);
strings.emplace_back(str.substr(start, end - start));
start = end + 1;
}
}
inline void append_with_sep(std::string& out, const char sep,
const std::string& arg) {
if (!out.empty()) {
out += sep;
}
out += arg;
}
// join 'args' strings with a separator without creating any intermediate
// objects, append to 'out'
template <typename... Args>
void append_with_sep(std::string& out, const char sep, const std::string& arg,
const Args&... args) {
append_with_sep(out, sep, arg);
append_with_sep(out, sep, args...);
}
} // namespace bmcweb
#endif // THIRD_PARTY_GBMCWEB_INCLUDE_STR_UTILITY_H_