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)
62 if (!HIWORD(x)) return (LPSTR)tolower((char)(int)x);
75 SetLastError( ERROR_INVALID_PARAMETER );
83 //DWORD STDCALL CharLowerBuffA(LPSTR lpsz, DWORD cchLength)
86 CharLowerBuffA(LPSTR str, DWORD len)
90 if (!str) return 0; /* YES */
92 lenW = MultiByteToWideChar(CP_ACP, 0, str, len, NULL, 0);
93 strW = HeapAlloc(GetProcessHeap(), 0, lenW * sizeof(WCHAR));
95 MultiByteToWideChar(CP_ACP, 0, str, len, strW, lenW);
96 CharLowerBuffW(strW, lenW);
97 len = WideCharToMultiByte(CP_ACP, 0, strW, lenW, str, len, NULL, NULL);
98 HeapFree(GetProcessHeap(), 0, strW);
104 //DWORD STDCALL CharLowerBuffW(LPWSTR lpsz, DWORD cchLength)
107 CharLowerBuffW(LPWSTR str, DWORD len)
110 if (!str) return 0; /* YES */
111 for (; len; len--, str++) *str = towlower(*str);
115 //LPWSTR STDCALL CharLowerW(LPWSTR lpsz)
123 return (LPWSTR)(INT)towlower((WORD)(((DWORD)(x)) & 0xFFFF));
127 //LPWSTR STDCALL CharPrevW(LPCWSTR lpszStart, LPCWSTR lpszCurrent)
130 CharPrevW(LPCWSTR start, LPCWSTR x)
132 if (x > start) return (LPWSTR)(x-1);
133 else return (LPWSTR)x;
136 //LPSTR STDCALL CharNextA(LPCSTR lpsz)
139 CharNextA(LPCSTR ptr)
141 if (!*ptr) return (LPSTR)ptr;
142 if (IsDBCSLeadByte(ptr[0]) && ptr[1]) return (LPSTR)(ptr + 2);
143 return (LPSTR)(ptr + 1);
146 //LPSTR STDCALL CharNextExA(WORD CodePage, LPCSTR lpCurrentChar, DWORD dwFlags)
149 CharNextExA(WORD codepage, LPCSTR ptr, DWORD flags)
151 if (!*ptr) return (LPSTR)ptr;
152 if (IsDBCSLeadByteEx(codepage, ptr[0]) && ptr[1]) return (LPSTR)(ptr + 2);
153 return (LPSTR)(ptr + 1);
156 //LPWSTR STDCALL CharNextW(LPCWSTR lpsz)
165 //LPSTR STDCALL CharPrevA(LPCSTR lpszStart, LPCSTR lpszCurrent)
168 CharPrevA(LPCSTR start, LPCSTR ptr)
170 while (*start && (start < ptr)) {
171 LPCSTR next = CharNextA(start);
172 if (next >= ptr) break;
178 //LPSTR STDCALL CharPrevExA(WORD CodePage, LPCSTR lpStart, LPCSTR lpCurrentChar, DWORD dwFlags)
179 LPSTR WINAPI CharPrevExA( WORD codepage, LPCSTR start, LPCSTR ptr, DWORD flags )
181 while (*start && (start < ptr))
183 LPCSTR next = CharNextExA( codepage, start, flags );
184 if (next > ptr) break;
190 //WINBOOL STDCALL CharToOemA(LPCSTR lpszSrc, LPSTR lpszDst)
193 CharToOemA(LPCSTR s, LPSTR d)
195 if (!s || !d) return TRUE;
196 return CharToOemBuffA(s, d, strlen(s) + 1);
199 //WINBOOL STDCALL CharToOemBuffA(LPCSTR lpszSrc, LPSTR lpszDst, DWORD cchDstLength)
202 CharToOemBuffA(LPCSTR s, LPSTR d, DWORD len)
206 bufW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
208 MultiByteToWideChar(CP_ACP, 0, s, len, bufW, len);
209 WideCharToMultiByte(CP_OEMCP, 0, bufW, len, d, len, NULL, NULL);
210 HeapFree(GetProcessHeap(), 0, bufW);
215 //WINBOOL STDCALL CharToOemBuffW(LPCWSTR lpszSrc, LPSTR lpszDst, DWORD cchDstLength)
218 CharToOemBuffW(LPCWSTR s, LPSTR d, DWORD len)
222 WideCharToMultiByte(CP_OEMCP, 0, s, len, d, len, NULL, NULL);
226 //WINBOOL STDCALL CharToOemW(LPCWSTR lpszSrc, LPSTR lpszDst)
229 CharToOemW(LPCWSTR s, LPSTR d)
231 return CharToOemBuffW(s, d, wcslen(s) + 1);
234 //LPSTR STDCALL CharUpperA(LPSTR lpsz)
235 LPSTR WINAPI CharUpperA(LPSTR x)
237 if (!HIWORD(x)) return (LPSTR)toupper((char)(int)x);
250 SetLastError( ERROR_INVALID_PARAMETER );
259 //DWORD STDCALL CharUpperBuffA(LPSTR lpsz, DWORD cchLength)
262 CharUpperBuffA(LPSTR str, DWORD len)
266 if (!str) return 0; /* YES */
268 lenW = MultiByteToWideChar(CP_ACP, 0, str, len, NULL, 0);
269 strW = HeapAlloc(GetProcessHeap(), 0, lenW * sizeof(WCHAR));
271 MultiByteToWideChar(CP_ACP, 0, str, len, strW, lenW);
272 CharUpperBuffW(strW, lenW);
273 len = WideCharToMultiByte(CP_ACP, 0, strW, lenW, str, len, NULL, NULL);
274 HeapFree(GetProcessHeap(), 0, strW);
280 //DWORD STDCALL CharUpperBuffW(LPWSTR lpsz, DWORD cchLength)
283 CharUpperBuffW(LPWSTR str, DWORD len)
286 if (!str) return 0; /* YES */
287 for (; len; len--, str++) *str = towupper(*str);
291 //LPWSTR STDCALL CharUpperW(LPWSTR lpsz)
296 if (HIWORD(x)) return _wcsupr(x);
297 else return (LPWSTR)(UINT)towlower((WORD)(((DWORD)(x)) & 0xFFFF));
300 //WINBOOL STDCALL IsCharAlphaA(CHAR ch)
306 MultiByteToWideChar(CP_ACP, 0, &x, 1, &wch, 1);
307 return IsCharAlphaW(wch);
310 const char IsCharAlphaNumericA_lookup_table[] = {
311 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x03,
312 0xfe, 0xff, 0xff, 0x07, 0xfe, 0xff, 0xff, 0x07,
313 0x08, 0x54, 0x00, 0xd4, 0x00, 0x00, 0x0c, 0x02,
314 0xff, 0xff, 0x7f, 0xff, 0xff, 0xff, 0x7f, 0xff
319 IsCharAlphaNumericA(CHAR ch)
321 // return (IsCharAlphaNumericA_lookup_table[ch / 8] & (1 << (ch % 8))) ? 1 : 0;
324 MultiByteToWideChar(CP_ACP, 0, &ch, 1, &wch, 1);
325 return IsCharAlphaNumericW(wch);
331 IsCharAlphaNumericW(WCHAR ch)
333 return (get_char_typeW(ch) & (C1_ALPHA|C1_DIGIT)) != 0;
337 //WINBOOL STDCALL IsCharAlphaW(WCHAR ch)
340 IsCharAlphaW(WCHAR x)
342 return (get_char_typeW(x) & C1_ALPHA) != 0;
345 //WINBOOL STDCALL IsCharLowerA(CHAR ch)
351 MultiByteToWideChar(CP_ACP, 0, &x, 1, &wch, 1);
352 return IsCharLowerW(wch);
355 //WINBOOL STDCALL IsCharLowerW(WCHAR ch)
358 IsCharLowerW(WCHAR x)
360 return (get_char_typeW(x) & C1_LOWER) != 0;
363 //WINBOOL STDCALL IsCharUpperA(CHAR ch)
369 MultiByteToWideChar(CP_ACP, 0, &x, 1, &wch, 1);
370 return IsCharUpperW(wch);
373 //WINBOOL STDCALL IsCharUpperW(WCHAR ch)
376 IsCharUpperW(WCHAR x)
378 return (get_char_typeW(x) & C1_UPPER) != 0;
381 //WINBOOL STDCALL OemToCharA(LPCSTR lpszSrc, LPSTR lpszDst)
384 OemToCharA(LPCSTR s, LPSTR d)
386 return OemToCharBuffA(s, d, strlen(s) + 1);
389 //WINBOOL STDCALL OemToCharBuffA(LPCSTR lpszSrc, LPSTR lpszDst, DWORD cchDstLength)
390 BOOL WINAPI OemToCharBuffA(LPCSTR s, LPSTR d, DWORD len)
394 bufW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
396 MultiByteToWideChar(CP_OEMCP, 0, s, len, bufW, len);
397 WideCharToMultiByte(CP_ACP, 0, bufW, len, d, len, NULL, NULL);
398 HeapFree(GetProcessHeap(), 0, bufW);
403 //WINBOOL STDCALL OemToCharBuffW(LPCSTR lpszSrc, LPWSTR lpszDst, DWORD cchDstLength)
406 OemToCharBuffW(LPCSTR s, LPWSTR d, DWORD len)
408 MultiByteToWideChar(CP_OEMCP, 0, s, len, d, len);
412 //WINBOOL STDCALL OemToCharW(LPCSTR lpszSrc, LPWSTR lpszDst)
413 BOOL WINAPI OemToCharW(LPCSTR s, LPWSTR d)
415 return OemToCharBuffW(s, d, strlen(s) + 1);