Changes in crossover-wine-src-6.1.0 except for configure
[wine/hacks.git] / dlls / comctl32 / string.c
blob33effbd0703b49e5097f48ecf0c921777b03526b
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 Free (*lppDest);
219 *lppDest = NULL;
222 return TRUE;
225 /**************************************************************************
226 * Str_GetPtrW [COMCTL32.235]
228 * See Str_GetPtrA.
230 INT WINAPI Str_GetPtrW (LPCWSTR lpSrc, LPWSTR lpDest, INT nMaxLen)
232 INT len;
234 TRACE("(%p %p %d)\n", lpSrc, lpDest, nMaxLen);
236 if (!lpDest && lpSrc)
237 return strlenW (lpSrc);
239 if (nMaxLen == 0)
240 return 0;
242 if (lpSrc == NULL) {
243 lpDest[0] = L'\0';
244 return 0;
247 len = strlenW (lpSrc);
248 if (len >= nMaxLen)
249 len = nMaxLen - 1;
251 RtlMoveMemory (lpDest, lpSrc, len*sizeof(WCHAR));
252 lpDest[len] = L'\0';
254 return len;
257 /**************************************************************************
258 * Str_SetPtrW [COMCTL32.236]
260 * See Str_SetPtrA.
262 BOOL WINAPI Str_SetPtrW (LPWSTR *lppDest, LPCWSTR lpSrc)
264 TRACE("(%p %p)\n", lppDest, lpSrc);
266 if (lpSrc) {
267 INT len = strlenW (lpSrc) + 1;
268 LPWSTR ptr = ReAlloc (*lppDest, len * sizeof(WCHAR));
269 if (!ptr)
270 return FALSE;
271 strcpyW (ptr, lpSrc);
272 *lppDest = ptr;
274 else {
275 Free (*lppDest);
276 *lppDest = NULL;
279 return TRUE;
282 /**************************************************************************
283 * StrChrA [COMCTL32.350]
285 * Find a given character in a string.
287 * PARAMS
288 * lpszStr [I] String to search in.
289 * ch [I] Character to search for.
291 * RETURNS
292 * Success: A pointer to the first occurrence of ch in lpszStr, or NULL if
293 * not found.
294 * Failure: NULL, if any arguments are invalid.
296 LPSTR WINAPI StrChrA(LPCSTR lpszStr, WORD ch)
298 TRACE("(%s,%i)\n", debugstr_a(lpszStr), ch);
300 if (lpszStr)
302 while (*lpszStr)
304 if (!COMCTL32_ChrCmpA(*lpszStr, ch))
305 return (LPSTR)lpszStr;
306 lpszStr = CharNextA(lpszStr);
309 return NULL;
312 /**************************************************************************
313 * StrCmpNIA [COMCTL32.353]
315 * Compare two strings, up to a maximum length, ignoring case.
317 * PARAMS
318 * lpszStr [I] First string to compare
319 * lpszComp [I] Second string to compare
320 * iLen [I] Maximum number of chars to compare.
322 * RETURNS
323 * An integer less than, equal to or greater than 0, indicating that
324 * lpszStr is less than, the same, or greater than lpszComp.
326 INT WINAPI StrCmpNIA(LPCSTR lpszStr, LPCSTR lpszComp, INT iLen)
328 INT iRet;
330 TRACE("(%s,%s,%i)\n", debugstr_a(lpszStr), debugstr_a(lpszComp), iLen);
332 iRet = CompareStringA(GetThreadLocale(), NORM_IGNORECASE, lpszStr, iLen, lpszComp, iLen);
333 return iRet == CSTR_LESS_THAN ? -1 : iRet == CSTR_GREATER_THAN ? 1 : 0;
336 /*************************************************************************
337 * StrCmpNIW [COMCTL32.361]
339 * See StrCmpNIA.
341 INT WINAPI StrCmpNIW(LPCWSTR lpszStr, LPCWSTR lpszComp, INT iLen)
343 INT iRet;
345 TRACE("(%s,%s,%i)\n", debugstr_w(lpszStr), debugstr_w(lpszComp), iLen);
347 iRet = CompareStringW(GetThreadLocale(), NORM_IGNORECASE, lpszStr, iLen, lpszComp, iLen);
348 return iRet == CSTR_LESS_THAN ? -1 : iRet == CSTR_GREATER_THAN ? 1 : 0;
351 /*************************************************************************
352 * COMCTL32_StrStrHelperA
354 * Internal implementation of StrStrA/StrStrIA
356 static LPSTR COMCTL32_StrStrHelperA(LPCSTR lpszStr, LPCSTR lpszSearch,
357 INT (WINAPI *pStrCmpFn)(LPCSTR,LPCSTR,INT))
359 size_t iLen;
361 if (!lpszStr || !lpszSearch || !*lpszSearch)
362 return NULL;
364 iLen = strlen(lpszSearch);
366 while (*lpszStr)
368 if (!pStrCmpFn(lpszStr, lpszSearch, iLen))
369 return (LPSTR)lpszStr;
370 lpszStr = CharNextA(lpszStr);
372 return NULL;
375 /*************************************************************************
376 * COMCTL32_StrStrHelperW
378 * Internal implementation of StrStrW/StrStrIW
380 static LPWSTR COMCTL32_StrStrHelperW(LPCWSTR lpszStr, LPCWSTR lpszSearch,
381 INT (WINAPI *pStrCmpFn)(LPCWSTR,LPCWSTR,INT))
383 int iLen;
385 if (!lpszStr || !lpszSearch || !*lpszSearch)
386 return NULL;
388 iLen = strlenW(lpszSearch);
390 while (*lpszStr)
392 if (!pStrCmpFn(lpszStr, lpszSearch, iLen))
393 return (LPWSTR)lpszStr;
394 lpszStr = CharNextW(lpszStr);
396 return NULL;
399 /**************************************************************************
400 * StrStrIA [COMCTL32.355]
402 * Find a substring within a string, ignoring case.
404 * PARAMS
405 * lpszStr [I] String to search in
406 * lpszSearch [I] String to look for
408 * RETURNS
409 * The start of lpszSearch within lpszStr, or NULL if not found.
411 LPSTR WINAPI StrStrIA(LPCSTR lpszStr, LPCSTR lpszSearch)
413 TRACE("(%s,%s)\n", debugstr_a(lpszStr), debugstr_a(lpszSearch));
415 return COMCTL32_StrStrHelperA(lpszStr, lpszSearch, StrCmpNIA);
418 /**************************************************************************
419 * StrToIntA [COMCTL32.357]
421 * Read a signed integer from a string.
423 * PARAMS
424 * lpszStr [I] String to read integer from
426 * RETURNS
427 * The signed integer value represented by the string, or 0 if no integer is
428 * present.
430 INT WINAPI StrToIntA (LPSTR lpszStr)
432 return atoi(lpszStr);
435 /**************************************************************************
436 * StrStrIW [COMCTL32.363]
438 * See StrStrIA.
440 LPWSTR WINAPI StrStrIW(LPCWSTR lpszStr, LPCWSTR lpszSearch)
442 TRACE("(%s,%s)\n", debugstr_w(lpszStr), debugstr_w(lpszSearch));
444 return COMCTL32_StrStrHelperW(lpszStr, lpszSearch, StrCmpNIW);
447 /**************************************************************************
448 * StrToIntW [COMCTL32.365]
450 * See StrToIntA.
452 INT WINAPI StrToIntW (LPWSTR lpString)
454 return atoiW(lpString);
457 /*************************************************************************
458 * COMCTL32_StrSpnHelperA (internal)
460 * Internal implementation of StrSpnA/StrCSpnA/StrCSpnIA
462 static int COMCTL32_StrSpnHelperA(LPCSTR lpszStr, LPCSTR lpszMatch,
463 LPSTR (WINAPI *pStrChrFn)(LPCSTR,WORD),
464 BOOL bInvert)
466 LPCSTR lpszRead = lpszStr;
467 if (lpszStr && *lpszStr && lpszMatch)
469 while (*lpszRead)
471 LPCSTR lpszTest = pStrChrFn(lpszMatch, *lpszRead);
473 if (!bInvert && !lpszTest)
474 break;
475 if (bInvert && lpszTest)
476 break;
477 lpszRead = CharNextA(lpszRead);
480 return lpszRead - lpszStr;
483 /**************************************************************************
484 * StrCSpnA [COMCTL32.356]
486 * Find the length of the start of a string that does not contain certain
487 * characters.
489 * PARAMS
490 * lpszStr [I] String to search
491 * lpszMatch [I] Characters that cannot be in the substring
493 * RETURNS
494 * The length of the part of lpszStr containing only chars not in lpszMatch,
495 * or 0 if any parameter is invalid.
497 int WINAPI StrCSpnA(LPCSTR lpszStr, LPCSTR lpszMatch)
499 TRACE("(%s,%s)\n",debugstr_a(lpszStr), debugstr_a(lpszMatch));
501 return COMCTL32_StrSpnHelperA(lpszStr, lpszMatch, StrChrA, TRUE);
504 /**************************************************************************
505 * StrChrW [COMCTL32.358]
507 * See StrChrA.
509 LPWSTR WINAPI StrChrW(LPCWSTR lpszStr, WCHAR ch)
511 LPWSTR lpszRet = NULL;
513 TRACE("(%s,%i)\n", debugstr_w(lpszStr), ch);
515 if (lpszStr)
516 lpszRet = strchrW(lpszStr, ch);
517 return lpszRet;
520 /**************************************************************************
521 * StrCmpNA [COMCTL32.352]
523 * Compare two strings, up to a maximum length.
525 * PARAMS
526 * lpszStr [I] First string to compare
527 * lpszComp [I] Second string to compare
528 * iLen [I] Maximum number of chars to compare.
530 * RETURNS
531 * An integer less than, equal to or greater than 0, indicating that
532 * lpszStr is less than, the same, or greater than lpszComp.
534 INT WINAPI StrCmpNA(LPCSTR lpszStr, LPCSTR lpszComp, INT iLen)
536 INT iRet;
538 TRACE("(%s,%s,%i)\n", debugstr_a(lpszStr), debugstr_a(lpszComp), iLen);
540 iRet = CompareStringA(GetThreadLocale(), 0, lpszStr, iLen, lpszComp, iLen);
541 return iRet == CSTR_LESS_THAN ? -1 : iRet == CSTR_GREATER_THAN ? 1 : 0;
544 /**************************************************************************
545 * StrCmpNW [COMCTL32.360]
547 * See StrCmpNA.
549 INT WINAPI StrCmpNW(LPCWSTR lpszStr, LPCWSTR lpszComp, INT iLen)
551 INT iRet;
553 TRACE("(%s,%s,%i)\n", debugstr_w(lpszStr), debugstr_w(lpszComp), iLen);
555 iRet = CompareStringW(GetThreadLocale(), 0, lpszStr, iLen, lpszComp, iLen);
556 return iRet == CSTR_LESS_THAN ? -1 : iRet == CSTR_GREATER_THAN ? 1 : 0;
559 /**************************************************************************
560 * StrRChrA [COMCTL32.351]
562 * Find the last occurrence of a character in string.
564 * PARAMS
565 * lpszStr [I] String to search in
566 * lpszEnd [I] Place to end search, or NULL to search until the end of lpszStr
567 * ch [I] Character to search for.
569 * RETURNS
570 * Success: A pointer to the last occurrence of ch in lpszStr before lpszEnd,
571 * or NULL if not found.
572 * Failure: NULL, if any arguments are invalid.
574 LPSTR WINAPI StrRChrA(LPCSTR lpszStr, LPCSTR lpszEnd, WORD ch)
576 LPCSTR lpszRet = NULL;
578 TRACE("(%s,%s,%x)\n", debugstr_a(lpszStr), debugstr_a(lpszEnd), ch);
580 if (lpszStr)
582 WORD ch2;
584 if (!lpszEnd)
585 lpszEnd = lpszStr + lstrlenA(lpszStr);
587 while (*lpszStr && lpszStr <= lpszEnd)
589 ch2 = IsDBCSLeadByte(*lpszStr)? *lpszStr << 8 | lpszStr[1] : *lpszStr;
591 if (!COMCTL32_ChrCmpA(ch, ch2))
592 lpszRet = lpszStr;
593 lpszStr = CharNextA(lpszStr);
596 return (LPSTR)lpszRet;
600 /**************************************************************************
601 * StrRChrW [COMCTL32.359]
603 * See StrRChrA.
605 LPWSTR WINAPI StrRChrW(LPCWSTR lpszStr, LPCWSTR lpszEnd, WORD ch)
607 LPCWSTR lpszRet = NULL;
609 TRACE("(%s,%s,%x)\n", debugstr_w(lpszStr), debugstr_w(lpszEnd), ch);
611 if (lpszStr)
613 if (!lpszEnd)
614 lpszEnd = lpszStr + strlenW(lpszStr);
616 while (*lpszStr && lpszStr <= lpszEnd)
618 if (!COMCTL32_ChrCmpW(ch, *lpszStr))
619 lpszRet = lpszStr;
620 lpszStr = CharNextW(lpszStr);
623 return (LPWSTR)lpszRet;
626 /**************************************************************************
627 * StrStrA [COMCTL32.354]
629 * Find a substring within a string.
631 * PARAMS
632 * lpszStr [I] String to search in
633 * lpszSearch [I] String to look for
635 * RETURNS
636 * The start of lpszSearch within lpszStr, or NULL if not found.
638 LPSTR WINAPI StrStrA(LPCSTR lpszStr, LPCSTR lpszSearch)
640 TRACE("(%s,%s)\n", debugstr_a(lpszStr), debugstr_a(lpszSearch));
642 return COMCTL32_StrStrHelperA(lpszStr, lpszSearch, StrCmpNA);
645 /**************************************************************************
646 * StrStrW [COMCTL32.362]
648 * See StrStrA.
650 LPWSTR WINAPI StrStrW(LPCWSTR lpszStr, LPCWSTR lpszSearch)
652 TRACE("(%s,%s)\n", debugstr_w(lpszStr), debugstr_w(lpszSearch));
654 return COMCTL32_StrStrHelperW(lpszStr, lpszSearch, StrCmpNW);
657 /*************************************************************************
658 * StrChrIA [COMCTL32.366]
660 * Find a given character in a string, ignoring case.
662 * PARAMS
663 * lpszStr [I] String to search in.
664 * ch [I] Character to search for.
666 * RETURNS
667 * Success: A pointer to the first occurrence of ch in lpszStr, or NULL if
668 * not found.
669 * Failure: NULL, if any arguments are invalid.
671 LPSTR WINAPI StrChrIA(LPCSTR lpszStr, WORD ch)
673 TRACE("(%s,%i)\n", debugstr_a(lpszStr), ch);
675 if (lpszStr)
677 while (*lpszStr)
679 if (!COMCTL32_ChrCmpIA(*lpszStr, ch))
680 return (LPSTR)lpszStr;
681 lpszStr = CharNextA(lpszStr);
684 return NULL;
687 /*************************************************************************
688 * StrChrIW [COMCTL32.367]
690 * See StrChrA.
692 LPWSTR WINAPI StrChrIW(LPCWSTR lpszStr, WCHAR ch)
694 TRACE("(%s,%i)\n", debugstr_w(lpszStr), ch);
696 if (lpszStr)
698 ch = toupperW(ch);
699 while (*lpszStr)
701 if (toupperW(*lpszStr) == ch)
702 return (LPWSTR)lpszStr;
703 lpszStr = CharNextW(lpszStr);
705 lpszStr = NULL;
707 return (LPWSTR)lpszStr;
710 /*************************************************************************
711 * StrRStrIA [COMCTL32.372]
713 * Find the last occurrence of a substring within a string.
715 * PARAMS
716 * lpszStr [I] String to search in
717 * lpszEnd [I] End of lpszStr
718 * lpszSearch [I] String to look for
720 * RETURNS
721 * The last occurrence lpszSearch within lpszStr, or NULL if not found.
723 LPSTR WINAPI StrRStrIA(LPCSTR lpszStr, LPCSTR lpszEnd, LPCSTR lpszSearch)
725 LPSTR lpszRet = NULL;
726 WORD ch1, ch2;
727 INT iLen;
729 TRACE("(%s,%s)\n", debugstr_a(lpszStr), debugstr_a(lpszSearch));
731 if (!lpszStr || !lpszSearch || !*lpszSearch)
732 return NULL;
734 if (!lpszEnd)
735 lpszEnd = lpszStr + lstrlenA(lpszStr);
737 if (IsDBCSLeadByte(*lpszSearch))
738 ch1 = *lpszSearch << 8 | lpszSearch[1];
739 else
740 ch1 = *lpszSearch;
741 iLen = lstrlenA(lpszSearch);
743 while (lpszStr <= lpszEnd && *lpszStr)
745 ch2 = IsDBCSLeadByte(*lpszStr)? *lpszStr << 8 | lpszStr[1] : *lpszStr;
746 if (!COMCTL32_ChrCmpIA(ch1, ch2))
748 if (!StrCmpNIA(lpszStr, lpszSearch, iLen))
749 lpszRet = (LPSTR)lpszStr;
751 lpszStr = CharNextA(lpszStr);
753 return lpszRet;
756 /*************************************************************************
757 * StrRStrIW [COMCTL32.373]
759 * See StrRStrIA.
761 LPWSTR WINAPI StrRStrIW(LPCWSTR lpszStr, LPCWSTR lpszEnd, LPCWSTR lpszSearch)
763 LPWSTR lpszRet = NULL;
764 INT iLen;
766 TRACE("(%s,%s)\n", debugstr_w(lpszStr), debugstr_w(lpszSearch));
768 if (!lpszStr || !lpszSearch || !*lpszSearch)
769 return NULL;
771 if (!lpszEnd)
772 lpszEnd = lpszStr + strlenW(lpszStr);
774 iLen = strlenW(lpszSearch);
776 while (lpszStr <= lpszEnd && *lpszStr)
778 if (!COMCTL32_ChrCmpIW(*lpszSearch, *lpszStr))
780 if (!StrCmpNIW(lpszStr, lpszSearch, iLen))
781 lpszRet = (LPWSTR)lpszStr;
783 lpszStr = CharNextW(lpszStr);
785 return lpszRet;
788 /*************************************************************************
789 * COMCTL32_StrSpnHelperW
791 * Internal implementation of StrSpnW/StrCSpnW/StrCSpnIW
793 static int COMCTL32_StrSpnHelperW(LPCWSTR lpszStr, LPCWSTR lpszMatch,
794 LPWSTR (WINAPI *pStrChrFn)(LPCWSTR,WCHAR),
795 BOOL bInvert)
797 LPCWSTR lpszRead = lpszStr;
798 if (lpszStr && *lpszStr && lpszMatch)
800 while (*lpszRead)
802 LPCWSTR lpszTest = pStrChrFn(lpszMatch, *lpszRead);
804 if (!bInvert && !lpszTest)
805 break;
806 if (bInvert && lpszTest)
807 break;
808 lpszRead = CharNextW(lpszRead);
811 return lpszRead - lpszStr;
814 /*************************************************************************
815 * StrCSpnIA [COMCTL32.374]
817 * Find the length of the start of a string that does not contain certain
818 * characters, ignoring case.
820 * PARAMS
821 * lpszStr [I] String to search
822 * lpszMatch [I] Characters that cannot be in the substring
824 * RETURNS
825 * The length of the part of lpszStr containing only chars not in lpszMatch,
826 * or 0 if any parameter is invalid.
828 int WINAPI StrCSpnIA(LPCSTR lpszStr, LPCSTR lpszMatch)
830 TRACE("(%s,%s)\n",debugstr_a(lpszStr), debugstr_a(lpszMatch));
832 return COMCTL32_StrSpnHelperA(lpszStr, lpszMatch, StrChrIA, TRUE);
835 /*************************************************************************
836 * StrCSpnIW [COMCTL32.375]
838 * See StrCSpnIA.
840 int WINAPI StrCSpnIW(LPCWSTR lpszStr, LPCWSTR lpszMatch)
842 TRACE("(%s,%s)\n",debugstr_w(lpszStr), debugstr_w(lpszMatch));
844 return COMCTL32_StrSpnHelperW(lpszStr, lpszMatch, StrChrIW, TRUE);
847 /**************************************************************************
848 * StrRChrIA [COMCTL32.368]
850 * Find the last occurrence of a character in string, ignoring case.
852 * PARAMS
853 * lpszStr [I] String to search in
854 * lpszEnd [I] Place to end search, or NULL to search until the end of lpszStr
855 * ch [I] Character to search for.
857 * RETURNS
858 * Success: A pointer to the last occurrence of ch in lpszStr before lpszEnd,
859 * or NULL if not found.
860 * Failure: NULL, if any arguments are invalid.
862 LPSTR WINAPI StrRChrIA(LPCSTR lpszStr, LPCSTR lpszEnd, WORD ch)
864 LPCSTR lpszRet = NULL;
866 TRACE("(%s,%s,%x)\n", debugstr_a(lpszStr), debugstr_a(lpszEnd), ch);
868 if (lpszStr)
870 WORD ch2;
872 if (!lpszEnd)
873 lpszEnd = lpszStr + lstrlenA(lpszStr);
875 while (*lpszStr && lpszStr <= lpszEnd)
877 ch2 = IsDBCSLeadByte(*lpszStr)? *lpszStr << 8 | lpszStr[1] : *lpszStr;
879 if (ch == ch2)
880 lpszRet = lpszStr;
881 lpszStr = CharNextA(lpszStr);
884 return (LPSTR)lpszRet;
887 /**************************************************************************
888 * StrRChrIW [COMCTL32.369]
890 * See StrRChrIA.
892 LPWSTR WINAPI StrRChrIW(LPCWSTR lpszStr, LPCWSTR lpszEnd, WORD ch)
894 LPCWSTR lpszRet = NULL;
896 TRACE("(%s,%s,%x)\n", debugstr_w(lpszStr), debugstr_w(lpszEnd), ch);
898 if (lpszStr)
900 if (!lpszEnd)
901 lpszEnd = lpszStr + strlenW(lpszStr);
903 while (*lpszStr && lpszStr <= lpszEnd)
905 if (ch == *lpszStr)
906 lpszRet = lpszStr;
907 lpszStr = CharNextW(lpszStr);
910 return (LPWSTR)lpszRet;
913 /*************************************************************************
914 * StrCSpnW [COMCTL32.364]
916 * See StrCSpnA.
918 int WINAPI StrCSpnW(LPCWSTR lpszStr, LPCWSTR lpszMatch)
920 TRACE("(%s,%s)\n",debugstr_w(lpszStr), debugstr_w(lpszMatch));
922 return COMCTL32_StrSpnHelperW(lpszStr, lpszMatch, StrChrW, TRUE);
925 /*************************************************************************
926 * IntlStrEqWorkerA [COMCTL32.376]
928 * Compare two strings.
930 * PARAMS
931 * bCase [I] Whether to compare case sensitively
932 * lpszStr [I] First string to compare
933 * lpszComp [I] Second string to compare
934 * iLen [I] Length to compare
936 * RETURNS
937 * TRUE If the strings are equal.
938 * FALSE Otherwise.
940 BOOL WINAPI IntlStrEqWorkerA(BOOL bCase, LPCSTR lpszStr, LPCSTR lpszComp,
941 int iLen)
943 DWORD dwFlags = LOCALE_USE_CP_ACP;
944 int iRet;
946 TRACE("(%d,%s,%s,%d)\n", bCase,
947 debugstr_a(lpszStr), debugstr_a(lpszComp), iLen);
949 /* FIXME: These flags are undocumented and unknown by our CompareString.
950 * We need defines for them.
952 dwFlags |= bCase ? 0x10000000 : 0x10000001;
954 iRet = CompareStringA(GetThreadLocale(),
955 dwFlags, lpszStr, iLen, lpszComp, iLen);
957 if (!iRet)
958 iRet = CompareStringA(2048, dwFlags, lpszStr, iLen, lpszComp, iLen);
960 return iRet == 2 ? TRUE : FALSE;
963 /*************************************************************************
964 * IntlStrEqWorkerW [COMCTL32.377]
966 * See IntlStrEqWorkerA.
968 BOOL WINAPI IntlStrEqWorkerW(BOOL bCase, LPCWSTR lpszStr, LPCWSTR lpszComp,
969 int iLen)
971 DWORD dwFlags;
972 int iRet;
974 TRACE("(%d,%s,%s,%d)\n", bCase,
975 debugstr_w(lpszStr),debugstr_w(lpszComp), iLen);
977 /* FIXME: These flags are undocumented and unknown by our CompareString.
978 * We need defines for them.
980 dwFlags = bCase ? 0x10000000 : 0x10000001;
982 iRet = CompareStringW(GetThreadLocale(),
983 dwFlags, lpszStr, iLen, lpszComp, iLen);
985 if (!iRet)
986 iRet = CompareStringW(2048, dwFlags, lpszStr, iLen, lpszComp, iLen);
988 return iRet == 2 ? TRUE : FALSE;