* Sync up to trunk head (r64921).
[reactos.git] / dll / win32 / comctl32 / string.c
1 /*
2 * String manipulation functions
3 *
4 * Copyright 1998 Eric Kohl
5 * 1998 Juergen Schmied <j.schmied@metronet.de>
6 * 2000 Eric Kohl for CodeWeavers
7 * Copyright 2002 Jon Griffiths
8 *
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.
13 *
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.
18 *
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
22 *
23 */
24
25 #include "comctl32.h"
26
27 WINE_DEFAULT_DEBUG_CHANNEL(commctrl);
28
29 /*************************************************************************
30 * COMCTL32_ChrCmpHelperA
31 *
32 * Internal helper for ChrCmpA/COMCTL32_ChrCmpIA.
33 *
34 * NOTES
35 * Both this function and its Unicode counterpart are very inefficient. To
36 * fix this, CompareString must be completely implemented and optimised
37 * first. Then the core character test can be taken out of that function and
38 * placed here, so that it need never be called at all. Until then, do not
39 * attempt to optimise this code unless you are willing to test that it
40 * still performs correctly.
41 */
42 static BOOL COMCTL32_ChrCmpHelperA(WORD ch1, WORD ch2, DWORD dwFlags)
43 {
44 char str1[3], str2[3];
45
46 str1[0] = LOBYTE(ch1);
47 if (IsDBCSLeadByte(str1[0]))
48 {
49 str1[1] = HIBYTE(ch1);
50 str1[2] = '\0';
51 }
52 else
53 str1[1] = '\0';
54
55 str2[0] = LOBYTE(ch2);
56 if (IsDBCSLeadByte(str2[0]))
57 {
58 str2[1] = HIBYTE(ch2);
59 str2[2] = '\0';
60 }
61 else
62 str2[1] = '\0';
63
64 return CompareStringA(GetThreadLocale(), dwFlags, str1, -1, str2, -1) - CSTR_EQUAL;
65 }
66
67 /*************************************************************************
68 * COMCTL32_ChrCmpA (internal)
69 *
70 * Internal helper function.
71 */
72 static BOOL COMCTL32_ChrCmpA(WORD ch1, WORD ch2)
73 {
74 return COMCTL32_ChrCmpHelperA(ch1, ch2, 0);
75 }
76
77 /*************************************************************************
78 * COMCTL32_ChrCmpIA (internal)
79 *
80 * Compare two characters, ignoring case.
81 *
82 * PARAMS
83 * ch1 [I] First character to compare
84 * ch2 [I] Second character to compare
85 *
86 * RETURNS
87 * FALSE, if the characters are equal.
88 * Non-zero otherwise.
89 */
90 static BOOL COMCTL32_ChrCmpIA(WORD ch1, WORD ch2)
91 {
92 TRACE("(%d,%d)\n", ch1, ch2);
93
94 return COMCTL32_ChrCmpHelperA(ch1, ch2, NORM_IGNORECASE);
95 }
96
97 /*************************************************************************
98 * COMCTL32_ChrCmpIW
99 *
100 * Internal helper function.
101 */
102 static inline BOOL COMCTL32_ChrCmpIW(WCHAR ch1, WCHAR ch2)
103 {
104 return CompareStringW(GetThreadLocale(), NORM_IGNORECASE, &ch1, 1, &ch2, 1) - CSTR_EQUAL;
105 }
106
107 /**************************************************************************
108 * Str_GetPtrA [COMCTL32.233]
109 *
110 * Copies a string into a destination buffer.
111 *
112 * PARAMS
113 * lpSrc [I] Source string
114 * lpDest [O] Destination buffer
115 * nMaxLen [I] Size of buffer in characters
116 *
117 * RETURNS
118 * The number of characters copied.
119 */
120 INT WINAPI Str_GetPtrA (LPCSTR lpSrc, LPSTR lpDest, INT nMaxLen)
121 {
122 INT len;
123
124 TRACE("(%p %p %d)\n", lpSrc, lpDest, nMaxLen);
125
126 if ((!lpDest || nMaxLen == 0) && lpSrc)
127 return (strlen(lpSrc) + 1);
128
129 if (nMaxLen == 0)
130 return 0;
131
132 if (lpSrc == NULL) {
133 lpDest[0] = '\0';
134 return 0;
135 }
136
137 len = strlen(lpSrc) + 1;
138 if (len >= nMaxLen)
139 len = nMaxLen;
140
141 RtlMoveMemory (lpDest, lpSrc, len - 1);
142 lpDest[len - 1] = '\0';
143
144 return len;
145 }
146
147 /**************************************************************************
148 * Str_SetPtrA [COMCTL32.234]
149 *
150 * Makes a copy of a string, allocating memory if necessary.
151 *
152 * PARAMS
153 * lppDest [O] Pointer to destination string
154 * lpSrc [I] Source string
155 *
156 * RETURNS
157 * Success: TRUE
158 * Failure: FALSE
159 *
160 * NOTES
161 * Set lpSrc to NULL to free the memory allocated by a previous call
162 * to this function.
163 */
164 BOOL WINAPI Str_SetPtrA (LPSTR *lppDest, LPCSTR lpSrc)
165 {
166 TRACE("(%p %p)\n", lppDest, lpSrc);
167
168 if (lpSrc) {
169 LPSTR ptr = ReAlloc (*lppDest, strlen (lpSrc) + 1);
170 if (!ptr)
171 return FALSE;
172 strcpy (ptr, lpSrc);
173 *lppDest = ptr;
174 }
175 else {
176 Free (*lppDest);
177 *lppDest = NULL;
178 }
179
180 return TRUE;
181 }
182
183 /**************************************************************************
184 * Str_GetPtrW [COMCTL32.235]
185 *
186 * See Str_GetPtrA.
187 */
188 INT WINAPI Str_GetPtrW (LPCWSTR lpSrc, LPWSTR lpDest, INT nMaxLen)
189 {
190 INT len;
191
192 TRACE("(%p %p %d)\n", lpSrc, lpDest, nMaxLen);
193
194 if (!lpDest && lpSrc)
195 return strlenW (lpSrc);
196
197 if (nMaxLen == 0)
198 return 0;
199
200 if (lpSrc == NULL) {
201 lpDest[0] = '\0';
202 return 0;
203 }
204
205 len = strlenW (lpSrc);
206 if (len >= nMaxLen)
207 len = nMaxLen - 1;
208
209 RtlMoveMemory (lpDest, lpSrc, len*sizeof(WCHAR));
210 lpDest[len] = '\0';
211
212 return len;
213 }
214
215 /**************************************************************************
216 * Str_SetPtrW [COMCTL32.236]
217 *
218 * See Str_SetPtrA.
219 */
220 BOOL WINAPI Str_SetPtrW (LPWSTR *lppDest, LPCWSTR lpSrc)
221 {
222 TRACE("(%p %s)\n", lppDest, debugstr_w(lpSrc));
223
224 if (lpSrc) {
225 INT len = strlenW (lpSrc) + 1;
226 LPWSTR ptr = ReAlloc (*lppDest, len * sizeof(WCHAR));
227 if (!ptr)
228 return FALSE;
229 strcpyW (ptr, lpSrc);
230 *lppDest = ptr;
231 }
232 else {
233 Free (*lppDest);
234 *lppDest = NULL;
235 }
236
237 return TRUE;
238 }
239
240 /**************************************************************************
241 * StrChrA [COMCTL32.350]
242 *
243 * Find a given character in a string.
244 *
245 * PARAMS
246 * lpszStr [I] String to search in.
247 * ch [I] Character to search for.
248 *
249 * RETURNS
250 * Success: A pointer to the first occurrence of ch in lpszStr, or NULL if
251 * not found.
252 * Failure: NULL, if any arguments are invalid.
253 */
254 LPSTR WINAPI StrChrA(LPCSTR lpszStr, WORD ch)
255 {
256 TRACE("(%s,%i)\n", debugstr_a(lpszStr), ch);
257
258 if (lpszStr)
259 {
260 while (*lpszStr)
261 {
262 if (!COMCTL32_ChrCmpA(*lpszStr, ch))
263 return (LPSTR)lpszStr;
264 lpszStr = CharNextA(lpszStr);
265 }
266 }
267 return NULL;
268 }
269
270 /**************************************************************************
271 * StrCmpNIA [COMCTL32.353]
272 *
273 * Compare two strings, up to a maximum length, ignoring case.
274 *
275 * PARAMS
276 * lpszStr [I] First string to compare
277 * lpszComp [I] Second string to compare
278 * iLen [I] Maximum number of chars to compare.
279 *
280 * RETURNS
281 * An integer less than, equal to or greater than 0, indicating that
282 * lpszStr is less than, the same, or greater than lpszComp.
283 */
284 INT WINAPI StrCmpNIA(LPCSTR lpszStr, LPCSTR lpszComp, INT iLen)
285 {
286 TRACE("(%s,%s,%i)\n", debugstr_a(lpszStr), debugstr_a(lpszComp), iLen);
287 return CompareStringA(GetThreadLocale(), NORM_IGNORECASE, lpszStr, iLen, lpszComp, iLen) - CSTR_EQUAL;
288 }
289
290 /*************************************************************************
291 * StrCmpNIW [COMCTL32.361]
292 *
293 * See StrCmpNIA.
294 */
295 INT WINAPI StrCmpNIW(LPCWSTR lpszStr, LPCWSTR lpszComp, INT iLen)
296 {
297 TRACE("(%s,%s,%i)\n", debugstr_w(lpszStr), debugstr_w(lpszComp), iLen);
298 return CompareStringW(GetThreadLocale(), NORM_IGNORECASE, lpszStr, iLen, lpszComp, iLen) - CSTR_EQUAL;
299 }
300
301 /*************************************************************************
302 * COMCTL32_StrStrHelperA
303 *
304 * Internal implementation of StrStrA/StrStrIA
305 */
306 static LPSTR COMCTL32_StrStrHelperA(LPCSTR lpszStr, LPCSTR lpszSearch,
307 INT (WINAPI *pStrCmpFn)(LPCSTR,LPCSTR,INT))
308 {
309 size_t iLen;
310
311 if (!lpszStr || !lpszSearch || !*lpszSearch)
312 return NULL;
313
314 iLen = strlen(lpszSearch);
315
316 while (*lpszStr)
317 {
318 if (!pStrCmpFn(lpszStr, lpszSearch, iLen))
319 return (LPSTR)lpszStr;
320 lpszStr = CharNextA(lpszStr);
321 }
322 return NULL;
323 }
324
325 /**************************************************************************
326 * StrStrIA [COMCTL32.355]
327 *
328 * Find a substring within a string, ignoring case.
329 *
330 * PARAMS
331 * lpszStr [I] String to search in
332 * lpszSearch [I] String to look for
333 *
334 * RETURNS
335 * The start of lpszSearch within lpszStr, or NULL if not found.
336 */
337 LPSTR WINAPI StrStrIA(LPCSTR lpszStr, LPCSTR lpszSearch)
338 {
339 TRACE("(%s,%s)\n", debugstr_a(lpszStr), debugstr_a(lpszSearch));
340
341 return COMCTL32_StrStrHelperA(lpszStr, lpszSearch, StrCmpNIA);
342 }
343
344 /**************************************************************************
345 * StrToIntA [COMCTL32.357]
346 *
347 * Read a signed integer from a string.
348 *
349 * PARAMS
350 * lpszStr [I] String to read integer from
351 *
352 * RETURNS
353 * The signed integer value represented by the string, or 0 if no integer is
354 * present.
355 */
356 INT WINAPI StrToIntA (LPCSTR lpszStr)
357 {
358 return atoi(lpszStr);
359 }
360
361 /**************************************************************************
362 * StrStrIW [COMCTL32.363]
363 *
364 * See StrStrIA.
365 */
366 LPWSTR WINAPI StrStrIW(LPCWSTR lpszStr, LPCWSTR lpszSearch)
367 {
368 int iLen;
369
370 TRACE("(%s,%s)\n", debugstr_w(lpszStr), debugstr_w(lpszSearch));
371
372 if (!lpszStr || !lpszSearch || !*lpszSearch)
373 return NULL;
374
375 iLen = strlenW(lpszSearch);
376
377 while (*lpszStr)
378 {
379 if (!StrCmpNIW(lpszStr, lpszSearch, iLen))
380 return (LPWSTR)lpszStr;
381 lpszStr++;
382 }
383 return NULL;
384 }
385
386 /**************************************************************************
387 * StrToIntW [COMCTL32.365]
388 *
389 * See StrToIntA.
390 */
391 INT WINAPI StrToIntW (LPCWSTR lpString)
392 {
393 return atoiW(lpString);
394 }
395
396 /*************************************************************************
397 * COMCTL32_StrSpnHelperA (internal)
398 *
399 * Internal implementation of StrSpnA/StrCSpnA/StrCSpnIA
400 */
401 static int COMCTL32_StrSpnHelperA(LPCSTR lpszStr, LPCSTR lpszMatch,
402 LPSTR (WINAPI *pStrChrFn)(LPCSTR,WORD),
403 BOOL bInvert)
404 {
405 LPCSTR lpszRead = lpszStr;
406 if (lpszStr && *lpszStr && lpszMatch)
407 {
408 while (*lpszRead)
409 {
410 LPCSTR lpszTest = pStrChrFn(lpszMatch, *lpszRead);
411
412 if (!bInvert && !lpszTest)
413 break;
414 if (bInvert && lpszTest)
415 break;
416 lpszRead = CharNextA(lpszRead);
417 };
418 }
419 return lpszRead - lpszStr;
420 }
421
422 /**************************************************************************
423 * StrCSpnA [COMCTL32.356]
424 *
425 * Find the length of the start of a string that does not contain certain
426 * characters.
427 *
428 * PARAMS
429 * lpszStr [I] String to search
430 * lpszMatch [I] Characters that cannot be in the substring
431 *
432 * RETURNS
433 * The length of the part of lpszStr containing only chars not in lpszMatch,
434 * or 0 if any parameter is invalid.
435 */
436 int WINAPI StrCSpnA(LPCSTR lpszStr, LPCSTR lpszMatch)
437 {
438 TRACE("(%s,%s)\n",debugstr_a(lpszStr), debugstr_a(lpszMatch));
439
440 return COMCTL32_StrSpnHelperA(lpszStr, lpszMatch, StrChrA, TRUE);
441 }
442
443 /**************************************************************************
444 * StrChrW [COMCTL32.358]
445 *
446 * See StrChrA.
447 */
448 LPWSTR WINAPI StrChrW(LPCWSTR lpszStr, WCHAR ch)
449 {
450 LPWSTR lpszRet = NULL;
451
452 TRACE("(%s,%i)\n", debugstr_w(lpszStr), ch);
453
454 if (lpszStr)
455 lpszRet = strchrW(lpszStr, ch);
456 return lpszRet;
457 }
458
459 /**************************************************************************
460 * StrCmpNA [COMCTL32.352]
461 *
462 * Compare two strings, up to a maximum length.
463 *
464 * PARAMS
465 * lpszStr [I] First string to compare
466 * lpszComp [I] Second string to compare
467 * iLen [I] Maximum number of chars to compare.
468 *
469 * RETURNS
470 * An integer less than, equal to or greater than 0, indicating that
471 * lpszStr is less than, the same, or greater than lpszComp.
472 */
473 INT WINAPI StrCmpNA(LPCSTR lpszStr, LPCSTR lpszComp, INT iLen)
474 {
475 TRACE("(%s,%s,%i)\n", debugstr_a(lpszStr), debugstr_a(lpszComp), iLen);
476 return CompareStringA(GetThreadLocale(), 0, lpszStr, iLen, lpszComp, iLen) - CSTR_EQUAL;
477 }
478
479 /**************************************************************************
480 * StrCmpNW [COMCTL32.360]
481 *
482 * See StrCmpNA.
483 */
484 INT WINAPI StrCmpNW(LPCWSTR lpszStr, LPCWSTR lpszComp, INT iLen)
485 {
486 TRACE("(%s,%s,%i)\n", debugstr_w(lpszStr), debugstr_w(lpszComp), iLen);
487 return CompareStringW(GetThreadLocale(), 0, lpszStr, iLen, lpszComp, iLen) - CSTR_EQUAL;
488 }
489
490 /**************************************************************************
491 * StrRChrA [COMCTL32.351]
492 *
493 * Find the last occurrence of a character in string.
494 *
495 * PARAMS
496 * lpszStr [I] String to search in
497 * lpszEnd [I] Place to end search, or NULL to search until the end of lpszStr
498 * ch [I] Character to search for.
499 *
500 * RETURNS
501 * Success: A pointer to the last occurrence of ch in lpszStr before lpszEnd,
502 * or NULL if not found.
503 * Failure: NULL, if any arguments are invalid.
504 */
505 LPSTR WINAPI StrRChrA(LPCSTR lpszStr, LPCSTR lpszEnd, WORD ch)
506 {
507 LPCSTR lpszRet = NULL;
508
509 TRACE("(%s,%s,%x)\n", debugstr_a(lpszStr), debugstr_a(lpszEnd), ch);
510
511 if (lpszStr)
512 {
513 WORD ch2;
514
515 if (!lpszEnd)
516 lpszEnd = lpszStr + lstrlenA(lpszStr);
517
518 while (*lpszStr && lpszStr <= lpszEnd)
519 {
520 ch2 = IsDBCSLeadByte(*lpszStr)? *lpszStr << 8 | lpszStr[1] : *lpszStr;
521
522 if (!COMCTL32_ChrCmpA(ch, ch2))
523 lpszRet = lpszStr;
524 lpszStr = CharNextA(lpszStr);
525 }
526 }
527 return (LPSTR)lpszRet;
528 }
529
530
531 /**************************************************************************
532 * StrRChrW [COMCTL32.359]
533 *
534 * See StrRChrA.
535 */
536 LPWSTR WINAPI StrRChrW(LPCWSTR str, LPCWSTR end, WORD ch)
537 {
538 WCHAR *ret = NULL;
539
540 if (!str) return NULL;
541 if (!end) end = str + strlenW(str);
542 while (str < end)
543 {
544 if (*str == ch) ret = (WCHAR *)str;
545 str++;
546 }
547 return ret;
548 }
549
550 /**************************************************************************
551 * StrStrA [COMCTL32.354]
552 *
553 * Find a substring within a string.
554 *
555 * PARAMS
556 * lpszStr [I] String to search in
557 * lpszSearch [I] String to look for
558 *
559 * RETURNS
560 * The start of lpszSearch within lpszStr, or NULL if not found.
561 */
562 LPSTR WINAPI StrStrA(LPCSTR lpszStr, LPCSTR lpszSearch)
563 {
564 TRACE("(%s,%s)\n", debugstr_a(lpszStr), debugstr_a(lpszSearch));
565
566 return COMCTL32_StrStrHelperA(lpszStr, lpszSearch, StrCmpNA);
567 }
568
569 /**************************************************************************
570 * StrStrW [COMCTL32.362]
571 *
572 * See StrStrA.
573 */
574 LPWSTR WINAPI StrStrW(LPCWSTR lpszStr, LPCWSTR lpszSearch)
575 {
576 if (!lpszStr || !lpszSearch) return NULL;
577 return strstrW( lpszStr, lpszSearch );
578 }
579
580 /*************************************************************************
581 * StrChrIA [COMCTL32.366]
582 *
583 * Find a given character in a string, ignoring case.
584 *
585 * PARAMS
586 * lpszStr [I] String to search in.
587 * ch [I] Character to search for.
588 *
589 * RETURNS
590 * Success: A pointer to the first occurrence of ch in lpszStr, or NULL if
591 * not found.
592 * Failure: NULL, if any arguments are invalid.
593 */
594 LPSTR WINAPI StrChrIA(LPCSTR lpszStr, WORD ch)
595 {
596 TRACE("(%s,%i)\n", debugstr_a(lpszStr), ch);
597
598 if (lpszStr)
599 {
600 while (*lpszStr)
601 {
602 if (!COMCTL32_ChrCmpIA(*lpszStr, ch))
603 return (LPSTR)lpszStr;
604 lpszStr = CharNextA(lpszStr);
605 }
606 }
607 return NULL;
608 }
609
610 /*************************************************************************
611 * StrChrIW [COMCTL32.367]
612 *
613 * See StrChrA.
614 */
615 LPWSTR WINAPI StrChrIW(LPCWSTR lpszStr, WCHAR ch)
616 {
617 TRACE("(%s,%i)\n", debugstr_w(lpszStr), ch);
618
619 if (lpszStr)
620 {
621 ch = toupperW(ch);
622 while (*lpszStr)
623 {
624 if (toupperW(*lpszStr) == ch)
625 return (LPWSTR)lpszStr;
626 lpszStr++;
627 }
628 lpszStr = NULL;
629 }
630 return (LPWSTR)lpszStr;
631 }
632
633 /*************************************************************************
634 * StrRStrIA [COMCTL32.372]
635 *
636 * Find the last occurrence of a substring within a string.
637 *
638 * PARAMS
639 * lpszStr [I] String to search in
640 * lpszEnd [I] End of lpszStr
641 * lpszSearch [I] String to look for
642 *
643 * RETURNS
644 * The last occurrence lpszSearch within lpszStr, or NULL if not found.
645 */
646 LPSTR WINAPI StrRStrIA(LPCSTR lpszStr, LPCSTR lpszEnd, LPCSTR lpszSearch)
647 {
648 LPSTR lpszRet = NULL;
649 WORD ch1, ch2;
650 INT iLen;
651
652 TRACE("(%s,%s)\n", debugstr_a(lpszStr), debugstr_a(lpszSearch));
653
654 if (!lpszStr || !lpszSearch || !*lpszSearch)
655 return NULL;
656
657 if (!lpszEnd)
658 lpszEnd = lpszStr + lstrlenA(lpszStr);
659
660 if (IsDBCSLeadByte(*lpszSearch))
661 ch1 = *lpszSearch << 8 | lpszSearch[1];
662 else
663 ch1 = *lpszSearch;
664 iLen = lstrlenA(lpszSearch);
665
666 while (lpszStr <= lpszEnd && *lpszStr)
667 {
668 ch2 = IsDBCSLeadByte(*lpszStr)? *lpszStr << 8 | lpszStr[1] : *lpszStr;
669 if (!COMCTL32_ChrCmpIA(ch1, ch2))
670 {
671 if (!StrCmpNIA(lpszStr, lpszSearch, iLen))
672 lpszRet = (LPSTR)lpszStr;
673 }
674 lpszStr = CharNextA(lpszStr);
675 }
676 return lpszRet;
677 }
678
679 /*************************************************************************
680 * StrRStrIW [COMCTL32.373]
681 *
682 * See StrRStrIA.
683 */
684 LPWSTR WINAPI StrRStrIW(LPCWSTR lpszStr, LPCWSTR lpszEnd, LPCWSTR lpszSearch)
685 {
686 LPWSTR lpszRet = NULL;
687 INT iLen;
688
689 TRACE("(%s,%s)\n", debugstr_w(lpszStr), debugstr_w(lpszSearch));
690
691 if (!lpszStr || !lpszSearch || !*lpszSearch)
692 return NULL;
693
694 if (!lpszEnd)
695 lpszEnd = lpszStr + strlenW(lpszStr);
696
697 iLen = strlenW(lpszSearch);
698
699 while (lpszStr <= lpszEnd && *lpszStr)
700 {
701 if (!COMCTL32_ChrCmpIW(*lpszSearch, *lpszStr))
702 {
703 if (!StrCmpNIW(lpszStr, lpszSearch, iLen))
704 lpszRet = (LPWSTR)lpszStr;
705 }
706 lpszStr++;
707 }
708 return lpszRet;
709 }
710
711 /*************************************************************************
712 * StrCSpnIA [COMCTL32.374]
713 *
714 * Find the length of the start of a string that does not contain certain
715 * characters, ignoring case.
716 *
717 * PARAMS
718 * lpszStr [I] String to search
719 * lpszMatch [I] Characters that cannot be in the substring
720 *
721 * RETURNS
722 * The length of the part of lpszStr containing only chars not in lpszMatch,
723 * or 0 if any parameter is invalid.
724 */
725 int WINAPI StrCSpnIA(LPCSTR lpszStr, LPCSTR lpszMatch)
726 {
727 TRACE("(%s,%s)\n",debugstr_a(lpszStr), debugstr_a(lpszMatch));
728
729 return COMCTL32_StrSpnHelperA(lpszStr, lpszMatch, StrChrIA, TRUE);
730 }
731
732 /*************************************************************************
733 * StrCSpnIW [COMCTL32.375]
734 *
735 * See StrCSpnIA.
736 */
737 int WINAPI StrCSpnIW(LPCWSTR lpszStr, LPCWSTR lpszMatch)
738 {
739 LPCWSTR lpszRead = lpszStr;
740
741 TRACE("(%s,%s)\n",debugstr_w(lpszStr), debugstr_w(lpszMatch));
742
743 if (lpszStr && *lpszStr && lpszMatch)
744 {
745 while (*lpszRead)
746 {
747 if (StrChrIW(lpszMatch, *lpszRead)) break;
748 lpszRead++;
749 }
750 }
751 return lpszRead - lpszStr;
752 }
753
754 /**************************************************************************
755 * StrRChrIA [COMCTL32.368]
756 *
757 * Find the last occurrence of a character in string, ignoring case.
758 *
759 * PARAMS
760 * lpszStr [I] String to search in
761 * lpszEnd [I] Place to end search, or NULL to search until the end of lpszStr
762 * ch [I] Character to search for.
763 *
764 * RETURNS
765 * Success: A pointer to the last occurrence of ch in lpszStr before lpszEnd,
766 * or NULL if not found.
767 * Failure: NULL, if any arguments are invalid.
768 */
769 LPSTR WINAPI StrRChrIA(LPCSTR lpszStr, LPCSTR lpszEnd, WORD ch)
770 {
771 LPCSTR lpszRet = NULL;
772
773 TRACE("(%s,%s,%x)\n", debugstr_a(lpszStr), debugstr_a(lpszEnd), ch);
774
775 if (lpszStr)
776 {
777 WORD ch2;
778
779 if (!lpszEnd)
780 lpszEnd = lpszStr + lstrlenA(lpszStr);
781
782 while (*lpszStr && lpszStr <= lpszEnd)
783 {
784 ch2 = IsDBCSLeadByte(*lpszStr)? *lpszStr << 8 | lpszStr[1] : *lpszStr;
785
786 if (ch == ch2)
787 lpszRet = lpszStr;
788 lpszStr = CharNextA(lpszStr);
789 }
790 }
791 return (LPSTR)lpszRet;
792 }
793
794 /**************************************************************************
795 * StrRChrIW [COMCTL32.369]
796 *
797 * See StrRChrIA.
798 */
799 LPWSTR WINAPI StrRChrIW(LPCWSTR str, LPCWSTR end, WORD ch)
800 {
801 WCHAR *ret = NULL;
802
803 if (!str) return NULL;
804 if (!end) end = str + strlenW(str);
805 while (str < end)
806 {
807 if (!COMCTL32_ChrCmpIW(*str, ch)) ret = (WCHAR *)str;
808 str++;
809 }
810 return ret;
811 }
812
813 /*************************************************************************
814 * StrCSpnW [COMCTL32.364]
815 *
816 * See StrCSpnA.
817 */
818 int WINAPI StrCSpnW(LPCWSTR lpszStr, LPCWSTR lpszMatch)
819 {
820 if (!lpszStr || !lpszMatch) return 0;
821 return strcspnW( lpszStr, lpszMatch );
822 }
823
824 /*************************************************************************
825 * IntlStrEqWorkerA [COMCTL32.376]
826 *
827 * Compare two strings.
828 *
829 * PARAMS
830 * bCase [I] Whether to compare case sensitively
831 * lpszStr [I] First string to compare
832 * lpszComp [I] Second string to compare
833 * iLen [I] Length to compare
834 *
835 * RETURNS
836 * TRUE If the strings are equal.
837 * FALSE Otherwise.
838 */
839 BOOL WINAPI IntlStrEqWorkerA(BOOL bCase, LPCSTR lpszStr, LPCSTR lpszComp,
840 int iLen)
841 {
842 DWORD dwFlags = LOCALE_USE_CP_ACP;
843 int iRet;
844
845 TRACE("(%d,%s,%s,%d)\n", bCase,
846 debugstr_a(lpszStr), debugstr_a(lpszComp), iLen);
847
848 /* FIXME: This flag is undocumented and unknown by our CompareString.
849 * We need a define for it.
850 */
851 dwFlags = 0x10000000;
852 if (!bCase) dwFlags |= NORM_IGNORECASE;
853
854 iRet = CompareStringA(GetThreadLocale(),
855 dwFlags, lpszStr, iLen, lpszComp, iLen);
856
857 if (!iRet)
858 iRet = CompareStringA(2048, dwFlags, lpszStr, iLen, lpszComp, iLen);
859
860 return iRet == CSTR_EQUAL;
861 }
862
863 /*************************************************************************
864 * IntlStrEqWorkerW [COMCTL32.377]
865 *
866 * See IntlStrEqWorkerA.
867 */
868 BOOL WINAPI IntlStrEqWorkerW(BOOL bCase, LPCWSTR lpszStr, LPCWSTR lpszComp,
869 int iLen)
870 {
871 DWORD dwFlags;
872 int iRet;
873
874 TRACE("(%d,%s,%s,%d)\n", bCase,
875 debugstr_w(lpszStr),debugstr_w(lpszComp), iLen);
876
877 /* FIXME: This flag is undocumented and unknown by our CompareString.
878 * We need a define for it.
879 */
880 dwFlags = 0x10000000;
881 if (!bCase) dwFlags |= NORM_IGNORECASE;
882
883 iRet = CompareStringW(GetThreadLocale(),
884 dwFlags, lpszStr, iLen, lpszComp, iLen);
885
886 if (!iRet)
887 iRet = CompareStringW(2048, dwFlags, lpszStr, iLen, lpszComp, iLen);
888
889 return iRet == CSTR_EQUAL;
890 }