Added Unicode ctype support.
[wine.git] / misc / lstr.c
blob5e717014cfa4bfde1fa383fe252dac90eb3cc13d
1 /*
2 * String functions
4 * Copyright 1993 Yngvi Sigurjonsson (yngvi@hafro.is)
5 * Copyright 1996 Marcus Meissner
6 */
8 #include "config.h"
10 #include <stdarg.h>
11 #include <stdlib.h>
12 #include <stdio.h>
13 #include <string.h>
14 #include <ctype.h>
16 #include "windef.h"
17 #include "winbase.h"
18 #include "wingdi.h"
19 #include "winuser.h"
20 #include "wine/winbase16.h"
21 #include "wine/winuser16.h"
22 #include "wine/unicode.h"
23 #include "winnls.h"
24 #include "heap.h"
25 #include "ldt.h"
26 #include "debugtools.h"
28 DEFAULT_DEBUG_CHANNEL(resource);
30 extern const WORD OLE2NLS_CT_CType3_LUT[]; /* FIXME: does not belong here */
32 /***********************************************************************
33 * CharLowerA (USER32.25)
34 * FIXME: handle current locale
36 LPSTR WINAPI CharLowerA(LPSTR x)
38 LPSTR s;
40 if (HIWORD(x))
42 s=x;
43 while (*s)
45 *s=tolower(*s);
46 s++;
48 return x;
50 else return (LPSTR)tolower((char)(int)x);
53 /***********************************************************************
54 * CharLowerBuffA (USER32.26)
55 * FIXME: handle current locale
57 DWORD WINAPI CharLowerBuffA(LPSTR x,DWORD buflen)
59 DWORD done=0;
61 if (!x) return 0; /* YES */
62 while (*x && (buflen--))
64 *x=tolower(*x);
65 x++;
66 done++;
68 return done;
71 /***********************************************************************
72 * CharLowerBuffW (USER32.27)
74 DWORD WINAPI CharLowerBuffW(LPWSTR x,DWORD buflen)
76 DWORD done=0;
78 if (!x) return 0; /* YES */
79 while (*x && (buflen--))
81 *x=tolowerW(*x);
82 x++;
83 done++;
85 return done;
88 /***********************************************************************
89 * CharLowerW (USER32.28)
90 * FIXME: handle current locale
92 LPWSTR WINAPI CharLowerW(LPWSTR x)
94 if (HIWORD(x))
96 LPWSTR s = x;
97 while (*s)
99 *s = tolowerW(*s);
100 s++;
102 return x;
104 else return (LPWSTR)((UINT)tolowerW(LOWORD(x)));
107 /***********************************************************************
108 * CharUpperA (USER32.41)
109 * FIXME: handle current locale
111 LPSTR WINAPI CharUpperA(LPSTR x)
113 if (HIWORD(x))
115 LPSTR s = x;
116 while (*s)
118 *s=toupper(*s);
119 s++;
121 return x;
123 return (LPSTR)toupper((char)(int)x);
126 /***********************************************************************
127 * CharUpperBuffA (USER32.42)
128 * FIXME: handle current locale
130 DWORD WINAPI CharUpperBuffA( LPSTR str, DWORD len )
132 DWORD ret = len;
133 if (!str) return 0; /* YES */
134 for (; len; len--, str++) *str = toupper(*str);
135 return ret;
138 /***********************************************************************
139 * CharUpperBuffW (USER32.43)
140 * FIXME: handle current locale
142 DWORD WINAPI CharUpperBuffW( LPWSTR str, DWORD len )
144 DWORD ret = len;
145 if (!str) return 0; /* YES */
146 for (; len; len--, str++) *str = toupperW(*str);
147 return ret;
150 /***********************************************************************
151 * CharUpperW (USER32.44)
152 * FIXME: handle current locale
154 LPWSTR WINAPI CharUpperW(LPWSTR x)
156 if (HIWORD(x))
158 LPWSTR s = x;
159 while (*s)
161 *s = toupperW(*s);
162 s++;
164 return x;
166 else return (LPWSTR)((UINT)toupperW(LOWORD(x)));
169 /***********************************************************************
170 * IsCharAlphaA (USER.433) (USER32.331)
171 * FIXME: handle current locale
173 BOOL WINAPI IsCharAlphaA(CHAR x)
175 return (OLE2NLS_CT_CType3_LUT[(unsigned char)x] & C3_ALPHA);
178 /***********************************************************************
179 * IsCharAlphaNumericA (USER.434) (USER32.332)
180 * FIXME: handle current locale
182 BOOL WINAPI IsCharAlphaNumericA(CHAR x)
184 return IsCharAlphaA(x) || isdigit(x) ;