ReactOS  0.4.13-dev-99-g7e18b6d
text.c
Go to the documentation of this file.
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 /*
20  * PROJECT: ReactOS user32.dll
21  * FILE: win32ss/user/user32/windows/text.c
22  * PURPOSE: Input
23  * PROGRAMMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
24  * UPDATE HISTORY:
25  * 09-05-2001 CSH Created
26  */
27 
28 #include <user32.h>
29 
30 static WORD
32 {
33  WORD CharType;
34 
35  if (! GetStringTypeW(CT_CTYPE1, &Ch, 1, &CharType))
36  {
37  return 0;
38  }
39 
40  return CharType;
41 }
42 
43 /*
44  * @implemented
45  */
46 LPSTR
47 WINAPI
49 {
50  if (!HIWORD(str))
51  {
52  char ch = LOWORD(str);
53  CharLowerBuffA( &ch, 1 );
54  return (LPSTR)(UINT_PTR)(BYTE)ch;
55  }
56 
57  _SEH2_TRY
58  {
60  }
62  {
64  _SEH2_YIELD(return NULL);
65  }
66  _SEH2_END;
67 
68  return str;
69 }
70 
71 /*
72  * @implemented
73  */
74 DWORD
75 WINAPI
77 {
78  DWORD lenW;
79  WCHAR *strW;
80  if (!str) return 0; /* YES */
81 
82  lenW = MultiByteToWideChar(CP_ACP, 0, str, len, NULL, 0);
83  strW = HeapAlloc(GetProcessHeap(), 0, lenW * sizeof(WCHAR));
84  if (strW) {
85  MultiByteToWideChar(CP_ACP, 0, str, len, strW, lenW);
86  CharLowerBuffW(strW, lenW);
87  len = WideCharToMultiByte(CP_ACP, 0, strW, lenW, str, len, NULL, NULL);
89  return len;
90  }
91  return 0;
92 }
93 
94 /*
95  * @implemented
96  */
97 DWORD
98 WINAPI
100 {
101  DWORD ret = len;
102  if (!str) return 0; /* YES */
103  for (; len; len--, str++) *str = towlower(*str);
104  return ret;
105 }
106 
107 /*
108  * @implemented
109  */
110 LPWSTR
111 WINAPI
113 {
114  if (HIWORD(x)) return strlwrW(x);
115  else return (LPWSTR)((UINT_PTR)tolowerW(LOWORD(x)));
116 }
117 
118 /*
119  * @implemented
120  */
121 LPWSTR
122 WINAPI
124 {
125  if (x > start) return (LPWSTR)(x-1);
126  else return (LPWSTR)x;
127 }
128 
129 /*
130  * @implemented
131  */
132 LPSTR
133 WINAPI
135 {
136  if (!*ptr) return (LPSTR)ptr;
137  if (IsDBCSLeadByte(ptr[0]) && ptr[1]) return (LPSTR)(ptr + 2);
138  return (LPSTR)(ptr + 1);
139 }
140 
141 /*
142  * @implemented
143  */
144 LPSTR
145 WINAPI
147 {
148  if (!*ptr) return (LPSTR)ptr;
149  if (IsDBCSLeadByteEx(codepage, ptr[0]) && ptr[1]) return (LPSTR)(ptr + 2);
150  return (LPSTR)(ptr + 1);
151 }
152 
153 /*
154  * @implemented
155  */
156 LPWSTR
157 WINAPI
159 {
160  if (*x) x++;
161  return (LPWSTR)x;
162 }
163 
164 /*
165  * @implemented
166  */
167 LPSTR
168 WINAPI
170 {
171  while (*start && (start < ptr)) {
173  if (next >= ptr) break;
174  start = next;
175  }
176  return (LPSTR)start;
177 }
178 
179 /*
180  * @implemented
181  */
183 {
184  while (*start && (start < ptr))
185  {
187  if (next > ptr) break;
188  start = next;
189  }
190  return (LPSTR)start;
191 }
192 
193 /*
194  * @implemented
195  */
196 BOOL
197 WINAPI
199 {
200  if (!s || !d) return FALSE;
201  return CharToOemBuffA(s, d, strlen(s) + 1);
202 }
203 
204 /*
205  * @implemented
206  */
207 BOOL
208 WINAPI
210 {
211  WCHAR* bufW;
212 
213  if ( !s || !d ) return FALSE;
214 
215  bufW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
216  if (bufW) {
217  MultiByteToWideChar(CP_ACP, 0, s, len, bufW, len);
218  WideCharToMultiByte(CP_OEMCP, 0, bufW, len, d, len, NULL, NULL);
219  HeapFree(GetProcessHeap(), 0, bufW);
220  }
221  return TRUE;
222 }
223 
224 /*
225  * @implemented
226  */
227 BOOL
228 WINAPI
230 {
231  if (!s || !d)
232  return FALSE;
234  return TRUE;
235 }
236 
237 /*
238  * @implemented
239  */
240 BOOL
241 WINAPI
243 {
244  if ( !s || !d ) return FALSE;
245  return CharToOemBuffW(s, d, wcslen(s) + 1);
246 }
247 
248 /*
249  * @implemented
250  */
252 {
253  if (!HIWORD(str))
254  {
255  char ch = LOWORD(str);
256  CharUpperBuffA( &ch, 1 );
257  return (LPSTR)(UINT_PTR)(BYTE)ch;
258  }
259 
260  _SEH2_TRY
261  {
263  }
265  {
267  _SEH2_YIELD(return NULL);
268  }
269  _SEH2_END;
270 
271  return str;
272 }
273 
274 /*
275  * @implemented
276  */
277 DWORD
278 WINAPI
280 {
281  DWORD lenW;
282  WCHAR* strW;
283  if (!str) return 0; /* YES */
284 
285  lenW = MultiByteToWideChar(CP_ACP, 0, str, len, NULL, 0);
286  strW = HeapAlloc(GetProcessHeap(), 0, lenW * sizeof(WCHAR));
287  if (strW) {
288  MultiByteToWideChar(CP_ACP, 0, str, len, strW, lenW);
289  CharUpperBuffW(strW, lenW);
290  len = WideCharToMultiByte(CP_ACP, 0, strW, lenW, str, len, NULL, NULL);
292  return len;
293  }
294  return 0;
295 }
296 
297 /*
298  * @implemented
299  */
300 DWORD
301 WINAPI
303 {
304  DWORD ret = len;
305  if (!str) return 0; /* YES */
306  for (; len; len--, str++) *str = towupper(*str);
307  return ret;
308 }
309 
310 /*
311  * @implemented
312  */
313 LPWSTR
314 WINAPI
316 {
317  if (HIWORD(x)) return struprW(x);
318  else return (LPWSTR)((UINT_PTR)toupperW(LOWORD(x)));
319 }
320 
321 /*
322  * @implemented
323  */
324 BOOL
325 WINAPI
327 {
328  WCHAR WCh;
329 
330  MultiByteToWideChar(CP_ACP, 0, &Ch, 1, &WCh, 1);
331  return IsCharAlphaW(WCh);
332 }
333 
334 /*
335  * @implemented
336  */
337 BOOL
338 WINAPI
340 {
341  WCHAR WCh;
342 
343  MultiByteToWideChar(CP_ACP, 0, &Ch, 1, &WCh, 1);
344  return IsCharAlphaNumericW(WCh);
345 }
346 
347 /*
348  * @implemented
349  */
350 BOOL
351 WINAPI
353 {
354  return (GetC1Type(Ch) & (C1_ALPHA|C1_DIGIT)) != 0;
355 }
356 
357 /*
358  * @implemented
359  */
360 BOOL
361 WINAPI
363 {
364  return (GetC1Type(Ch) & C1_ALPHA) != 0;
365 }
366 
367 /*
368  * @implemented
369  */
370 BOOL
371 WINAPI
373 {
374  WCHAR WCh;
375 
376  MultiByteToWideChar(CP_ACP, 0, &Ch, 1, &WCh, 1);
377  return IsCharLowerW(WCh);
378 }
379 
380 /*
381  * @implemented
382  */
383 BOOL
384 WINAPI
386 {
387  return (GetC1Type(Ch) & C1_LOWER) != 0;
388 }
389 
390 /*
391  * @implemented
392  */
393 BOOL
394 WINAPI
396 {
397  WCHAR WCh;
398 
399  MultiByteToWideChar(CP_ACP, 0, &Ch, 1, &WCh, 1);
400  return IsCharUpperW(WCh);
401 }
402 
403 /*
404  * @implemented
405  */
406 BOOL
407 WINAPI
409 {
410  return (GetC1Type(Ch) & C1_UPPER) != 0;
411 }
412 
413 /*
414  * @implemented
415  */
416 BOOL
417 WINAPI
419 {
420  if ( !s || !d ) return FALSE;
421  return OemToCharBuffA(s, d, strlen(s) + 1);
422 }
423 
424 /*
425  * @implemented
426  */
428 {
429  WCHAR* bufW;
430 
431  if ( !s || !d ) return FALSE;
432 
433  bufW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
434  if (bufW) {
435  MultiByteToWideChar(CP_OEMCP, 0, s, len, bufW, len);
436  WideCharToMultiByte(CP_ACP, 0, bufW, len, d, len, NULL, NULL);
437  HeapFree(GetProcessHeap(), 0, bufW);
438  }
439  return TRUE;
440 }
441 
442 /*
443  * @implemented
444  */
445 BOOL
446 WINAPI
448 {
449  if ( !s || !d ) return FALSE;
451  return TRUE;
452 }
453 
454 /*
455  * @implemented
456  */
458 {
459  if ( !s || !d ) return FALSE;
460  return OemToCharBuffW(s, d, strlen(s) + 1);
461 }
462 
463 /* EOF */
DWORD WINAPI CharLowerBuffW(LPWSTR str, DWORD len)
Definition: text.c:99
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
unsigned __int3264 UINT_PTR
Definition: activex.cpp:275
BOOL WINAPI CharToOemBuffW(LPCWSTR s, LPSTR d, DWORD len)
Definition: text.c:229
BOOL WINAPI IsCharAlphaNumericW(WCHAR Ch)
Definition: text.c:352
#define TRUE
Definition: types.h:120
LPWSTR WINAPI CharPrevW(LPCWSTR start, LPCWSTR x)
Definition: text.c:123
WINE_UNICODE_INLINE WCHAR * strlwrW(WCHAR *str)
Definition: unicode.h:281
LPSTR WINAPI CharPrevExA(WORD codepage, LPCSTR start, LPCSTR ptr, DWORD flags)
Definition: text.c:182
LPSTR WINAPI CharNextA(LPCSTR ptr)
Definition: text.c:134
#define WideCharToMultiByte
Definition: compat.h:101
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
BOOL WINAPI IsCharLowerA(CHAR Ch)
Definition: text.c:372
#define CP_ACP
Definition: compat.h:99
char CHAR
Definition: xmlstorage.h:175
LPSTR WINAPI CharUpperA(LPSTR str)
Definition: text.c:251
BOOL WINAPI OemToCharW(LPCSTR s, LPWSTR d)
Definition: text.c:457
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
BOOL WINAPI OemToCharA(LPCSTR s, LPSTR d)
Definition: text.c:418
#define Ch(x, y, z)
Definition: sha2.c:141
char * LPSTR
Definition: xmlstorage.h:182
#define C1_LOWER
Definition: unicode.h:32
_SEH2_TRY
Definition: create.c:4250
BOOL WINAPI IsDBCSLeadByteEx(UINT CodePage, BYTE TestByte)
Definition: nls.c:2199
unsigned int BOOL
Definition: ntddk_ex.h:94
WCHAR strW[12]
Definition: clipboard.c:2029
LPSTR WINAPI CharPrevA(LPCSTR start, LPCSTR ptr)
Definition: text.c:169
static PVOID ptr
Definition: dispmode.c:27
int codepage
Definition: win_iconv.c:156
DWORD WINAPI CharUpperBuffA(LPSTR str, DWORD len)
Definition: text.c:279
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
const WCHAR * str
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI IsCharLowerW(WCHAR Ch)
Definition: text.c:385
BOOL WINAPI IsDBCSLeadByte(BYTE TestByte)
Definition: nls.c:2221
BOOL WINAPI IsCharAlphaNumericA(CHAR Ch)
Definition: text.c:339
const char * LPCSTR
Definition: xmlstorage.h:183
static WORD GetC1Type(WCHAR Ch)
Definition: text.c:31
BOOL WINAPI CharToOemW(LPCWSTR s, LPSTR d)
Definition: text.c:242
WINE_UNICODE_INLINE WCHAR toupperW(WCHAR ch)
Definition: unicode.h:141
BOOL WINAPI IsCharUpperA(CHAR Ch)
Definition: text.c:395
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
#define d
Definition: ke_i.h:81
#define _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
#define C1_ALPHA
Definition: unicode.h:39
__wchar_t WCHAR
Definition: xmlstorage.h:180
BOOL WINAPI GetStringTypeW(DWORD type, LPCWSTR src, INT count, LPWORD chartype)
Definition: lang.c:1699
#define C1_DIGIT
Definition: unicode.h:33
#define WINAPI
Definition: msvc.h:8
unsigned short WORD
Definition: ntddk_ex.h:93
WINE_UNICODE_INLINE WCHAR tolowerW(WCHAR ch)
Definition: unicode.h:135
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL WINAPI CharToOemBuffA(LPCSTR s, LPSTR d, DWORD len)
Definition: text.c:209
#define SetLastError(x)
Definition: compat.h:409
DWORD WINAPI CharUpperBuffW(LPWSTR str, DWORD len)
Definition: text.c:302
GLbitfield flags
Definition: glext.h:7161
#define CT_CTYPE1
Definition: winnls.h:234
int ret
#define C1_UPPER
Definition: unicode.h:31
GLenum GLsizei len
Definition: glext.h:6722
unsigned char BYTE
Definition: mem.h:68
GLdouble s
Definition: gl.h:2039
LPSTR WINAPI CharNextExA(WORD codepage, LPCSTR ptr, DWORD flags)
Definition: text.c:146
BOOL WINAPI IsCharAlphaW(WCHAR Ch)
Definition: text.c:362
BOOL WINAPI CharToOemA(LPCSTR s, LPSTR d)
Definition: text.c:198
_SEH2_END
Definition: create.c:4424
static unsigned __int64 next
Definition: rand_nt.c:6
GLuint start
Definition: gl.h:1545
#define MultiByteToWideChar
Definition: compat.h:100
BOOL WINAPI OemToCharBuffA(LPCSTR s, LPSTR d, DWORD len)
Definition: text.c:427
BOOL WINAPI OemToCharBuffW(LPCSTR s, LPWSTR d, DWORD len)
Definition: text.c:447
#define HIWORD(l)
Definition: typedefs.h:246
LPWSTR WINAPI CharLowerW(LPWSTR x)
Definition: text.c:112
#define towlower(c)
Definition: wctype.h:97
DWORD WINAPI CharLowerBuffA(LPSTR str, DWORD len)
Definition: text.c:76
BOOL WINAPI IsCharAlphaA(CHAR Ch)
Definition: text.c:326
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define towupper(c)
Definition: wctype.h:99
WCHAR * LPWSTR
Definition: xmlstorage.h:184
LPWSTR WINAPI CharNextW(LPCWSTR x)
Definition: text.c:158
LPSTR WINAPI CharLowerA(LPSTR str)
Definition: text.c:48
#define LOWORD(l)
Definition: pedump.c:82
#define CP_OEMCP
Definition: winnls.h:228
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define HeapFree(x, y, z)
Definition: compat.h:394
LPWSTR WINAPI CharUpperW(LPWSTR x)
Definition: text.c:315
BOOL WINAPI IsCharUpperW(WCHAR Ch)
Definition: text.c:408
WINE_UNICODE_INLINE WCHAR * struprW(WCHAR *str)
Definition: unicode.h:288