hhctrl.ocx: Remove redundant casts.
[wine/wine-gecko.git] / dlls / comctl32 / string.c
blobc36208176723537d8cf256d01ccc85d0af176499
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) - 2;
83 /*************************************************************************
84 * COMCTL32_ChrCmpHelperW
86 * Internal helper for COMCTL32_ChrCmpW/ChrCmpIW.
88 static BOOL COMCTL32_ChrCmpHelperW(WCHAR ch1, WCHAR ch2, DWORD dwFlags)
90 WCHAR str1[2], str2[2];
92 str1[0] = ch1;
93 str1[1] = '\0';
94 str2[0] = ch2;
95 str2[1] = '\0';
96 return CompareStringW(GetThreadLocale(), dwFlags, str1, 2, str2, 2) - 2;
99 /*************************************************************************
100 * COMCTL32_ChrCmpA (internal)
102 * Internal helper function.
104 static BOOL COMCTL32_ChrCmpA(WORD ch1, WORD ch2)
106 return COMCTL32_ChrCmpHelperA(ch1, ch2, 0);
109 /*************************************************************************
110 * COMCTL32_ChrCmpIA (internal)
112 * Compare two characters, ignoring case.
114 * PARAMS
115 * ch1 [I] First character to compare
116 * ch2 [I] Second character to compare
118 * RETURNS
119 * FALSE, if the characters are equal.
120 * Non-zero otherwise.
122 static BOOL COMCTL32_ChrCmpIA(WORD ch1, WORD ch2)
124 TRACE("(%d,%d)\n", ch1, ch2);
126 return COMCTL32_ChrCmpHelperA(ch1, ch2, NORM_IGNORECASE);
129 /*************************************************************************
130 * COMCTL32_ChrCmpW
132 * Internal helper function.
134 static BOOL COMCTL32_ChrCmpW(WCHAR ch1, WCHAR ch2)
136 return COMCTL32_ChrCmpHelperW(ch1, ch2, 0);
139 /*************************************************************************
140 * COMCTL32_ChrCmpIW
142 * Internal helper function.
144 static BOOL COMCTL32_ChrCmpIW(WCHAR ch1, WCHAR ch2)
146 return COMCTL32_ChrCmpHelperW(ch1, ch2, NORM_IGNORECASE);
149 /**************************************************************************
150 * Str_GetPtrA [COMCTL32.233]
152 * Copies a string into a destination buffer.
154 * PARAMS
155 * lpSrc [I] Source string
156 * lpDest [O] Destination buffer
157 * nMaxLen [I] Size of buffer in characters
159 * RETURNS
160 * The number of characters copied.
162 INT WINAPI Str_GetPtrA (LPCSTR lpSrc, LPSTR lpDest, INT nMaxLen)
164 INT len;
166 TRACE("(%p %p %d)\n", lpSrc, lpDest, nMaxLen);
168 if ((!lpDest || nMaxLen == 0) && lpSrc)
169 return (strlen(lpSrc) + 1);
171 if (nMaxLen == 0)
172 return 0;
174 if (lpSrc == NULL) {
175 lpDest[0] = '\0';
176 return 0;
179 len = strlen(lpSrc) + 1;
180 if (len >= nMaxLen)
181 len = nMaxLen;
183 RtlMoveMemory (lpDest, lpSrc, len - 1);
184 lpDest[len - 1] = '\0';
186 return len;
189 /**************************************************************************
190 * Str_SetPtrA [COMCTL32.234]
192 * Makes a copy of a string, allocating memory if necessary.
194 * PARAMS
195 * lppDest [O] Pointer to destination string
196 * lpSrc [I] Source string
198 * RETURNS
199 * Success: TRUE
200 * Failure: FALSE
202 * NOTES
203 * Set lpSrc to NULL to free the memory allocated by a previous call
204 * to this function.
206 BOOL WINAPI Str_SetPtrA (LPSTR *lppDest, LPCSTR lpSrc)
208 TRACE("(%p %p)\n", lppDest, lpSrc);
210 if (lpSrc) {
211 LPSTR ptr = ReAlloc (*lppDest, strlen (lpSrc) + 1);
212 if (!ptr)
213 return FALSE;
214 strcpy (ptr, lpSrc);
215 *lppDest = ptr;
217 else {
218 if (*lppDest) {
219 Free (*lppDest);
220 *lppDest = NULL;
224 return TRUE;
227 /**************************************************************************
228 * Str_GetPtrW [COMCTL32.235]
230 * See Str_GetPtrA.
232 INT WINAPI Str_GetPtrW (LPCWSTR lpSrc, LPWSTR lpDest, INT nMaxLen)
234 INT len;
236 TRACE("(%p %p %d)\n", lpSrc, lpDest, nMaxLen);
238 if (!lpDest && lpSrc)
239 return strlenW (lpSrc);
241 if (nMaxLen == 0)
242 return 0;
244 if (lpSrc == NULL) {
245 lpDest[0] = L'\0';
246 return 0;
249 len = strlenW (lpSrc);
250 if (len >= nMaxLen)
251 len = nMaxLen - 1;
253 RtlMoveMemory (lpDest, lpSrc, len*sizeof(WCHAR));
254 lpDest[len] = L'\0';
256 return len;
259 /**************************************************************************
260 * Str_SetPtrW [COMCTL32.236]
262 * See Str_SetPtrA.
264 BOOL WINAPI Str_SetPtrW (LPWSTR *lppDest, LPCWSTR lpSrc)
266 TRACE("(%p %p)\n", lppDest, lpSrc);
268 if (lpSrc) {
269 INT len = strlenW (lpSrc) + 1;
270 LPWSTR ptr = ReAlloc (*lppDest, len * sizeof(WCHAR));
271 if (!ptr)
272 return FALSE;
273 strcpyW (ptr, lpSrc);
274 *lppDest = ptr;
276 else {
277 if (*lppDest) {
278 Free (*lppDest);
279 *lppDest = NULL;
283 return TRUE;
286 /**************************************************************************
287 * StrChrA [COMCTL32.350]
289 * Find a given character in a string.
291 * PARAMS
292 * lpszStr [I] String to search in.
293 * ch [I] Character to search for.
295 * RETURNS
296 * Success: A pointer to the first occurrence of ch in lpszStr, or NULL if
297 * not found.
298 * Failure: NULL, if any arguments are invalid.
300 LPSTR WINAPI StrChrA(LPCSTR lpszStr, WORD ch)
302 TRACE("(%s,%i)\n", debugstr_a(lpszStr), ch);
304 if (lpszStr)
306 while (*lpszStr)
308 if (!COMCTL32_ChrCmpA(*lpszStr, ch))
309 return (LPSTR)lpszStr;
310 lpszStr = CharNextA(lpszStr);
313 return NULL;
316 /**************************************************************************
317 * StrCmpNIA [COMCTL32.353]
319 * Compare two strings, up to a maximum length, ignoring case.
321 * PARAMS
322 * lpszStr [I] First string to compare
323 * lpszComp [I] Second string to compare
324 * iLen [I] Maximum number of chars to compare.
326 * RETURNS
327 * An integer less than, equal to or greater than 0, indicating that
328 * lpszStr is less than, the same, or greater than lpszComp.
330 INT WINAPI StrCmpNIA(LPCSTR lpszStr, LPCSTR lpszComp, INT iLen)
332 INT iRet;
334 TRACE("(%s,%s,%i)\n", debugstr_a(lpszStr), debugstr_a(lpszComp), iLen);
336 iRet = CompareStringA(GetThreadLocale(), NORM_IGNORECASE, lpszStr, iLen, lpszComp, iLen);
337 return iRet == CSTR_LESS_THAN ? -1 : iRet == CSTR_GREATER_THAN ? 1 : 0;
340 /*************************************************************************
341 * StrCmpNIW [COMCTL32.361]
343 * See StrCmpNIA.
345 INT WINAPI StrCmpNIW(LPCWSTR lpszStr, LPCWSTR lpszComp, INT iLen)
347 INT iRet;
349 TRACE("(%s,%s,%i)\n", debugstr_w(lpszStr), debugstr_w(lpszComp), iLen);
351 iRet = CompareStringW(GetThreadLocale(), NORM_IGNORECASE, lpszStr, iLen, lpszComp, iLen);
352 return iRet == CSTR_LESS_THAN ? -1 : iRet == CSTR_GREATER_THAN ? 1 : 0;
355 /*************************************************************************
356 * COMCTL32_StrStrHelperA
358 * Internal implementation of StrStrA/StrStrIA
360 static LPSTR COMCTL32_StrStrHelperA(LPCSTR lpszStr, LPCSTR lpszSearch,
361 INT (WINAPI *pStrCmpFn)(LPCSTR,LPCSTR,INT))
363 size_t iLen;
365 if (!lpszStr || !lpszSearch || !*lpszSearch)
366 return NULL;
368 iLen = strlen(lpszSearch);
370 while (*lpszStr)
372 if (!pStrCmpFn(lpszStr, lpszSearch, iLen))
373 return (LPSTR)lpszStr;
374 lpszStr = CharNextA(lpszStr);
376 return NULL;
379 /*************************************************************************
380 * COMCTL32_StrStrHelperW
382 * Internal implementation of StrStrW/StrStrIW
384 static LPWSTR COMCTL32_StrStrHelperW(LPCWSTR lpszStr, LPCWSTR lpszSearch,
385 INT (WINAPI *pStrCmpFn)(LPCWSTR,LPCWSTR,INT))
387 int iLen;
389 if (!lpszStr || !lpszSearch || !*lpszSearch)
390 return NULL;
392 iLen = strlenW(lpszSearch);
394 while (*lpszStr)
396 if (!pStrCmpFn(lpszStr, lpszSearch, iLen))
397 return (LPWSTR)lpszStr;
398 lpszStr = CharNextW(lpszStr);
400 return NULL;
403 /**************************************************************************
404 * StrStrIA [COMCTL32.355]
406 * Find a substring within a string, ignoring case.
408 * PARAMS
409 * lpszStr [I] String to search in
410 * lpszSearch [I] String to look for
412 * RETURNS
413 * The start of lpszSearch within lpszStr, or NULL if not found.
415 LPSTR WINAPI StrStrIA(LPCSTR lpszStr, LPCSTR lpszSearch)
417 TRACE("(%s,%s)\n", debugstr_a(lpszStr), debugstr_a(lpszSearch));
419 return COMCTL32_StrStrHelperA(lpszStr, lpszSearch, StrCmpNIA);
422 /**************************************************************************
423 * StrToIntA [COMCTL32.357]
425 * Read a signed integer from a string.
427 * PARAMS
428 * lpszStr [I] String to read integer from
430 * RETURNS
431 * The signed integer value represented by the string, or 0 if no integer is
432 * present.
434 INT WINAPI StrToIntA (LPSTR lpszStr)
436 return atoi(lpszStr);
439 /**************************************************************************
440 * StrStrIW [COMCTL32.363]
442 * See StrStrIA.
444 LPWSTR WINAPI StrStrIW(LPCWSTR lpszStr, LPCWSTR lpszSearch)
446 TRACE("(%s,%s)\n", debugstr_w(lpszStr), debugstr_w(lpszSearch));
448 return COMCTL32_StrStrHelperW(lpszStr, lpszSearch, StrCmpNIW);
451 /**************************************************************************
452 * StrToIntW [COMCTL32.365]
454 * See StrToIntA.
456 INT WINAPI StrToIntW (LPWSTR lpString)
458 return atoiW(lpString);
461 /*************************************************************************
462 * COMCTL32_StrSpnHelperA (internal)
464 * Internal implementation of StrSpnA/StrCSpnA/StrCSpnIA
466 static int COMCTL32_StrSpnHelperA(LPCSTR lpszStr, LPCSTR lpszMatch,
467 LPSTR (WINAPI *pStrChrFn)(LPCSTR,WORD),
468 BOOL bInvert)
470 LPCSTR lpszRead = lpszStr;
471 if (lpszStr && *lpszStr && lpszMatch)
473 while (*lpszRead)
475 LPCSTR lpszTest = pStrChrFn(lpszMatch, *lpszRead);
477 if (!bInvert && !lpszTest)
478 break;
479 if (bInvert && lpszTest)
480 break;
481 lpszRead = CharNextA(lpszRead);
484 return lpszRead - lpszStr;
487 /**************************************************************************
488 * StrCSpnA [COMCTL32.356]
490 * Find the length of the start of a string that does not contain certain
491 * characters.
493 * PARAMS
494 * lpszStr [I] String to search
495 * lpszMatch [I] Characters that cannot be in the substring
497 * RETURNS
498 * The length of the part of lpszStr containing only chars not in lpszMatch,
499 * or 0 if any parameter is invalid.
501 int WINAPI StrCSpnA(LPCSTR lpszStr, LPCSTR lpszMatch)
503 TRACE("(%s,%s)\n",debugstr_a(lpszStr), debugstr_a(lpszMatch));
505 return COMCTL32_StrSpnHelperA(lpszStr, lpszMatch, StrChrA, TRUE);
508 /**************************************************************************
509 * StrChrW [COMCTL32.358]
511 * See StrChrA.
513 LPWSTR WINAPI StrChrW(LPCWSTR lpszStr, WCHAR ch)
515 LPWSTR lpszRet = NULL;
517 TRACE("(%s,%i)\n", debugstr_w(lpszStr), ch);
519 if (lpszStr)
520 lpszRet = strchrW(lpszStr, ch);
521 return lpszRet;
524 /**************************************************************************
525 * StrCmpNA [COMCTL32.352]
527 * Compare two strings, up to a maximum length.
529 * PARAMS
530 * lpszStr [I] First string to compare
531 * lpszComp [I] Second string to compare
532 * iLen [I] Maximum number of chars to compare.
534 * RETURNS
535 * An integer less than, equal to or greater than 0, indicating that
536 * lpszStr is less than, the same, or greater than lpszComp.
538 INT WINAPI StrCmpNA(LPCSTR lpszStr, LPCSTR lpszComp, INT iLen)
540 INT iRet;
542 TRACE("(%s,%s,%i)\n", debugstr_a(lpszStr), debugstr_a(lpszComp), iLen);
544 iRet = CompareStringA(GetThreadLocale(), 0, lpszStr, iLen, lpszComp, iLen);
545 return iRet == CSTR_LESS_THAN ? -1 : iRet == CSTR_GREATER_THAN ? 1 : 0;
548 /**************************************************************************
549 * StrCmpNW [COMCTL32.360]
551 * See StrCmpNA.
553 INT WINAPI StrCmpNW(LPCWSTR lpszStr, LPCWSTR lpszComp, INT iLen)
555 INT iRet;
557 TRACE("(%s,%s,%i)\n", debugstr_w(lpszStr), debugstr_w(lpszComp), iLen);
559 iRet = CompareStringW(GetThreadLocale(), 0, lpszStr, iLen, lpszComp, iLen);
560 return iRet == CSTR_LESS_THAN ? -1 : iRet == CSTR_GREATER_THAN ? 1 : 0;
563 /**************************************************************************
564 * StrRChrA [COMCTL32.351]
566 * Find the last occurrence of a character in string.
568 * PARAMS
569 * lpszStr [I] String to search in
570 * lpszEnd [I] Place to end search, or NULL to search until the end of lpszStr
571 * ch [I] Character to search for.
573 * RETURNS
574 * Success: A pointer to the last occurrence of ch in lpszStr before lpszEnd,
575 * or NULL if not found.
576 * Failure: NULL, if any arguments are invalid.
578 LPSTR WINAPI StrRChrA(LPCSTR lpszStr, LPCSTR lpszEnd, WORD ch)
580 LPCSTR lpszRet = NULL;
582 TRACE("(%s,%s,%x)\n", debugstr_a(lpszStr), debugstr_a(lpszEnd), ch);
584 if (lpszStr)
586 WORD ch2;
588 if (!lpszEnd)
589 lpszEnd = lpszStr + lstrlenA(lpszStr);
591 while (*lpszStr && lpszStr <= lpszEnd)
593 ch2 = IsDBCSLeadByte(*lpszStr)? *lpszStr << 8 | lpszStr[1] : *lpszStr;
595 if (!COMCTL32_ChrCmpA(ch, ch2))
596 lpszRet = lpszStr;
597 lpszStr = CharNextA(lpszStr);
600 return (LPSTR)lpszRet;
604 /**************************************************************************
605 * StrRChrW [COMCTL32.359]
607 * See StrRChrA.
609 LPWSTR WINAPI StrRChrW(LPCWSTR lpszStr, LPCWSTR lpszEnd, WORD ch)
611 LPCWSTR lpszRet = NULL;
613 TRACE("(%s,%s,%x)\n", debugstr_w(lpszStr), debugstr_w(lpszEnd), ch);
615 if (lpszStr)
617 if (!lpszEnd)
618 lpszEnd = lpszStr + strlenW(lpszStr);
620 while (*lpszStr && lpszStr <= lpszEnd)
622 if (!COMCTL32_ChrCmpW(ch, *lpszStr))
623 lpszRet = lpszStr;
624 lpszStr = CharNextW(lpszStr);
627 return (LPWSTR)lpszRet;
630 /**************************************************************************
631 * StrStrA [COMCTL32.354]
633 * Find a substring within a string.
635 * PARAMS
636 * lpszStr [I] String to search in
637 * lpszSearch [I] String to look for
639 * RETURNS
640 * The start of lpszSearch within lpszStr, or NULL if not found.
642 LPSTR WINAPI StrStrA(LPCSTR lpszStr, LPCSTR lpszSearch)
644 TRACE("(%s,%s)\n", debugstr_a(lpszStr), debugstr_a(lpszSearch));
646 return COMCTL32_StrStrHelperA(lpszStr, lpszSearch, StrCmpNA);
649 /**************************************************************************
650 * StrStrW [COMCTL32.362]
652 * See StrStrA.
654 LPWSTR WINAPI StrStrW(LPCWSTR lpszStr, LPCWSTR lpszSearch)
656 TRACE("(%s,%s)\n", debugstr_w(lpszStr), debugstr_w(lpszSearch));
658 return COMCTL32_StrStrHelperW(lpszStr, lpszSearch, StrCmpNW);
661 /*************************************************************************
662 * StrChrIA [COMCTL32.366]
664 * Find a given character in a string, ignoring case.
666 * PARAMS
667 * lpszStr [I] String to search in.
668 * ch [I] Character to search for.
670 * RETURNS
671 * Success: A pointer to the first occurrence of ch in lpszStr, or NULL if
672 * not found.
673 * Failure: NULL, if any arguments are invalid.
675 LPSTR WINAPI StrChrIA(LPCSTR lpszStr, WORD ch)
677 TRACE("(%s,%i)\n", debugstr_a(lpszStr), ch);
679 if (lpszStr)
681 while (*lpszStr)
683 if (!COMCTL32_ChrCmpIA(*lpszStr, ch))
684 return (LPSTR)lpszStr;
685 lpszStr = CharNextA(lpszStr);
688 return NULL;
691 /*************************************************************************
692 * StrChrIW [COMCTL32.367]
694 * See StrChrA.
696 LPWSTR WINAPI StrChrIW(LPCWSTR lpszStr, WCHAR ch)
698 TRACE("(%s,%i)\n", debugstr_w(lpszStr), ch);
700 if (lpszStr)
702 ch = toupperW(ch);
703 while (*lpszStr)
705 if (toupperW(*lpszStr) == ch)
706 return (LPWSTR)lpszStr;
707 lpszStr = CharNextW(lpszStr);
709 lpszStr = NULL;
711 return (LPWSTR)lpszStr;
714 /*************************************************************************
715 * StrRStrIA [COMCTL32.372]
717 * Find the last occurrence of a substring within a string.
719 * PARAMS
720 * lpszStr [I] String to search in
721 * lpszEnd [I] End of lpszStr
722 * lpszSearch [I] String to look for
724 * RETURNS
725 * The last occurrence lpszSearch within lpszStr, or NULL if not found.
727 LPSTR WINAPI StrRStrIA(LPCSTR lpszStr, LPCSTR lpszEnd, LPCSTR lpszSearch)
729 LPSTR lpszRet = NULL;
730 WORD ch1, ch2;
731 INT iLen;
733 TRACE("(%s,%s)\n", debugstr_a(lpszStr), debugstr_a(lpszSearch));
735 if (!lpszStr || !lpszSearch || !*lpszSearch)
736 return NULL;
738 if (!lpszEnd)
739 lpszEnd = lpszStr + lstrlenA(lpszStr);
741 if (IsDBCSLeadByte(*lpszSearch))
742 ch1 = *lpszSearch << 8 | lpszSearch[1];
743 else
744 ch1 = *lpszSearch;
745 iLen = lstrlenA(lpszSearch);
747 while (lpszStr <= lpszEnd && *lpszStr)
749 ch2 = IsDBCSLeadByte(*lpszStr)? *lpszStr << 8 | lpszStr[1] : *lpszStr;
750 if (!COMCTL32_ChrCmpIA(ch1, ch2))
752 if (!StrCmpNIA(lpszStr, lpszSearch, iLen))
753 lpszRet = (LPSTR)lpszStr;
755 lpszStr = CharNextA(lpszStr);
757 return lpszRet;
760 /*************************************************************************
761 * StrRStrIW [COMCTL32.373]
763 * See StrRStrIA.
765 LPWSTR WINAPI StrRStrIW(LPCWSTR lpszStr, LPCWSTR lpszEnd, LPCWSTR lpszSearch)
767 LPWSTR lpszRet = NULL;
768 INT iLen;
770 TRACE("(%s,%s)\n", debugstr_w(lpszStr), debugstr_w(lpszSearch));
772 if (!lpszStr || !lpszSearch || !*lpszSearch)
773 return NULL;
775 if (!lpszEnd)
776 lpszEnd = lpszStr + strlenW(lpszStr);
778 iLen = strlenW(lpszSearch);
780 while (lpszStr <= lpszEnd && *lpszStr)
782 if (!COMCTL32_ChrCmpIW(*lpszSearch, *lpszStr))
784 if (!StrCmpNIW(lpszStr, lpszSearch, iLen))
785 lpszRet = (LPWSTR)lpszStr;
787 lpszStr = CharNextW(lpszStr);
789 return lpszRet;
792 /*************************************************************************
793 * COMCTL32_StrSpnHelperW
795 * Internal implementation of StrSpnW/StrCSpnW/StrCSpnIW
797 static int COMCTL32_StrSpnHelperW(LPCWSTR lpszStr, LPCWSTR lpszMatch,
798 LPWSTR (WINAPI *pStrChrFn)(LPCWSTR,WCHAR),
799 BOOL bInvert)
801 LPCWSTR lpszRead = lpszStr;
802 if (lpszStr && *lpszStr && lpszMatch)
804 while (*lpszRead)
806 LPCWSTR lpszTest = pStrChrFn(lpszMatch, *lpszRead);
808 if (!bInvert && !lpszTest)
809 break;
810 if (bInvert && lpszTest)
811 break;
812 lpszRead = CharNextW(lpszRead);
815 return lpszRead - lpszStr;
818 /*************************************************************************
819 * StrCSpnIA [COMCTL32.374]
821 * Find the length of the start of a string that does not contain certain
822 * characters, ignoring case.
824 * PARAMS
825 * lpszStr [I] String to search
826 * lpszMatch [I] Characters that cannot be in the substring
828 * RETURNS
829 * The length of the part of lpszStr containing only chars not in lpszMatch,
830 * or 0 if any parameter is invalid.
832 int WINAPI StrCSpnIA(LPCSTR lpszStr, LPCSTR lpszMatch)
834 TRACE("(%s,%s)\n",debugstr_a(lpszStr), debugstr_a(lpszMatch));
836 return COMCTL32_StrSpnHelperA(lpszStr, lpszMatch, StrChrIA, TRUE);
839 /*************************************************************************
840 * StrCSpnIW [COMCTL32.375]
842 * See StrCSpnIA.
844 int WINAPI StrCSpnIW(LPCWSTR lpszStr, LPCWSTR lpszMatch)
846 TRACE("(%s,%s)\n",debugstr_w(lpszStr), debugstr_w(lpszMatch));
848 return COMCTL32_StrSpnHelperW(lpszStr, lpszMatch, StrChrIW, TRUE);
851 /**************************************************************************
852 * StrRChrIA [COMCTL32.368]
854 * Find the last occurrence of a character in string, ignoring case.
856 * PARAMS
857 * lpszStr [I] String to search in
858 * lpszEnd [I] Place to end search, or NULL to search until the end of lpszStr
859 * ch [I] Character to search for.
861 * RETURNS
862 * Success: A pointer to the last occurrence of ch in lpszStr before lpszEnd,
863 * or NULL if not found.
864 * Failure: NULL, if any arguments are invalid.
866 LPSTR WINAPI StrRChrIA(LPCSTR lpszStr, LPCSTR lpszEnd, WORD ch)
868 LPCSTR lpszRet = NULL;
870 TRACE("(%s,%s,%x)\n", debugstr_a(lpszStr), debugstr_a(lpszEnd), ch);
872 if (lpszStr)
874 WORD ch2;
876 if (!lpszEnd)
877 lpszEnd = lpszStr + lstrlenA(lpszStr);
879 while (*lpszStr && lpszStr <= lpszEnd)
881 ch2 = IsDBCSLeadByte(*lpszStr)? *lpszStr << 8 | lpszStr[1] : *lpszStr;
883 if (ch == ch2)
884 lpszRet = lpszStr;
885 lpszStr = CharNextA(lpszStr);
888 return (LPSTR)lpszRet;
891 /**************************************************************************
892 * StrRChrIW [COMCTL32.369]
894 * See StrRChrIA.
896 LPWSTR WINAPI StrRChrIW(LPCWSTR lpszStr, LPCWSTR lpszEnd, WORD ch)
898 LPCWSTR lpszRet = NULL;
900 TRACE("(%s,%s,%x)\n", debugstr_w(lpszStr), debugstr_w(lpszEnd), ch);
902 if (lpszStr)
904 if (!lpszEnd)
905 lpszEnd = lpszStr + strlenW(lpszStr);
907 while (*lpszStr && lpszStr <= lpszEnd)
909 if (ch == *lpszStr)
910 lpszRet = lpszStr;
911 lpszStr = CharNextW(lpszStr);
914 return (LPWSTR)lpszRet;
917 /*************************************************************************
918 * StrCSpnW [COMCTL32.364]
920 * See StrCSpnA.
922 int WINAPI StrCSpnW(LPCWSTR lpszStr, LPCWSTR lpszMatch)
924 TRACE("(%s,%s)\n",debugstr_w(lpszStr), debugstr_w(lpszMatch));
926 return COMCTL32_StrSpnHelperW(lpszStr, lpszMatch, StrChrW, TRUE);
929 /*************************************************************************
930 * IntlStrEqWorkerA [COMCTL32.376]
932 * Compare two strings.
934 * PARAMS
935 * bCase [I] Whether to compare case sensitively
936 * lpszStr [I] First string to compare
937 * lpszComp [I] Second string to compare
938 * iLen [I] Length to compare
940 * RETURNS
941 * TRUE If the strings are equal.
942 * FALSE Otherwise.
944 BOOL WINAPI IntlStrEqWorkerA(BOOL bCase, LPCSTR lpszStr, LPCSTR lpszComp,
945 int iLen)
947 DWORD dwFlags = LOCALE_USE_CP_ACP;
948 int iRet;
950 TRACE("(%d,%s,%s,%d)\n", bCase,
951 debugstr_a(lpszStr), debugstr_a(lpszComp), iLen);
953 /* FIXME: These flags are undocumented and unknown by our CompareString.
954 * We need defines for them.
956 dwFlags |= bCase ? 0x10000000 : 0x10000001;
958 iRet = CompareStringA(GetThreadLocale(),
959 dwFlags, lpszStr, iLen, lpszComp, iLen);
961 if (!iRet)
962 iRet = CompareStringA(2048, dwFlags, lpszStr, iLen, lpszComp, iLen);
964 return iRet == 2 ? TRUE : FALSE;
967 /*************************************************************************
968 * IntlStrEqWorkerW [COMCTL32.377]
970 * See IntlStrEqWorkerA.
972 BOOL WINAPI IntlStrEqWorkerW(BOOL bCase, LPCWSTR lpszStr, LPCWSTR lpszComp,
973 int iLen)
975 DWORD dwFlags;
976 int iRet;
978 TRACE("(%d,%s,%s,%d)\n", bCase,
979 debugstr_w(lpszStr),debugstr_w(lpszComp), iLen);
981 /* FIXME: These flags are undocumented and unknown by our CompareString.
982 * We need defines for them.
984 dwFlags = bCase ? 0x10000000 : 0x10000001;
986 iRet = CompareStringW(GetThreadLocale(),
987 dwFlags, lpszStr, iLen, lpszComp, iLen);
989 if (!iRet)
990 iRet = CompareStringW(2048, dwFlags, lpszStr, iLen, lpszComp, iLen);
992 return iRet == 2 ? TRUE : FALSE;