configure: Make the font warning more explicit about what package is missing.
[wine/multimedia.git] / dlls / user / lstr.c
blobf75aa36eb54cfd5f9141d28a2236518f30408025
1 /*
2 * USER string functions
4 * Copyright 1993 Yngvi Sigurjonsson (yngvi@hafro.is)
5 * Copyright 1996 Alexandre Julliard
6 * Copyright 1996 Marcus Meissner
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "config.h"
24 #include "wine/port.h"
26 #include <ctype.h>
27 #include <stdarg.h>
28 #include <stdlib.h>
29 #include <stdio.h>
30 #include <string.h>
32 #include "windef.h"
33 #include "winbase.h"
34 #include "winuser.h"
35 #include "winerror.h"
37 #include "wine/exception.h"
38 #include "wine/unicode.h"
39 #include "excpt.h"
41 #include "wine/debug.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(resource);
46 /***********************************************************************
47 * CharNextA (USER32.@)
49 LPSTR WINAPI CharNextA( LPCSTR ptr )
51 if (!*ptr) return (LPSTR)ptr;
52 if (IsDBCSLeadByte( ptr[0] ) && ptr[1]) return (LPSTR)(ptr + 2);
53 return (LPSTR)(ptr + 1);
57 /***********************************************************************
58 * CharNextExA (USER32.@)
60 LPSTR WINAPI CharNextExA( WORD codepage, LPCSTR ptr, DWORD flags )
62 if (!*ptr) return (LPSTR)ptr;
63 if (IsDBCSLeadByteEx( codepage, ptr[0] ) && ptr[1]) return (LPSTR)(ptr + 2);
64 return (LPSTR)(ptr + 1);
68 /***********************************************************************
69 * CharNextExW (USER32.@)
71 LPWSTR WINAPI CharNextExW( WORD codepage, LPCWSTR ptr, DWORD flags )
73 /* doesn't make sense, there are no codepages for Unicode */
74 return NULL;
78 /***********************************************************************
79 * CharNextW (USER32.@)
81 LPWSTR WINAPI CharNextW(LPCWSTR x)
83 if (*x) x++;
85 return (LPWSTR)x;
89 /***********************************************************************
90 * CharPrevA (USER32.@)
92 LPSTR WINAPI CharPrevA( LPCSTR start, LPCSTR ptr )
94 while (*start && (start < ptr))
96 LPCSTR next = CharNextA( start );
97 if (next >= ptr) break;
98 start = next;
100 return (LPSTR)start;
104 /***********************************************************************
105 * CharPrevExA (USER32.@)
107 LPSTR WINAPI CharPrevExA( WORD codepage, LPCSTR start, LPCSTR ptr, DWORD flags )
109 while (*start && (start < ptr))
111 LPCSTR next = CharNextExA( codepage, start, flags );
112 if (next >= ptr) break;
113 start = next;
115 return (LPSTR)start;
119 /***********************************************************************
120 * CharPrevExW (USER32.@)
122 LPSTR WINAPI CharPrevExW( WORD codepage, LPCWSTR start, LPCWSTR ptr, DWORD flags )
124 /* doesn't make sense, there are no codepages for Unicode */
125 return NULL;
129 /***********************************************************************
130 * CharPrevW (USER32.@)
132 LPWSTR WINAPI CharPrevW(LPCWSTR start,LPCWSTR x)
134 if (x>start) return (LPWSTR)(x-1);
135 else return (LPWSTR)x;
139 /***********************************************************************
140 * CharToOemA (USER32.@)
142 BOOL WINAPI CharToOemA( LPCSTR s, LPSTR d )
144 if ( !s || !d ) return TRUE;
145 return CharToOemBuffA( s, d, strlen( s ) + 1 );
149 /***********************************************************************
150 * CharToOemBuffA (USER32.@)
152 BOOL WINAPI CharToOemBuffA( LPCSTR s, LPSTR d, DWORD len )
154 WCHAR *bufW;
156 bufW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
157 if( bufW )
159 MultiByteToWideChar( CP_ACP, 0, s, len, bufW, len );
160 WideCharToMultiByte( CP_OEMCP, 0, bufW, len, d, len, NULL, NULL );
161 HeapFree( GetProcessHeap(), 0, bufW );
163 return TRUE;
167 /***********************************************************************
168 * CharToOemBuffW (USER32.@)
170 BOOL WINAPI CharToOemBuffW( LPCWSTR s, LPSTR d, DWORD len )
172 if ( !s || !d ) return TRUE;
173 WideCharToMultiByte( CP_OEMCP, 0, s, len, d, len, NULL, NULL );
174 return TRUE;
178 /***********************************************************************
179 * CharToOemW (USER32.@)
181 BOOL WINAPI CharToOemW( LPCWSTR s, LPSTR d )
183 return CharToOemBuffW( s, d, strlenW( s ) + 1 );
187 /***********************************************************************
188 * OemToCharA (USER32.@)
190 BOOL WINAPI OemToCharA( LPCSTR s, LPSTR d )
192 return OemToCharBuffA( s, d, strlen( s ) + 1 );
196 /***********************************************************************
197 * OemToCharBuffA (USER32.@)
199 BOOL WINAPI OemToCharBuffA( LPCSTR s, LPSTR d, DWORD len )
201 WCHAR *bufW;
203 bufW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
204 if( bufW )
206 MultiByteToWideChar( CP_OEMCP, 0, s, len, bufW, len );
207 WideCharToMultiByte( CP_ACP, 0, bufW, len, d, len, NULL, NULL );
208 HeapFree( GetProcessHeap(), 0, bufW );
210 return TRUE;
214 /***********************************************************************
215 * OemToCharBuffW (USER32.@)
217 BOOL WINAPI OemToCharBuffW( LPCSTR s, LPWSTR d, DWORD len )
219 MultiByteToWideChar( CP_OEMCP, 0, s, len, d, len );
220 return TRUE;
224 /***********************************************************************
225 * OemToCharW (USER32.@)
227 BOOL WINAPI OemToCharW( LPCSTR s, LPWSTR d )
229 return OemToCharBuffW( s, d, strlen( s ) + 1 );
233 /***********************************************************************
234 * CharLowerA (USER32.@)
236 LPSTR WINAPI CharLowerA(LPSTR str)
238 if (!HIWORD(str))
240 char ch = LOWORD(str);
241 CharLowerBuffA( &ch, 1 );
242 return (LPSTR)(UINT_PTR)(BYTE)ch;
245 __TRY
247 CharLowerBuffA( str, strlen(str) );
249 __EXCEPT_PAGE_FAULT
251 SetLastError( ERROR_INVALID_PARAMETER );
252 return NULL;
254 __ENDTRY
255 return str;
259 /***********************************************************************
260 * CharUpperA (USER32.@)
262 LPSTR WINAPI CharUpperA(LPSTR str)
264 if (!HIWORD(str))
266 char ch = LOWORD(str);
267 CharUpperBuffA( &ch, 1 );
268 return (LPSTR)(UINT_PTR)(BYTE)ch;
271 __TRY
273 CharUpperBuffA( str, strlen(str) );
275 __EXCEPT_PAGE_FAULT
277 SetLastError( ERROR_INVALID_PARAMETER );
278 return NULL;
280 __ENDTRY
281 return str;
285 /***********************************************************************
286 * CharLowerW (USER32.@)
288 LPWSTR WINAPI CharLowerW(LPWSTR x)
290 if (HIWORD(x)) return strlwrW(x);
291 else return (LPWSTR)((UINT)tolowerW(LOWORD(x)));
295 /***********************************************************************
296 * CharUpperW (USER32.@)
298 LPWSTR WINAPI CharUpperW(LPWSTR x)
300 if (HIWORD(x)) return struprW(x);
301 else return (LPWSTR)((UINT)toupperW(LOWORD(x)));
305 /***********************************************************************
306 * CharLowerBuffA (USER32.@)
308 DWORD WINAPI CharLowerBuffA( LPSTR str, DWORD len )
310 DWORD lenW;
311 WCHAR buffer[32];
312 WCHAR *strW = buffer;
314 if (!str) return 0; /* YES */
316 lenW = MultiByteToWideChar(CP_ACP, 0, str, len, NULL, 0);
317 if (lenW > sizeof(buffer)/sizeof(WCHAR))
319 strW = HeapAlloc(GetProcessHeap(), 0, lenW * sizeof(WCHAR));
320 if (!strW) return 0;
322 MultiByteToWideChar(CP_ACP, 0, str, len, strW, lenW);
323 CharLowerBuffW(strW, lenW);
324 len = WideCharToMultiByte(CP_ACP, 0, strW, lenW, str, len, NULL, NULL);
325 if (strW != buffer) HeapFree(GetProcessHeap(), 0, strW);
326 return len;
330 /***********************************************************************
331 * CharLowerBuffW (USER32.@)
333 DWORD WINAPI CharLowerBuffW( LPWSTR str, DWORD len )
335 DWORD ret = len;
336 if (!str) return 0; /* YES */
337 for (; len; len--, str++) *str = tolowerW(*str);
338 return ret;
342 /***********************************************************************
343 * CharUpperBuffA (USER32.@)
345 DWORD WINAPI CharUpperBuffA( LPSTR str, DWORD len )
347 DWORD lenW;
348 WCHAR buffer[32];
349 WCHAR *strW = buffer;
351 if (!str) return 0; /* YES */
353 lenW = MultiByteToWideChar(CP_ACP, 0, str, len, NULL, 0);
354 if (lenW > sizeof(buffer)/sizeof(WCHAR))
356 strW = HeapAlloc(GetProcessHeap(), 0, lenW * sizeof(WCHAR));
357 if (!strW) return 0;
359 MultiByteToWideChar(CP_ACP, 0, str, len, strW, lenW);
360 CharUpperBuffW(strW, lenW);
361 len = WideCharToMultiByte(CP_ACP, 0, strW, lenW, str, len, NULL, NULL);
362 if (strW != buffer) HeapFree(GetProcessHeap(), 0, strW);
363 return len;
367 /***********************************************************************
368 * CharUpperBuffW (USER32.@)
370 DWORD WINAPI CharUpperBuffW( LPWSTR str, DWORD len )
372 DWORD ret = len;
373 if (!str) return 0; /* YES */
374 for (; len; len--, str++) *str = toupperW(*str);
375 return ret;
379 /***********************************************************************
380 * IsCharLower (USER.436)
381 * IsCharLowerA (USER32.@)
383 BOOL WINAPI IsCharLowerA(CHAR x)
385 WCHAR wch;
386 MultiByteToWideChar(CP_ACP, 0, &x, 1, &wch, 1);
387 return IsCharLowerW(wch);
391 /***********************************************************************
392 * IsCharLowerW (USER32.@)
394 BOOL WINAPI IsCharLowerW(WCHAR x)
396 return (get_char_typeW(x) & C1_LOWER) != 0;
400 /***********************************************************************
401 * IsCharUpper (USER.435)
402 * IsCharUpperA (USER32.@)
404 BOOL WINAPI IsCharUpperA(CHAR x)
406 WCHAR wch;
407 MultiByteToWideChar(CP_ACP, 0, &x, 1, &wch, 1);
408 return IsCharUpperW(wch);
412 /***********************************************************************
413 * IsCharUpperW (USER32.@)
415 BOOL WINAPI IsCharUpperW(WCHAR x)
417 return (get_char_typeW(x) & C1_UPPER) != 0;
421 /***********************************************************************
422 * IsCharAlphaNumeric (USER.434)
423 * IsCharAlphaNumericA (USER32.@)
425 BOOL WINAPI IsCharAlphaNumericA(CHAR x)
427 WCHAR wch;
428 MultiByteToWideChar(CP_ACP, 0, &x, 1, &wch, 1);
429 return IsCharAlphaNumericW(wch);
433 /***********************************************************************
434 * IsCharAlphaNumericW (USER32.@)
436 BOOL WINAPI IsCharAlphaNumericW(WCHAR x)
438 return (get_char_typeW(x) & (C1_ALPHA|C1_DIGIT)) != 0;
442 /***********************************************************************
443 * IsCharAlpha (USER.433)
444 * IsCharAlphaA (USER32.@)
446 BOOL WINAPI IsCharAlphaA(CHAR x)
448 WCHAR wch;
449 MultiByteToWideChar(CP_ACP, 0, &x, 1, &wch, 1);
450 return IsCharAlphaW(wch);
454 /***********************************************************************
455 * IsCharAlphaW (USER32.@)
457 BOOL WINAPI IsCharAlphaW(WCHAR x)
459 return (get_char_typeW(x) & C1_ALPHA) != 0;