mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2025-02-16 20:15:38 +00:00
Fixed an issue where the StringUtil::replace function did not remove repeating occurances.
This commit is contained in:
parent
2001a9f639
commit
03e457516a
|
@ -586,17 +586,28 @@ namespace Utils
|
||||||
const std::string& from,
|
const std::string& from,
|
||||||
const std::string& to)
|
const std::string& to)
|
||||||
{
|
{
|
||||||
std::string replaced;
|
std::string result {stringArg};
|
||||||
size_t lastPos {0};
|
|
||||||
size_t findPos {0};
|
|
||||||
|
|
||||||
while ((findPos = stringArg.find(from, lastPos)) != std::string::npos) {
|
// The outer loop makes sure that we're eliminating all repeating occurances
|
||||||
replaced.append(stringArg, lastPos, findPos - lastPos).append(to);
|
// of the 'from' value.
|
||||||
lastPos = findPos + from.length();
|
while (result.find(from) != std::string::npos) {
|
||||||
|
// Prevent endless loops.
|
||||||
|
if (from == to)
|
||||||
|
break;
|
||||||
|
|
||||||
|
std::string replaced;
|
||||||
|
size_t lastPos {0};
|
||||||
|
size_t findPos {0};
|
||||||
|
|
||||||
|
while ((findPos = result.find(from, lastPos)) != std::string::npos) {
|
||||||
|
replaced.append(result, lastPos, findPos - lastPos).append(to);
|
||||||
|
lastPos = findPos + from.length();
|
||||||
|
}
|
||||||
|
|
||||||
|
replaced.append(result.substr(lastPos));
|
||||||
|
result = replaced;
|
||||||
}
|
}
|
||||||
|
return result;
|
||||||
replaced.append(stringArg.substr(lastPos));
|
|
||||||
return replaced;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::wstring stringToWideString(const std::string& stringArg)
|
std::wstring stringToWideString(const std::string& stringArg)
|
||||||
|
|
Loading…
Reference in a new issue