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