- Silence some debug messages
[reactos.git] / reactos / lib / user32 / windows / text.c
1 /*
2 * ReactOS kernel
3 * Copyright (C) 1998, 1999, 2000, 2001 ReactOS Team
4 *
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.
9 *
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.
14 *
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.
18 */
19 /* $Id$
20 *
21 * PROJECT: ReactOS user32.dll
22 * FILE: lib/user32/windows/input.c
23 * PURPOSE: Input
24 * PROGRAMMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
25 * UPDATE HISTORY:
26 * 09-05-2001 CSH Created
27 */
28
29 /* INCLUDES ******************************************************************/
30
31 #include <user32.h>
32
33 /* FUNCTIONS *****************************************************************/
34
35 static WORD
36 GetC1Type(WCHAR Ch)
37 {
38 WORD CharType;
39
40 if (! GetStringTypeW(CT_CTYPE1, &Ch, 1, &CharType))
41 {
42 return 0;
43 }
44
45 return CharType;
46 }
47
48 /*
49 * @implemented
50 */
51 LPSTR
52 WINAPI
53 CharLowerA(LPSTR x)
54 {
55 if (!HIWORD(x)) return (LPSTR)tolower((char)(int)x);
56 /*
57 __TRY
58 {
59 LPSTR s = x;
60 while (*s)
61 {
62 *s=tolower(*s);
63 s++;
64 }
65 }
66 __EXCEPT(page_fault)
67 {
68 SetLastError( ERROR_INVALID_PARAMETER );
69 return NULL;
70 }
71 __ENDTRY
72 */
73 return x;
74 }
75
76 /*
77 * @implemented
78 */
79 DWORD
80 WINAPI
81 CharLowerBuffA(LPSTR str, DWORD len)
82 {
83 DWORD lenW;
84 WCHAR *strW;
85 if (!str) return 0; /* YES */
86
87 lenW = MultiByteToWideChar(CP_ACP, 0, str, len, NULL, 0);
88 strW = HeapAlloc(GetProcessHeap(), 0, lenW * sizeof(WCHAR));
89 if (strW) {
90 MultiByteToWideChar(CP_ACP, 0, str, len, strW, lenW);
91 CharLowerBuffW(strW, lenW);
92 len = WideCharToMultiByte(CP_ACP, 0, strW, lenW, str, len, NULL, NULL);
93 HeapFree(GetProcessHeap(), 0, strW);
94 return len;
95 }
96 return 0;
97 }
98
99 /*
100 * @implemented
101 */
102 DWORD
103 WINAPI
104 CharLowerBuffW(LPWSTR str, DWORD len)
105 {
106 DWORD ret = len;
107 if (!str) return 0; /* YES */
108 for (; len; len--, str++) *str = towlower(*str);
109 return ret;
110 }
111
112 /*
113 * @implemented
114 */
115 LPWSTR
116 WINAPI
117 CharLowerW(LPWSTR x)
118 {
119 if (HIWORD(x)) {
120 return _wcslwr(x);
121 } else {
122 return (LPWSTR)(INT)towlower((WORD)(((DWORD)(x)) & 0xFFFF));
123 }
124 }
125
126 /*
127 * @implemented
128 */
129 LPWSTR
130 WINAPI
131 CharPrevW(LPCWSTR start, LPCWSTR x)
132 {
133 if (x > start) return (LPWSTR)(x-1);
134 else return (LPWSTR)x;
135 }
136
137 /*
138 * @implemented
139 */
140 LPSTR
141 WINAPI
142 CharNextA(LPCSTR ptr)
143 {
144 if (!*ptr) return (LPSTR)ptr;
145 if (IsDBCSLeadByte(ptr[0]) && ptr[1]) return (LPSTR)(ptr + 2);
146 return (LPSTR)(ptr + 1);
147 }
148
149 /*
150 * @implemented
151 */
152 LPSTR
153 WINAPI
154 CharNextExA(WORD codepage, LPCSTR ptr, DWORD flags)
155 {
156 if (!*ptr) return (LPSTR)ptr;
157 if (IsDBCSLeadByteEx(codepage, ptr[0]) && ptr[1]) return (LPSTR)(ptr + 2);
158 return (LPSTR)(ptr + 1);
159 }
160
161 /*
162 * @implemented
163 */
164 LPWSTR
165 WINAPI
166 CharNextW(LPCWSTR x)
167 {
168 if (*x) x++;
169 return (LPWSTR)x;
170 }
171
172 /*
173 * @implemented
174 */
175 LPSTR
176 WINAPI
177 CharPrevA(LPCSTR start, LPCSTR ptr)
178 {
179 while (*start && (start < ptr)) {
180 LPCSTR next = CharNextA(start);
181 if (next >= ptr) break;
182 start = next;
183 }
184 return (LPSTR)start;
185 }
186
187 /*
188 * @implemented
189 */
190 LPSTR WINAPI CharPrevExA( WORD codepage, LPCSTR start, LPCSTR ptr, DWORD flags )
191 {
192 while (*start && (start < ptr))
193 {
194 LPCSTR next = CharNextExA( codepage, start, flags );
195 if (next > ptr) break;
196 start = next;
197 }
198 return (LPSTR)start;
199 }
200
201 /*
202 * @implemented
203 */
204 BOOL
205 WINAPI
206 CharToOemA(LPCSTR s, LPSTR d)
207 {
208 if (!s || !d) return TRUE;
209 return CharToOemBuffA(s, d, strlen(s) + 1);
210 }
211
212 /*
213 * @implemented
214 */
215 BOOL
216 WINAPI
217 CharToOemBuffA(LPCSTR s, LPSTR d, DWORD len)
218 {
219 WCHAR* bufW;
220
221 bufW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
222 if (bufW) {
223 MultiByteToWideChar(CP_ACP, 0, s, len, bufW, len);
224 WideCharToMultiByte(CP_OEMCP, 0, bufW, len, d, len, NULL, NULL);
225 HeapFree(GetProcessHeap(), 0, bufW);
226 }
227 return TRUE;
228 }
229
230 /*
231 * @implemented
232 */
233 BOOL
234 WINAPI
235 CharToOemBuffW(LPCWSTR s, LPSTR d, DWORD len)
236 {
237 if (!s || !d)
238 return TRUE;
239 WideCharToMultiByte(CP_OEMCP, 0, s, len, d, len, NULL, NULL);
240 return TRUE;
241 }
242
243 /*
244 * @implemented
245 */
246 BOOL
247 WINAPI
248 CharToOemW(LPCWSTR s, LPSTR d)
249 {
250 return CharToOemBuffW(s, d, wcslen(s) + 1);
251 }
252
253 /*
254 * @implemented
255 */
256 LPSTR WINAPI CharUpperA(LPSTR x)
257 {
258 if (!HIWORD(x)) return (LPSTR)toupper((char)(int)x);
259 CharUpperBuffA(x, strlen(x));
260 return x;
261 }
262
263 /*
264 * @implemented
265 */
266 DWORD
267 WINAPI
268 CharUpperBuffA(LPSTR str, DWORD len)
269 {
270 DWORD lenW;
271 WCHAR* strW;
272 if (!str) return 0; /* YES */
273
274 lenW = MultiByteToWideChar(CP_ACP, 0, str, len, NULL, 0);
275 strW = HeapAlloc(GetProcessHeap(), 0, lenW * sizeof(WCHAR));
276 if (strW) {
277 MultiByteToWideChar(CP_ACP, 0, str, len, strW, lenW);
278 CharUpperBuffW(strW, lenW);
279 len = WideCharToMultiByte(CP_ACP, 0, strW, lenW, str, len, NULL, NULL);
280 HeapFree(GetProcessHeap(), 0, strW);
281 return len;
282 }
283 return 0;
284 }
285
286 /*
287 * @implemented
288 */
289 DWORD
290 WINAPI
291 CharUpperBuffW(LPWSTR str, DWORD len)
292 {
293 DWORD ret = len;
294 if (!str) return 0; /* YES */
295 for (; len; len--, str++) *str = towupper(*str);
296 return ret;
297 }
298
299 /*
300 * @implemented
301 */
302 LPWSTR
303 WINAPI
304 CharUpperW(LPWSTR x)
305 {
306 if (HIWORD(x)) return _wcsupr(x);
307 else return (LPWSTR)(UINT)towlower((WORD)(((DWORD)(x)) & 0xFFFF));
308 }
309
310 /*
311 * @implemented
312 */
313 BOOL
314 WINAPI
315 IsCharAlphaA(CHAR Ch)
316 {
317 WCHAR WCh;
318
319 MultiByteToWideChar(CP_ACP, 0, &Ch, 1, &WCh, 1);
320 return IsCharAlphaW(WCh);
321 }
322
323 /*
324 * @implemented
325 */
326 BOOL
327 STDCALL
328 IsCharAlphaNumericA(CHAR Ch)
329 {
330 WCHAR WCh;
331
332 MultiByteToWideChar(CP_ACP, 0, &Ch, 1, &WCh, 1);
333 return IsCharAlphaNumericW(WCh);
334 }
335
336 /*
337 * @implemented
338 */
339 BOOL
340 STDCALL
341 IsCharAlphaNumericW(WCHAR Ch)
342 {
343 return (GetC1Type(Ch) & (C1_ALPHA|C1_DIGIT)) != 0;
344 }
345
346 /*
347 * @implemented
348 */
349 BOOL
350 WINAPI
351 IsCharAlphaW(WCHAR Ch)
352 {
353 return (GetC1Type(Ch) & C1_ALPHA) != 0;
354 }
355
356 /*
357 * @implemented
358 */
359 BOOL
360 WINAPI
361 IsCharLowerA(CHAR Ch)
362 {
363 WCHAR WCh;
364
365 MultiByteToWideChar(CP_ACP, 0, &Ch, 1, &WCh, 1);
366 return IsCharLowerW(WCh);
367 }
368
369 /*
370 * @implemented
371 */
372 BOOL
373 WINAPI
374 IsCharLowerW(WCHAR Ch)
375 {
376 return (GetC1Type(Ch) & C1_LOWER) != 0;
377 }
378
379 /*
380 * @implemented
381 */
382 BOOL
383 WINAPI
384 IsCharUpperA(CHAR Ch)
385 {
386 WCHAR WCh;
387
388 MultiByteToWideChar(CP_ACP, 0, &Ch, 1, &WCh, 1);
389 return IsCharUpperW(WCh);
390 }
391
392 /*
393 * @implemented
394 */
395 BOOL
396 WINAPI
397 IsCharUpperW(WCHAR Ch)
398 {
399 return (GetC1Type(Ch) & C1_UPPER) != 0;
400 }
401
402 /*
403 * @implemented
404 */
405 BOOL
406 WINAPI
407 OemToCharA(LPCSTR s, LPSTR d)
408 {
409 return OemToCharBuffA(s, d, strlen(s) + 1);
410 }
411
412 /*
413 * @implemented
414 */
415 BOOL WINAPI OemToCharBuffA(LPCSTR s, LPSTR d, DWORD len)
416 {
417 WCHAR* bufW;
418
419 bufW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
420 if (bufW) {
421 MultiByteToWideChar(CP_OEMCP, 0, s, len, bufW, len);
422 WideCharToMultiByte(CP_ACP, 0, bufW, len, d, len, NULL, NULL);
423 HeapFree(GetProcessHeap(), 0, bufW);
424 }
425 return TRUE;
426 }
427
428 /*
429 * @implemented
430 */
431 BOOL
432 WINAPI
433 OemToCharBuffW(LPCSTR s, LPWSTR d, DWORD len)
434 {
435 MultiByteToWideChar(CP_OEMCP, 0, s, len, d, len);
436 return TRUE;
437 }
438
439 /*
440 * @implemented
441 */
442 BOOL WINAPI OemToCharW(LPCSTR s, LPWSTR d)
443 {
444 return OemToCharBuffW(s, d, strlen(s) + 1);
445 }
446
447 /* EOF */