3 * Copyright (C) 1998, 1999, 2000, 2001 ReactOS Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * PROJECT: ReactOS user32.dll
22 * FILE: lib/user32/windows/input.c
24 * PROGRAMMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
26 * 09-05-2001 CSH Created
29 /* INCLUDES ******************************************************************/
36 //#include <kernel32/winnls.h>
42 const unsigned short wctype_table[] =
46 /* the character type contains the C1_* flags in the low 12 bits */
47 /* and the C2_* type in the high 4 bits */
48 static inline unsigned short get_char_typeW(WCHAR ch)
50 extern const unsigned short wctype_table[];
51 return wctype_table[wctype_table[ch >> 8] + (ch & 0xff)];
55 /* FUNCTIONS *****************************************************************/
57 //LPSTR STDCALL CharLowerA(LPSTR lpsz)
65 if (!HIWORD(x)) return (LPSTR)tolower((char)(int)x);
78 SetLastError( ERROR_INVALID_PARAMETER );
86 //DWORD STDCALL CharLowerBuffA(LPSTR lpsz, DWORD cchLength)
92 CharLowerBuffA(LPSTR str, DWORD len)
96 if (!str) return 0; /* YES */
98 lenW = MultiByteToWideChar(CP_ACP, 0, str, len, NULL, 0);
99 strW = HeapAlloc(GetProcessHeap(), 0, lenW * sizeof(WCHAR));
101 MultiByteToWideChar(CP_ACP, 0, str, len, strW, lenW);
102 CharLowerBuffW(strW, lenW);
103 len = WideCharToMultiByte(CP_ACP, 0, strW, lenW, str, len, NULL, NULL);
104 HeapFree(GetProcessHeap(), 0, strW);
110 //DWORD STDCALL CharLowerBuffW(LPWSTR lpsz, DWORD cchLength)
116 CharLowerBuffW(LPWSTR str, DWORD len)
119 if (!str) return 0; /* YES */
120 for (; len; len--, str++) *str = towlower(*str);
124 //LPWSTR STDCALL CharLowerW(LPWSTR lpsz)
135 return (LPWSTR)(INT)towlower((WORD)(((DWORD)(x)) & 0xFFFF));
139 //LPWSTR STDCALL CharPrevW(LPCWSTR lpszStart, LPCWSTR lpszCurrent)
145 CharPrevW(LPCWSTR start, LPCWSTR x)
147 if (x > start) return (LPWSTR)(x-1);
148 else return (LPWSTR)x;
151 //LPSTR STDCALL CharNextA(LPCSTR lpsz)
157 CharNextA(LPCSTR ptr)
159 if (!*ptr) return (LPSTR)ptr;
160 if (IsDBCSLeadByte(ptr[0]) && ptr[1]) return (LPSTR)(ptr + 2);
161 return (LPSTR)(ptr + 1);
164 //LPSTR STDCALL CharNextExA(WORD CodePage, LPCSTR lpCurrentChar, DWORD dwFlags)
170 CharNextExA(WORD codepage, LPCSTR ptr, DWORD flags)
172 if (!*ptr) return (LPSTR)ptr;
173 if (IsDBCSLeadByteEx(codepage, ptr[0]) && ptr[1]) return (LPSTR)(ptr + 2);
174 return (LPSTR)(ptr + 1);
177 //LPWSTR STDCALL CharNextW(LPCWSTR lpsz)
189 //LPSTR STDCALL CharPrevA(LPCSTR lpszStart, LPCSTR lpszCurrent)
195 CharPrevA(LPCSTR start, LPCSTR ptr)
197 while (*start && (start < ptr)) {
198 LPCSTR next = CharNextA(start);
199 if (next >= ptr) break;
205 //LPSTR STDCALL CharPrevExA(WORD CodePage, LPCSTR lpStart, LPCSTR lpCurrentChar, DWORD dwFlags)
209 LPSTR WINAPI CharPrevExA( WORD codepage, LPCSTR start, LPCSTR ptr, DWORD flags )
211 while (*start && (start < ptr))
213 LPCSTR next = CharNextExA( codepage, start, flags );
214 if (next > ptr) break;
220 //WINBOOL STDCALL CharToOemA(LPCSTR lpszSrc, LPSTR lpszDst)
226 CharToOemA(LPCSTR s, LPSTR d)
228 if (!s || !d) return TRUE;
229 return CharToOemBuffA(s, d, strlen(s) + 1);
232 //WINBOOL STDCALL CharToOemBuffA(LPCSTR lpszSrc, LPSTR lpszDst, DWORD cchDstLength)
238 CharToOemBuffA(LPCSTR s, LPSTR d, DWORD len)
242 bufW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
244 MultiByteToWideChar(CP_ACP, 0, s, len, bufW, len);
245 WideCharToMultiByte(CP_OEMCP, 0, bufW, len, d, len, NULL, NULL);
246 HeapFree(GetProcessHeap(), 0, bufW);
251 //WINBOOL STDCALL CharToOemBuffW(LPCWSTR lpszSrc, LPSTR lpszDst, DWORD cchDstLength)
257 CharToOemBuffW(LPCWSTR s, LPSTR d, DWORD len)
261 WideCharToMultiByte(CP_OEMCP, 0, s, len, d, len, NULL, NULL);
265 //WINBOOL STDCALL CharToOemW(LPCWSTR lpszSrc, LPSTR lpszDst)
271 CharToOemW(LPCWSTR s, LPSTR d)
273 return CharToOemBuffW(s, d, wcslen(s) + 1);
276 //LPSTR STDCALL CharUpperA(LPSTR lpsz)
280 LPSTR WINAPI CharUpperA(LPSTR x)
282 if (!HIWORD(x)) return (LPSTR)toupper((char)(int)x);
295 SetLastError( ERROR_INVALID_PARAMETER );
304 //DWORD STDCALL CharUpperBuffA(LPSTR lpsz, DWORD cchLength)
310 CharUpperBuffA(LPSTR str, DWORD len)
314 if (!str) return 0; /* YES */
316 lenW = MultiByteToWideChar(CP_ACP, 0, str, len, NULL, 0);
317 strW = HeapAlloc(GetProcessHeap(), 0, lenW * sizeof(WCHAR));
319 MultiByteToWideChar(CP_ACP, 0, str, len, strW, lenW);
320 CharUpperBuffW(strW, lenW);
321 len = WideCharToMultiByte(CP_ACP, 0, strW, lenW, str, len, NULL, NULL);
322 HeapFree(GetProcessHeap(), 0, strW);
328 //DWORD STDCALL CharUpperBuffW(LPWSTR lpsz, DWORD cchLength)
334 CharUpperBuffW(LPWSTR str, DWORD len)
337 if (!str) return 0; /* YES */
338 for (; len; len--, str++) *str = towupper(*str);
342 //LPWSTR STDCALL CharUpperW(LPWSTR lpsz)
350 if (HIWORD(x)) return _wcsupr(x);
351 else return (LPWSTR)(UINT)towlower((WORD)(((DWORD)(x)) & 0xFFFF));
354 //WINBOOL STDCALL IsCharAlphaA(CHAR ch)
363 MultiByteToWideChar(CP_ACP, 0, &x, 1, &wch, 1);
364 return IsCharAlphaW(wch);
367 const char IsCharAlphaNumericA_lookup_table[] = {
368 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x03,
369 0xfe, 0xff, 0xff, 0x07, 0xfe, 0xff, 0xff, 0x07,
370 0x08, 0x54, 0x00, 0xd4, 0x00, 0x00, 0x0c, 0x02,
371 0xff, 0xff, 0x7f, 0xff, 0xff, 0xff, 0x7f, 0xff
379 IsCharAlphaNumericA(CHAR ch)
381 // return (IsCharAlphaNumericA_lookup_table[ch / 8] & (1 << (ch % 8))) ? 1 : 0;
384 MultiByteToWideChar(CP_ACP, 0, &ch, 1, &wch, 1);
385 return IsCharAlphaNumericW(wch);
394 IsCharAlphaNumericW(WCHAR ch)
396 return (get_char_typeW(ch) & (C1_ALPHA|C1_DIGIT)) != 0;
400 //WINBOOL STDCALL IsCharAlphaW(WCHAR ch)
406 IsCharAlphaW(WCHAR x)
408 return (get_char_typeW(x) & C1_ALPHA) != 0;
411 //WINBOOL STDCALL IsCharLowerA(CHAR ch)
420 MultiByteToWideChar(CP_ACP, 0, &x, 1, &wch, 1);
421 return IsCharLowerW(wch);
424 //WINBOOL STDCALL IsCharLowerW(WCHAR ch)
430 IsCharLowerW(WCHAR x)
432 return (get_char_typeW(x) & C1_LOWER) != 0;
435 //WINBOOL STDCALL IsCharUpperA(CHAR ch)
444 MultiByteToWideChar(CP_ACP, 0, &x, 1, &wch, 1);
445 return IsCharUpperW(wch);
448 //WINBOOL STDCALL IsCharUpperW(WCHAR ch)
454 IsCharUpperW(WCHAR x)
456 return (get_char_typeW(x) & C1_UPPER) != 0;
459 //WINBOOL STDCALL OemToCharA(LPCSTR lpszSrc, LPSTR lpszDst)
465 OemToCharA(LPCSTR s, LPSTR d)
467 return OemToCharBuffA(s, d, strlen(s) + 1);
470 //WINBOOL STDCALL OemToCharBuffA(LPCSTR lpszSrc, LPSTR lpszDst, DWORD cchDstLength)
474 BOOL WINAPI OemToCharBuffA(LPCSTR s, LPSTR d, DWORD len)
478 bufW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
480 MultiByteToWideChar(CP_OEMCP, 0, s, len, bufW, len);
481 WideCharToMultiByte(CP_ACP, 0, bufW, len, d, len, NULL, NULL);
482 HeapFree(GetProcessHeap(), 0, bufW);
487 //WINBOOL STDCALL OemToCharBuffW(LPCSTR lpszSrc, LPWSTR lpszDst, DWORD cchDstLength)
493 OemToCharBuffW(LPCSTR s, LPWSTR d, DWORD len)
495 MultiByteToWideChar(CP_OEMCP, 0, s, len, d, len);
499 //WINBOOL STDCALL OemToCharW(LPCSTR lpszSrc, LPWSTR lpszDst)
503 BOOL WINAPI OemToCharW(LPCSTR s, LPWSTR d)
505 return OemToCharBuffW(s, d, strlen(s) + 1);