FIX: config: fix a endless loop issue when replace string

jira: STUDIO-7545
Change-Id: I7ea06556142242f44b183599d9d23d063ad509f9
(cherry picked from commit 842e238d6265abb34f33614c255d1292c3345c34)
This commit is contained in:
lane.wei 2024-07-18 17:05:40 +08:00 committed by Lane.Wei
parent f402685aee
commit 0cfa60b657
1 changed files with 6 additions and 1 deletions

View File

@ -38,7 +38,12 @@ std::set<std::string> SplitStringAndRemoveDuplicateElement(const std::string &st
void ReplaceString(std::string &resource_str, const std::string &old_str, const std::string &new_str)
{
std::string::size_type pos = 0;
while ((pos = resource_str.find(old_str)) != std::string::npos) { resource_str.replace(pos, old_str.length(), new_str); }
size_t new_size = 0;
while ((pos = resource_str.find(old_str, pos + new_size)) != std::string::npos)
{
resource_str.replace(pos, old_str.length(), new_str);
new_size = new_str.size();
}
}
}