d3d8: Get rid of the format switching code in d3d8_device_CopyRects().
[wine.git] / dlls / comctl32 / string.c
bloba9544fa8d23697b78dfda1957fb6d7e414c9c147
1 /*
2 * String manipulation functions
4 * Copyright 1998 Eric Kohl
5 * 1998 Juergen Schmied <j.schmied@metronet.de>
6 * 2000 Eric Kohl for CodeWeavers
7 * Copyright 2002 Jon Griffiths
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include "config.h"
26 #include "wine/port.h"
28 #include <stdarg.h>
29 #include <string.h>
30 #include <stdlib.h> /* atoi */
32 #include "windef.h"
33 #include "winbase.h"
34 #include "winuser.h"
35 #include "winnls.h"
37 #include "comctl32.h"
39 #include "wine/unicode.h"
41 #include "wine/debug.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(commctrl);
45 /*************************************************************************
46 * COMCTL32_ChrCmpHelperA
48 * Internal helper for ChrCmpA/COMCTL32_ChrCmpIA.
50 * NOTES
51 * Both this function and its Unicode counterpart are very inefficient. To
52 * fix this, CompareString must be completely implemented and optimised
53 * first. Then the core character test can be taken out of that function and
54 * placed here, so that it need never be called at all. Until then, do not
55 * attempt to optimise this code unless you are willing to test that it
56 * still performs correctly.
58 static BOOL COMCTL32_ChrCmpHelperA(WORD ch1, WORD ch2, DWORD dwFlags)
60 char str1[3], str2[3];
62 str1[0] = LOBYTE(ch1);
63 if (IsDBCSLeadByte(str1[0]))
65 str1[1] = HIBYTE(ch1);
66 str1[2] = '\0';
68 else
69 str1[1] = '\0';
71 str2[0] = LOBYTE(ch2);
72 if (IsDBCSLeadByte(str2[0]))
74 str2[1] = HIBYTE(ch2);
75 str2[2] = '\0';
77 else
78 str2[1] = '\0';
80 return CompareStringA(GetThreadLocale(), dwFlags, str1, -1, str2, -1) - CSTR_EQUAL;
83 /*************************************************************************
84 * COMCTL32_ChrCmpA (internal)
86 * Internal helper function.
88 static BOOL COMCTL32_ChrCmpA(WORD ch1, WORD ch2)
90 return COMCTL32_ChrCmpHelperA(ch1, ch2, 0);
93 /*************************************************************************
94 * COMCTL32_ChrCmpIA (internal)
96 * Compare two characters, ignoring case.
98 * PARAMS
99 * ch1 [I] First character to compare
100 * ch2 [I] Second character to compare
102 * RETURNS
103 * FALSE, if the characters are equal.
104 * Non-zero otherwise.
106 static BOOL COMCTL32_ChrCmpIA(WORD ch1, WORD ch2)
108 TRACE("(%d,%d)\n", ch1, ch2);
110 return COMCTL32_ChrCmpHelperA(ch1, ch2, NORM_IGNORECASE);
113 /*************************************************************************
114 * COMCTL32_ChrCmpIW
116 * Internal helper function.
118 static inline BOOL COMCTL32_ChrCmpIW(WCHAR ch1, WCHAR ch2)
120 return CompareStringW(GetThreadLocale(), NORM_IGNORECASE, &ch1, 1, &ch2, 1) - CSTR_EQUAL;
123 /**************************************************************************
124 * Str_GetPtrA [COMCTL32.233]
126 * Copies a string into a destination buffer.
128 * PARAMS
129 * lpSrc [I] Source string
130 * lpDest [O] Destination buffer
131 * nMaxLen [I] Size of buffer in characters
133 * RETURNS
134 * The number of characters copied.
136 INT WINAPI Str_GetPtrA (LPCSTR lpSrc, LPSTR lpDest, INT nMaxLen)
138 INT len;
140 TRACE("(%p %p %d)\n", lpSrc, lpDest, nMaxLen);
142 if ((!lpDest || nMaxLen == 0) && lpSrc)
143 return (strlen(lpSrc) + 1);
145 if (nMaxLen == 0)
146 return 0;
148 if (lpSrc == NULL) {
149 lpDest[0] = '\0';
150 return 0;
153 len = strlen(lpSrc) + 1;
154 if (len >= nMaxLen)
155 len = nMaxLen;
157 RtlMoveMemory (lpDest, lpSrc, len - 1);
158 lpDest[len - 1] = '\0';
160 return len;
163 /**************************************************************************
164 * Str_SetPtrA [COMCTL32.234]
166 * Makes a copy of a string, allocating memory if necessary.
168 * PARAMS
169 * lppDest [O] Pointer to destination string
170 * lpSrc [I] Source string
172 * RETURNS
173 * Success: TRUE
174 * Failure: FALSE
176 * NOTES
177 * Set lpSrc to NULL to free the memory allocated by a previous call
178 * to this function.
180 BOOL WINAPI Str_SetPtrA (LPSTR *lppDest, LPCSTR lpSrc)
182 TRACE("(%p %p)\n", lppDest, lpSrc);
184 if (lpSrc) {
185 LPSTR ptr = ReAlloc (*lppDest, strlen (lpSrc) + 1);
186 if (!ptr)
187 return FALSE;
188 strcpy (ptr, lpSrc);
189 *lppDest = ptr;
191 else {
192 Free (*lppDest);
193 *lppDest = NULL;
196 return TRUE;
199 /**************************************************************************
200 * Str_GetPtrW [COMCTL32.235]
202 * See Str_GetPtrA.
204 INT WINAPI Str_GetPtrW (LPCWSTR lpSrc, LPWSTR lpDest, INT nMaxLen)
206 INT len;
208 TRACE("(%p %p %d)\n", lpSrc, lpDest, nMaxLen);
210 if (!lpDest && lpSrc)
211 return strlenW (lpSrc);
213 if (nMaxLen == 0)
214 return 0;
216 if (lpSrc == NULL) {
217 lpDest[0] = '\0';
218 return 0;
221 len = strlenW (lpSrc);
222 if (len >= nMaxLen)
223 len = nMaxLen - 1;
225 RtlMoveMemory (lpDest, lpSrc, len*sizeof(WCHAR));
226 lpDest[len] = '\0';
228 return len;
231 /**************************************************************************
232 * Str_SetPtrW [COMCTL32.236]
234 * See Str_SetPtrA.
236 BOOL WINAPI Str_SetPtrW (LPWSTR *lppDest, LPCWSTR lpSrc)
238 TRACE("(%p %s)\n", lppDest, debugstr_w(lpSrc));
240 if (lpSrc) {
241 INT len = strlenW (lpSrc) + 1;
242 LPWSTR ptr = ReAlloc (*lppDest, len * sizeof(WCHAR));
243 if (!ptr)
244 return FALSE;
245 strcpyW (ptr, lpSrc);
246 *lppDest = ptr;
248 else {
249 Free (*lppDest);
250 *lppDest = NULL;
253 return TRUE;
256 /**************************************************************************
257 * StrChrA [COMCTL32.350]
259 * Find a given character in a string.
261 * PARAMS
262 * lpszStr [I] String to search in.
263 * ch [I] Character to search for.
265 * RETURNS
266 * Success: A pointer to the first occurrence of ch in lpszStr, or NULL if
267 * not found.
268 * Failure: NULL, if any arguments are invalid.
270 LPSTR WINAPI StrChrA(LPCSTR lpszStr, WORD ch)
272 TRACE("(%s,%i)\n", debugstr_a(lpszStr), ch);
274 if (lpszStr)
276 while (*lpszStr)
278 if (!COMCTL32_ChrCmpA(*lpszStr, ch))
279 return (LPSTR)lpszStr;
280 lpszStr = CharNextA(lpszStr);
283 return NULL;
286 /**************************************************************************
287 * StrCmpNIA [COMCTL32.353]
289 * Compare two strings, up to a maximum length, ignoring case.
291 * PARAMS
292 * lpszStr [I] First string to compare
293 * lpszComp [I] Second string to compare
294 * iLen [I] Maximum number of chars to compare.
296 * RETURNS
297 * An integer less than, equal to or greater than 0, indicating that
298 * lpszStr is less than, the same, or greater than lpszComp.
300 INT WINAPI StrCmpNIA(LPCSTR lpszStr, LPCSTR lpszComp, INT iLen)
302 TRACE("(%s,%s,%i)\n", debugstr_a(lpszStr), debugstr_a(lpszComp), iLen);
303 return CompareStringA(GetThreadLocale(), NORM_IGNORECASE, lpszStr, iLen, lpszComp, iLen) - CSTR_EQUAL;
306 /*************************************************************************
307 * StrCmpNIW [COMCTL32.361]
309 * See StrCmpNIA.
311 INT WINAPI StrCmpNIW(LPCWSTR lpszStr, LPCWSTR lpszComp, INT iLen)
313 TRACE("(%s,%s,%i)\n", debugstr_w(lpszStr), debugstr_w(lpszComp), iLen);
314 return CompareStringW(GetThreadLocale(), NORM_IGNORECASE, lpszStr, iLen, lpszComp, iLen) - CSTR_EQUAL;
317 /*************************************************************************
318 * COMCTL32_StrStrHelperA
320 * Internal implementation of StrStrA/StrStrIA
322 static LPSTR COMCTL32_StrStrHelperA(LPCSTR lpszStr, LPCSTR lpszSearch,
323 INT (WINAPI *pStrCmpFn)(LPCSTR,LPCSTR,INT))
325 size_t iLen;
327 if (!lpszStr || !lpszSearch || !*lpszSearch)
328 return NULL;
330 iLen = strlen(lpszSearch);
332 while (*lpszStr)
334 if (!pStrCmpFn(lpszStr, lpszSearch, iLen))
335 return (LPSTR)lpszStr;
336 lpszStr = CharNextA(lpszStr);
338 return NULL;
341 /**************************************************************************
342 * StrStrIA [COMCTL32.355]
344 * Find a substring within a string, ignoring case.
346 * PARAMS
347 * lpszStr [I] String to search in
348 * lpszSearch [I] String to look for
350 * RETURNS
351 * The start of lpszSearch within lpszStr, or NULL if not found.
353 LPSTR WINAPI StrStrIA(LPCSTR lpszStr, LPCSTR lpszSearch)
355 TRACE("(%s,%s)\n", debugstr_a(lpszStr), debugstr_a(lpszSearch));
357 return COMCTL32_StrStrHelperA(lpszStr, lpszSearch, StrCmpNIA);
360 /**************************************************************************
361 * StrToIntA [COMCTL32.357]
363 * Read a signed integer from a string.
365 * PARAMS
366 * lpszStr [I] String to read integer from
368 * RETURNS
369 * The signed integer value represented by the string, or 0 if no integer is
370 * present.
372 INT WINAPI StrToIntA (LPCSTR lpszStr)
374 return atoi(lpszStr);
377 /**************************************************************************
378 * StrStrIW [COMCTL32.363]
380 * See StrStrIA.
382 LPWSTR WINAPI StrStrIW(LPCWSTR lpszStr, LPCWSTR lpszSearch)
384 int iLen;
386 TRACE("(%s,%s)\n", debugstr_w(lpszStr), debugstr_w(lpszSearch));
388 if (!lpszStr || !lpszSearch || !*lpszSearch)
389 return NULL;
391 iLen = strlenW(lpszSearch);
393 while (*lpszStr)
395 if (!StrCmpNIW(lpszStr, lpszSearch, iLen))
396 return (LPWSTR)lpszStr;
397 lpszStr++;
399 return NULL;
402 /**************************************************************************
403 * StrToIntW [COMCTL32.365]
405 * See StrToIntA.
407 INT WINAPI StrToIntW (LPCWSTR lpString)
409 return atoiW(lpString);
412 /*************************************************************************
413 * COMCTL32_StrSpnHelperA (internal)
415 * Internal implementation of StrSpnA/StrCSpnA/StrCSpnIA
417 static int COMCTL32_StrSpnHelperA(LPCSTR lpszStr, LPCSTR lpszMatch,
418 LPSTR (WINAPI *pStrChrFn)(LPCSTR,WORD),
419 BOOL bInvert)
421 LPCSTR lpszRead = lpszStr;
422 if (lpszStr && *lpszStr && lpszMatch)
424 while (*lpszRead)
426 LPCSTR lpszTest = pStrChrFn(lpszMatch, *lpszRead);
428 if (!bInvert && !lpszTest)
429 break;
430 if (bInvert && lpszTest)
431 break;
432 lpszRead = CharNextA(lpszRead);
435 return lpszRead - lpszStr;
438 /**************************************************************************
439 * StrCSpnA [COMCTL32.356]
441 * Find the length of the start of a string that does not contain certain
442 * characters.
444 * PARAMS
445 * lpszStr [I] String to search
446 * lpszMatch [I] Characters that cannot be in the substring
448 * RETURNS
449 * The length of the part of lpszStr containing only chars not in lpszMatch,
450 * or 0 if any parameter is invalid.
452 int WINAPI StrCSpnA(LPCSTR lpszStr, LPCSTR lpszMatch)
454 TRACE("(%s,%s)\n",debugstr_a(lpszStr), debugstr_a(lpszMatch));
456 return COMCTL32_StrSpnHelperA(lpszStr, lpszMatch, StrChrA, TRUE);
459 /**************************************************************************
460 * StrChrW [COMCTL32.358]
462 * See StrChrA.
464 LPWSTR WINAPI StrChrW(LPCWSTR lpszStr, WCHAR ch)
466 LPWSTR lpszRet = NULL;
468 TRACE("(%s,%i)\n", debugstr_w(lpszStr), ch);
470 if (lpszStr)
471 lpszRet = strchrW(lpszStr, ch);
472 return lpszRet;
475 /**************************************************************************
476 * StrCmpNA [COMCTL32.352]
478 * Compare two strings, up to a maximum length.
480 * PARAMS
481 * lpszStr [I] First string to compare
482 * lpszComp [I] Second string to compare
483 * iLen [I] Maximum number of chars to compare.
485 * RETURNS
486 * An integer less than, equal to or greater than 0, indicating that
487 * lpszStr is less than, the same, or greater than lpszComp.
489 INT WINAPI StrCmpNA(LPCSTR lpszStr, LPCSTR lpszComp, INT iLen)
491 TRACE("(%s,%s,%i)\n", debugstr_a(lpszStr), debugstr_a(lpszComp), iLen);
492 return CompareStringA(GetThreadLocale(), 0, lpszStr, iLen, lpszComp, iLen) - CSTR_EQUAL;
495 /**************************************************************************
496 * StrCmpNW [COMCTL32.360]
498 * See StrCmpNA.
500 INT WINAPI StrCmpNW(LPCWSTR lpszStr, LPCWSTR lpszComp, INT iLen)
502 TRACE("(%s,%s,%i)\n", debugstr_w(lpszStr), debugstr_w(lpszComp), iLen);
503 return CompareStringW(GetThreadLocale(), 0, lpszStr, iLen, lpszComp, iLen) - CSTR_EQUAL;
506 /**************************************************************************
507 * StrRChrA [COMCTL32.351]
509 * Find the last occurrence of a character in string.
511 * PARAMS
512 * lpszStr [I] String to search in
513 * lpszEnd [I] Place to end search, or NULL to search until the end of lpszStr
514 * ch [I] Character to search for.
516 * RETURNS
517 * Success: A pointer to the last occurrence of ch in lpszStr before lpszEnd,
518 * or NULL if not found.
519 * Failure: NULL, if any arguments are invalid.
521 LPSTR WINAPI StrRChrA(LPCSTR lpszStr, LPCSTR lpszEnd, WORD ch)
523 LPCSTR lpszRet = NULL;
525 TRACE("(%s,%s,%x)\n", debugstr_a(lpszStr), debugstr_a(lpszEnd), ch);
527 if (lpszStr)
529 WORD ch2;
531 if (!lpszEnd)
532 lpszEnd = lpszStr + lstrlenA(lpszStr);
534 while (*lpszStr && lpszStr <= lpszEnd)
536 ch2 = IsDBCSLeadByte(*lpszStr)? *lpszStr << 8 | lpszStr[1] : *lpszStr;
538 if (!COMCTL32_ChrCmpA(ch, ch2))
539 lpszRet = lpszStr;
540 lpszStr = CharNextA(lpszStr);
543 return (LPSTR)lpszRet;
547 /**************************************************************************
548 * StrRChrW [COMCTL32.359]
550 * See StrRChrA.
552 LPWSTR WINAPI StrRChrW(LPCWSTR str, LPCWSTR end, WORD ch)
554 WCHAR *ret = NULL;
556 if (!str) return NULL;
557 if (!end) end = str + strlenW(str);
558 while (str < end)
560 if (*str == ch) ret = (WCHAR *)str;
561 str++;
563 return ret;
566 /**************************************************************************
567 * StrStrA [COMCTL32.354]
569 * Find a substring within a string.
571 * PARAMS
572 * lpszStr [I] String to search in
573 * lpszSearch [I] String to look for
575 * RETURNS
576 * The start of lpszSearch within lpszStr, or NULL if not found.
578 LPSTR WINAPI StrStrA(LPCSTR lpszStr, LPCSTR lpszSearch)
580 TRACE("(%s,%s)\n", debugstr_a(lpszStr), debugstr_a(lpszSearch));
582 return COMCTL32_StrStrHelperA(lpszStr, lpszSearch, StrCmpNA);
585 /**************************************************************************
586 * StrStrW [COMCTL32.362]
588 * See StrStrA.
590 LPWSTR WINAPI StrStrW(LPCWSTR lpszStr, LPCWSTR lpszSearch)
592 if (!lpszStr || !lpszSearch) return NULL;
593 return strstrW( lpszStr, lpszSearch );
596 /*************************************************************************
597 * StrChrIA [COMCTL32.366]
599 * Find a given character in a string, ignoring case.
601 * PARAMS
602 * lpszStr [I] String to search in.
603 * ch [I] Character to search for.
605 * RETURNS
606 * Success: A pointer to the first occurrence of ch in lpszStr, or NULL if
607 * not found.
608 * Failure: NULL, if any arguments are invalid.
610 LPSTR WINAPI StrChrIA(LPCSTR lpszStr, WORD ch)
612 TRACE("(%s,%i)\n", debugstr_a(lpszStr), ch);
614 if (lpszStr)
616 while (*lpszStr)
618 if (!COMCTL32_ChrCmpIA(*lpszStr, ch))
619 return (LPSTR)lpszStr;
620 lpszStr = CharNextA(lpszStr);
623 return NULL;
626 /*************************************************************************
627 * StrChrIW [COMCTL32.367]
629 * See StrChrA.
631 LPWSTR WINAPI StrChrIW(LPCWSTR lpszStr, WCHAR ch)
633 TRACE("(%s,%i)\n", debugstr_w(lpszStr), ch);
635 if (lpszStr)
637 ch = toupperW(ch);
638 while (*lpszStr)
640 if (toupperW(*lpszStr) == ch)
641 return (LPWSTR)lpszStr;
642 lpszStr++;
644 lpszStr = NULL;
646 return (LPWSTR)lpszStr;
649 /*************************************************************************
650 * StrRStrIA [COMCTL32.372]
652 * Find the last occurrence of a substring within a string.
654 * PARAMS
655 * lpszStr [I] String to search in
656 * lpszEnd [I] End of lpszStr
657 * lpszSearch [I] String to look for
659 * RETURNS
660 * The last occurrence lpszSearch within lpszStr, or NULL if not found.
662 LPSTR WINAPI StrRStrIA(LPCSTR lpszStr, LPCSTR lpszEnd, LPCSTR lpszSearch)
664 LPSTR lpszRet = NULL;
665 WORD ch1, ch2;
666 INT iLen;
668 TRACE("(%s,%s)\n", debugstr_a(lpszStr), debugstr_a(lpszSearch));
670 if (!lpszStr || !lpszSearch || !*lpszSearch)
671 return NULL;
673 if (!lpszEnd)
674 lpszEnd = lpszStr + lstrlenA(lpszStr);
676 if (IsDBCSLeadByte(*lpszSearch))
677 ch1 = *lpszSearch << 8 | lpszSearch[1];
678 else
679 ch1 = *lpszSearch;
680 iLen = lstrlenA(lpszSearch);
682 while (lpszStr <= lpszEnd && *lpszStr)
684 ch2 = IsDBCSLeadByte(*lpszStr)? *lpszStr << 8 | lpszStr[1] : *lpszStr;
685 if (!COMCTL32_ChrCmpIA(ch1, ch2))
687 if (!StrCmpNIA(lpszStr, lpszSearch, iLen))
688 lpszRet = (LPSTR)lpszStr;
690 lpszStr = CharNextA(lpszStr);
692 return lpszRet;
695 /*************************************************************************
696 * StrRStrIW [COMCTL32.373]
698 * See StrRStrIA.
700 LPWSTR WINAPI StrRStrIW(LPCWSTR lpszStr, LPCWSTR lpszEnd, LPCWSTR lpszSearch)
702 LPWSTR lpszRet = NULL;
703 INT iLen;
705 TRACE("(%s,%s)\n", debugstr_w(lpszStr), debugstr_w(lpszSearch));
707 if (!lpszStr || !lpszSearch || !*lpszSearch)
708 return NULL;
710 if (!lpszEnd)
711 lpszEnd = lpszStr + strlenW(lpszStr);
713 iLen = strlenW(lpszSearch);
715 while (lpszStr <= lpszEnd && *lpszStr)
717 if (!COMCTL32_ChrCmpIW(*lpszSearch, *lpszStr))
719 if (!StrCmpNIW(lpszStr, lpszSearch, iLen))
720 lpszRet = (LPWSTR)lpszStr;
722 lpszStr++;
724 return lpszRet;
727 /*************************************************************************
728 * StrCSpnIA [COMCTL32.374]
730 * Find the length of the start of a string that does not contain certain
731 * characters, ignoring case.
733 * PARAMS
734 * lpszStr [I] String to search
735 * lpszMatch [I] Characters that cannot be in the substring
737 * RETURNS
738 * The length of the part of lpszStr containing only chars not in lpszMatch,
739 * or 0 if any parameter is invalid.
741 int WINAPI StrCSpnIA(LPCSTR lpszStr, LPCSTR lpszMatch)
743 TRACE("(%s,%s)\n",debugstr_a(lpszStr), debugstr_a(lpszMatch));
745 return COMCTL32_StrSpnHelperA(lpszStr, lpszMatch, StrChrIA, TRUE);
748 /*************************************************************************
749 * StrCSpnIW [COMCTL32.375]
751 * See StrCSpnIA.
753 int WINAPI StrCSpnIW(LPCWSTR lpszStr, LPCWSTR lpszMatch)
755 LPCWSTR lpszRead = lpszStr;
757 TRACE("(%s,%s)\n",debugstr_w(lpszStr), debugstr_w(lpszMatch));
759 if (lpszStr && *lpszStr && lpszMatch)
761 while (*lpszRead)
763 if (StrChrIW(lpszMatch, *lpszRead)) break;
764 lpszRead++;
767 return lpszRead - lpszStr;
770 /**************************************************************************
771 * StrRChrIA [COMCTL32.368]
773 * Find the last occurrence of a character in string, ignoring case.
775 * PARAMS
776 * lpszStr [I] String to search in
777 * lpszEnd [I] Place to end search, or NULL to search until the end of lpszStr
778 * ch [I] Character to search for.
780 * RETURNS
781 * Success: A pointer to the last occurrence of ch in lpszStr before lpszEnd,
782 * or NULL if not found.
783 * Failure: NULL, if any arguments are invalid.
785 LPSTR WINAPI StrRChrIA(LPCSTR lpszStr, LPCSTR lpszEnd, WORD ch)
787 LPCSTR lpszRet = NULL;
789 TRACE("(%s,%s,%x)\n", debugstr_a(lpszStr), debugstr_a(lpszEnd), ch);
791 if (lpszStr)
793 WORD ch2;
795 if (!lpszEnd)
796 lpszEnd = lpszStr + lstrlenA(lpszStr);
798 while (*lpszStr && lpszStr <= lpszEnd)
800 ch2 = IsDBCSLeadByte(*lpszStr)? *lpszStr << 8 | lpszStr[1] : *lpszStr;
802 if (ch == ch2)
803 lpszRet = lpszStr;
804 lpszStr = CharNextA(lpszStr);
807 return (LPSTR)lpszRet;
810 /**************************************************************************
811 * StrRChrIW [COMCTL32.369]
813 * See StrRChrIA.
815 LPWSTR WINAPI StrRChrIW(LPCWSTR str, LPCWSTR end, WORD ch)
817 WCHAR *ret = NULL;
819 if (!str) return NULL;
820 if (!end) end = str + strlenW(str);
821 while (str < end)
823 if (!COMCTL32_ChrCmpIW(*str, ch)) ret = (WCHAR *)str;
824 str++;
826 return ret;
829 /*************************************************************************
830 * StrCSpnW [COMCTL32.364]
832 * See StrCSpnA.
834 int WINAPI StrCSpnW(LPCWSTR lpszStr, LPCWSTR lpszMatch)
836 if (!lpszStr || !lpszMatch) return 0;
837 return strcspnW( lpszStr, lpszMatch );
840 /*************************************************************************
841 * IntlStrEqWorkerA [COMCTL32.376]
843 * Compare two strings.
845 * PARAMS
846 * bCase [I] Whether to compare case sensitively
847 * lpszStr [I] First string to compare
848 * lpszComp [I] Second string to compare
849 * iLen [I] Length to compare
851 * RETURNS
852 * TRUE If the strings are equal.
853 * FALSE Otherwise.
855 BOOL WINAPI IntlStrEqWorkerA(BOOL bCase, LPCSTR lpszStr, LPCSTR lpszComp,
856 int iLen)
858 DWORD dwFlags = LOCALE_USE_CP_ACP;
859 int iRet;
861 TRACE("(%d,%s,%s,%d)\n", bCase,
862 debugstr_a(lpszStr), debugstr_a(lpszComp), iLen);
864 /* FIXME: This flag is undocumented and unknown by our CompareString.
865 * We need a define for it.
867 dwFlags = 0x10000000;
868 if (!bCase) dwFlags |= NORM_IGNORECASE;
870 iRet = CompareStringA(GetThreadLocale(),
871 dwFlags, lpszStr, iLen, lpszComp, iLen);
873 if (!iRet)
874 iRet = CompareStringA(2048, dwFlags, lpszStr, iLen, lpszComp, iLen);
876 return iRet == CSTR_EQUAL;
879 /*************************************************************************
880 * IntlStrEqWorkerW [COMCTL32.377]
882 * See IntlStrEqWorkerA.
884 BOOL WINAPI IntlStrEqWorkerW(BOOL bCase, LPCWSTR lpszStr, LPCWSTR lpszComp,
885 int iLen)
887 DWORD dwFlags;
888 int iRet;
890 TRACE("(%d,%s,%s,%d)\n", bCase,
891 debugstr_w(lpszStr),debugstr_w(lpszComp), iLen);
893 /* FIXME: This flag is undocumented and unknown by our CompareString.
894 * We need a define for it.
896 dwFlags = 0x10000000;
897 if (!bCase) dwFlags |= NORM_IGNORECASE;
899 iRet = CompareStringW(GetThreadLocale(),
900 dwFlags, lpszStr, iLen, lpszComp, iLen);
902 if (!iRet)
903 iRet = CompareStringW(2048, dwFlags, lpszStr, iLen, lpszComp, iLen);
905 return iRet == CSTR_EQUAL;