shadPS4/src/common/string_util.cpp

23 lines
620 B
C++
Raw Normal View History

#include <algorithm>
#include <sstream>
#include <string>
2023-11-05 12:41:10 +01:00
#include "common/string_util.h"
namespace StringUtil {
std::vector<std::string> split_string(const std::string &str, char delimiter) {
std::stringstream str_stream(str);
std::string segment;
std::vector<std::string> seglist;
const size_t num_segments = std::count_if(str.begin(), str.end(), [&](char c) { return c == delimiter; }) + (str.empty() ? 1 : 0);
seglist.reserve(num_segments);
while (std::getline(str_stream, segment, delimiter)) {
seglist.push_back(segment);
}
return seglist;
}
} // namespace StringUtil