pocoproject / poco

The POCO C++ Libraries are powerful cross-platform C++ libraries for building network- and internet-based applications that run on desktop, server, mobile, IoT, and embedded systems.
https://pocoproject.org
Other
8.43k stars 2.17k forks source link

replaceInPlace std::wstring #4713

Open micheleselea opened 1 month ago

micheleselea commented 1 month ago

It's not possible to use this

std::wstring wstr;
Poco::replaceInPlace(wstr, L"STRINGB", L"STRINGA");

due to a compile error in this line typename S::size_type fromLen = std::strlen(from); of String.h

template <class S>
S& replaceInPlace(S& str, const typename S::value_type* from, const typename S::value_type* to, typename S::size_type start = 0)
{
    poco_assert (*from);

    S result;
    typename S::size_type pos = 0;
    typename S::size_type fromLen = std::strlen(from); //**HERE**
    result.append(str, 0, start);
    do
    {
        pos = str.find(from, start);
        if (pos != S::npos)
        {
            result.append(str, start, pos - start);
            result.append(to);
            start = pos + fromLen;
        }
        else result.append(str, start, str.size() - start);
    }
    while (pos != S::npos);
    str.swap(result);
    return str;
}
micheleselea commented 1 month ago

probably we can change the line in something like typename S::size_type fromLen = S(from).length();