Alexandre Julliard : comctl32: Get rid of CharNextW/CharPrevW.
Simplify some string functions.
Alexandre Julliard
julliard at wine.codeweavers.com
Mon Jun 25 07:28:38 CDT 2007
Module: wine
Branch: master
Commit: 52e5d3849ffb2eb22aba2e624ff5248ec685f2d1
URL: http://source.winehq.org/git/wine.git/?a=commit;h=52e5d3849ffb2eb22aba2e624ff5248ec685f2d1
Author: Alexandre Julliard <julliard at winehq.org>
Date: Mon Jun 25 13:51:00 2007 +0200
comctl32: Get rid of CharNextW/CharPrevW. Simplify some string functions.
---
dlls/comctl32/string.c | 167 ++++++++++++++----------------------------------
1 files changed, 49 insertions(+), 118 deletions(-)
diff --git a/dlls/comctl32/string.c b/dlls/comctl32/string.c
index 654c467..f6dbd8c 100644
--- a/dlls/comctl32/string.c
+++ b/dlls/comctl32/string.c
@@ -81,22 +81,6 @@ static BOOL COMCTL32_ChrCmpHelperA(WORD ch1, WORD ch2, DWORD dwFlags)
}
/*************************************************************************
- * COMCTL32_ChrCmpHelperW
- *
- * Internal helper for COMCTL32_ChrCmpW/ChrCmpIW.
- */
-static BOOL COMCTL32_ChrCmpHelperW(WCHAR ch1, WCHAR ch2, DWORD dwFlags)
-{
- WCHAR str1[2], str2[2];
-
- str1[0] = ch1;
- str1[1] = '\0';
- str2[0] = ch2;
- str2[1] = '\0';
- return CompareStringW(GetThreadLocale(), dwFlags, str1, 2, str2, 2) - 2;
-}
-
-/*************************************************************************
* COMCTL32_ChrCmpA (internal)
*
* Internal helper function.
@@ -127,23 +111,13 @@ static BOOL COMCTL32_ChrCmpIA(WORD ch1, WORD ch2)
}
/*************************************************************************
- * COMCTL32_ChrCmpW
- *
- * Internal helper function.
- */
-static BOOL COMCTL32_ChrCmpW(WCHAR ch1, WCHAR ch2)
-{
- return COMCTL32_ChrCmpHelperW(ch1, ch2, 0);
-}
-
-/*************************************************************************
* COMCTL32_ChrCmpIW
*
* Internal helper function.
*/
-static BOOL COMCTL32_ChrCmpIW(WCHAR ch1, WCHAR ch2)
+static inline BOOL COMCTL32_ChrCmpIW(WCHAR ch1, WCHAR ch2)
{
- return COMCTL32_ChrCmpHelperW(ch1, ch2, NORM_IGNORECASE);
+ return CompareStringW(GetThreadLocale(), NORM_IGNORECASE, &ch1, 1, &ch2, 1) - 2;
}
/**************************************************************************
@@ -372,30 +346,6 @@ static LPSTR COMCTL32_StrStrHelperA(LPCSTR lpszStr, LPCSTR lpszSearch,
return NULL;
}
-/*************************************************************************
- * COMCTL32_StrStrHelperW
- *
- * Internal implementation of StrStrW/StrStrIW
- */
-static LPWSTR COMCTL32_StrStrHelperW(LPCWSTR lpszStr, LPCWSTR lpszSearch,
- INT (WINAPI *pStrCmpFn)(LPCWSTR,LPCWSTR,INT))
-{
- int iLen;
-
- if (!lpszStr || !lpszSearch || !*lpszSearch)
- return NULL;
-
- iLen = strlenW(lpszSearch);
-
- while (*lpszStr)
- {
- if (!pStrCmpFn(lpszStr, lpszSearch, iLen))
- return (LPWSTR)lpszStr;
- lpszStr = CharNextW(lpszStr);
- }
- return NULL;
-}
-
/**************************************************************************
* StrStrIA [COMCTL32.355]
*
@@ -439,9 +389,22 @@ INT WINAPI StrToIntA (LPCSTR lpszStr)
*/
LPWSTR WINAPI StrStrIW(LPCWSTR lpszStr, LPCWSTR lpszSearch)
{
+ int iLen;
+
TRACE("(%s,%s)\n", debugstr_w(lpszStr), debugstr_w(lpszSearch));
- return COMCTL32_StrStrHelperW(lpszStr, lpszSearch, StrCmpNIW);
+ if (!lpszStr || !lpszSearch || !*lpszSearch)
+ return NULL;
+
+ iLen = strlenW(lpszSearch);
+
+ while (*lpszStr)
+ {
+ if (!StrCmpNIW(lpszStr, lpszSearch, iLen))
+ return (LPWSTR)lpszStr;
+ lpszStr++;
+ }
+ return NULL;
}
/**************************************************************************
@@ -602,25 +565,18 @@ LPSTR WINAPI StrRChrA(LPCSTR lpszStr, LPCSTR lpszEnd, WORD ch)
*
* See StrRChrA.
*/
-LPWSTR WINAPI StrRChrW(LPCWSTR lpszStr, LPCWSTR lpszEnd, WORD ch)
+LPWSTR WINAPI StrRChrW(LPCWSTR str, LPCWSTR end, WORD ch)
{
- LPCWSTR lpszRet = NULL;
-
- TRACE("(%s,%s,%x)\n", debugstr_w(lpszStr), debugstr_w(lpszEnd), ch);
-
- if (lpszStr)
- {
- if (!lpszEnd)
- lpszEnd = lpszStr + strlenW(lpszStr);
+ WCHAR *ret = NULL;
- while (*lpszStr && lpszStr <= lpszEnd)
+ if (!str) return NULL;
+ if (!end) end = str + strlenW(str);
+ while (str < end)
{
- if (!COMCTL32_ChrCmpW(ch, *lpszStr))
- lpszRet = lpszStr;
- lpszStr = CharNextW(lpszStr);
+ if (*str == ch) ret = (WCHAR *)str;
+ str++;
}
- }
- return (LPWSTR)lpszRet;
+ return ret;
}
/**************************************************************************
@@ -649,9 +605,8 @@ LPSTR WINAPI StrStrA(LPCSTR lpszStr, LPCSTR lpszSearch)
*/
LPWSTR WINAPI StrStrW(LPCWSTR lpszStr, LPCWSTR lpszSearch)
{
- TRACE("(%s,%s)\n", debugstr_w(lpszStr), debugstr_w(lpszSearch));
-
- return COMCTL32_StrStrHelperW(lpszStr, lpszSearch, StrCmpNW);
+ if (!lpszStr || !lpszSearch) return NULL;
+ return strstrW( lpszStr, lpszSearch );
}
/*************************************************************************
@@ -700,7 +655,7 @@ LPWSTR WINAPI StrChrIW(LPCWSTR lpszStr, WCHAR ch)
{
if (toupperW(*lpszStr) == ch)
return (LPWSTR)lpszStr;
- lpszStr = CharNextW(lpszStr);
+ lpszStr++;
}
lpszStr = NULL;
}
@@ -780,38 +735,12 @@ LPWSTR WINAPI StrRStrIW(LPCWSTR lpszStr, LPCWSTR lpszEnd, LPCWSTR lpszSearch)
if (!StrCmpNIW(lpszStr, lpszSearch, iLen))
lpszRet = (LPWSTR)lpszStr;
}
- lpszStr = CharNextW(lpszStr);
+ lpszStr++;
}
return lpszRet;
}
/*************************************************************************
- * COMCTL32_StrSpnHelperW
- *
- * Internal implementation of StrSpnW/StrCSpnW/StrCSpnIW
- */
-static int COMCTL32_StrSpnHelperW(LPCWSTR lpszStr, LPCWSTR lpszMatch,
- LPWSTR (WINAPI *pStrChrFn)(LPCWSTR,WCHAR),
- BOOL bInvert)
-{
- LPCWSTR lpszRead = lpszStr;
- if (lpszStr && *lpszStr && lpszMatch)
- {
- while (*lpszRead)
- {
- LPCWSTR lpszTest = pStrChrFn(lpszMatch, *lpszRead);
-
- if (!bInvert && !lpszTest)
- break;
- if (bInvert && lpszTest)
- break;
- lpszRead = CharNextW(lpszRead);
- };
- }
- return lpszRead - lpszStr;
-}
-
-/*************************************************************************
* StrCSpnIA [COMCTL32.374]
*
* Find the length of the start of a string that does not contain certain
@@ -839,9 +768,19 @@ int WINAPI StrCSpnIA(LPCSTR lpszStr, LPCSTR lpszMatch)
*/
int WINAPI StrCSpnIW(LPCWSTR lpszStr, LPCWSTR lpszMatch)
{
+ LPCWSTR lpszRead = lpszStr;
+
TRACE("(%s,%s)\n",debugstr_w(lpszStr), debugstr_w(lpszMatch));
- return COMCTL32_StrSpnHelperW(lpszStr, lpszMatch, StrChrIW, TRUE);
+ if (lpszStr && *lpszStr && lpszMatch)
+ {
+ while (*lpszRead)
+ {
+ if (StrChrIW(lpszMatch, *lpszRead)) break;
+ lpszRead++;
+ }
+ }
+ return lpszRead - lpszStr;
}
/**************************************************************************
@@ -889,25 +828,18 @@ LPSTR WINAPI StrRChrIA(LPCSTR lpszStr, LPCSTR lpszEnd, WORD ch)
*
* See StrRChrIA.
*/
-LPWSTR WINAPI StrRChrIW(LPCWSTR lpszStr, LPCWSTR lpszEnd, WORD ch)
+LPWSTR WINAPI StrRChrIW(LPCWSTR str, LPCWSTR end, WORD ch)
{
- LPCWSTR lpszRet = NULL;
-
- TRACE("(%s,%s,%x)\n", debugstr_w(lpszStr), debugstr_w(lpszEnd), ch);
-
- if (lpszStr)
- {
- if (!lpszEnd)
- lpszEnd = lpszStr + strlenW(lpszStr);
+ WCHAR *ret = NULL;
- while (*lpszStr && lpszStr <= lpszEnd)
+ if (!str) return NULL;
+ if (!end) end = str + strlenW(str);
+ while (str < end)
{
- if (ch == *lpszStr)
- lpszRet = lpszStr;
- lpszStr = CharNextW(lpszStr);
+ if (!COMCTL32_ChrCmpIW(*str, ch)) ret = (WCHAR *)str;
+ str++;
}
- }
- return (LPWSTR)lpszRet;
+ return ret;
}
/*************************************************************************
@@ -917,9 +849,8 @@ LPWSTR WINAPI StrRChrIW(LPCWSTR lpszStr, LPCWSTR lpszEnd, WORD ch)
*/
int WINAPI StrCSpnW(LPCWSTR lpszStr, LPCWSTR lpszMatch)
{
- TRACE("(%s,%s)\n",debugstr_w(lpszStr), debugstr_w(lpszMatch));
-
- return COMCTL32_StrSpnHelperW(lpszStr, lpszMatch, StrChrW, TRUE);
+ if (!lpszStr || !lpszMatch) return 0;
+ return strcspnW( lpszStr, lpszMatch );
}
/*************************************************************************
More information about the wine-cvs
mailing list