Hi,
On 04/02/11 08:49, Vincent Pelletier wrote:
+size_t __thiscall MSVCP_basic_string_char_find_cstr(
basic_string_char *this, const char *str, size_t offset)
+{
- const char *this_str = basic_string_char_const_ptr(this);
- const char *found = strstr(this_str+offset, str);
- if (found)
return found - this_str;
- return MSVCP_basic_string_char_npos;
+}
It's better to implement basic_string<char>::find(const char *str, size_t offset, size_t count) first and then call it in MSVCP_basic_string_char_find_cstr implementation.
basic_string may contain nullbytes, your implementation will not work in this case. cstr may contain nullbytes as well when length is specified.
Adding some tests similar to following code may be useful: basic_string<char> test = basic_string<char>("aaa"); test += '\0'; test += "bbb"; basic_string<char> test2 = basic_string<char>(test); test2 += '\0';
printf("%d %s\n", test.length(), test.c_str()); printf("%d\n", test.find("bbb", 0)); printf("%d\n", test.find(test, 0)); printf("%d\n", test.find(test.c_str(), 0, test.length())); printf("%d\n", test.find(test2, 0)); printf("%d\n", test.find(test2.c_str(), 0, test2.length()));
Cheers, Piotr