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