mirror of
https://github.com/NoelFB/blah.git
synced 2024-11-28 16:58:57 +08:00
fixed Str::replace
This commit is contained in:
parent
78b8140f53
commit
63c2493fd3
|
@ -404,12 +404,12 @@ Str& Str::replace(const Str& os, const Str& ns)
|
|||
{
|
||||
for (int i = 0; i < m_length - os.m_length + 1; i++)
|
||||
{
|
||||
if (strcmp(data() + i, os.data()) == 0)
|
||||
if (strncmp(data() + i, os.data(), os.m_length) == 0)
|
||||
{
|
||||
if (ns.m_length > os.m_length)
|
||||
reserve(ns.m_length - os.m_length);
|
||||
|
||||
memcpy(data() + i + os.m_length, data() + i + ns.m_length, m_length - i - os.m_length);
|
||||
memmove(data() + i + ns.m_length, data() + i + os.m_length, m_length - i - os.m_length);
|
||||
memcpy(data() + i, ns.cstr(), ns.m_length);
|
||||
set_length(m_length + ns.m_length - os.m_length);
|
||||
i += os.m_length - 1;
|
||||
|
|
Loading…
Reference in New Issue
Block a user