From 90cb553e5eaec08187e325a5eb7ec8f3c393ac5b Mon Sep 17 00:00:00 2001 From: Daniel Lehman Date: Wed, 12 Sep 2012 16:13:47 -0700 Subject: [PATCH] msvcp90: Return last index in string::find_last_not_of_cstr_substr if input is empty. --- dlls/msvcp90/string.c | 4 +-- dlls/msvcp90/tests/string.c | 59 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 2 deletions(-) diff --git a/dlls/msvcp90/string.c b/dlls/msvcp90/string.c index 23322fe8afb..f412ddb7758 100644 --- a/dlls/msvcp90/string.c +++ b/dlls/msvcp90/string.c @@ -1837,7 +1837,7 @@ MSVCP_size_t __thiscall MSVCP_basic_string_char_find_last_not_of_cstr_substr( TRACE("%p %p %lu %lu\n", this, find, off, len); - if(len>0 && this->size>0) { + if(this->size>0) { if(off >= this->size) off = this->size-1; @@ -3861,7 +3861,7 @@ MSVCP_size_t __thiscall MSVCP_basic_string_wchar_find_last_not_of_cstr_substr( TRACE("%p %p %lu %lu\n", this, find, off, len); - if(len>0 && this->size>0) { + if(this->size>0) { if(off >= this->size) off = this->size-1; diff --git a/dlls/msvcp90/tests/string.c b/dlls/msvcp90/tests/string.c index 511d846a2de..6cc06ce5af5 100644 --- a/dlls/msvcp90/tests/string.c +++ b/dlls/msvcp90/tests/string.c @@ -78,6 +78,7 @@ static int (__thiscall *p_basic_string_char_compare_substr_cstr_len)(basic_strin static size_t (__thiscall *p_basic_string_char_find_cstr_substr)(basic_string_char*, const char*, size_t, size_t); static size_t (__thiscall *p_basic_string_char_rfind_cstr_substr)(basic_string_char*, const char*, size_t, size_t); static basic_string_char* (__thiscall *p_basic_string_char_replace_cstr)(basic_string_char*, size_t, size_t, const char*); +static size_t (__thiscall *p_basic_string_char_find_last_not_of_cstr_substr)(const basic_string_char*, const char*, size_t, size_t); static size_t *p_basic_string_char_npos; @@ -229,6 +230,8 @@ static BOOL init(void) "?rfind@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEBA_KPEBD_K1@Z"); SET(p_basic_string_char_replace_cstr, "?replace@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAAAEAV12@_K0PEBD@Z"); + SET(p_basic_string_char_find_last_not_of_cstr_substr, + "?find_last_not_of@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEBA_KPEBD_K1@Z"); SET(p_basic_string_char_npos, "?npos@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@2_KB"); @@ -295,6 +298,8 @@ static BOOL init(void) "?rfind@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEIPBDII@Z"); SET(p_basic_string_char_replace_cstr, "?replace@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV12@IIPBD@Z"); + SET(p_basic_string_char_find_last_not_of_cstr_substr, + "?find_last_not_of@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEIPBDII@Z"); SET(p_basic_string_char_npos, "?npos@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@2IB"); @@ -708,6 +713,59 @@ static void test_basic_string_wchar_swap(void) { call_func1(p_basic_string_wchar_dtor, &str2); } +static void test_basic_string_char_find_last_not_of(void) { + struct find_last_not_of_test { + const char *str; + const char *find; + size_t off; + size_t len; + size_t ret; + }; + + int i; + size_t ret; + basic_string_char str; + struct find_last_not_of_test tests[] = { + /* simple cases where find is not in string */ + { "AAAAA", "B", 0, 1, 0 }, + { "AAAAA", "B", 5, 1, 4 }, + { "AAAAA", "BCDE", 0, 4, 0 }, + { "AAAAA", "BCDE", 5, 4, 4 }, + + /* simple cases where find is in string */ + { "AAAAA", "A", 5, 1, -1 }, + { "AAAAB", "A", 5, 1, 4 }, + { "AAAAB", "A", 4, 1, 4 }, + { "AAAAB", "A", 3, 1, -1 }, + { "ABCDE", "ABCDE", 0, 5, -1 }, + { "ABCDE", "ABCDE", 5, 5, -1 }, + { "ABCDE", "AB DE", 5, 5, 2 }, + + /* cases where find appears in multiple spots */ + { "ABABA", "A", 0, 1, -1 }, + { "ABABA", "A", 1, 1, 1 }, + { "ABABA", "A", 2, 1, 1 }, + { "ABABA", "A", 3, 1, 3 }, + + /* using empty strings */ + { "", "", 0, 0, -1 }, + { "", "A", 0, 1, -1 }, + { "ABCDE", "", 0, 0, 0 }, + { "ABCDE", "", 3, 0, 3 }, + { "ABCDE", "", 5, 0, 4 }, + }; + + for(i=0; i