]> git.saurik.com Git - wxWidgets.git/blob - include/wx/chartype.h
Return valid pointers from wxDateTime::ParseXXX() with non-wxString strings.
[wxWidgets.git] / include / wx / chartype.h
1 /*
2 * Name: wx/chartype.h
3 * Purpose: Declarations of wxChar and related types
4 * Author: Joel Farley, Ove Kåven
5 * Modified by: Vadim Zeitlin, Robert Roebling, Ron Lee
6 * Created: 1998/06/12
7 * RCS-ID: $Id$
8 * Copyright: (c) 1998-2006 wxWidgets dev team
9 * Licence: wxWindows licence
10 */
11
12 /* THIS IS A C FILE, DON'T USE C++ FEATURES (IN PARTICULAR COMMENTS) IN IT */
13
14 #ifndef _WX_WXCHARTYPE_H_
15 #define _WX_WXCHARTYPE_H_
16
17 /* defs.h indirectly includes this file, so don't include it here */
18 #include "wx/platform.h"
19
20 /* check whether we have wchar_t and which size it is if we do */
21 #if !defined(wxUSE_WCHAR_T)
22 #if defined(__UNIX__)
23 #if defined(HAVE_WCSTR_H) || defined(HAVE_WCHAR_H) || defined(__FreeBSD__) || defined(__DARWIN__)
24 #define wxUSE_WCHAR_T 1
25 #else
26 #define wxUSE_WCHAR_T 0
27 #endif
28 #elif defined(__GNUWIN32__) && !defined(__MINGW32__)
29 #define wxUSE_WCHAR_T 0
30 #elif defined(__WATCOMC__)
31 #define wxUSE_WCHAR_T 0
32 #elif defined(__VISAGECPP__) && (__IBMCPP__ < 400)
33 #define wxUSE_WCHAR_T 0
34 #else
35 /* add additional compiler checks if this fails */
36 #define wxUSE_WCHAR_T 1
37 #endif
38 #endif /* !defined(wxUSE_WCHAR_T) */
39
40 /* Unicode support requires wchar_t */
41 #if !wxUSE_WCHAR_T
42 #error "wchar_t must be available"
43 #endif /* Unicode */
44
45 /*
46 non Unix compilers which do have wchar.h (but not tchar.h which is included
47 below and which includes wchar.h anyhow).
48
49 Actually MinGW has tchar.h, but it does not include wchar.h
50 */
51 #if defined(__MWERKS__) || defined(__VISAGECPP__) || defined(__MINGW32__) || defined(__WATCOMC__)
52 #ifndef HAVE_WCHAR_H
53 #define HAVE_WCHAR_H
54 #endif
55 #endif
56 #if defined(__MWERKS__) && !defined(__MACH__)
57 #ifndef HAVE_WCSLEN
58 #define HAVE_WCSLEN
59 #endif
60 #endif
61
62 #ifdef HAVE_WCHAR_H
63 /* the current (as of Nov 2002) version of cygwin has a bug in its */
64 /* wchar.h -- there is no extern "C" around the declarations in it */
65 /* and this results in linking errors later; also, at least on some */
66 /* Cygwin versions, wchar.h requires sys/types.h */
67 #ifdef __CYGWIN__
68 #include <sys/types.h>
69 #ifdef __cplusplus
70 extern "C" {
71 #endif
72 #endif /* Cygwin */
73
74 #include <wchar.h>
75
76 #if defined(__CYGWIN__) && defined(__cplusplus)
77 }
78 #endif /* Cygwin and C++ */
79
80 #elif defined(HAVE_WCSTR_H)
81 /* old compilers have relevant declarations here */
82 #include <wcstr.h>
83 #elif defined(__FreeBSD__) || defined(__DARWIN__) || defined(__EMX__)
84 /* include stdlib.h for wchar_t */
85 #include <stdlib.h>
86 #endif /* HAVE_WCHAR_H */
87
88 #ifdef HAVE_WIDEC_H
89 #include <widec.h>
90 #endif
91
92 /* -------------------------------------------------------------------------- */
93 /* define wxHAVE_TCHAR_SUPPORT for the compilers which support the TCHAR type */
94 /* mapped to either char or wchar_t depending on the ASCII/Unicode mode and */
95 /* have the function mapping _tfoo() -> foo() or wfoo() */
96 /* -------------------------------------------------------------------------- */
97
98 /* VC++ and BC++ starting with 5.2 have TCHAR support */
99 #ifdef __VISUALC__
100 #define wxHAVE_TCHAR_SUPPORT
101 #elif defined(__BORLANDC__) && (__BORLANDC__ >= 0x520)
102 #define wxHAVE_TCHAR_SUPPORT
103 #include <ctype.h>
104 #elif defined(__WATCOMC__)
105 #define wxHAVE_TCHAR_SUPPORT
106 #elif defined(__DMC__)
107 #define wxHAVE_TCHAR_SUPPORT
108 #elif defined(__MINGW32__) && wxCHECK_W32API_VERSION( 1, 0 )
109 #define wxHAVE_TCHAR_SUPPORT
110 #include <stddef.h>
111 #include <string.h>
112 #include <ctype.h>
113 #elif 0 && defined(__VISAGECPP__) && (__IBMCPP__ >= 400)
114 /* VZ: the old VisualAge definitions were completely wrong and had no */
115 /* chance at all to work in Unicode build anyhow so let's pretend */
116 /* that VisualAge does _not_ support TCHAR for the moment (as */
117 /* indicated by "0 &&" above) until someone really has time to delve */
118 /* into Unicode issues under OS/2 */
119
120 /* VisualAge 4.0+ supports TCHAR */
121 #define wxHAVE_TCHAR_SUPPORT
122 #endif /* compilers with (good) TCHAR support */
123
124 #ifdef wxHAVE_TCHAR_SUPPORT
125 /* get TCHAR definition if we've got it */
126 #include <tchar.h>
127
128 /* we surely do have wchar_t if we have TCHAR */
129 #ifndef wxUSE_WCHAR_T
130 #define wxUSE_WCHAR_T 1
131 #endif /* !defined(wxUSE_WCHAR_T) */
132 #endif /* wxHAVE_TCHAR_SUPPORT */
133
134 /* ------------------------------------------------------------------------- */
135 /* define wxChar type */
136 /* ------------------------------------------------------------------------- */
137
138 /* TODO: define wxCharInt to be equal to either int or wint_t? */
139
140 #if !wxUSE_UNICODE
141 typedef char wxChar;
142 typedef signed char wxSChar;
143 typedef unsigned char wxUChar;
144 #else
145 /* VZ: note that VC++ defines _T[SU]CHAR simply as wchar_t and not as */
146 /* signed/unsigned version of it which (a) makes sense to me (unlike */
147 /* char wchar_t is always unsigned) and (b) was how the previous */
148 /* definitions worked so keep it like this */
149
150 /* Sun's SunPro compiler supports the wchar_t type and wide character */
151 /* functions, but does not define __WCHAR_TYPE__. Define it here to */
152 /* allow unicode enabled builds. */
153 #if (defined(__SUNPRO_CC) || defined(__SUNPRO_C)) && !defined(__WCHAR_TYPE__)
154 #define __WCHAR_TYPE__ wxchar_t
155 #endif
156
157 /* GNU libc has __WCHAR_TYPE__ which requires special treatment, see */
158 /* comment below */
159 #if !defined(__WCHAR_TYPE__) || \
160 (!defined(__GNUC__) || wxCHECK_GCC_VERSION(2, 96))
161 /* standard case */
162 typedef wchar_t wxChar;
163 typedef wchar_t wxSChar;
164 typedef wchar_t wxUChar;
165 #else /* __WCHAR_TYPE__ and gcc < 2.96 */
166 /* VS: wxWidgets used to define wxChar as __WCHAR_TYPE__ here. */
167 /* However, this doesn't work with new GCC 3.x compilers because */
168 /* wchar_t is C++'s builtin type in the new standard. OTOH, old */
169 /* compilers (GCC 2.x) won't accept new definition of */
170 /* wx{S,U}CharType, so we have to define wxChar */
171 /* conditionally depending on detected compiler & compiler */
172 /* version. */
173
174 /* with old definition of wxChar. */
175 #define wchar_t __WCHAR_TYPE__
176 typedef __WCHAR_TYPE__ wxChar;
177 typedef __WCHAR_TYPE__ wxSChar;
178 typedef __WCHAR_TYPE__ wxUChar;
179 #endif /* __WCHAR_TYPE__ */
180 #endif /* ASCII/Unicode */
181
182 /* ------------------------------------------------------------------------- */
183 /* define wxStringCharType */
184 /* ------------------------------------------------------------------------- */
185
186 /* depending on the platform, Unicode build can either store wxStrings as
187 wchar_t* or UTF-8 encoded char*: */
188 #if wxUSE_UNICODE
189 /* FIXME-UTF8: what would be better place for this? */
190 #if defined(wxUSE_UTF8_LOCALE_ONLY) && !defined(wxUSE_UNICODE_UTF8)
191 #error "wxUSE_UTF8_LOCALE_ONLY only makes sense with wxUSE_UNICODE_UTF8"
192 #endif
193 #ifndef wxUSE_UTF8_LOCALE_ONLY
194 #define wxUSE_UTF8_LOCALE_ONLY 0
195 #endif
196
197 #ifndef wxUSE_UNICODE_UTF8
198 #define wxUSE_UNICODE_UTF8 0
199 #endif
200
201 #if wxUSE_UNICODE_UTF8
202 #define wxUSE_UNICODE_WCHAR 0
203 #else
204 #define wxUSE_UNICODE_WCHAR 1
205 #endif
206 #else
207 #define wxUSE_UNICODE_WCHAR 0
208 #define wxUSE_UNICODE_UTF8 0
209 #define wxUSE_UTF8_LOCALE_ONLY 0
210 #endif
211
212 /* define char type used by wxString internal representation: */
213 #if wxUSE_UNICODE_WCHAR
214 typedef wchar_t wxStringCharType;
215 #else /* wxUSE_UNICODE_UTF8 || ANSI */
216 typedef char wxStringCharType;
217 #endif
218
219
220 /* ------------------------------------------------------------------------- */
221 /* define wxT() and related macros */
222 /* ------------------------------------------------------------------------- */
223
224 /* BSD systems define _T() to be something different in ctype.h, override it */
225 #if defined(__FreeBSD__) || defined(__DARWIN__)
226 #include <ctype.h>
227 #undef _T
228 #endif
229
230 /*
231 wxT ("wx text") macro turns a literal string constant into a wide char
232 constant. It is mostly unnecessary with wx 2.9 but defined for
233 compatibility.
234 */
235 #ifndef wxT
236 #if !wxUSE_UNICODE
237 #define wxT(x) x
238 #else /* Unicode */
239 /*
240 Notice that we use an intermediate macro to allow x to be expanded
241 if it's a macro itself.
242 */
243 #ifndef wxCOMPILER_BROKEN_CONCAT_OPER
244 #define wxT(x) wxCONCAT_HELPER(L, x)
245 #else
246 #define wxT(x) wxPREPEND_L(x)
247 #endif
248 #endif /* ASCII/Unicode */
249 #endif /* !defined(wxT) */
250
251 /*
252 wxT_2 exists only for compatibility with wx 2.x and is the same as wxT() in
253 that version but nothing in the newer ones.
254 */
255 #define wxT_2(x) x
256
257 /*
258 wxS ("wx string") macro can be used to create literals using the same
259 representation as wxString does internally, i.e. wchar_t in Unicode build
260 under Windows or char in UTF-8-based Unicode builds and (deprecated) ANSI
261 builds everywhere (see wxStringCharType definition above).
262 */
263 #if wxUSE_UNICODE_WCHAR
264 /*
265 As above with wxT(), wxS() argument is expanded if it's a macro.
266 */
267 #ifndef wxCOMPILER_BROKEN_CONCAT_OPER
268 #define wxS(x) wxCONCAT_HELPER(L, x)
269 #else
270 #define wxS(x) wxPREPEND_L(x)
271 #endif
272 #else /* wxUSE_UNICODE_UTF8 || ANSI */
273 #define wxS(x) x
274 #endif
275
276 /*
277 _T() is a synonym for wxT() familiar to Windows programmers. As this macro
278 has even higher risk of conflicting with system headers, its use is
279 discouraged and you may predefine wxNO__T to disable it. Additionally, we
280 do it ourselves for Sun CC which is known to use it in its standard headers
281 (see #10660).
282 */
283 #if defined(__SUNPRO_C) || defined(__SUNPRO_CC)
284 #ifndef wxNO__T
285 #define wxNO__T
286 #endif
287 #endif
288
289 #if !defined(_T) && !defined(wxNO__T)
290 #define _T(x) wxT(x)
291 #endif
292
293 /* a helper macro allowing to make another macro Unicode-friendly, see below */
294 #define wxAPPLY_T(x) wxT(x)
295
296 /* Unicode-friendly __FILE__, __DATE__ and __TIME__ analogs */
297 #ifndef __TFILE__
298 #define __TFILE__ wxAPPLY_T(__FILE__)
299 #endif
300
301 #ifndef __TDATE__
302 #define __TDATE__ wxAPPLY_T(__DATE__)
303 #endif
304
305 #ifndef __TTIME__
306 #define __TTIME__ wxAPPLY_T(__TIME__)
307 #endif
308
309 #endif /* _WX_WXCHARTYPE_H_ */
310