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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include "wine/port.h"
37 #include "wine/exception.h"
38 #include "wine/unicode.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 */
78 /***********************************************************************
79 * CharNextW (USER32.@)
81 LPWSTR WINAPI
CharNextW(LPCWSTR 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;
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;
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 */
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
)
156 bufW
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
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
);
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
);
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
)
203 bufW
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
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
);
214 /***********************************************************************
215 * OemToCharBuffW (USER32.@)
217 BOOL WINAPI
OemToCharBuffW( LPCSTR s
, LPWSTR d
, DWORD len
)
219 MultiByteToWideChar( CP_OEMCP
, 0, s
, len
, d
, len
);
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
)
240 char ch
= LOWORD(str
);
241 CharLowerBuffA( &ch
, 1 );
242 return (LPSTR
)(UINT_PTR
)(BYTE
)ch
;
247 CharLowerBuffA( str
, strlen(str
) );
251 SetLastError( ERROR_INVALID_PARAMETER
);
259 /***********************************************************************
260 * CharUpperA (USER32.@)
262 LPSTR WINAPI
CharUpperA(LPSTR str
)
266 char ch
= LOWORD(str
);
267 CharUpperBuffA( &ch
, 1 );
268 return (LPSTR
)(UINT_PTR
)(BYTE
)ch
;
273 CharUpperBuffA( str
, strlen(str
) );
277 SetLastError( ERROR_INVALID_PARAMETER
);
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
)
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
));
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
);
330 /***********************************************************************
331 * CharLowerBuffW (USER32.@)
333 DWORD WINAPI
CharLowerBuffW( LPWSTR str
, DWORD len
)
336 if (!str
) return 0; /* YES */
337 for (; len
; len
--, str
++) *str
= tolowerW(*str
);
342 /***********************************************************************
343 * CharUpperBuffA (USER32.@)
345 DWORD WINAPI
CharUpperBuffA( LPSTR str
, DWORD len
)
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
));
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
);
367 /***********************************************************************
368 * CharUpperBuffW (USER32.@)
370 DWORD WINAPI
CharUpperBuffW( LPWSTR str
, DWORD len
)
373 if (!str
) return 0; /* YES */
374 for (; len
; len
--, str
++) *str
= toupperW(*str
);
379 /***********************************************************************
380 * IsCharLower (USER.436)
381 * IsCharLowerA (USER32.@)
383 BOOL WINAPI
IsCharLowerA(CHAR x
)
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
)
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
)
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
)
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;