Closed alexey-malov closed 8 years ago
Use CALL in *.bat files & IF NOT ERRORLEVEL 1
Исправлено
std::string FindAndReplace(const std::string & inputStr, const std::string & searchStr, const std::string & replaceStr)
{
auto currentStr = inputStr;
auto it = currentStr.find(searchStr);
while (it != std::string::npos)
{
currentStr.replace(it, searchStr.length(), replaceStr);
it = currentStr.find(searchStr, it + replaceStr.length());
}
return currentStr;
}
Абсолютные пути исправлены во всех проектах, it переименован в pos
Исправлена сложность алгоритма с O(n^2) на O(n) [https://github.com/eligantRU/oop/commit/a86e24652161b1b5bf664d84c056c6eb2301f7ed]
std::string FindAndReplace(const std::string & inputStr, const std::string & searchStr, const std::string & replaceStr)
{
std::string result;
size_t initialPos = 0;
auto pos = inputStr.find(searchStr);
while (pos != std::string::npos)
{
result.append(inputStr, initialPos, pos - initialPos);
result.append(replaceStr);
initialPos = pos + searchStr.length();
pos = inputStr.find(searchStr, initialPos);
}
result.append(inputStr, initialPos);
return result;
}
Рекомендации:
Исправлено
for (auto pos = inputStr.find(searchStr); pos != std::string::npos; pos = inputStr.find(searchStr, initialPos))
{
result.append(inputStr, initialPos, pos - initialPos);
result.append(replaceStr);
initialPos = pos + searchStr.length();
}
Исправлено: 7e10ac9ebb9f0ab8e15c4b4240a563b65c2e6108
принято