]> git.saurik.com Git - wxWidgets.git/blob - include/wx/wxcrt.h
Avoid setting attributes in GTK wxDataViewRenderer if not supported.
[wxWidgets.git] / include / wx / wxcrt.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/wxcrt.h
3 // Purpose: Type-safe ANSI and Unicode builds compatible wrappers for
4 // CRT functions
5 // Author: Joel Farley, Ove Kaaven
6 // Modified by: Vadim Zeitlin, Robert Roebling, Ron Lee, Vaclav Slavik
7 // Created: 1998/06/12
8 // RCS-ID: $Id$
9 // Copyright: (c) 1998-2006 wxWidgets dev team
10 // Licence: wxWindows licence
11 ///////////////////////////////////////////////////////////////////////////////
12
13 #ifndef _WX_WXCRT_H_
14 #define _WX_WXCRT_H_
15
16 #include "wx/wxcrtbase.h"
17 #include "wx/string.h"
18
19 #ifndef __WX_SETUP_H__
20 // For non-configure builds assume vsscanf is available, if not Visual C or DMC
21 #if !defined (__VISUALC__) && !defined (__DMC__)
22 #define HAVE_VSSCANF 1
23 #endif
24 #endif
25
26 // ============================================================================
27 // misc functions
28 // ============================================================================
29
30 /* checks whether the passed in pointer is NULL and if the string is empty */
31 inline bool wxIsEmpty(const char *s) { return !s || !*s; }
32 inline bool wxIsEmpty(const wchar_t *s) { return !s || !*s; }
33 inline bool wxIsEmpty(const wxScopedCharBuffer& s) { return wxIsEmpty(s.data()); }
34 inline bool wxIsEmpty(const wxScopedWCharBuffer& s) { return wxIsEmpty(s.data()); }
35 inline bool wxIsEmpty(const wxString& s) { return s.empty(); }
36 inline bool wxIsEmpty(const wxCStrData& s) { return s.AsString().empty(); }
37
38
39
40 /* multibyte to wide char conversion functions and macros */
41
42 #if wxUSE_WCHAR_T
43 /* multibyte<->widechar conversion */
44 WXDLLIMPEXP_BASE size_t wxMB2WC(wchar_t *buf, const char *psz, size_t n);
45 WXDLLIMPEXP_BASE size_t wxWC2MB(char *buf, const wchar_t *psz, size_t n);
46
47 #if wxUSE_UNICODE
48 #define wxMB2WX wxMB2WC
49 #define wxWX2MB wxWC2MB
50 #define wxWC2WX wxStrncpy
51 #define wxWX2WC wxStrncpy
52 #else
53 #define wxMB2WX wxStrncpy
54 #define wxWX2MB wxStrncpy
55 #define wxWC2WX wxWC2MB
56 #define wxWX2WC wxMB2WC
57 #endif
58 #else /* !wxUSE_UNICODE */
59 /* No wxUSE_WCHAR_T: we have to do something (JACS) */
60 #define wxMB2WC wxStrncpy
61 #define wxWC2MB wxStrncpy
62 #define wxMB2WX wxStrncpy
63 #define wxWX2MB wxStrncpy
64 #define wxWC2WX wxWC2MB
65 #define wxWX2WC wxMB2WC
66 #endif
67
68
69 // RN: We could do the usual tricky compiler detection here,
70 // and use their variant (such as wmemchr, etc.). The problem
71 // is that these functions are quite rare, even though they are
72 // part of the current POSIX standard. In addition, most compilers
73 // (including even MSC) inline them just like we do right in their
74 // headers.
75 //
76 #include <string.h>
77
78 #if wxUSE_UNICODE
79 //implement our own wmem variants
80 inline wxChar* wxTmemchr(const wxChar* s, wxChar c, size_t l)
81 {
82 for(;l && *s != c;--l, ++s) {}
83
84 if(l)
85 return (wxChar*)s;
86 return NULL;
87 }
88
89 inline int wxTmemcmp(const wxChar* sz1, const wxChar* sz2, size_t len)
90 {
91 for(; *sz1 == *sz2 && len; --len, ++sz1, ++sz2) {}
92
93 if(len)
94 return *sz1 < *sz2 ? -1 : *sz1 > *sz2;
95 else
96 return 0;
97 }
98
99 inline wxChar* wxTmemcpy(wxChar* szOut, const wxChar* szIn, size_t len)
100 {
101 return (wxChar*) memcpy(szOut, szIn, len * sizeof(wxChar));
102 }
103
104 inline wxChar* wxTmemmove(wxChar* szOut, const wxChar* szIn, size_t len)
105 {
106 return (wxChar*) memmove(szOut, szIn, len * sizeof(wxChar));
107 }
108
109 inline wxChar* wxTmemset(wxChar* szOut, const wxChar cIn, size_t len)
110 {
111 wxChar* szRet = szOut;
112
113 while (len--)
114 *szOut++ = cIn;
115
116 return szRet;
117 }
118 #endif /* wxUSE_UNICODE */
119
120 // provide trivial wrappers for char* versions for both ANSI and Unicode builds
121 // (notice that these intentionally return "char *" and not "void *" unlike the
122 // standard memxxx() for symmetry with the wide char versions):
123 inline char* wxTmemchr(const char* s, char c, size_t len)
124 { return (char*)memchr(s, c, len); }
125 inline int wxTmemcmp(const char* sz1, const char* sz2, size_t len)
126 { return memcmp(sz1, sz2, len); }
127 inline char* wxTmemcpy(char* szOut, const char* szIn, size_t len)
128 { return (char*)memcpy(szOut, szIn, len); }
129 inline char* wxTmemmove(char* szOut, const char* szIn, size_t len)
130 { return (char*)memmove(szOut, szIn, len); }
131 inline char* wxTmemset(char* szOut, const char cIn, size_t len)
132 { return (char*)memset(szOut, cIn, len); }
133
134
135 // ============================================================================
136 // wx wrappers for CRT functions in both char* and wchar_t* versions
137 // ============================================================================
138
139 // A few notes on implementation of these wrappers:
140 //
141 // We need both char* and wchar_t* versions of functions like wxStrlen() for
142 // compatibility with both ANSI and Unicode builds.
143 //
144 // This makes passing wxString or c_str()/mb_str()/wc_str() result to them
145 // ambiguous, so we need to provide overrides for that as well (in cases where
146 // it makes sense).
147 //
148 // We can do this without problems for some functions (wxStrlen()), but in some
149 // cases, we can't stay compatible with both ANSI and Unicode builds, e.g. for
150 // wxStrcpy(const wxString&), which can only return either char* or wchar_t*.
151 // In these cases, we preserve ANSI build compatibility by returning char*.
152
153 // ----------------------------------------------------------------------------
154 // locale functions
155 // ----------------------------------------------------------------------------
156
157 // NB: we can't provide const wchar_t* (= wxChar*) overload, because calling
158 // wxSetlocale(category, NULL) -- which is a common thing to do -- would be
159 // ambiguous
160 WXDLLIMPEXP_BASE char* wxSetlocale(int category, const char *locale);
161 inline char* wxSetlocale(int category, const wxScopedCharBuffer& locale)
162 { return wxSetlocale(category, locale.data()); }
163 inline char* wxSetlocale(int category, const wxString& locale)
164 { return wxSetlocale(category, locale.mb_str()); }
165 inline char* wxSetlocale(int category, const wxCStrData& locale)
166 { return wxSetlocale(category, locale.AsCharBuf()); }
167
168 // ----------------------------------------------------------------------------
169 // string functions
170 // ----------------------------------------------------------------------------
171
172 /* safe version of strlen() (returns 0 if passed NULL pointer) */
173 // NB: these are defined in wxcrtbase.h, see the comment there
174 // inline size_t wxStrlen(const char *s) { return s ? strlen(s) : 0; }
175 // inline size_t wxStrlen(const wchar_t *s) { return s ? wxCRT_Strlen_(s) : 0; }
176 inline size_t wxStrlen(const wxScopedCharBuffer& s) { return wxStrlen(s.data()); }
177 inline size_t wxStrlen(const wxScopedWCharBuffer& s) { return wxStrlen(s.data()); }
178 inline size_t wxStrlen(const wxString& s) { return s.length(); }
179 inline size_t wxStrlen(const wxCStrData& s) { return s.AsString().length(); }
180
181 // this is a function new in 2.9 so we don't care about backwards compatibility and
182 // so don't need to support wxScopedCharBuffer/wxScopedWCharBuffer overloads
183 #if defined(wxCRT_StrnlenA)
184 inline size_t wxStrnlen(const char *str, size_t maxlen) { return wxCRT_StrnlenA(str, maxlen); }
185 #else
186 inline size_t wxStrnlen(const char *str, size_t maxlen)
187 {
188 size_t n;
189 for ( n = 0; n < maxlen; n++ )
190 if ( !str[n] )
191 break;
192
193 return n;
194 }
195 #endif
196
197 #if defined(wxCRT_StrnlenW)
198 inline size_t wxStrnlen(const wchar_t *str, size_t maxlen) { return wxCRT_StrnlenW(str, maxlen); }
199 #else
200 inline size_t wxStrnlen(const wchar_t *str, size_t maxlen)
201 {
202 size_t n;
203 for ( n = 0; n < maxlen; n++ )
204 if ( !str[n] )
205 break;
206
207 return n;
208 }
209 #endif
210
211 // NB: these are defined in wxcrtbase.h, see the comment there
212 // inline char* wxStrdup(const char *s) { return wxStrdupA(s); }
213 // inline wchar_t* wxStrdup(const wchar_t *s) { return wxStrdupW(s); }
214 inline char* wxStrdup(const wxScopedCharBuffer& s) { return wxStrdup(s.data()); }
215 inline wchar_t* wxStrdup(const wxScopedWCharBuffer& s) { return wxStrdup(s.data()); }
216 inline char* wxStrdup(const wxString& s) { return wxStrdup(s.mb_str()); }
217 inline char* wxStrdup(const wxCStrData& s) { return wxStrdup(s.AsCharBuf()); }
218
219 inline char *wxStrcpy(char *dest, const char *src)
220 { return wxCRT_StrcpyA(dest, src); }
221 inline wchar_t *wxStrcpy(wchar_t *dest, const wchar_t *src)
222 { return wxCRT_StrcpyW(dest, src); }
223 inline char *wxStrcpy(char *dest, const wxString& src)
224 { return wxCRT_StrcpyA(dest, src.mb_str()); }
225 inline char *wxStrcpy(char *dest, const wxCStrData& src)
226 { return wxCRT_StrcpyA(dest, src.AsCharBuf()); }
227 inline char *wxStrcpy(char *dest, const wxScopedCharBuffer& src)
228 { return wxCRT_StrcpyA(dest, src.data()); }
229 inline wchar_t *wxStrcpy(wchar_t *dest, const wxString& src)
230 { return wxCRT_StrcpyW(dest, src.wc_str()); }
231 inline wchar_t *wxStrcpy(wchar_t *dest, const wxCStrData& src)
232 { return wxCRT_StrcpyW(dest, src.AsWCharBuf()); }
233 inline wchar_t *wxStrcpy(wchar_t *dest, const wxScopedWCharBuffer& src)
234 { return wxCRT_StrcpyW(dest, src.data()); }
235 inline char *wxStrcpy(char *dest, const wchar_t *src)
236 { return wxCRT_StrcpyA(dest, wxConvLibc.cWC2MB(src)); }
237 inline wchar_t *wxStrcpy(wchar_t *dest, const char *src)
238 { return wxCRT_StrcpyW(dest, wxConvLibc.cMB2WC(src)); }
239
240 inline char *wxStrncpy(char *dest, const char *src, size_t n)
241 { return wxCRT_StrncpyA(dest, src, n); }
242 inline wchar_t *wxStrncpy(wchar_t *dest, const wchar_t *src, size_t n)
243 { return wxCRT_StrncpyW(dest, src, n); }
244 inline char *wxStrncpy(char *dest, const wxString& src, size_t n)
245 { return wxCRT_StrncpyA(dest, src.mb_str(), n); }
246 inline char *wxStrncpy(char *dest, const wxCStrData& src, size_t n)
247 { return wxCRT_StrncpyA(dest, src.AsCharBuf(), n); }
248 inline char *wxStrncpy(char *dest, const wxScopedCharBuffer& src, size_t n)
249 { return wxCRT_StrncpyA(dest, src.data(), n); }
250 inline wchar_t *wxStrncpy(wchar_t *dest, const wxString& src, size_t n)
251 { return wxCRT_StrncpyW(dest, src.wc_str(), n); }
252 inline wchar_t *wxStrncpy(wchar_t *dest, const wxCStrData& src, size_t n)
253 { return wxCRT_StrncpyW(dest, src.AsWCharBuf(), n); }
254 inline wchar_t *wxStrncpy(wchar_t *dest, const wxScopedWCharBuffer& src, size_t n)
255 { return wxCRT_StrncpyW(dest, src.data(), n); }
256 inline char *wxStrncpy(char *dest, const wchar_t *src, size_t n)
257 { return wxCRT_StrncpyA(dest, wxConvLibc.cWC2MB(src), n); }
258 inline wchar_t *wxStrncpy(wchar_t *dest, const char *src, size_t n)
259 { return wxCRT_StrncpyW(dest, wxConvLibc.cMB2WC(src), n); }
260
261 // this is a function new in 2.9 so we don't care about backwards compatibility and
262 // so don't need to support wchar_t/char overloads
263 inline size_t wxStrlcpy(char *dest, const char *src, size_t n)
264 {
265 const size_t len = wxCRT_StrlenA(src);
266
267 if ( n )
268 {
269 if ( n-- > len )
270 n = len;
271 wxCRT_StrncpyA(dest, src, n);
272 dest[n] = '\0';
273 }
274
275 return len;
276 }
277 inline size_t wxStrlcpy(wchar_t *dest, const wchar_t *src, size_t n)
278 {
279 const size_t len = wxCRT_StrlenW(src);
280 if ( n )
281 {
282 if ( n-- > len )
283 n = len;
284 wxCRT_StrncpyW(dest, src, n);
285 dest[n] = L'\0';
286 }
287
288 return len;
289 }
290
291 inline char *wxStrcat(char *dest, const char *src)
292 { return wxCRT_StrcatA(dest, src); }
293 inline wchar_t *wxStrcat(wchar_t *dest, const wchar_t *src)
294 { return wxCRT_StrcatW(dest, src); }
295 inline char *wxStrcat(char *dest, const wxString& src)
296 { return wxCRT_StrcatA(dest, src.mb_str()); }
297 inline char *wxStrcat(char *dest, const wxCStrData& src)
298 { return wxCRT_StrcatA(dest, src.AsCharBuf()); }
299 inline char *wxStrcat(char *dest, const wxScopedCharBuffer& src)
300 { return wxCRT_StrcatA(dest, src.data()); }
301 inline wchar_t *wxStrcat(wchar_t *dest, const wxString& src)
302 { return wxCRT_StrcatW(dest, src.wc_str()); }
303 inline wchar_t *wxStrcat(wchar_t *dest, const wxCStrData& src)
304 { return wxCRT_StrcatW(dest, src.AsWCharBuf()); }
305 inline wchar_t *wxStrcat(wchar_t *dest, const wxScopedWCharBuffer& src)
306 { return wxCRT_StrcatW(dest, src.data()); }
307 inline char *wxStrcat(char *dest, const wchar_t *src)
308 { return wxCRT_StrcatA(dest, wxConvLibc.cWC2MB(src)); }
309 inline wchar_t *wxStrcat(wchar_t *dest, const char *src)
310 { return wxCRT_StrcatW(dest, wxConvLibc.cMB2WC(src)); }
311
312 inline char *wxStrncat(char *dest, const char *src, size_t n)
313 { return wxCRT_StrncatA(dest, src, n); }
314 inline wchar_t *wxStrncat(wchar_t *dest, const wchar_t *src, size_t n)
315 { return wxCRT_StrncatW(dest, src, n); }
316 inline char *wxStrncat(char *dest, const wxString& src, size_t n)
317 { return wxCRT_StrncatA(dest, src.mb_str(), n); }
318 inline char *wxStrncat(char *dest, const wxCStrData& src, size_t n)
319 { return wxCRT_StrncatA(dest, src.AsCharBuf(), n); }
320 inline char *wxStrncat(char *dest, const wxScopedCharBuffer& src, size_t n)
321 { return wxCRT_StrncatA(dest, src.data(), n); }
322 inline wchar_t *wxStrncat(wchar_t *dest, const wxString& src, size_t n)
323 { return wxCRT_StrncatW(dest, src.wc_str(), n); }
324 inline wchar_t *wxStrncat(wchar_t *dest, const wxCStrData& src, size_t n)
325 { return wxCRT_StrncatW(dest, src.AsWCharBuf(), n); }
326 inline wchar_t *wxStrncat(wchar_t *dest, const wxScopedWCharBuffer& src, size_t n)
327 { return wxCRT_StrncatW(dest, src.data(), n); }
328 inline char *wxStrncat(char *dest, const wchar_t *src, size_t n)
329 { return wxCRT_StrncatA(dest, wxConvLibc.cWC2MB(src), n); }
330 inline wchar_t *wxStrncat(wchar_t *dest, const char *src, size_t n)
331 { return wxCRT_StrncatW(dest, wxConvLibc.cMB2WC(src), n); }
332
333
334 #define WX_STR_DECL(name, T1, T2) name(T1 s1, T2 s2)
335 #define WX_STR_CALL(func, a1, a2) func(a1, a2)
336
337 // This macro defines string function for all possible variants of arguments,
338 // except for those taking wxString or wxCStrData as second argument.
339 // Parameters:
340 // rettype - return type
341 // name - name of the (overloaded) function to define
342 // crtA - function to call for char* versions (takes two arguments)
343 // crtW - ditto for wchar_t* function
344 // forString - function to call when the *first* argument is wxString;
345 // the second argument can be any string type, so this is
346 // typically a template
347 #define WX_STR_FUNC_NO_INVERT(rettype, name, crtA, crtW, forString) \
348 inline rettype WX_STR_DECL(name, const char *, const char *) \
349 { return WX_STR_CALL(crtA, s1, s2); } \
350 inline rettype WX_STR_DECL(name, const char *, const wchar_t *) \
351 { return WX_STR_CALL(forString, wxString(s1), wxString(s2)); } \
352 inline rettype WX_STR_DECL(name, const char *, const wxScopedCharBuffer&) \
353 { return WX_STR_CALL(crtA, s1, s2.data()); } \
354 inline rettype WX_STR_DECL(name, const char *, const wxScopedWCharBuffer&) \
355 { return WX_STR_CALL(forString, wxString(s1), s2.data()); } \
356 \
357 inline rettype WX_STR_DECL(name, const wchar_t *, const wchar_t *) \
358 { return WX_STR_CALL(crtW, s1, s2); } \
359 inline rettype WX_STR_DECL(name, const wchar_t *, const char *) \
360 { return WX_STR_CALL(forString, wxString(s1), wxString(s2)); } \
361 inline rettype WX_STR_DECL(name, const wchar_t *, const wxScopedWCharBuffer&) \
362 { return WX_STR_CALL(crtW, s1, s2.data()); } \
363 inline rettype WX_STR_DECL(name, const wchar_t *, const wxScopedCharBuffer&) \
364 { return WX_STR_CALL(forString, wxString(s1), s2.data()); } \
365 \
366 inline rettype WX_STR_DECL(name, const wxScopedCharBuffer&, const char *) \
367 { return WX_STR_CALL(crtA, s1.data(), s2); } \
368 inline rettype WX_STR_DECL(name, const wxScopedCharBuffer&, const wchar_t *) \
369 { return WX_STR_CALL(forString, wxString(s1), wxString(s2)); } \
370 inline rettype WX_STR_DECL(name, const wxScopedCharBuffer&, const wxScopedCharBuffer&)\
371 { return WX_STR_CALL(crtA, s1.data(), s2.data()); } \
372 inline rettype WX_STR_DECL(name, const wxScopedCharBuffer&, const wxScopedWCharBuffer&) \
373 { return WX_STR_CALL(forString, wxString(s1), wxString(s2)); } \
374 \
375 inline rettype WX_STR_DECL(name, const wxScopedWCharBuffer&, const wchar_t *) \
376 { return WX_STR_CALL(crtW, s1.data(), s2); } \
377 inline rettype WX_STR_DECL(name, const wxScopedWCharBuffer&, const char *) \
378 { return WX_STR_CALL(forString, wxString(s1), wxString(s2)); } \
379 inline rettype WX_STR_DECL(name, const wxScopedWCharBuffer&, const wxScopedWCharBuffer&) \
380 { return WX_STR_CALL(crtW, s1.data(), s2.data()); } \
381 inline rettype WX_STR_DECL(name, const wxScopedWCharBuffer&, const wxScopedCharBuffer&) \
382 { return WX_STR_CALL(forString, wxString(s1), wxString(s2)); } \
383 \
384 inline rettype WX_STR_DECL(name, const wxString&, const char*) \
385 { return WX_STR_CALL(forString, s1, s2); } \
386 inline rettype WX_STR_DECL(name, const wxString&, const wchar_t*) \
387 { return WX_STR_CALL(forString, s1, s2); } \
388 inline rettype WX_STR_DECL(name, const wxString&, const wxScopedCharBuffer&) \
389 { return WX_STR_CALL(forString, s1, s2); } \
390 inline rettype WX_STR_DECL(name, const wxString&, const wxScopedWCharBuffer&) \
391 { return WX_STR_CALL(forString, s1, s2); } \
392 inline rettype WX_STR_DECL(name, const wxString&, const wxString&) \
393 { return WX_STR_CALL(forString, s1, s2); } \
394 inline rettype WX_STR_DECL(name, const wxString&, const wxCStrData&) \
395 { return WX_STR_CALL(forString, s1, s2); } \
396 \
397 inline rettype WX_STR_DECL(name, const wxCStrData&, const char*) \
398 { return WX_STR_CALL(forString, s1.AsString(), s2); } \
399 inline rettype WX_STR_DECL(name, const wxCStrData&, const wchar_t*) \
400 { return WX_STR_CALL(forString, s1.AsString(), s2); } \
401 inline rettype WX_STR_DECL(name, const wxCStrData&, const wxScopedCharBuffer&) \
402 { return WX_STR_CALL(forString, s1.AsString(), s2); } \
403 inline rettype WX_STR_DECL(name, const wxCStrData&, const wxScopedWCharBuffer&) \
404 { return WX_STR_CALL(forString, s1.AsString(), s2); } \
405 inline rettype WX_STR_DECL(name, const wxCStrData&, const wxString&) \
406 { return WX_STR_CALL(forString, s1.AsString(), s2); } \
407 inline rettype WX_STR_DECL(name, const wxCStrData&, const wxCStrData&) \
408 { return WX_STR_CALL(forString, s1.AsString(), s2); }
409
410 // This defines strcmp-like function, i.e. one returning the result of
411 // comparison; see WX_STR_FUNC_NO_INVERT for explanation of the arguments
412 #define WX_STRCMP_FUNC(name, crtA, crtW, forString) \
413 WX_STR_FUNC_NO_INVERT(int, name, crtA, crtW, forString) \
414 \
415 inline int WX_STR_DECL(name, const char *, const wxCStrData&) \
416 { return -WX_STR_CALL(forString, s2.AsString(), s1); } \
417 inline int WX_STR_DECL(name, const char *, const wxString&) \
418 { return -WX_STR_CALL(forString, s2, s1); } \
419 \
420 inline int WX_STR_DECL(name, const wchar_t *, const wxCStrData&) \
421 { return -WX_STR_CALL(forString, s2.AsString(), s1); } \
422 inline int WX_STR_DECL(name, const wchar_t *, const wxString&) \
423 { return -WX_STR_CALL(forString, s2, s1); } \
424 \
425 inline int WX_STR_DECL(name, const wxScopedCharBuffer&, const wxCStrData&) \
426 { return -WX_STR_CALL(forString, s2.AsString(), s1.data()); } \
427 inline int WX_STR_DECL(name, const wxScopedCharBuffer&, const wxString&) \
428 { return -WX_STR_CALL(forString, s2, s1.data()); } \
429 \
430 inline int WX_STR_DECL(name, const wxScopedWCharBuffer&, const wxCStrData&) \
431 { return -WX_STR_CALL(forString, s2.AsString(), s1.data()); } \
432 inline int WX_STR_DECL(name, const wxScopedWCharBuffer&, const wxString&) \
433 { return -WX_STR_CALL(forString, s2, s1.data()); }
434
435
436 // This defines a string function that is *not* strcmp-like, i.e. doesn't
437 // return the result of comparison and so if the second argument is a string,
438 // it has to be converted to char* or wchar_t*
439 #define WX_STR_FUNC(rettype, name, crtA, crtW, forString) \
440 WX_STR_FUNC_NO_INVERT(rettype, name, crtA, crtW, forString) \
441 \
442 inline rettype WX_STR_DECL(name, const char *, const wxCStrData&) \
443 { return WX_STR_CALL(crtA, s1, s2.AsCharBuf()); } \
444 inline rettype WX_STR_DECL(name, const char *, const wxString&) \
445 { return WX_STR_CALL(crtA, s1, s2.mb_str()); } \
446 \
447 inline rettype WX_STR_DECL(name, const wchar_t *, const wxCStrData&) \
448 { return WX_STR_CALL(crtW, s1, s2.AsWCharBuf()); } \
449 inline rettype WX_STR_DECL(name, const wchar_t *, const wxString&) \
450 { return WX_STR_CALL(crtW, s1, s2.wc_str()); } \
451 \
452 inline rettype WX_STR_DECL(name, const wxScopedCharBuffer&, const wxCStrData&) \
453 { return WX_STR_CALL(crtA, s1.data(), s2.AsCharBuf()); } \
454 inline rettype WX_STR_DECL(name, const wxScopedCharBuffer&, const wxString&) \
455 { return WX_STR_CALL(crtA, s1.data(), s2.mb_str()); } \
456 \
457 inline rettype WX_STR_DECL(name, const wxScopedWCharBuffer&, const wxCStrData&) \
458 { return WX_STR_CALL(crtW, s1.data(), s2.AsWCharBuf()); } \
459 inline rettype WX_STR_DECL(name, const wxScopedWCharBuffer&, const wxString&) \
460 { return WX_STR_CALL(crtW, s1.data(), s2.wc_str()); }
461
462 template<typename T>
463 inline int wxStrcmp_String(const wxString& s1, const T& s2)
464 { return s1.compare(s2); }
465 WX_STRCMP_FUNC(wxStrcmp, wxCRT_StrcmpA, wxCRT_StrcmpW, wxStrcmp_String)
466
467 template<typename T>
468 inline int wxStricmp_String(const wxString& s1, const T& s2)
469 { return s1.CmpNoCase(s2); }
470 WX_STRCMP_FUNC(wxStricmp, wxCRT_StricmpA, wxCRT_StricmpW, wxStricmp_String)
471
472 #if defined(wxCRT_StrcollA) && defined(wxCRT_StrcollW)
473
474 // GCC 3.3 and other compilers have a bug that causes it to fail compilation if
475 // the template's implementation uses overloaded function declared later (see
476 // the wxStrcoll() call in wxStrcoll_String<T>()), so we have to
477 // forward-declare the template and implement it below WX_STRCMP_FUNC. OTOH,
478 // this fails to compile with VC6, so don't do it for VC. It also causes
479 // problems with GCC visibility in newer GCC versions.
480 #if !(defined(__VISUALC__) || wxCHECK_GCC_VERSION(3,4))
481 template<typename T>
482 inline int wxStrcoll_String(const wxString& s1, const T& s2);
483 WX_STRCMP_FUNC(wxStrcoll, wxCRT_StrcollA, wxCRT_StrcollW, wxStrcoll_String)
484 #endif // !__VISUALC__
485
486 template<typename T>
487 inline int wxStrcoll_String(const wxString& s1, const T& s2)
488 {
489 #if wxUSE_UNICODE
490 // NB: strcoll() doesn't work correctly on UTF-8 strings, so we have to use
491 // wc_str() even if wxUSE_UNICODE_UTF8; the (const wchar_t*) cast is
492 // there just as optimization to avoid going through
493 // wxStrcoll<wxScopedWCharBuffer>:
494 return wxStrcoll((const wchar_t*)s1.wc_str(), s2);
495 #else
496 return wxStrcoll((const char*)s1.mb_str(), s2);
497 #endif
498 }
499
500 #if defined(__VISUALC__) || wxCHECK_GCC_VERSION(3,4)
501 // this is exactly the same WX_STRCMP_FUNC line as above wxStrcoll_String<>
502 WX_STRCMP_FUNC(wxStrcoll, wxCRT_StrcollA, wxCRT_StrcollW, wxStrcoll_String)
503 #endif
504
505 #endif // defined(wxCRT_Strcoll[AW])
506
507 template<typename T>
508 inline size_t wxStrspn_String(const wxString& s1, const T& s2)
509 {
510 size_t pos = s1.find_first_not_of(s2);
511 return pos == wxString::npos ? s1.length() : pos;
512 }
513 WX_STR_FUNC(size_t, wxStrspn, wxCRT_StrspnA, wxCRT_StrspnW, wxStrspn_String)
514
515 template<typename T>
516 inline size_t wxStrcspn_String(const wxString& s1, const T& s2)
517 {
518 size_t pos = s1.find_first_of(s2);
519 return pos == wxString::npos ? s1.length() : pos;
520 }
521 WX_STR_FUNC(size_t, wxStrcspn, wxCRT_StrcspnA, wxCRT_StrcspnW, wxStrcspn_String)
522
523 #undef WX_STR_DECL
524 #undef WX_STR_CALL
525 #define WX_STR_DECL(name, T1, T2) name(T1 s1, T2 s2, size_t n)
526 #define WX_STR_CALL(func, a1, a2) func(a1, a2, n)
527
528 template<typename T>
529 inline int wxStrncmp_String(const wxString& s1, const T& s2, size_t n)
530 { return s1.compare(0, n, s2, 0, n); }
531 WX_STRCMP_FUNC(wxStrncmp, wxCRT_StrncmpA, wxCRT_StrncmpW, wxStrncmp_String)
532
533 template<typename T>
534 inline int wxStrnicmp_String(const wxString& s1, const T& s2, size_t n)
535 { return s1.substr(0, n).CmpNoCase(wxString(s2).substr(0, n)); }
536 WX_STRCMP_FUNC(wxStrnicmp, wxCRT_StrnicmpA, wxCRT_StrnicmpW, wxStrnicmp_String)
537
538 #undef WX_STR_DECL
539 #undef WX_STR_CALL
540 #undef WX_STRCMP_FUNC
541 #undef WX_STR_FUNC
542 #undef WX_STR_FUNC_NO_INVERT
543
544 #if defined(wxCRT_StrxfrmA) && defined(wxCRT_StrxfrmW)
545
546 inline size_t wxStrxfrm(char *dest, const char *src, size_t n)
547 { return wxCRT_StrxfrmA(dest, src, n); }
548 inline size_t wxStrxfrm(wchar_t *dest, const wchar_t *src, size_t n)
549 { return wxCRT_StrxfrmW(dest, src, n); }
550 template<typename T>
551 inline size_t wxStrxfrm(T *dest, const wxScopedCharTypeBuffer<T>& src, size_t n)
552 { return wxStrxfrm(dest, src.data(), n); }
553 inline size_t wxStrxfrm(char *dest, const wxString& src, size_t n)
554 { return wxCRT_StrxfrmA(dest, src.mb_str(), n); }
555 inline size_t wxStrxfrm(wchar_t *dest, const wxString& src, size_t n)
556 { return wxCRT_StrxfrmW(dest, src.wc_str(), n); }
557 inline size_t wxStrxfrm(char *dest, const wxCStrData& src, size_t n)
558 { return wxCRT_StrxfrmA(dest, src.AsCharBuf(), n); }
559 inline size_t wxStrxfrm(wchar_t *dest, const wxCStrData& src, size_t n)
560 { return wxCRT_StrxfrmW(dest, src.AsWCharBuf(), n); }
561
562 #endif // defined(wxCRT_Strxfrm[AW])
563
564 inline char *wxStrtok(char *str, const char *delim, char **saveptr)
565 { return wxCRT_StrtokA(str, delim, saveptr); }
566 inline wchar_t *wxStrtok(wchar_t *str, const wchar_t *delim, wchar_t **saveptr)
567 { return wxCRT_StrtokW(str, delim, saveptr); }
568 template<typename T>
569 inline T *wxStrtok(T *str, const wxScopedCharTypeBuffer<T>& delim, T **saveptr)
570 { return wxStrtok(str, delim.data(), saveptr); }
571 inline char *wxStrtok(char *str, const wxCStrData& delim, char **saveptr)
572 { return wxCRT_StrtokA(str, delim.AsCharBuf(), saveptr); }
573 inline wchar_t *wxStrtok(wchar_t *str, const wxCStrData& delim, wchar_t **saveptr)
574 { return wxCRT_StrtokW(str, delim.AsWCharBuf(), saveptr); }
575 inline char *wxStrtok(char *str, const wxString& delim, char **saveptr)
576 { return wxCRT_StrtokA(str, delim.mb_str(), saveptr); }
577 inline wchar_t *wxStrtok(wchar_t *str, const wxString& delim, wchar_t **saveptr)
578 { return wxCRT_StrtokW(str, delim.wc_str(), saveptr); }
579
580 inline const char *wxStrstr(const char *haystack, const char *needle)
581 { return wxCRT_StrstrA(haystack, needle); }
582 inline const wchar_t *wxStrstr(const wchar_t *haystack, const wchar_t *needle)
583 { return wxCRT_StrstrW(haystack, needle); }
584 inline const char *wxStrstr(const char *haystack, const wxString& needle)
585 { return wxCRT_StrstrA(haystack, needle.mb_str()); }
586 inline const wchar_t *wxStrstr(const wchar_t *haystack, const wxString& needle)
587 { return wxCRT_StrstrW(haystack, needle.wc_str()); }
588 // these functions return char* pointer into the non-temporary conversion buffer
589 // used by c_str()'s implicit conversion to char*, for ANSI build compatibility
590 inline const char *wxStrstr(const wxString& haystack, const wxString& needle)
591 { return wxCRT_StrstrA(haystack.c_str(), needle.mb_str()); }
592 inline const char *wxStrstr(const wxCStrData& haystack, const wxString& needle)
593 { return wxCRT_StrstrA(haystack, needle.mb_str()); }
594 inline const char *wxStrstr(const wxCStrData& haystack, const wxCStrData& needle)
595 { return wxCRT_StrstrA(haystack, needle.AsCharBuf()); }
596 // if 'needle' is char/wchar_t, then the same is probably wanted as return value
597 inline const char *wxStrstr(const wxString& haystack, const char *needle)
598 { return wxCRT_StrstrA(haystack.c_str(), needle); }
599 inline const char *wxStrstr(const wxCStrData& haystack, const char *needle)
600 { return wxCRT_StrstrA(haystack, needle); }
601 inline const wchar_t *wxStrstr(const wxString& haystack, const wchar_t *needle)
602 { return wxCRT_StrstrW(haystack.c_str(), needle); }
603 inline const wchar_t *wxStrstr(const wxCStrData& haystack, const wchar_t *needle)
604 { return wxCRT_StrstrW(haystack, needle); }
605
606 inline const char *wxStrchr(const char *s, char c)
607 { return wxCRT_StrchrA(s, c); }
608 inline const wchar_t *wxStrchr(const wchar_t *s, wchar_t c)
609 { return wxCRT_StrchrW(s, c); }
610 inline const char *wxStrrchr(const char *s, char c)
611 { return wxCRT_StrrchrA(s, c); }
612 inline const wchar_t *wxStrrchr(const wchar_t *s, wchar_t c)
613 { return wxCRT_StrrchrW(s, c); }
614 inline const char *wxStrchr(const char *s, const wxUniChar& c)
615 { return wxCRT_StrchrA(s, (char)c); }
616 inline const wchar_t *wxStrchr(const wchar_t *s, const wxUniChar& c)
617 { return wxCRT_StrchrW(s, (wchar_t)c); }
618 inline const char *wxStrrchr(const char *s, const wxUniChar& c)
619 { return wxCRT_StrrchrA(s, (char)c); }
620 inline const wchar_t *wxStrrchr(const wchar_t *s, const wxUniChar& c)
621 { return wxCRT_StrrchrW(s, (wchar_t)c); }
622 inline const char *wxStrchr(const char *s, const wxUniCharRef& c)
623 { return wxCRT_StrchrA(s, (char)c); }
624 inline const wchar_t *wxStrchr(const wchar_t *s, const wxUniCharRef& c)
625 { return wxCRT_StrchrW(s, (wchar_t)c); }
626 inline const char *wxStrrchr(const char *s, const wxUniCharRef& c)
627 { return wxCRT_StrrchrA(s, (char)c); }
628 inline const wchar_t *wxStrrchr(const wchar_t *s, const wxUniCharRef& c)
629 { return wxCRT_StrrchrW(s, (wchar_t)c); }
630 template<typename T>
631 inline const T* wxStrchr(const wxScopedCharTypeBuffer<T>& s, T c)
632 { return wxStrchr(s.data(), c); }
633 template<typename T>
634 inline const T* wxStrrchr(const wxScopedCharTypeBuffer<T>& s, T c)
635 { return wxStrrchr(s.data(), c); }
636 template<typename T>
637 inline const T* wxStrchr(const wxScopedCharTypeBuffer<T>& s, const wxUniChar& c)
638 { return wxStrchr(s.data(), (T)c); }
639 template<typename T>
640 inline const T* wxStrrchr(const wxScopedCharTypeBuffer<T>& s, const wxUniChar& c)
641 { return wxStrrchr(s.data(), (T)c); }
642 template<typename T>
643 inline const T* wxStrchr(const wxScopedCharTypeBuffer<T>& s, const wxUniCharRef& c)
644 { return wxStrchr(s.data(), (T)c); }
645 template<typename T>
646 inline const T* wxStrrchr(const wxScopedCharTypeBuffer<T>& s, const wxUniCharRef& c)
647 { return wxStrrchr(s.data(), (T)c); }
648 // these functions return char* pointer into the non-temporary conversion buffer
649 // used by c_str()'s implicit conversion to char*, for ANSI build compatibility
650 inline const char* wxStrchr(const wxString& s, char c)
651 { return wxCRT_StrchrA((const char*)s.c_str(), c); }
652 inline const char* wxStrrchr(const wxString& s, char c)
653 { return wxCRT_StrrchrA((const char*)s.c_str(), c); }
654 inline const char* wxStrchr(const wxString& s, int c)
655 { return wxCRT_StrchrA((const char*)s.c_str(), c); }
656 inline const char* wxStrrchr(const wxString& s, int c)
657 { return wxCRT_StrrchrA((const char*)s.c_str(), c); }
658 inline const char* wxStrchr(const wxString& s, const wxUniChar& c)
659 { return wxCRT_StrchrA((const char*)s.c_str(), (char)c); }
660 inline const char* wxStrrchr(const wxString& s, const wxUniChar& c)
661 { return wxCRT_StrrchrA((const char*)s.c_str(), (char)c); }
662 inline const char* wxStrchr(const wxString& s, const wxUniCharRef& c)
663 { return wxCRT_StrchrA((const char*)s.c_str(), (char)c); }
664 inline const char* wxStrrchr(const wxString& s, const wxUniCharRef& c)
665 { return wxCRT_StrrchrA((const char*)s.c_str(), (char)c); }
666 inline const wchar_t* wxStrchr(const wxString& s, wchar_t c)
667 { return wxCRT_StrchrW((const wchar_t*)s.c_str(), c); }
668 inline const wchar_t* wxStrrchr(const wxString& s, wchar_t c)
669 { return wxCRT_StrrchrW((const wchar_t*)s.c_str(), c); }
670 inline const char* wxStrchr(const wxCStrData& s, char c)
671 { return wxCRT_StrchrA(s.AsChar(), c); }
672 inline const char* wxStrrchr(const wxCStrData& s, char c)
673 { return wxCRT_StrrchrA(s.AsChar(), c); }
674 inline const char* wxStrchr(const wxCStrData& s, int c)
675 { return wxCRT_StrchrA(s.AsChar(), c); }
676 inline const char* wxStrrchr(const wxCStrData& s, int c)
677 { return wxCRT_StrrchrA(s.AsChar(), c); }
678 inline const char* wxStrchr(const wxCStrData& s, const wxUniChar& c)
679 { return wxCRT_StrchrA(s.AsChar(), (char)c); }
680 inline const char* wxStrrchr(const wxCStrData& s, const wxUniChar& c)
681 { return wxCRT_StrrchrA(s.AsChar(), (char)c); }
682 inline const char* wxStrchr(const wxCStrData& s, const wxUniCharRef& c)
683 { return wxCRT_StrchrA(s.AsChar(), (char)c); }
684 inline const char* wxStrrchr(const wxCStrData& s, const wxUniCharRef& c)
685 { return wxCRT_StrrchrA(s.AsChar(), (char)c); }
686 inline const wchar_t* wxStrchr(const wxCStrData& s, wchar_t c)
687 { return wxCRT_StrchrW(s.AsWChar(), c); }
688 inline const wchar_t* wxStrrchr(const wxCStrData& s, wchar_t c)
689 { return wxCRT_StrrchrW(s.AsWChar(), c); }
690
691 inline const char *wxStrpbrk(const char *s, const char *accept)
692 { return wxCRT_StrpbrkA(s, accept); }
693 inline const wchar_t *wxStrpbrk(const wchar_t *s, const wchar_t *accept)
694 { return wxCRT_StrpbrkW(s, accept); }
695 inline const char *wxStrpbrk(const char *s, const wxString& accept)
696 { return wxCRT_StrpbrkA(s, accept.mb_str()); }
697 inline const char *wxStrpbrk(const char *s, const wxCStrData& accept)
698 { return wxCRT_StrpbrkA(s, accept.AsCharBuf()); }
699 inline const wchar_t *wxStrpbrk(const wchar_t *s, const wxString& accept)
700 { return wxCRT_StrpbrkW(s, accept.wc_str()); }
701 inline const wchar_t *wxStrpbrk(const wchar_t *s, const wxCStrData& accept)
702 { return wxCRT_StrpbrkW(s, accept.AsWCharBuf()); }
703 inline const char *wxStrpbrk(const wxString& s, const wxString& accept)
704 { return wxCRT_StrpbrkA(s.c_str(), accept.mb_str()); }
705 inline const char *wxStrpbrk(const wxString& s, const char *accept)
706 { return wxCRT_StrpbrkA(s.c_str(), accept); }
707 inline const wchar_t *wxStrpbrk(const wxString& s, const wchar_t *accept)
708 { return wxCRT_StrpbrkW(s.wc_str(), accept); }
709 inline const char *wxStrpbrk(const wxString& s, const wxCStrData& accept)
710 { return wxCRT_StrpbrkA(s.c_str(), accept.AsCharBuf()); }
711 inline const char *wxStrpbrk(const wxCStrData& s, const wxString& accept)
712 { return wxCRT_StrpbrkA(s.AsChar(), accept.mb_str()); }
713 inline const char *wxStrpbrk(const wxCStrData& s, const char *accept)
714 { return wxCRT_StrpbrkA(s.AsChar(), accept); }
715 inline const wchar_t *wxStrpbrk(const wxCStrData& s, const wchar_t *accept)
716 { return wxCRT_StrpbrkW(s.AsWChar(), accept); }
717 inline const char *wxStrpbrk(const wxCStrData& s, const wxCStrData& accept)
718 { return wxCRT_StrpbrkA(s.AsChar(), accept.AsCharBuf()); }
719 template <typename S, typename T>
720 inline const T *wxStrpbrk(const S& s, const wxScopedCharTypeBuffer<T>& accept)
721 { return wxStrpbrk(s, accept.data()); }
722
723
724 /* inlined non-const versions */
725 template <typename T>
726 inline char *wxStrstr(char *haystack, T needle)
727 { return (char *)wxStrstr((const char *)haystack, needle); }
728 template <typename T>
729 inline wchar_t *wxStrstr(wchar_t *haystack, T needle)
730 { return (wchar_t *)wxStrstr((const wchar_t *)haystack, needle); }
731
732 template <typename T>
733 inline char * wxStrchr(char *s, T c)
734 { return (char *)wxStrchr((const char *)s, c); }
735 template <typename T>
736 inline wchar_t * wxStrchr(wchar_t *s, T c)
737 { return (wchar_t *)wxStrchr((const wchar_t *)s, c); }
738 template <typename T>
739 inline char * wxStrrchr(char *s, T c)
740 { return (char *)wxStrrchr((const char *)s, c); }
741 template <typename T>
742 inline wchar_t * wxStrrchr(wchar_t *s, T c)
743 { return (wchar_t *)wxStrrchr((const wchar_t *)s, c); }
744
745 template <typename T>
746 inline char * wxStrpbrk(char *s, T accept)
747 { return (char *)wxStrpbrk((const char *)s, accept); }
748 template <typename T>
749 inline wchar_t * wxStrpbrk(wchar_t *s, T accept)
750 { return (wchar_t *)wxStrpbrk((const wchar_t *)s, accept); }
751
752
753 // ----------------------------------------------------------------------------
754 // stdio.h functions
755 // ----------------------------------------------------------------------------
756
757 // NB: using fn_str() for mode is a hack to get the same type (char*/wchar_t*)
758 // as needed, the conversion itself doesn't matter, it's ASCII
759 inline FILE *wxFopen(const wxString& path, const wxString& mode)
760 { return wxCRT_Fopen(path.fn_str(), mode.fn_str()); }
761 inline FILE *wxFreopen(const wxString& path, const wxString& mode, FILE *stream)
762 { return wxCRT_Freopen(path.fn_str(), mode.fn_str(), stream); }
763 inline int wxRemove(const wxString& path)
764 { return wxCRT_Remove(path.fn_str()); }
765 inline int wxRename(const wxString& oldpath, const wxString& newpath)
766 { return wxCRT_Rename(oldpath.fn_str(), newpath.fn_str()); }
767
768 extern WXDLLIMPEXP_BASE int wxPuts(const wxString& s);
769 extern WXDLLIMPEXP_BASE int wxFputs(const wxString& s, FILE *stream);
770 extern WXDLLIMPEXP_BASE void wxPerror(const wxString& s);
771
772 extern WXDLLIMPEXP_BASE int wxFputc(const wxUniChar& c, FILE *stream);
773
774 #define wxPutc(c, stream) wxFputc(c, stream)
775 #define wxPutchar(c) wxFputc(c, stdout)
776 #define wxFputchar(c) wxPutchar(c)
777
778 // NB: We only provide ANSI version of fgets() because fgetws() interprets the
779 // stream according to current locale, which is rarely what is desired.
780 inline char *wxFgets(char *s, int size, FILE *stream)
781 { return wxCRT_FgetsA(s, size, stream); }
782 // This version calls ANSI version and converts the string using wxConvLibc
783 extern WXDLLIMPEXP_BASE wchar_t *wxFgets(wchar_t *s, int size, FILE *stream);
784
785 #define wxGets(s) wxGets_is_insecure_and_dangerous_use_wxFgets_instead
786
787 // NB: We only provide ANSI versions of this for the same reasons as in the
788 // case of wxFgets() above
789 inline int wxFgetc(FILE *stream) { return wxCRT_FgetcA(stream); }
790 inline int wxUngetc(int c, FILE *stream) { return wxCRT_UngetcA(c, stream); }
791
792 #define wxGetc(stream) wxFgetc(stream)
793 #define wxGetchar() wxFgetc(stdin)
794 #define wxFgetchar() wxGetchar()
795
796 // ----------------------------------------------------------------------------
797 // stdlib.h functions
798 // ----------------------------------------------------------------------------
799
800 #ifdef wxCRT_AtoiW
801 inline int wxAtoi(const wxString& str) { return wxCRT_AtoiW(str.wc_str()); }
802 #else
803 inline int wxAtoi(const wxString& str) { return wxCRT_AtoiA(str.mb_str()); }
804 #endif
805
806 #ifdef wxCRT_AtolW
807 inline long wxAtol(const wxString& str) { return wxCRT_AtolW(str.wc_str()); }
808 #else
809 inline long wxAtol(const wxString& str) { return wxCRT_AtolA(str.mb_str()); }
810 #endif
811
812 #ifdef wxCRT_AtofW
813 inline double wxAtof(const wxString& str) { return wxCRT_AtofW(str.wc_str()); }
814 #else
815 inline double wxAtof(const wxString& str) { return wxCRT_AtofA(str.mb_str()); }
816 #endif
817
818 inline double wxStrtod(const char *nptr, char **endptr)
819 { return wxCRT_StrtodA(nptr, endptr); }
820 inline double wxStrtod(const wchar_t *nptr, wchar_t **endptr)
821 { return wxCRT_StrtodW(nptr, endptr); }
822 template<typename T>
823 inline double wxStrtod(const wxScopedCharTypeBuffer<T>& nptr, T **endptr)
824 { return wxStrtod(nptr.data(), endptr); }
825
826 // We implement wxStrto*() like this so that the code compiles when NULL is
827 // passed in - - if we had just char** and wchar_t** overloads for 'endptr', it
828 // would be ambiguous. The solution is to use a template so that endptr can be
829 // any type: when NULL constant is used, the type will be int and we can handle
830 // that case specially. Otherwise, we infer the type that 'nptr' should be
831 // converted to from the type of 'endptr'. We need wxStrtoxCharType<T> template
832 // to make the code compile even for T=int (that's the case when it's not going
833 // to be ever used, but it still has to compile).
834 template<typename T> struct wxStrtoxCharType {};
835 template<> struct wxStrtoxCharType<char**>
836 {
837 typedef const char* Type;
838 static char** AsPointer(char **p) { return p; }
839 };
840 template<> struct wxStrtoxCharType<wchar_t**>
841 {
842 typedef const wchar_t* Type;
843 static wchar_t** AsPointer(wchar_t **p) { return p; }
844 };
845 template<> struct wxStrtoxCharType<int>
846 {
847 typedef const char* Type; /* this one is never used */
848 static char** AsPointer(int WXUNUSED_UNLESS_DEBUG(p))
849 {
850 wxASSERT_MSG( p == 0, "passing non-NULL int is invalid" );
851 return NULL;
852 }
853 };
854
855 template<typename T>
856 inline double wxStrtod(const wxString& nptr, T endptr)
857 {
858 if ( endptr == 0 )
859 {
860 // when we don't care about endptr, use the string representation that
861 // doesn't require any conversion (it doesn't matter for this function
862 // even if its UTF-8):
863 return wxStrtod(nptr.wx_str(), (wxStringCharType**)NULL);
864 }
865 else
866 {
867 // note that it is important to use c_str() here and not mb_str() or
868 // wc_str(), because we store the pointer into (possibly converted)
869 // buffer in endptr and so it must be valid even when wxStrtod() returns
870 typedef typename wxStrtoxCharType<T>::Type CharType;
871 return wxStrtod((CharType)nptr.c_str(),
872 wxStrtoxCharType<T>::AsPointer(endptr));
873 }
874 }
875 template<typename T>
876 inline double wxStrtod(const wxCStrData& nptr, T endptr)
877 { return wxStrtod(nptr.AsString(), endptr); }
878
879
880 #define WX_STRTOX_FUNC(rettype, name, implA, implW) \
881 /* see wxStrtod() above for explanation of this code: */ \
882 inline rettype name(const char *nptr, char **endptr, int base) \
883 { return implA(nptr, endptr, base); } \
884 inline rettype name(const wchar_t *nptr, wchar_t **endptr, int base) \
885 { return implW(nptr, endptr, base); } \
886 template<typename T> \
887 inline rettype name(const wxScopedCharTypeBuffer<T>& nptr, T **endptr, int base)\
888 { return name(nptr.data(), endptr); } \
889 template<typename T> \
890 inline rettype name(const wxString& nptr, T endptr, int base) \
891 { \
892 if ( endptr == 0 ) \
893 return name(nptr.wx_str(), (wxStringCharType**)NULL, base); \
894 else \
895 { \
896 typedef typename wxStrtoxCharType<T>::Type CharType; \
897 return name((CharType)nptr.c_str(), \
898 wxStrtoxCharType<T>::AsPointer(endptr), \
899 base); \
900 } \
901 } \
902 template<typename T> \
903 inline rettype name(const wxCStrData& nptr, T endptr, int base) \
904 { return name(nptr.AsString(), endptr, base); }
905
906 WX_STRTOX_FUNC(long, wxStrtol, wxCRT_StrtolA, wxCRT_StrtolW)
907 WX_STRTOX_FUNC(unsigned long, wxStrtoul, wxCRT_StrtoulA, wxCRT_StrtoulW)
908 #ifdef wxLongLong_t
909 WX_STRTOX_FUNC(wxLongLong_t, wxStrtoll, wxCRT_StrtollA, wxCRT_StrtollW)
910 WX_STRTOX_FUNC(wxULongLong_t, wxStrtoull, wxCRT_StrtoullA, wxCRT_StrtoullW)
911 #endif // wxLongLong_t
912
913 #undef WX_STRTOX_FUNC
914
915
916 // there is no command interpreter under CE, hence no system()
917 #ifndef __WXWINCE__
918
919 // mingw32 doesn't provide _tsystem() even though it provides other stdlib.h
920 // functions in their wide versions
921 #ifdef wxCRT_SystemW
922 inline int wxSystem(const wxString& str) { return wxCRT_SystemW(str.wc_str()); }
923 #else
924 inline int wxSystem(const wxString& str) { return wxCRT_SystemA(str.mb_str()); }
925 #endif
926
927 #endif // !__WXWINCE__/__WXWINCE__
928
929 inline char* wxGetenv(const char *name) { return wxCRT_GetenvA(name); }
930 inline wchar_t* wxGetenv(const wchar_t *name) { return wxCRT_GetenvW(name); }
931 inline char* wxGetenv(const wxString& name) { return wxCRT_GetenvA(name.mb_str()); }
932 inline char* wxGetenv(const wxCStrData& name) { return wxCRT_GetenvA(name.AsCharBuf()); }
933 inline char* wxGetenv(const wxScopedCharBuffer& name) { return wxCRT_GetenvA(name.data()); }
934 inline wchar_t* wxGetenv(const wxScopedWCharBuffer& name) { return wxCRT_GetenvW(name.data()); }
935
936 // ----------------------------------------------------------------------------
937 // time.h functions
938 // ----------------------------------------------------------------------------
939
940 inline size_t wxStrftime(char *s, size_t max,
941 const wxString& format, const struct tm *tm)
942 { return wxCRT_StrftimeA(s, max, format.mb_str(), tm); }
943
944 inline size_t wxStrftime(wchar_t *s, size_t max,
945 const wxString& format, const struct tm *tm)
946 { return wxCRT_StrftimeW(s, max, format.wc_str(), tm); }
947
948 // NB: we can't provide both char* and wchar_t* versions for obvious reasons
949 // and returning wxString wouldn't work either (it would be immediately
950 // destroyed and if assigned to char*/wchar_t*, the pointer would be
951 // invalid), so we only keep ASCII version, because the returned value
952 // is always ASCII anyway
953 #define wxAsctime asctime
954 #define wxCtime ctime
955
956
957 // ----------------------------------------------------------------------------
958 // ctype.h functions
959 // ----------------------------------------------------------------------------
960
961 // FIXME-UTF8: we'd be better off implementing these ourselves, as the CRT
962 // version is locale-dependent
963 // FIXME-UTF8: these don't work when EOF is passed in because of wxUniChar,
964 // is this OK or not?
965
966 inline bool wxIsalnum(const wxUniChar& c) { return wxCRT_IsalnumW(c) != 0; }
967 inline bool wxIsalpha(const wxUniChar& c) { return wxCRT_IsalphaW(c) != 0; }
968 inline bool wxIscntrl(const wxUniChar& c) { return wxCRT_IscntrlW(c) != 0; }
969 inline bool wxIsdigit(const wxUniChar& c) { return wxCRT_IsdigitW(c) != 0; }
970 inline bool wxIsgraph(const wxUniChar& c) { return wxCRT_IsgraphW(c) != 0; }
971 inline bool wxIslower(const wxUniChar& c) { return wxCRT_IslowerW(c) != 0; }
972 inline bool wxIsprint(const wxUniChar& c) { return wxCRT_IsprintW(c) != 0; }
973 inline bool wxIspunct(const wxUniChar& c) { return wxCRT_IspunctW(c) != 0; }
974 inline bool wxIsspace(const wxUniChar& c) { return wxCRT_IsspaceW(c) != 0; }
975 inline bool wxIsupper(const wxUniChar& c) { return wxCRT_IsupperW(c) != 0; }
976 inline bool wxIsxdigit(const wxUniChar& c) { return wxCRT_IsxdigitW(c) != 0; }
977
978 inline wxUniChar wxTolower(const wxUniChar& c) { return wxCRT_TolowerW(c); }
979 inline wxUniChar wxToupper(const wxUniChar& c) { return wxCRT_ToupperW(c); }
980
981 #if WXWIN_COMPATIBILITY_2_8
982 // we had goofed and defined wxIsctrl() instead of (correct) wxIscntrl() in the
983 // initial versions of this header -- now it is too late to remove it so
984 // although we fixed the function/macro name above, still provide the
985 // backwards-compatible synonym.
986 wxDEPRECATED( inline int wxIsctrl(const wxUniChar& c) );
987 inline int wxIsctrl(const wxUniChar& c) { return wxIscntrl(c); }
988 #endif // WXWIN_COMPATIBILITY_2_8
989
990 #endif /* _WX_WXCRT_H_ */