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 ******************************************************************/
33 /* FUNCTIONS *****************************************************************/
40 if (! GetStringTypeW(CT_CTYPE1
, &Ch
, 1, &CharType
))
55 if (!HIWORD(x
)) return (LPSTR
)tolower((char)(int)x
);
56 CharLowerBuffA(x
, strlen(x
));
69 SetLastError( ERROR_INVALID_PARAMETER );
82 CharLowerBuffA(LPSTR str
, DWORD len
)
86 if (!str
) return 0; /* YES */
88 lenW
= MultiByteToWideChar(CP_ACP
, 0, str
, len
, NULL
, 0);
89 strW
= HeapAlloc(GetProcessHeap(), 0, lenW
* sizeof(WCHAR
));
91 MultiByteToWideChar(CP_ACP
, 0, str
, len
, strW
, lenW
);
92 CharLowerBuffW(strW
, lenW
);
93 len
= WideCharToMultiByte(CP_ACP
, 0, strW
, lenW
, str
, len
, NULL
, NULL
);
94 HeapFree(GetProcessHeap(), 0, strW
);
105 CharLowerBuffW(LPWSTR str
, DWORD len
)
108 if (!str
) return 0; /* YES */
109 for (; len
; len
--, str
++) *str
= towlower(*str
);
123 return (LPWSTR
)(INT
)towlower((WORD
)(((DWORD
)(x
)) & 0xFFFF));
132 CharPrevW(LPCWSTR start
, LPCWSTR x
)
134 if (x
> start
) return (LPWSTR
)(x
-1);
135 else return (LPWSTR
)x
;
143 CharNextA(LPCSTR ptr
)
145 if (!*ptr
) return (LPSTR
)ptr
;
146 if (IsDBCSLeadByte(ptr
[0]) && ptr
[1]) return (LPSTR
)(ptr
+ 2);
147 return (LPSTR
)(ptr
+ 1);
155 CharNextExA(WORD codepage
, LPCSTR ptr
, DWORD flags
)
157 if (!*ptr
) return (LPSTR
)ptr
;
158 if (IsDBCSLeadByteEx(codepage
, ptr
[0]) && ptr
[1]) return (LPSTR
)(ptr
+ 2);
159 return (LPSTR
)(ptr
+ 1);
178 CharPrevA(LPCSTR start
, LPCSTR ptr
)
180 while (*start
&& (start
< ptr
)) {
181 LPCSTR next
= CharNextA(start
);
182 if (next
>= ptr
) break;
191 LPSTR WINAPI
CharPrevExA( WORD codepage
, LPCSTR start
, LPCSTR ptr
, DWORD flags
)
193 while (*start
&& (start
< ptr
))
195 LPCSTR next
= CharNextExA( codepage
, start
, flags
);
196 if (next
> ptr
) break;
207 CharToOemA(LPCSTR s
, LPSTR d
)
209 if (!s
|| !d
) return TRUE
;
210 return CharToOemBuffA(s
, d
, strlen(s
) + 1);
218 CharToOemBuffA(LPCSTR s
, LPSTR d
, DWORD len
)
222 bufW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
224 MultiByteToWideChar(CP_ACP
, 0, s
, len
, bufW
, len
);
225 WideCharToMultiByte(CP_OEMCP
, 0, bufW
, len
, d
, len
, NULL
, NULL
);
226 HeapFree(GetProcessHeap(), 0, bufW
);
236 CharToOemBuffW(LPCWSTR s
, LPSTR d
, DWORD len
)
240 WideCharToMultiByte(CP_OEMCP
, 0, s
, len
, d
, len
, NULL
, NULL
);
249 CharToOemW(LPCWSTR s
, LPSTR d
)
251 return CharToOemBuffW(s
, d
, wcslen(s
) + 1);
257 LPSTR WINAPI
CharUpperA(LPSTR x
)
259 if (!HIWORD(x
)) return (LPSTR
)toupper((char)(int)x
);
260 CharUpperBuffA(x
, strlen(x
));
269 CharUpperBuffA(LPSTR str
, DWORD len
)
273 if (!str
) return 0; /* YES */
275 lenW
= MultiByteToWideChar(CP_ACP
, 0, str
, len
, NULL
, 0);
276 strW
= HeapAlloc(GetProcessHeap(), 0, lenW
* sizeof(WCHAR
));
278 MultiByteToWideChar(CP_ACP
, 0, str
, len
, strW
, lenW
);
279 CharUpperBuffW(strW
, lenW
);
280 len
= WideCharToMultiByte(CP_ACP
, 0, strW
, lenW
, str
, len
, NULL
, NULL
);
281 HeapFree(GetProcessHeap(), 0, strW
);
292 CharUpperBuffW(LPWSTR str
, DWORD len
)
295 if (!str
) return 0; /* YES */
296 for (; len
; len
--, str
++) *str
= towupper(*str
);
307 if (HIWORD(x
)) return _wcsupr(x
);
308 else return (LPWSTR
)(UINT
)towlower((WORD
)(((DWORD
)(x
)) & 0xFFFF));
316 IsCharAlphaA(CHAR Ch
)
320 MultiByteToWideChar(CP_ACP
, 0, &Ch
, 1, &WCh
, 1);
321 return IsCharAlphaW(WCh
);
329 IsCharAlphaNumericA(CHAR Ch
)
333 MultiByteToWideChar(CP_ACP
, 0, &Ch
, 1, &WCh
, 1);
334 return IsCharAlphaNumericW(WCh
);
342 IsCharAlphaNumericW(WCHAR Ch
)
344 return (GetC1Type(Ch
) & (C1_ALPHA
|C1_DIGIT
)) != 0;
352 IsCharAlphaW(WCHAR Ch
)
354 return (GetC1Type(Ch
) & C1_ALPHA
) != 0;
362 IsCharLowerA(CHAR Ch
)
366 MultiByteToWideChar(CP_ACP
, 0, &Ch
, 1, &WCh
, 1);
367 return IsCharLowerW(WCh
);
375 IsCharLowerW(WCHAR Ch
)
377 return (GetC1Type(Ch
) & C1_LOWER
) != 0;
385 IsCharUpperA(CHAR Ch
)
389 MultiByteToWideChar(CP_ACP
, 0, &Ch
, 1, &WCh
, 1);
390 return IsCharUpperW(WCh
);
398 IsCharUpperW(WCHAR Ch
)
400 return (GetC1Type(Ch
) & C1_UPPER
) != 0;
408 OemToCharA(LPCSTR s
, LPSTR d
)
410 return OemToCharBuffA(s
, d
, strlen(s
) + 1);
416 BOOL WINAPI
OemToCharBuffA(LPCSTR s
, LPSTR d
, DWORD len
)
420 bufW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
422 MultiByteToWideChar(CP_OEMCP
, 0, s
, len
, bufW
, len
);
423 WideCharToMultiByte(CP_ACP
, 0, bufW
, len
, d
, len
, NULL
, NULL
);
424 HeapFree(GetProcessHeap(), 0, bufW
);
434 OemToCharBuffW(LPCSTR s
, LPWSTR d
, DWORD len
)
436 MultiByteToWideChar(CP_OEMCP
, 0, s
, len
, d
, len
);
443 BOOL WINAPI
OemToCharW(LPCSTR s
, LPWSTR d
)
445 return OemToCharBuffW(s
, d
, strlen(s
) + 1);