mirror of
git://source.winehq.org/git/wine.git
synced 2024-09-15 07:40:21 +00:00
comctl32: Get rid of CharNextW/CharPrevW. Simplify some string functions.
This commit is contained in:
parent
73032be74a
commit
52e5d3849f
|
@ -80,22 +80,6 @@ static BOOL COMCTL32_ChrCmpHelperA(WORD ch1, WORD ch2, DWORD dwFlags)
|
||||||
return CompareStringA(GetThreadLocale(), dwFlags, str1, -1, str2, -1) - 2;
|
return CompareStringA(GetThreadLocale(), dwFlags, str1, -1, str2, -1) - 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*************************************************************************
|
|
||||||
* 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)
|
* COMCTL32_ChrCmpA (internal)
|
||||||
*
|
*
|
||||||
|
@ -126,24 +110,14 @@ static BOOL COMCTL32_ChrCmpIA(WORD ch1, WORD ch2)
|
||||||
return COMCTL32_ChrCmpHelperA(ch1, ch2, NORM_IGNORECASE);
|
return COMCTL32_ChrCmpHelperA(ch1, ch2, NORM_IGNORECASE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*************************************************************************
|
|
||||||
* COMCTL32_ChrCmpW
|
|
||||||
*
|
|
||||||
* Internal helper function.
|
|
||||||
*/
|
|
||||||
static BOOL COMCTL32_ChrCmpW(WCHAR ch1, WCHAR ch2)
|
|
||||||
{
|
|
||||||
return COMCTL32_ChrCmpHelperW(ch1, ch2, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
* COMCTL32_ChrCmpIW
|
* COMCTL32_ChrCmpIW
|
||||||
*
|
*
|
||||||
* Internal helper function.
|
* 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;
|
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]
|
* StrStrIA [COMCTL32.355]
|
||||||
*
|
*
|
||||||
|
@ -439,9 +389,22 @@ INT WINAPI StrToIntA (LPCSTR lpszStr)
|
||||||
*/
|
*/
|
||||||
LPWSTR WINAPI StrStrIW(LPCWSTR lpszStr, LPCWSTR lpszSearch)
|
LPWSTR WINAPI StrStrIW(LPCWSTR lpszStr, LPCWSTR lpszSearch)
|
||||||
{
|
{
|
||||||
|
int iLen;
|
||||||
|
|
||||||
TRACE("(%s,%s)\n", debugstr_w(lpszStr), debugstr_w(lpszSearch));
|
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.
|
* See StrRChrA.
|
||||||
*/
|
*/
|
||||||
LPWSTR WINAPI StrRChrW(LPCWSTR lpszStr, LPCWSTR lpszEnd, WORD ch)
|
LPWSTR WINAPI StrRChrW(LPCWSTR str, LPCWSTR end, WORD ch)
|
||||||
{
|
{
|
||||||
LPCWSTR lpszRet = NULL;
|
WCHAR *ret = NULL;
|
||||||
|
|
||||||
TRACE("(%s,%s,%x)\n", debugstr_w(lpszStr), debugstr_w(lpszEnd), ch);
|
if (!str) return NULL;
|
||||||
|
if (!end) end = str + strlenW(str);
|
||||||
if (lpszStr)
|
while (str < end)
|
||||||
{
|
|
||||||
if (!lpszEnd)
|
|
||||||
lpszEnd = lpszStr + strlenW(lpszStr);
|
|
||||||
|
|
||||||
while (*lpszStr && lpszStr <= lpszEnd)
|
|
||||||
{
|
{
|
||||||
if (!COMCTL32_ChrCmpW(ch, *lpszStr))
|
if (*str == ch) ret = (WCHAR *)str;
|
||||||
lpszRet = lpszStr;
|
str++;
|
||||||
lpszStr = CharNextW(lpszStr);
|
|
||||||
}
|
}
|
||||||
}
|
return ret;
|
||||||
return (LPWSTR)lpszRet;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
|
@ -649,9 +605,8 @@ LPSTR WINAPI StrStrA(LPCSTR lpszStr, LPCSTR lpszSearch)
|
||||||
*/
|
*/
|
||||||
LPWSTR WINAPI StrStrW(LPCWSTR lpszStr, LPCWSTR lpszSearch)
|
LPWSTR WINAPI StrStrW(LPCWSTR lpszStr, LPCWSTR lpszSearch)
|
||||||
{
|
{
|
||||||
TRACE("(%s,%s)\n", debugstr_w(lpszStr), debugstr_w(lpszSearch));
|
if (!lpszStr || !lpszSearch) return NULL;
|
||||||
|
return strstrW( lpszStr, lpszSearch );
|
||||||
return COMCTL32_StrStrHelperW(lpszStr, lpszSearch, StrCmpNW);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
|
@ -700,7 +655,7 @@ LPWSTR WINAPI StrChrIW(LPCWSTR lpszStr, WCHAR ch)
|
||||||
{
|
{
|
||||||
if (toupperW(*lpszStr) == ch)
|
if (toupperW(*lpszStr) == ch)
|
||||||
return (LPWSTR)lpszStr;
|
return (LPWSTR)lpszStr;
|
||||||
lpszStr = CharNextW(lpszStr);
|
lpszStr++;
|
||||||
}
|
}
|
||||||
lpszStr = NULL;
|
lpszStr = NULL;
|
||||||
}
|
}
|
||||||
|
@ -780,37 +735,11 @@ LPWSTR WINAPI StrRStrIW(LPCWSTR lpszStr, LPCWSTR lpszEnd, LPCWSTR lpszSearch)
|
||||||
if (!StrCmpNIW(lpszStr, lpszSearch, iLen))
|
if (!StrCmpNIW(lpszStr, lpszSearch, iLen))
|
||||||
lpszRet = (LPWSTR)lpszStr;
|
lpszRet = (LPWSTR)lpszStr;
|
||||||
}
|
}
|
||||||
lpszStr = CharNextW(lpszStr);
|
lpszStr++;
|
||||||
}
|
}
|
||||||
return lpszRet;
|
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]
|
* StrCSpnIA [COMCTL32.374]
|
||||||
*
|
*
|
||||||
|
@ -839,9 +768,19 @@ int WINAPI StrCSpnIA(LPCSTR lpszStr, LPCSTR lpszMatch)
|
||||||
*/
|
*/
|
||||||
int WINAPI StrCSpnIW(LPCWSTR lpszStr, LPCWSTR lpszMatch)
|
int WINAPI StrCSpnIW(LPCWSTR lpszStr, LPCWSTR lpszMatch)
|
||||||
{
|
{
|
||||||
|
LPCWSTR lpszRead = lpszStr;
|
||||||
|
|
||||||
TRACE("(%s,%s)\n",debugstr_w(lpszStr), debugstr_w(lpszMatch));
|
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.
|
* See StrRChrIA.
|
||||||
*/
|
*/
|
||||||
LPWSTR WINAPI StrRChrIW(LPCWSTR lpszStr, LPCWSTR lpszEnd, WORD ch)
|
LPWSTR WINAPI StrRChrIW(LPCWSTR str, LPCWSTR end, WORD ch)
|
||||||
{
|
{
|
||||||
LPCWSTR lpszRet = NULL;
|
WCHAR *ret = NULL;
|
||||||
|
|
||||||
TRACE("(%s,%s,%x)\n", debugstr_w(lpszStr), debugstr_w(lpszEnd), ch);
|
if (!str) return NULL;
|
||||||
|
if (!end) end = str + strlenW(str);
|
||||||
if (lpszStr)
|
while (str < end)
|
||||||
{
|
|
||||||
if (!lpszEnd)
|
|
||||||
lpszEnd = lpszStr + strlenW(lpszStr);
|
|
||||||
|
|
||||||
while (*lpszStr && lpszStr <= lpszEnd)
|
|
||||||
{
|
{
|
||||||
if (ch == *lpszStr)
|
if (!COMCTL32_ChrCmpIW(*str, ch)) ret = (WCHAR *)str;
|
||||||
lpszRet = lpszStr;
|
str++;
|
||||||
lpszStr = CharNextW(lpszStr);
|
|
||||||
}
|
}
|
||||||
}
|
return ret;
|
||||||
return (LPWSTR)lpszRet;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
|
@ -917,9 +849,8 @@ LPWSTR WINAPI StrRChrIW(LPCWSTR lpszStr, LPCWSTR lpszEnd, WORD ch)
|
||||||
*/
|
*/
|
||||||
int WINAPI StrCSpnW(LPCWSTR lpszStr, LPCWSTR lpszMatch)
|
int WINAPI StrCSpnW(LPCWSTR lpszStr, LPCWSTR lpszMatch)
|
||||||
{
|
{
|
||||||
TRACE("(%s,%s)\n",debugstr_w(lpszStr), debugstr_w(lpszMatch));
|
if (!lpszStr || !lpszMatch) return 0;
|
||||||
|
return strcspnW( lpszStr, lpszMatch );
|
||||||
return COMCTL32_StrSpnHelperW(lpszStr, lpszMatch, StrChrW, TRUE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
|
|
Loading…
Reference in a new issue