From 0443f2c7d13076e9e3da17207a8030bd376add62 Mon Sep 17 00:00:00 2001 From: Aric Stewart Date: Thu, 24 Sep 2009 07:31:17 -0500 Subject: [PATCH] shlwapi: Implement StrChrNW. --- dlls/shlwapi/shlwapi.spec | 1 + dlls/shlwapi/string.c | 19 +++++++++++++++++++ dlls/shlwapi/tests/string.c | 24 ++++++++++++++++++++++++ 3 files changed, 44 insertions(+) diff --git a/dlls/shlwapi/shlwapi.spec b/dlls/shlwapi/shlwapi.spec index 4acda49594..342772285c 100644 --- a/dlls/shlwapi/shlwapi.spec +++ b/dlls/shlwapi/shlwapi.spec @@ -757,6 +757,7 @@ @ stdcall StrChrA (str long) @ stdcall StrChrIA (str long) @ stdcall StrChrIW (wstr long) +@ stdcall StrChrNW(wstr long long) @ stdcall StrChrW (wstr long) @ stdcall StrCmpIW (wstr wstr) @ stdcall StrCmpLogicalW(wstr wstr) diff --git a/dlls/shlwapi/string.c b/dlls/shlwapi/string.c index 755360d790..cfb59ea440 100644 --- a/dlls/shlwapi/string.c +++ b/dlls/shlwapi/string.c @@ -318,6 +318,25 @@ LPWSTR WINAPI StrChrIW(LPCWSTR lpszStr, WCHAR ch) return (LPWSTR)lpszStr; } +/************************************************************************* + * StrChrNW [SHLWAPI.@] + */ +LPWSTR WINAPI StrChrNW(LPCWSTR lpszStr, WCHAR ch, UINT cchMax) +{ + TRACE("(%s(%i),%i)\n", debugstr_wn(lpszStr,cchMax), cchMax, ch); + + if (lpszStr) + { + while (*lpszStr && cchMax-- > 0) + { + if (*lpszStr == ch) + return (LPWSTR)lpszStr; + lpszStr++; + } + } + return NULL; +} + /************************************************************************* * StrCmpIW [SHLWAPI.@] * diff --git a/dlls/shlwapi/tests/string.c b/dlls/shlwapi/tests/string.c index fa50626f9a..eae890556e 100644 --- a/dlls/shlwapi/tests/string.c +++ b/dlls/shlwapi/tests/string.c @@ -58,6 +58,7 @@ static HRESULT (WINAPI *pStrRetToBufA)(STRRET*,LPCITEMIDLIST,LPSTR,UINT); static HRESULT (WINAPI *pStrRetToBufW)(STRRET*,LPCITEMIDLIST,LPWSTR,UINT); static INT (WINAPIV *pwnsprintfA)(LPSTR,INT,LPCSTR, ...); static INT (WINAPIV *pwnsprintfW)(LPWSTR,INT,LPCWSTR, ...); +static LPWSTR (WINAPI *pStrChrNW)(LPWSTR,WCHAR,UINT); static int strcmpW(const WCHAR *str1, const WCHAR *str2) { @@ -373,6 +374,27 @@ static void test_StrCpyW(void) } } +static void test_StrChrNW(void) +{ + static WCHAR string[] = {'T','e','s','t','i','n','g',' ','S','t','r','i','n','g',0}; + LPWSTR p; + + if (!pStrChrNW) + { + win_skip("StrChrNW not available\n"); + return; + } + + p = pStrChrNW(string,'t',10); + ok(*p=='t',"Found wrong 't'\n"); + ok(*(p+1)=='i',"next should be 'i'\n"); + + p = pStrChrNW(string,'S',10); + ok(*p=='S',"Found wrong 'S'\n"); + + p = pStrChrNW(string,'r',10); + ok(p==NULL,"Should not have found 'r'\n"); +} static void test_StrToIntA(void) { @@ -911,6 +933,7 @@ START_TEST(string) pStrCatBuffW = (void *)GetProcAddress(hShlwapi, "StrCatBuffW"); pStrCpyNXA = (void *)GetProcAddress(hShlwapi, (LPSTR)399); pStrCpyNXW = (void *)GetProcAddress(hShlwapi, (LPSTR)400); + pStrChrNW = (void *)GetProcAddress(hShlwapi, "StrChrNW"); pStrFormatByteSize64A = (void *)GetProcAddress(hShlwapi, "StrFormatByteSize64A"); pStrFormatKBSizeA = (void *)GetProcAddress(hShlwapi, "StrFormatKBSizeA"); pStrFormatKBSizeW = (void *)GetProcAddress(hShlwapi, "StrFormatKBSizeW"); @@ -929,6 +952,7 @@ START_TEST(string) test_StrRChrA(); test_StrRChrW(); test_StrCpyW(); + test_StrChrNW(); test_StrToIntA(); test_StrToIntW(); test_StrToIntExA();