Skip to content

Commit 6570e8f

Browse files
committed
Minor modification.
1 parent 7ac8b41 commit 6570e8f

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

Sources/NodeEngine/NE_StringUtils.cpp

+13-14
Original file line numberDiff line numberDiff line change
@@ -19,30 +19,29 @@ std::string WStringToString (const std::wstring& str)
1919
return std::string (convert.to_bytes (str));
2020
}
2121

22-
std::wstring ReplaceAll (const std::wstring& string, const std::wstring& from, const std::wstring& to)
22+
std::wstring ReplaceAll (const std::wstring& string, const std::wstring& fromString, const std::wstring& toString)
2323
{
2424
std::wstring result = string;
25-
size_t searchPos = string.find (from);
25+
size_t searchPos = string.find (fromString);
2626
while (searchPos != std::wstring::npos) {
27-
result.replace (searchPos, from.length (), to);
28-
searchPos = result.find (from, searchPos + to.length ());
27+
result.replace (searchPos, fromString.length (), toString);
28+
searchPos = result.find (fromString, searchPos + toString.length ());
2929
}
3030
return result;
3131
}
3232

33-
std::wstring ReplaceAll (const std::wstring& string, const std::wstring& from, const std::initializer_list<std::wstring>& to)
33+
std::wstring ReplaceAll (const std::wstring& string, const std::wstring& fromString, const std::initializer_list<std::wstring>& toStrings)
3434
{
3535
std::wstring result = string;
36-
auto toIt = to.begin ();
37-
size_t searchPos = string.find (from);
38-
while (searchPos != std::wstring::npos && toIt != to.end ()) {
39-
const std::wstring currStr = *toIt;
40-
result.replace (searchPos, from.length (), currStr);
41-
searchPos = result.find (from, searchPos + currStr.length ());
42-
++toIt;
36+
auto toStringIt = toStrings.begin ();
37+
size_t searchPos = string.find (fromString);
38+
while (searchPos != std::wstring::npos && toStringIt != toStrings.end ()) {
39+
const std::wstring& currStr = *toStringIt;
40+
result.replace (searchPos, fromString.length (), currStr);
41+
searchPos = result.find (fromString, searchPos + currStr.length ());
42+
++toStringIt;
4343
}
44-
45-
DBGASSERT (searchPos == std::wstring::npos && toIt == to.end ());
44+
DBGASSERT (searchPos == std::wstring::npos && toStringIt == toStrings.end ());
4645
return result;
4746
}
4847

Sources/NodeEngine/NE_StringUtils.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ namespace NE
99
std::wstring StringToWString (const std::string& str);
1010
std::string WStringToString (const std::wstring& str);
1111

12-
std::wstring ReplaceAll (const std::wstring& string, const std::wstring& from, const std::wstring& to);
13-
std::wstring ReplaceAll (const std::wstring& string, const std::wstring& from, const std::initializer_list<std::wstring>& to);
12+
std::wstring ReplaceAll (const std::wstring& string, const std::wstring& fromString, const std::wstring& toString);
13+
std::wstring ReplaceAll (const std::wstring& string, const std::wstring& fromString, const std::initializer_list<std::wstring>& toStrings);
1414

1515
}
1616

0 commit comments

Comments
 (0)