Added Unicode ctype support.
[wine] / misc / lstr.c
1 /*
2  * String functions
3  *
4  * Copyright 1993 Yngvi Sigurjonsson (yngvi@hafro.is)
5  * Copyright 1996 Marcus Meissner
6  */
7
8 #include "config.h"
9
10 #include <stdarg.h>
11 #include <stdlib.h>
12 #include <stdio.h>
13 #include <string.h>
14 #include <ctype.h>
15
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"
27
28 DEFAULT_DEBUG_CHANNEL(resource);
29
30 extern const WORD OLE2NLS_CT_CType3_LUT[]; /* FIXME: does not belong here */
31
32 /***********************************************************************
33  *           CharLowerA   (USER32.25)
34  * FIXME: handle current locale
35  */
36 LPSTR WINAPI CharLowerA(LPSTR x)
37 {
38     LPSTR       s;
39
40     if (HIWORD(x))
41     {
42         s=x;
43         while (*s)
44         {
45             *s=tolower(*s);
46             s++;
47         }
48         return x;
49     }
50     else return (LPSTR)tolower((char)(int)x);
51 }
52
53 /***********************************************************************
54  *           CharLowerBuffA   (USER32.26)
55  * FIXME: handle current locale
56  */
57 DWORD WINAPI CharLowerBuffA(LPSTR x,DWORD buflen)
58 {
59     DWORD done=0;
60
61     if (!x) return 0; /* YES */
62     while (*x && (buflen--))
63     {
64         *x=tolower(*x);
65         x++;
66         done++;
67     }
68     return done;
69 }
70
71 /***********************************************************************
72  *           CharLowerBuffW   (USER32.27)
73  */
74 DWORD WINAPI CharLowerBuffW(LPWSTR x,DWORD buflen)
75 {
76     DWORD done=0;
77
78     if (!x) return 0; /* YES */
79     while (*x && (buflen--))
80     {
81         *x=tolowerW(*x);
82         x++;
83         done++;
84     }
85     return done;
86 }
87
88 /***********************************************************************
89  *           CharLowerW   (USER32.28)
90  * FIXME: handle current locale
91  */
92 LPWSTR WINAPI CharLowerW(LPWSTR x)
93 {
94     if (HIWORD(x))
95     {
96         LPWSTR s = x;
97         while (*s)
98         {
99             *s = tolowerW(*s);
100             s++;
101         }
102         return x;
103     }
104     else return (LPWSTR)((UINT)tolowerW(LOWORD(x)));
105 }
106
107 /***********************************************************************
108  *           CharUpperA   (USER32.41)
109  * FIXME: handle current locale
110  */
111 LPSTR WINAPI CharUpperA(LPSTR x)
112 {
113     if (HIWORD(x))
114     {
115         LPSTR s = x;
116         while (*s)
117         {
118             *s=toupper(*s);
119             s++;
120         }
121         return x;
122     }
123     return (LPSTR)toupper((char)(int)x);
124 }
125
126 /***********************************************************************
127  *           CharUpperBuffA   (USER32.42)
128  * FIXME: handle current locale
129  */
130 DWORD WINAPI CharUpperBuffA( LPSTR str, DWORD len )
131 {
132     DWORD ret = len;
133     if (!str) return 0; /* YES */
134     for (; len; len--, str++) *str = toupper(*str);
135     return ret;
136 }
137
138 /***********************************************************************
139  *           CharUpperBuffW   (USER32.43)
140  * FIXME: handle current locale
141  */
142 DWORD WINAPI CharUpperBuffW( LPWSTR str, DWORD len )
143 {
144     DWORD ret = len;
145     if (!str) return 0; /* YES */
146     for (; len; len--, str++) *str = toupperW(*str);
147     return ret;
148 }
149
150 /***********************************************************************
151  *           CharUpperW   (USER32.44)
152  * FIXME: handle current locale
153  */
154 LPWSTR WINAPI CharUpperW(LPWSTR x)
155 {
156     if (HIWORD(x))
157     {
158         LPWSTR s = x;
159         while (*s)
160         {
161             *s = toupperW(*s);
162             s++;
163         }
164         return x;
165     }
166     else return (LPWSTR)((UINT)toupperW(LOWORD(x)));
167 }
168
169 /***********************************************************************
170  *           IsCharAlphaA   (USER.433) (USER32.331)
171  * FIXME: handle current locale
172  */
173 BOOL WINAPI IsCharAlphaA(CHAR x)
174 {
175     return (OLE2NLS_CT_CType3_LUT[(unsigned char)x] & C3_ALPHA);
176 }
177
178 /***********************************************************************
179  *           IsCharAlphaNumericA   (USER.434) (USER32.332)
180  * FIXME: handle current locale
181  */
182 BOOL WINAPI IsCharAlphaNumericA(CHAR x)
183 {
184     return IsCharAlphaA(x) || isdigit(x) ;
185 }