shadPS4/src/Util/string_util.cpp

24 lines
614 B
C++
Raw Normal View History

2023-08-04 10:33:00 +02:00
#include "string_util.h"
#include <algorithm>
#include <sstream>
#include <string>
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