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