2 * CRTDLL wide-char functions
4 * Copyright 1999 Alexandre Julliard
7 * These functions are really necessary only if sizeof(WCHAR) != sizeof(wchar_t),
8 * otherwise we could use the libc functions directly.
24 /*********************************************************************
25 * CRTDLL__wcsdup (CRTDLL.320)
27 LPWSTR __cdecl CRTDLL__wcsdup( LPCWSTR str )
32 int size = (CRTDLL_wcslen(str) + 1) * sizeof(WCHAR);
33 ret = CRTDLL_malloc( size );
34 if (ret) memcpy( ret, str, size );
40 /*********************************************************************
41 * CRTDLL__wcsicmp (CRTDLL.321)
43 INT __cdecl CRTDLL__wcsicmp( LPCWSTR str1, LPCWSTR str2 )
45 while (*str1 && (CRTDLL_towupper(*str1) == CRTDLL_towupper(*str2)))
50 return CRTDLL_towupper(*str1) - CRTDLL_towupper(*str2);
54 /*********************************************************************
55 * CRTDLL__wcsicoll (CRTDLL.322)
57 INT __cdecl CRTDLL__wcsicoll( LPCWSTR str1, LPCWSTR str2 )
59 /* FIXME: handle collates */
60 return CRTDLL__wcsicmp( str1, str2 );
64 /*********************************************************************
65 * CRTDLL__wcslwr (CRTDLL.323)
67 LPWSTR __cdecl CRTDLL__wcslwr( LPWSTR str )
70 for ( ; *str; str++) *str = CRTDLL_towlower(*str);
75 /*********************************************************************
76 * CRTDLL__wcsnicmp (CRTDLL.324)
78 INT __cdecl CRTDLL__wcsnicmp( LPCWSTR str1, LPCWSTR str2, INT n )
81 while ((--n > 0) && *str1 && (CRTDLL_towupper(*str1) == CRTDLL_towupper(*str2)))
86 return CRTDLL_towupper(*str1) - CRTDLL_towupper(*str2);
90 /*********************************************************************
91 * CRTDLL__wcsnset (CRTDLL.325)
93 LPWSTR __cdecl CRTDLL__wcsnset( LPWSTR str, WCHAR c, INT n )
96 while ((n-- > 0) && *str) *str++ = c;
101 /*********************************************************************
102 * CRTDLL__wcsrev (CRTDLL.326)
104 LPWSTR __cdecl CRTDLL__wcsrev( LPWSTR str )
107 LPWSTR end = str + CRTDLL_wcslen(str) - 1;
118 /*********************************************************************
119 * CRTDLL__wcsset (CRTDLL.327)
121 LPWSTR __cdecl CRTDLL__wcsset( LPWSTR str, WCHAR c )
124 while (*str) *str++ = c;
129 /*********************************************************************
130 * CRTDLL__wcsupr (CRTDLL.328)
132 LPWSTR __cdecl CRTDLL__wcsupr( LPWSTR str )
135 for ( ; *str; str++) *str = CRTDLL_towupper(*str);
140 /*********************************************************************
141 * CRTDLL_towlower (CRTDLL.493)
143 WCHAR __cdecl CRTDLL_towlower( WCHAR ch )
146 ch = (WCHAR)towlower( (wchar_t)ch );
148 if (!HIBYTE(ch)) ch = (WCHAR)tolower( LOBYTE(ch) ); /* FIXME */
154 /*********************************************************************
155 * CRTDLL_towupper (CRTDLL.494)
157 WCHAR __cdecl CRTDLL_towupper( WCHAR ch )
160 ch = (WCHAR)towupper( (wchar_t)ch );
162 if (!HIBYTE(ch)) ch = (WCHAR)toupper( LOBYTE(ch) ); /* FIXME */
168 /***********************************************************************
169 * CRTDLL_wcscat (CRTDLL.503)
171 LPWSTR __cdecl CRTDLL_wcscat( LPWSTR dst, LPCWSTR src )
175 while ((*p++ = *src++));
180 /*********************************************************************
181 * CRTDLL_wcschr (CRTDLL.504)
183 LPWSTR __cdecl CRTDLL_wcschr( LPCWSTR str, WCHAR ch )
187 if (*str == ch) return (LPWSTR)str;
194 /*********************************************************************
195 * CRTDLL_wcscmp (CRTDLL.505)
197 INT __cdecl CRTDLL_wcscmp( LPCWSTR str1, LPCWSTR str2 )
199 while (*str1 && (*str1 == *str2)) { str1++; str2++; }
200 return (INT)(*str1 - *str2);
204 /*********************************************************************
205 * CRTDLL_wcscoll (CRTDLL.506)
207 DWORD __cdecl CRTDLL_wcscoll( LPCWSTR str1, LPCWSTR str2 )
209 /* FIXME: handle collates */
210 return CRTDLL_wcscmp( str1, str2 );
214 /***********************************************************************
215 * CRTDLL_wcscpy (CRTDLL.507)
217 LPWSTR __cdecl CRTDLL_wcscpy( LPWSTR dst, LPCWSTR src )
220 while ((*p++ = *src++));
225 /*********************************************************************
226 * CRTDLL_wcscspn (CRTDLL.508)
228 INT __cdecl CRTDLL_wcscspn( LPCWSTR str, LPCWSTR reject )
234 while (*p && (*p != *str)) p++;
242 /***********************************************************************
243 * CRTDLL_wcslen (CRTDLL.510)
245 INT __cdecl CRTDLL_wcslen( LPCWSTR str )
253 /*********************************************************************
254 * CRTDLL_wcsncat (CRTDLL.511)
256 LPWSTR __cdecl CRTDLL_wcsncat( LPWSTR s1, LPCWSTR s2, INT n )
260 while (n-- > 0) if (!(*s1++ = *s2++)) return ret;
266 /*********************************************************************
267 * CRTDLL_wcsncmp (CRTDLL.512)
269 INT __cdecl CRTDLL_wcsncmp( LPCWSTR str1, LPCWSTR str2, INT n )
272 while ((--n > 0) && *str1 && (*str1 == *str2)) { str1++; str2++; }
273 return (INT)(*str1 - *str2);
277 /*********************************************************************
278 * CRTDLL_wcsncpy (CRTDLL.513)
280 LPWSTR __cdecl CRTDLL_wcsncpy( LPWSTR s1, LPCWSTR s2, INT n )
283 while (n-- > 0) if (!(*s1++ = *s2++)) break;
284 while (n-- > 0) *s1++ = 0;
289 /*********************************************************************
290 * CRTDLL_wcspbrk (CRTDLL.514)
292 LPWSTR __cdecl CRTDLL_wcspbrk( LPCWSTR str, LPCWSTR accept )
297 for (p = accept; *p; p++) if (*p == *str) return (LPWSTR)str;
304 /*********************************************************************
305 * CRTDLL_wcsrchr (CRTDLL.515)
307 LPWSTR __cdecl CRTDLL_wcsrchr( LPWSTR str, WCHAR ch )
312 if (*str == ch) last = str;
319 /*********************************************************************
320 * CRTDLL_wcsspn (CRTDLL.516)
322 INT __cdecl CRTDLL_wcsspn( LPCWSTR str, LPCWSTR accept )
328 while (*p && (*p != *str)) p++;
336 /*********************************************************************
337 * CRTDLL_wcsstr (CRTDLL.517)
339 LPWSTR __cdecl CRTDLL_wcsstr( LPCWSTR str, LPCWSTR sub )
343 LPCWSTR p1 = str, p2 = sub;
344 while (*p1 && *p2 && *p1 == *p2) { p1++; p2++; }
345 if (!*p2) return (LPWSTR)str;
352 /*********************************************************************
353 * CRTDLL_wcstok (CRTDLL.519)
355 LPWSTR __cdecl CRTDLL_wcstok( LPWSTR str, LPCWSTR delim )
357 static LPWSTR next = NULL;
361 if (!(str = next)) return NULL;
363 while (*str && CRTDLL_wcschr( delim, *str )) str++;
364 if (!*str) return NULL;
366 while (*str && !CRTDLL_wcschr( delim, *str )) str++;
367 if (*str) *str++ = 0;
373 /*********************************************************************
374 * CRTDLL_wcstombs (CRTDLL.521)
376 * FIXME: the reason I do not use wcstombs is that it seems to fail
377 * for any latin-1 valid character. Not good.
379 INT __cdecl CRTDLL_wcstombs( LPSTR dst, LPCWSTR src, INT n )
382 while ((n>0) && *src) {
384 /* FIXME: could potentially overflow if we ever have MB of 2 bytes*/
385 ret = wctomb(dst,(wchar_t)*src);
387 /* FIXME: sadly, some versions of glibc do not like latin characters
388 * as UNICODE chars for some reason (like german umlauts). Just
389 * copy those anyway. MM 991106
402 /*********************************************************************
403 * CRTDLL_wctomb (CRTDLL.524)
405 INT __cdecl CRTDLL_wctomb( LPSTR dst, WCHAR ch )
407 return wctomb( dst, (wchar_t)ch );