eligantRU / oop

This is repository for labs of OOP
0 stars 2 forks source link

Замечания по программе Replace #3

Closed alexey-malov closed 8 years ago

alexey-malov commented 8 years ago
eligantRU commented 8 years ago

Use CALL in *.bat files & IF NOT ERRORLEVEL 1

eligantRU commented 8 years ago

Исправлено

alexey-malov commented 8 years ago
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;
}
alexey-malov commented 8 years ago
eligantRU commented 8 years ago

Абсолютные пути исправлены во всех проектах, it переименован в pos

eligantRU commented 8 years ago

Исправлена сложность алгоритма с O(n^2) на O(n) [https://github.com/eligantRU/oop/commit/a86e24652161b1b5bf664d84c056c6eb2301f7ed]

alexey-malov commented 8 years ago
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;
}

Рекомендации:

alexey-malov commented 8 years ago
eligantRU commented 8 years ago

Исправлено

alexey-malov commented 8 years ago
    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();
    }
eligantRU commented 8 years ago

Исправлено: 7e10ac9ebb9f0ab8e15c4b4240a563b65c2e6108

alexey-malov commented 8 years ago

принято