Merge pull request #5596 from leoetlino/return-by-value
StringUtil: Make SplitString return by value
This commit is contained in:
commit
1bf62cc084
|
@ -84,8 +84,7 @@ std::string EscapeFileName(const std::string& filename)
|
||||||
|
|
||||||
std::string EscapePath(const std::string& path)
|
std::string EscapePath(const std::string& path)
|
||||||
{
|
{
|
||||||
std::vector<std::string> split_strings;
|
const std::vector<std::string> split_strings = SplitString(path, '/');
|
||||||
SplitString(path, '/', split_strings);
|
|
||||||
|
|
||||||
std::vector<std::string> escaped_split_strings;
|
std::vector<std::string> escaped_split_strings;
|
||||||
escaped_split_strings.reserve(split_strings.size());
|
escaped_split_strings.reserve(split_strings.size());
|
||||||
|
|
|
@ -341,15 +341,16 @@ void BuildCompleteFilename(std::string& _CompleteFilename, const std::string& _P
|
||||||
_CompleteFilename += _Filename;
|
_CompleteFilename += _Filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SplitString(const std::string& str, const char delim, std::vector<std::string>& output)
|
std::vector<std::string> SplitString(const std::string& str, const char delim)
|
||||||
{
|
{
|
||||||
std::istringstream iss(str);
|
std::istringstream iss(str);
|
||||||
output.resize(1);
|
std::vector<std::string> output(1);
|
||||||
|
|
||||||
while (std::getline(iss, *output.rbegin(), delim))
|
while (std::getline(iss, *output.rbegin(), delim))
|
||||||
output.push_back("");
|
output.push_back("");
|
||||||
|
|
||||||
output.pop_back();
|
output.pop_back();
|
||||||
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string JoinStrings(const std::vector<std::string>& strings, const std::string& delimiter)
|
std::string JoinStrings(const std::vector<std::string>& strings, const std::string& delimiter)
|
||||||
|
|
|
@ -106,7 +106,7 @@ bool AsciiToHex(const std::string& _szValue, u32& result);
|
||||||
|
|
||||||
std::string TabsToSpaces(int tab_size, const std::string& in);
|
std::string TabsToSpaces(int tab_size, const std::string& in);
|
||||||
|
|
||||||
void SplitString(const std::string& str, char delim, std::vector<std::string>& output);
|
std::vector<std::string> SplitString(const std::string& str, char delim);
|
||||||
std::string JoinStrings(const std::vector<std::string>& strings, const std::string& delimiter);
|
std::string JoinStrings(const std::vector<std::string>& strings, const std::string& delimiter);
|
||||||
|
|
||||||
// "C:/Windows/winhelp.exe" to "C:/Windows/", "winhelp", ".exe"
|
// "C:/Windows/winhelp.exe" to "C:/Windows/", "winhelp", ".exe"
|
||||||
|
|
|
@ -175,8 +175,6 @@ std::vector<ARCode> LoadCodes(const IniFile& global_ini, const IniFile& local_in
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> pieces;
|
|
||||||
|
|
||||||
// Check if the line is a name of the code
|
// Check if the line is a name of the code
|
||||||
if (line[0] == '$')
|
if (line[0] == '$')
|
||||||
{
|
{
|
||||||
|
@ -199,7 +197,7 @@ std::vector<ARCode> LoadCodes(const IniFile& global_ini, const IniFile& local_in
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SplitString(line, ' ', pieces);
|
std::vector<std::string> pieces = SplitString(line, ' ');
|
||||||
|
|
||||||
// Check if the AR code is decrypted
|
// Check if the AR code is decrypted
|
||||||
if (pieces.size() == 2 && pieces[0].size() == 8 && pieces[1].size() == 8)
|
if (pieces.size() == 2 && pieces[0].size() == 8 && pieces[1].size() == 8)
|
||||||
|
@ -225,7 +223,7 @@ std::vector<ARCode> LoadCodes(const IniFile& global_ini, const IniFile& local_in
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SplitString(line, '-', pieces);
|
pieces = SplitString(line, '-');
|
||||||
if (pieces.size() == 3 && pieces[0].size() == 4 && pieces[1].size() == 4 &&
|
if (pieces.size() == 3 && pieces[0].size() == 4 && pieces[1].size() == 4 &&
|
||||||
pieces[2].size() == 5)
|
pieces[2].size() == 5)
|
||||||
{
|
{
|
||||||
|
|
|
@ -686,10 +686,8 @@ void SConfig::LoadUSBPassthroughSettings(IniFile& ini)
|
||||||
IniFile::Section* section = ini.GetOrCreateSection("USBPassthrough");
|
IniFile::Section* section = ini.GetOrCreateSection("USBPassthrough");
|
||||||
m_usb_passthrough_devices.clear();
|
m_usb_passthrough_devices.clear();
|
||||||
std::string devices_string;
|
std::string devices_string;
|
||||||
std::vector<std::string> pairs;
|
|
||||||
section->Get("Devices", &devices_string, "");
|
section->Get("Devices", &devices_string, "");
|
||||||
SplitString(devices_string, ',', pairs);
|
for (const auto& pair : SplitString(devices_string, ','))
|
||||||
for (const auto& pair : pairs)
|
|
||||||
{
|
{
|
||||||
const auto index = pair.find(':');
|
const auto index = pair.find(':');
|
||||||
if (index == std::string::npos)
|
if (index == std::string::npos)
|
||||||
|
|
|
@ -520,9 +520,7 @@ void BluetoothReal::LoadLinkKeys()
|
||||||
const std::string& entries = SConfig::GetInstance().m_bt_passthrough_link_keys;
|
const std::string& entries = SConfig::GetInstance().m_bt_passthrough_link_keys;
|
||||||
if (entries.empty())
|
if (entries.empty())
|
||||||
return;
|
return;
|
||||||
std::vector<std::string> pairs;
|
for (const auto& pair : SplitString(entries, ','))
|
||||||
SplitString(entries, ',', pairs);
|
|
||||||
for (const auto& pair : pairs)
|
|
||||||
{
|
{
|
||||||
const auto index = pair.find('=');
|
const auto index = pair.find('=');
|
||||||
if (index == std::string::npos)
|
if (index == std::string::npos)
|
||||||
|
|
|
@ -86,8 +86,7 @@ void LoadPatchSection(const std::string& section, std::vector<Patch>& patches, I
|
||||||
line[loc] = ':';
|
line[loc] = ':';
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> items;
|
const std::vector<std::string> items = SplitString(line, ':');
|
||||||
SplitString(line, ':', items);
|
|
||||||
|
|
||||||
if (items.size() >= 3)
|
if (items.size() >= 3)
|
||||||
{
|
{
|
||||||
|
|
|
@ -94,8 +94,8 @@ void ARCodeAddEdit::SaveCheatData(wxCommandEvent& WXUNUSED(event))
|
||||||
std::vector<std::string> encrypted_lines;
|
std::vector<std::string> encrypted_lines;
|
||||||
|
|
||||||
// Split the entered cheat into lines.
|
// Split the entered cheat into lines.
|
||||||
std::vector<std::string> input_lines;
|
const std::vector<std::string> input_lines =
|
||||||
SplitString(WxStrToStr(m_cheat_codes->GetValue()), '\n', input_lines);
|
SplitString(WxStrToStr(m_cheat_codes->GetValue()), '\n');
|
||||||
|
|
||||||
for (size_t i = 0; i < input_lines.size(); i++)
|
for (size_t i = 0; i < input_lines.size(); i++)
|
||||||
{
|
{
|
||||||
|
@ -106,8 +106,7 @@ void ARCodeAddEdit::SaveCheatData(wxCommandEvent& WXUNUSED(event))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Let's parse the current line. Is it in encrypted or decrypted form?
|
// Let's parse the current line. Is it in encrypted or decrypted form?
|
||||||
std::vector<std::string> pieces;
|
std::vector<std::string> pieces = SplitString(line_str, ' ');
|
||||||
SplitString(line_str, ' ', pieces);
|
|
||||||
|
|
||||||
if (pieces.size() == 2 && pieces[0].size() == 8 && pieces[1].size() == 8)
|
if (pieces.size() == 2 && pieces[0].size() == 8 && pieces[1].size() == 8)
|
||||||
{
|
{
|
||||||
|
@ -120,7 +119,7 @@ void ARCodeAddEdit::SaveCheatData(wxCommandEvent& WXUNUSED(event))
|
||||||
}
|
}
|
||||||
else if (pieces.size() == 1)
|
else if (pieces.size() == 1)
|
||||||
{
|
{
|
||||||
SplitString(line_str, '-', pieces);
|
pieces = SplitString(line_str, '-');
|
||||||
|
|
||||||
if (pieces.size() == 3 && pieces[0].size() == 4 && pieces[1].size() == 4 &&
|
if (pieces.size() == 3 && pieces[0].size() == 4 && pieces[1].size() == 4 &&
|
||||||
pieces[2].size() == 5)
|
pieces[2].size() == 5)
|
||||||
|
|
|
@ -564,8 +564,7 @@ void CCodeView::OnPaint(wxPaintEvent& event)
|
||||||
// If running
|
// If running
|
||||||
if (m_debugger->IsAlive())
|
if (m_debugger->IsAlive())
|
||||||
{
|
{
|
||||||
std::vector<std::string> dis;
|
std::vector<std::string> dis = SplitString(m_debugger->Disassemble(address), '\t');
|
||||||
SplitString(m_debugger->Disassemble(address), '\t', dis);
|
|
||||||
dis.resize(2);
|
dis.resize(2);
|
||||||
|
|
||||||
static const size_t VALID_BRANCH_LENGTH = 10;
|
static const size_t VALID_BRANCH_LENGTH = 10;
|
||||||
|
|
|
@ -746,7 +746,6 @@ void CFrame::DoLoadPerspective()
|
||||||
void CFrame::LoadIniPerspectives()
|
void CFrame::LoadIniPerspectives()
|
||||||
{
|
{
|
||||||
m_perspectives.clear();
|
m_perspectives.clear();
|
||||||
std::vector<std::string> VPerspectives;
|
|
||||||
std::string _Perspectives;
|
std::string _Perspectives;
|
||||||
|
|
||||||
IniFile ini;
|
IniFile ini;
|
||||||
|
@ -755,13 +754,11 @@ void CFrame::LoadIniPerspectives()
|
||||||
IniFile::Section* perspectives = ini.GetOrCreateSection("Perspectives");
|
IniFile::Section* perspectives = ini.GetOrCreateSection("Perspectives");
|
||||||
perspectives->Get("Perspectives", &_Perspectives, "Perspective 1");
|
perspectives->Get("Perspectives", &_Perspectives, "Perspective 1");
|
||||||
perspectives->Get("Active", &m_active_perspective, 0);
|
perspectives->Get("Active", &m_active_perspective, 0);
|
||||||
SplitString(_Perspectives, ',', VPerspectives);
|
|
||||||
|
|
||||||
for (auto& VPerspective : VPerspectives)
|
for (auto& VPerspective : SplitString(_Perspectives, ','))
|
||||||
{
|
{
|
||||||
SPerspectives Tmp;
|
SPerspectives Tmp;
|
||||||
std::string _Section, _Perspective, _Widths, _Heights;
|
std::string _Section, _Perspective, _Widths, _Heights;
|
||||||
std::vector<std::string> _SWidth, _SHeight;
|
|
||||||
Tmp.name = VPerspective;
|
Tmp.name = VPerspective;
|
||||||
|
|
||||||
// Don't save a blank perspective
|
// Don't save a blank perspective
|
||||||
|
@ -783,15 +780,13 @@ void CFrame::LoadIniPerspectives()
|
||||||
|
|
||||||
Tmp.perspective = StrToWxStr(_Perspective);
|
Tmp.perspective = StrToWxStr(_Perspective);
|
||||||
|
|
||||||
SplitString(_Widths, ',', _SWidth);
|
for (auto& Width : SplitString(_Widths, ','))
|
||||||
SplitString(_Heights, ',', _SHeight);
|
|
||||||
for (auto& Width : _SWidth)
|
|
||||||
{
|
{
|
||||||
int _Tmp;
|
int _Tmp;
|
||||||
if (TryParse(Width, &_Tmp))
|
if (TryParse(Width, &_Tmp))
|
||||||
Tmp.width.push_back(_Tmp);
|
Tmp.width.push_back(_Tmp);
|
||||||
}
|
}
|
||||||
for (auto& Height : _SHeight)
|
for (auto& Height : SplitString(_Heights, ','))
|
||||||
{
|
{
|
||||||
int _Tmp;
|
int _Tmp;
|
||||||
if (TryParse(Height, &_Tmp))
|
if (TryParse(Height, &_Tmp))
|
||||||
|
|
|
@ -136,8 +136,7 @@ void PipeDevice::SetAxis(const std::string& entry, double value)
|
||||||
|
|
||||||
void PipeDevice::ParseCommand(const std::string& command)
|
void PipeDevice::ParseCommand(const std::string& command)
|
||||||
{
|
{
|
||||||
std::vector<std::string> tokens;
|
const std::vector<std::string> tokens = SplitString(command, ' ');
|
||||||
SplitString(command, ' ', tokens);
|
|
||||||
if (tokens.size() < 2 || tokens.size() > 4)
|
if (tokens.size() < 2 || tokens.size() > 4)
|
||||||
return;
|
return;
|
||||||
if (tokens[0] == "PRESS" || tokens[0] == "RELEASE")
|
if (tokens[0] == "PRESS" || tokens[0] == "RELEASE")
|
||||||
|
|
Loading…
Reference in New Issue