mirror of
				https://github.com/NoelFB/blah.git
				synced 2025-10-31 01:01:33 +08:00 
			
		
		
		
	fixed Str::replace
This commit is contained in:
		| @ -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; | ||||
|  | ||||
		Reference in New Issue
	
	Block a user