Release 1.1.37.
[wine/gsoc-2012-control.git] / dlls / comctl32 / string.c
blobf6dbd8c5589dcd06ba7b9ca6aa56bb8d81221efd
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_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) - 2;
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 %p)\n", lppDest, 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 INT iRet;
304 TRACE("(%s,%s,%i)\n", debugstr_a(lpszStr), debugstr_a(lpszComp), iLen);
306 iRet = CompareStringA(GetThreadLocale(), NORM_IGNORECASE, lpszStr, iLen, lpszComp, iLen);
307 return iRet == CSTR_LESS_THAN ? -1 : iRet == CSTR_GREATER_THAN ? 1 : 0;
310 /*************************************************************************
311 * StrCmpNIW [COMCTL32.361]
313 * See StrCmpNIA.
315 INT WINAPI StrCmpNIW(LPCWSTR lpszStr, LPCWSTR lpszComp, INT iLen)
317 INT iRet;
319 TRACE("(%s,%s,%i)\n", debugstr_w(lpszStr), debugstr_w(lpszComp), iLen);
321 iRet = CompareStringW(GetThreadLocale(), NORM_IGNORECASE, lpszStr, iLen, lpszComp, iLen);
322 return iRet == CSTR_LESS_THAN ? -1 : iRet == CSTR_GREATER_THAN ? 1 : 0;
325 /*************************************************************************
326 * COMCTL32_StrStrHelperA
328 * Internal implementation of StrStrA/StrStrIA
330 static LPSTR COMCTL32_StrStrHelperA(LPCSTR lpszStr, LPCSTR lpszSearch,
331 INT (WINAPI *pStrCmpFn)(LPCSTR,LPCSTR,INT))
333 size_t iLen;
335 if (!lpszStr || !lpszSearch || !*lpszSearch)
336 return NULL;
338 iLen = strlen(lpszSearch);
340 while (*lpszStr)
342 if (!pStrCmpFn(lpszStr, lpszSearch, iLen))
343 return (LPSTR)lpszStr;
344 lpszStr = CharNextA(lpszStr);
346 return NULL;
349 /**************************************************************************
350 * StrStrIA [COMCTL32.355]
352 * Find a substring within a string, ignoring case.
354 * PARAMS
355 * lpszStr [I] String to search in
356 * lpszSearch [I] String to look for
358 * RETURNS
359 * The start of lpszSearch within lpszStr, or NULL if not found.
361 LPSTR WINAPI StrStrIA(LPCSTR lpszStr, LPCSTR lpszSearch)
363 TRACE("(%s,%s)\n", debugstr_a(lpszStr), debugstr_a(lpszSearch));
365 return COMCTL32_StrStrHelperA(lpszStr, lpszSearch, StrCmpNIA);
368 /**************************************************************************
369 * StrToIntA [COMCTL32.357]
371 * Read a signed integer from a string.
373 * PARAMS
374 * lpszStr [I] String to read integer from
376 * RETURNS
377 * The signed integer value represented by the string, or 0 if no integer is
378 * present.
380 INT WINAPI StrToIntA (LPCSTR lpszStr)
382 return atoi(lpszStr);
385 /**************************************************************************
386 * StrStrIW [COMCTL32.363]
388 * See StrStrIA.
390 LPWSTR WINAPI StrStrIW(LPCWSTR lpszStr, LPCWSTR lpszSearch)
392 int iLen;
394 TRACE("(%s,%s)\n", debugstr_w(lpszStr), debugstr_w(lpszSearch));
396 if (!lpszStr || !lpszSearch || !*lpszSearch)
397 return NULL;
399 iLen = strlenW(lpszSearch);
401 while (*lpszStr)
403 if (!StrCmpNIW(lpszStr, lpszSearch, iLen))
404 return (LPWSTR)lpszStr;
405 lpszStr++;
407 return NULL;
410 /**************************************************************************
411 * StrToIntW [COMCTL32.365]
413 * See StrToIntA.
415 INT WINAPI StrToIntW (LPCWSTR lpString)
417 return atoiW(lpString);
420 /*************************************************************************
421 * COMCTL32_StrSpnHelperA (internal)
423 * Internal implementation of StrSpnA/StrCSpnA/StrCSpnIA
425 static int COMCTL32_StrSpnHelperA(LPCSTR lpszStr, LPCSTR lpszMatch,
426 LPSTR (WINAPI *pStrChrFn)(LPCSTR,WORD),
427 BOOL bInvert)
429 LPCSTR lpszRead = lpszStr;
430 if (lpszStr && *lpszStr && lpszMatch)
432 while (*lpszRead)
434 LPCSTR lpszTest = pStrChrFn(lpszMatch, *lpszRead);
436 if (!bInvert && !lpszTest)
437 break;
438 if (bInvert && lpszTest)
439 break;
440 lpszRead = CharNextA(lpszRead);
443 return lpszRead - lpszStr;
446 /**************************************************************************
447 * StrCSpnA [COMCTL32.356]
449 * Find the length of the start of a string that does not contain certain
450 * characters.
452 * PARAMS
453 * lpszStr [I] String to search
454 * lpszMatch [I] Characters that cannot be in the substring
456 * RETURNS
457 * The length of the part of lpszStr containing only chars not in lpszMatch,
458 * or 0 if any parameter is invalid.
460 int WINAPI StrCSpnA(LPCSTR lpszStr, LPCSTR lpszMatch)
462 TRACE("(%s,%s)\n",debugstr_a(lpszStr), debugstr_a(lpszMatch));
464 return COMCTL32_StrSpnHelperA(lpszStr, lpszMatch, StrChrA, TRUE);
467 /**************************************************************************
468 * StrChrW [COMCTL32.358]
470 * See StrChrA.
472 LPWSTR WINAPI StrChrW(LPCWSTR lpszStr, WCHAR ch)
474 LPWSTR lpszRet = NULL;
476 TRACE("(%s,%i)\n", debugstr_w(lpszStr), ch);
478 if (lpszStr)
479 lpszRet = strchrW(lpszStr, ch);
480 return lpszRet;
483 /**************************************************************************
484 * StrCmpNA [COMCTL32.352]
486 * Compare two strings, up to a maximum length.
488 * PARAMS
489 * lpszStr [I] First string to compare
490 * lpszComp [I] Second string to compare
491 * iLen [I] Maximum number of chars to compare.
493 * RETURNS
494 * An integer less than, equal to or greater than 0, indicating that
495 * lpszStr is less than, the same, or greater than lpszComp.
497 INT WINAPI StrCmpNA(LPCSTR lpszStr, LPCSTR lpszComp, INT iLen)
499 INT iRet;
501 TRACE("(%s,%s,%i)\n", debugstr_a(lpszStr), debugstr_a(lpszComp), iLen);
503 iRet = CompareStringA(GetThreadLocale(), 0, lpszStr, iLen, lpszComp, iLen);
504 return iRet == CSTR_LESS_THAN ? -1 : iRet == CSTR_GREATER_THAN ? 1 : 0;
507 /**************************************************************************
508 * StrCmpNW [COMCTL32.360]
510 * See StrCmpNA.
512 INT WINAPI StrCmpNW(LPCWSTR lpszStr, LPCWSTR lpszComp, INT iLen)
514 INT iRet;
516 TRACE("(%s,%s,%i)\n", debugstr_w(lpszStr), debugstr_w(lpszComp), iLen);
518 iRet = CompareStringW(GetThreadLocale(), 0, lpszStr, iLen, lpszComp, iLen);
519 return iRet == CSTR_LESS_THAN ? -1 : iRet == CSTR_GREATER_THAN ? 1 : 0;
522 /**************************************************************************
523 * StrRChrA [COMCTL32.351]
525 * Find the last occurrence of a character in string.
527 * PARAMS
528 * lpszStr [I] String to search in
529 * lpszEnd [I] Place to end search, or NULL to search until the end of lpszStr
530 * ch [I] Character to search for.
532 * RETURNS
533 * Success: A pointer to the last occurrence of ch in lpszStr before lpszEnd,
534 * or NULL if not found.
535 * Failure: NULL, if any arguments are invalid.
537 LPSTR WINAPI StrRChrA(LPCSTR lpszStr, LPCSTR lpszEnd, WORD ch)
539 LPCSTR lpszRet = NULL;
541 TRACE("(%s,%s,%x)\n", debugstr_a(lpszStr), debugstr_a(lpszEnd), ch);
543 if (lpszStr)
545 WORD ch2;
547 if (!lpszEnd)
548 lpszEnd = lpszStr + lstrlenA(lpszStr);
550 while (*lpszStr && lpszStr <= lpszEnd)
552 ch2 = IsDBCSLeadByte(*lpszStr)? *lpszStr << 8 | lpszStr[1] : *lpszStr;
554 if (!COMCTL32_ChrCmpA(ch, ch2))
555 lpszRet = lpszStr;
556 lpszStr = CharNextA(lpszStr);
559 return (LPSTR)lpszRet;
563 /**************************************************************************
564 * StrRChrW [COMCTL32.359]
566 * See StrRChrA.
568 LPWSTR WINAPI StrRChrW(LPCWSTR str, LPCWSTR end, WORD ch)
570 WCHAR *ret = NULL;
572 if (!str) return NULL;
573 if (!end) end = str + strlenW(str);
574 while (str < end)
576 if (*str == ch) ret = (WCHAR *)str;
577 str++;
579 return ret;
582 /**************************************************************************
583 * StrStrA [COMCTL32.354]
585 * Find a substring within a string.
587 * PARAMS
588 * lpszStr [I] String to search in
589 * lpszSearch [I] String to look for
591 * RETURNS
592 * The start of lpszSearch within lpszStr, or NULL if not found.
594 LPSTR WINAPI StrStrA(LPCSTR lpszStr, LPCSTR lpszSearch)
596 TRACE("(%s,%s)\n", debugstr_a(lpszStr), debugstr_a(lpszSearch));
598 return COMCTL32_StrStrHelperA(lpszStr, lpszSearch, StrCmpNA);
601 /**************************************************************************
602 * StrStrW [COMCTL32.362]
604 * See StrStrA.
606 LPWSTR WINAPI StrStrW(LPCWSTR lpszStr, LPCWSTR lpszSearch)
608 if (!lpszStr || !lpszSearch) return NULL;
609 return strstrW( lpszStr, lpszSearch );
612 /*************************************************************************
613 * StrChrIA [COMCTL32.366]
615 * Find a given character in a string, ignoring case.
617 * PARAMS
618 * lpszStr [I] String to search in.
619 * ch [I] Character to search for.
621 * RETURNS
622 * Success: A pointer to the first occurrence of ch in lpszStr, or NULL if
623 * not found.
624 * Failure: NULL, if any arguments are invalid.
626 LPSTR WINAPI StrChrIA(LPCSTR lpszStr, WORD ch)
628 TRACE("(%s,%i)\n", debugstr_a(lpszStr), ch);
630 if (lpszStr)
632 while (*lpszStr)
634 if (!COMCTL32_ChrCmpIA(*lpszStr, ch))
635 return (LPSTR)lpszStr;
636 lpszStr = CharNextA(lpszStr);
639 return NULL;
642 /*************************************************************************
643 * StrChrIW [COMCTL32.367]
645 * See StrChrA.
647 LPWSTR WINAPI StrChrIW(LPCWSTR lpszStr, WCHAR ch)
649 TRACE("(%s,%i)\n", debugstr_w(lpszStr), ch);
651 if (lpszStr)
653 ch = toupperW(ch);
654 while (*lpszStr)
656 if (toupperW(*lpszStr) == ch)
657 return (LPWSTR)lpszStr;
658 lpszStr++;
660 lpszStr = NULL;
662 return (LPWSTR)lpszStr;
665 /*************************************************************************
666 * StrRStrIA [COMCTL32.372]
668 * Find the last occurrence of a substring within a string.
670 * PARAMS
671 * lpszStr [I] String to search in
672 * lpszEnd [I] End of lpszStr
673 * lpszSearch [I] String to look for
675 * RETURNS
676 * The last occurrence lpszSearch within lpszStr, or NULL if not found.
678 LPSTR WINAPI StrRStrIA(LPCSTR lpszStr, LPCSTR lpszEnd, LPCSTR lpszSearch)
680 LPSTR lpszRet = NULL;
681 WORD ch1, ch2;
682 INT iLen;
684 TRACE("(%s,%s)\n", debugstr_a(lpszStr), debugstr_a(lpszSearch));
686 if (!lpszStr || !lpszSearch || !*lpszSearch)
687 return NULL;
689 if (!lpszEnd)
690 lpszEnd = lpszStr + lstrlenA(lpszStr);
692 if (IsDBCSLeadByte(*lpszSearch))
693 ch1 = *lpszSearch << 8 | lpszSearch[1];
694 else
695 ch1 = *lpszSearch;
696 iLen = lstrlenA(lpszSearch);
698 while (lpszStr <= lpszEnd && *lpszStr)
700 ch2 = IsDBCSLeadByte(*lpszStr)? *lpszStr << 8 | lpszStr[1] : *lpszStr;
701 if (!COMCTL32_ChrCmpIA(ch1, ch2))
703 if (!StrCmpNIA(lpszStr, lpszSearch, iLen))
704 lpszRet = (LPSTR)lpszStr;
706 lpszStr = CharNextA(lpszStr);
708 return lpszRet;
711 /*************************************************************************
712 * StrRStrIW [COMCTL32.373]
714 * See StrRStrIA.
716 LPWSTR WINAPI StrRStrIW(LPCWSTR lpszStr, LPCWSTR lpszEnd, LPCWSTR lpszSearch)
718 LPWSTR lpszRet = NULL;
719 INT iLen;
721 TRACE("(%s,%s)\n", debugstr_w(lpszStr), debugstr_w(lpszSearch));
723 if (!lpszStr || !lpszSearch || !*lpszSearch)
724 return NULL;
726 if (!lpszEnd)
727 lpszEnd = lpszStr + strlenW(lpszStr);
729 iLen = strlenW(lpszSearch);
731 while (lpszStr <= lpszEnd && *lpszStr)
733 if (!COMCTL32_ChrCmpIW(*lpszSearch, *lpszStr))
735 if (!StrCmpNIW(lpszStr, lpszSearch, iLen))
736 lpszRet = (LPWSTR)lpszStr;
738 lpszStr++;
740 return lpszRet;
743 /*************************************************************************
744 * StrCSpnIA [COMCTL32.374]
746 * Find the length of the start of a string that does not contain certain
747 * characters, ignoring case.
749 * PARAMS
750 * lpszStr [I] String to search
751 * lpszMatch [I] Characters that cannot be in the substring
753 * RETURNS
754 * The length of the part of lpszStr containing only chars not in lpszMatch,
755 * or 0 if any parameter is invalid.
757 int WINAPI StrCSpnIA(LPCSTR lpszStr, LPCSTR lpszMatch)
759 TRACE("(%s,%s)\n",debugstr_a(lpszStr), debugstr_a(lpszMatch));
761 return COMCTL32_StrSpnHelperA(lpszStr, lpszMatch, StrChrIA, TRUE);
764 /*************************************************************************
765 * StrCSpnIW [COMCTL32.375]
767 * See StrCSpnIA.
769 int WINAPI StrCSpnIW(LPCWSTR lpszStr, LPCWSTR lpszMatch)
771 LPCWSTR lpszRead = lpszStr;
773 TRACE("(%s,%s)\n",debugstr_w(lpszStr), debugstr_w(lpszMatch));
775 if (lpszStr && *lpszStr && lpszMatch)
777 while (*lpszRead)
779 if (StrChrIW(lpszMatch, *lpszRead)) break;
780 lpszRead++;
783 return lpszRead - lpszStr;
786 /**************************************************************************
787 * StrRChrIA [COMCTL32.368]
789 * Find the last occurrence of a character in string, ignoring case.
791 * PARAMS
792 * lpszStr [I] String to search in
793 * lpszEnd [I] Place to end search, or NULL to search until the end of lpszStr
794 * ch [I] Character to search for.
796 * RETURNS
797 * Success: A pointer to the last occurrence of ch in lpszStr before lpszEnd,
798 * or NULL if not found.
799 * Failure: NULL, if any arguments are invalid.
801 LPSTR WINAPI StrRChrIA(LPCSTR lpszStr, LPCSTR lpszEnd, WORD ch)
803 LPCSTR lpszRet = NULL;
805 TRACE("(%s,%s,%x)\n", debugstr_a(lpszStr), debugstr_a(lpszEnd), ch);
807 if (lpszStr)
809 WORD ch2;
811 if (!lpszEnd)
812 lpszEnd = lpszStr + lstrlenA(lpszStr);
814 while (*lpszStr && lpszStr <= lpszEnd)
816 ch2 = IsDBCSLeadByte(*lpszStr)? *lpszStr << 8 | lpszStr[1] : *lpszStr;
818 if (ch == ch2)
819 lpszRet = lpszStr;
820 lpszStr = CharNextA(lpszStr);
823 return (LPSTR)lpszRet;
826 /**************************************************************************
827 * StrRChrIW [COMCTL32.369]
829 * See StrRChrIA.
831 LPWSTR WINAPI StrRChrIW(LPCWSTR str, LPCWSTR end, WORD ch)
833 WCHAR *ret = NULL;
835 if (!str) return NULL;
836 if (!end) end = str + strlenW(str);
837 while (str < end)
839 if (!COMCTL32_ChrCmpIW(*str, ch)) ret = (WCHAR *)str;
840 str++;
842 return ret;
845 /*************************************************************************
846 * StrCSpnW [COMCTL32.364]
848 * See StrCSpnA.
850 int WINAPI StrCSpnW(LPCWSTR lpszStr, LPCWSTR lpszMatch)
852 if (!lpszStr || !lpszMatch) return 0;
853 return strcspnW( lpszStr, lpszMatch );
856 /*************************************************************************
857 * IntlStrEqWorkerA [COMCTL32.376]
859 * Compare two strings.
861 * PARAMS
862 * bCase [I] Whether to compare case sensitively
863 * lpszStr [I] First string to compare
864 * lpszComp [I] Second string to compare
865 * iLen [I] Length to compare
867 * RETURNS
868 * TRUE If the strings are equal.
869 * FALSE Otherwise.
871 BOOL WINAPI IntlStrEqWorkerA(BOOL bCase, LPCSTR lpszStr, LPCSTR lpszComp,
872 int iLen)
874 DWORD dwFlags = LOCALE_USE_CP_ACP;
875 int iRet;
877 TRACE("(%d,%s,%s,%d)\n", bCase,
878 debugstr_a(lpszStr), debugstr_a(lpszComp), iLen);
880 /* FIXME: These flags are undocumented and unknown by our CompareString.
881 * We need defines for them.
883 dwFlags |= bCase ? 0x10000000 : 0x10000001;
885 iRet = CompareStringA(GetThreadLocale(),
886 dwFlags, lpszStr, iLen, lpszComp, iLen);
888 if (!iRet)
889 iRet = CompareStringA(2048, dwFlags, lpszStr, iLen, lpszComp, iLen);
891 return iRet == 2 ? TRUE : FALSE;
894 /*************************************************************************
895 * IntlStrEqWorkerW [COMCTL32.377]
897 * See IntlStrEqWorkerA.
899 BOOL WINAPI IntlStrEqWorkerW(BOOL bCase, LPCWSTR lpszStr, LPCWSTR lpszComp,
900 int iLen)
902 DWORD dwFlags;
903 int iRet;
905 TRACE("(%d,%s,%s,%d)\n", bCase,
906 debugstr_w(lpszStr),debugstr_w(lpszComp), iLen);
908 /* FIXME: These flags are undocumented and unknown by our CompareString.
909 * We need defines for them.
911 dwFlags = bCase ? 0x10000000 : 0x10000001;
913 iRet = CompareStringW(GetThreadLocale(),
914 dwFlags, lpszStr, iLen, lpszComp, iLen);
916 if (!iRet)
917 iRet = CompareStringW(2048, dwFlags, lpszStr, iLen, lpszComp, iLen);
919 return iRet == 2 ? TRUE : FALSE;