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.
20 * PROJECT: ReactOS user32.dll
21 * FILE: win32ss/user/user32/windows/text.c
23 * PROGRAMMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
25 * 09-05-2001 CSH Created
28 /* INCLUDES ******************************************************************/
32 #include <wine/debug.h>
34 /* FUNCTIONS *****************************************************************/
41 if (! GetStringTypeW(CT_CTYPE1
, &Ch
, 1, &CharType
))
58 char ch
= LOWORD(str
);
59 CharLowerBuffA( &ch
, 1 );
60 return (LPSTR
)(UINT_PTR
)(BYTE
)ch
;
65 CharLowerBuffA( str
, strlen(str
) );
67 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
69 SetLastError( ERROR_INVALID_PARAMETER
);
70 _SEH2_YIELD(return NULL
);
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
);
120 if (HIWORD(x
)) return strlwrW(x
);
121 else return (LPWSTR
)((UINT_PTR
)tolowerW(LOWORD(x
)));
129 CharPrevW(LPCWSTR start
, LPCWSTR x
)
131 if (x
> start
) return (LPWSTR
)(x
-1);
132 else return (LPWSTR
)x
;
140 CharNextA(LPCSTR ptr
)
142 if (!*ptr
) return (LPSTR
)ptr
;
143 if (IsDBCSLeadByte(ptr
[0]) && ptr
[1]) return (LPSTR
)(ptr
+ 2);
144 return (LPSTR
)(ptr
+ 1);
152 CharNextExA(WORD codepage
, LPCSTR ptr
, DWORD flags
)
154 if (!*ptr
) return (LPSTR
)ptr
;
155 if (IsDBCSLeadByteEx(codepage
, ptr
[0]) && ptr
[1]) return (LPSTR
)(ptr
+ 2);
156 return (LPSTR
)(ptr
+ 1);
175 CharPrevA(LPCSTR start
, LPCSTR ptr
)
177 while (*start
&& (start
< ptr
)) {
178 LPCSTR next
= CharNextA(start
);
179 if (next
>= ptr
) break;
188 LPSTR WINAPI
CharPrevExA( WORD codepage
, LPCSTR start
, LPCSTR ptr
, DWORD flags
)
190 while (*start
&& (start
< ptr
))
192 LPCSTR next
= CharNextExA( codepage
, start
, flags
);
193 if (next
> ptr
) break;
204 CharToOemA(LPCSTR s
, LPSTR d
)
206 if (!s
|| !d
) return FALSE
;
207 return CharToOemBuffA(s
, d
, strlen(s
) + 1);
215 CharToOemBuffA(LPCSTR s
, LPSTR d
, DWORD len
)
219 if ( !s
|| !d
) return FALSE
;
221 bufW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
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
);
235 CharToOemBuffW(LPCWSTR s
, LPSTR d
, DWORD len
)
239 WideCharToMultiByte(CP_OEMCP
, 0, s
, len
, d
, len
, NULL
, NULL
);
248 CharToOemW(LPCWSTR s
, LPSTR d
)
250 if ( !s
|| !d
) return FALSE
;
251 return CharToOemBuffW(s
, d
, wcslen(s
) + 1);
257 LPSTR WINAPI
CharUpperA(LPSTR str
)
261 char ch
= LOWORD(str
);
262 CharUpperBuffA( &ch
, 1 );
263 return (LPSTR
)(UINT_PTR
)(BYTE
)ch
;
268 CharUpperBuffA( str
, strlen(str
) );
270 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
272 SetLastError( ERROR_INVALID_PARAMETER
);
273 _SEH2_YIELD(return NULL
);
285 CharUpperBuffA(LPSTR str
, DWORD len
)
289 if (!str
) return 0; /* YES */
291 lenW
= MultiByteToWideChar(CP_ACP
, 0, str
, len
, NULL
, 0);
292 strW
= HeapAlloc(GetProcessHeap(), 0, lenW
* sizeof(WCHAR
));
294 MultiByteToWideChar(CP_ACP
, 0, str
, len
, strW
, lenW
);
295 CharUpperBuffW(strW
, lenW
);
296 len
= WideCharToMultiByte(CP_ACP
, 0, strW
, lenW
, str
, len
, NULL
, NULL
);
297 HeapFree(GetProcessHeap(), 0, strW
);
308 CharUpperBuffW(LPWSTR str
, DWORD len
)
311 if (!str
) return 0; /* YES */
312 for (; len
; len
--, str
++) *str
= towupper(*str
);
323 if (HIWORD(x
)) return struprW(x
);
324 else return (LPWSTR
)((UINT_PTR
)toupperW(LOWORD(x
)));
332 IsCharAlphaA(CHAR Ch
)
336 MultiByteToWideChar(CP_ACP
, 0, &Ch
, 1, &WCh
, 1);
337 return IsCharAlphaW(WCh
);
345 IsCharAlphaNumericA(CHAR Ch
)
349 MultiByteToWideChar(CP_ACP
, 0, &Ch
, 1, &WCh
, 1);
350 return IsCharAlphaNumericW(WCh
);
358 IsCharAlphaNumericW(WCHAR Ch
)
360 return (GetC1Type(Ch
) & (C1_ALPHA
|C1_DIGIT
)) != 0;
368 IsCharAlphaW(WCHAR Ch
)
370 return (GetC1Type(Ch
) & C1_ALPHA
) != 0;
378 IsCharLowerA(CHAR Ch
)
382 MultiByteToWideChar(CP_ACP
, 0, &Ch
, 1, &WCh
, 1);
383 return IsCharLowerW(WCh
);
391 IsCharLowerW(WCHAR Ch
)
393 return (GetC1Type(Ch
) & C1_LOWER
) != 0;
401 IsCharUpperA(CHAR Ch
)
405 MultiByteToWideChar(CP_ACP
, 0, &Ch
, 1, &WCh
, 1);
406 return IsCharUpperW(WCh
);
414 IsCharUpperW(WCHAR Ch
)
416 return (GetC1Type(Ch
) & C1_UPPER
) != 0;
424 OemToCharA(LPCSTR s
, LPSTR d
)
426 if ( !s
|| !d
) return FALSE
;
427 return OemToCharBuffA(s
, d
, strlen(s
) + 1);
433 BOOL WINAPI
OemToCharBuffA(LPCSTR s
, LPSTR d
, DWORD len
)
437 if ( !s
|| !d
) return FALSE
;
439 bufW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
441 MultiByteToWideChar(CP_OEMCP
, 0, s
, len
, bufW
, len
);
442 WideCharToMultiByte(CP_ACP
, 0, bufW
, len
, d
, len
, NULL
, NULL
);
443 HeapFree(GetProcessHeap(), 0, bufW
);
453 OemToCharBuffW(LPCSTR s
, LPWSTR d
, DWORD len
)
455 if ( !s
|| !d
) return FALSE
;
456 MultiByteToWideChar(CP_OEMCP
, 0, s
, len
, d
, len
);
463 BOOL WINAPI
OemToCharW(LPCSTR s
, LPWSTR d
)
465 if ( !s
|| !d
) return FALSE
;
466 return OemToCharBuffW(s
, d
, strlen(s
) + 1);