mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-12-10 05:38:49 +00:00
improved StringUtil algo + some PhysicalMemory work
This commit is contained in:
23
src/Util/StringUtil.cpp
Normal file
23
src/Util/StringUtil.cpp
Normal file
@@ -0,0 +1,23 @@
|
||||
#include "StringUtil.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
|
||||
@@ -4,23 +4,6 @@
|
||||
|
||||
namespace StringUtil {
|
||||
|
||||
static std::vector<std::string> split(const std::string& s, char seperator)
|
||||
{
|
||||
std::vector<std::string> output;
|
||||
std::vector<std::string> split_string(const std::string& str, char delimiter);
|
||||
|
||||
std::string::size_type prev_pos = 0, pos = 0;
|
||||
|
||||
while ((pos = s.find(seperator, pos)) != std::string::npos)
|
||||
{
|
||||
std::string substring(s.substr(prev_pos, pos - prev_pos));
|
||||
|
||||
output.push_back(substring);
|
||||
|
||||
prev_pos = ++pos;
|
||||
}
|
||||
|
||||
output.push_back(s.substr(prev_pos, pos - prev_pos)); // Last word
|
||||
|
||||
return output;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user