]> git.saurik.com Git - wxWidgets.git/blame - include/wx/wxcrt.h
remove unneccessary header dependencies on wx/thread.h
[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
57e2b887 5// Author: Joel Farley, Ove K�ven
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
91a151d3
CE
22#if defined (__VISUALC__) || defined (__DMC__)
23 #define HAVE_NO_VSSCANF 1
24#endif
25
52de37c7
VS
26// ============================================================================
27// misc functions
28// ============================================================================
e3f6cbd9 29
e3f6cbd9 30/* checks whether the passed in pointer is NULL and if the string is empty */
52de37c7
VS
31inline bool wxIsEmpty(const char *s) { return !s || !*s; }
32inline bool wxIsEmpty(const wchar_t *s) { return !s || !*s; }
33inline bool wxIsEmpty(const wxCharBuffer& s) { return wxIsEmpty(s.data()); }
34inline bool wxIsEmpty(const wxWCharBuffer& s) { return wxIsEmpty(s.data()); }
35inline bool wxIsEmpty(const wxString& s) { return s.empty(); }
36inline bool wxIsEmpty(const wxCStrData& s) { return s.AsString().empty(); }
e3f6cbd9 37
e3f6cbd9 38
52de37c7 39// FIXME-UTF8: get rid of this, it's ANSI only anyway
e3f6cbd9 40WXDLLIMPEXP_BASE bool wxOKlibc(); /* for internal use */
17482893 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
234inline char *wxStrcat(char *dest, const char *src)
235 { return wxCRT_StrcatA(dest, src); }
236inline wchar_t *wxStrcat(wchar_t *dest, const wchar_t *src)
237 { return wxCRT_StrcatW(dest, src); }
238inline char *wxStrcat(char *dest, const wxString& src)
239 { return wxCRT_StrcatA(dest, src.mb_str()); }
240inline char *wxStrcat(char *dest, const wxCStrData& src)
241 { return wxCRT_StrcatA(dest, src.AsCharBuf()); }
242inline char *wxStrcat(char *dest, const wxCharBuffer& src)
243 { return wxCRT_StrcatA(dest, src.data()); }
244inline wchar_t *wxStrcat(wchar_t *dest, const wxString& src)
245 { return wxCRT_StrcatW(dest, src.wc_str()); }
246inline wchar_t *wxStrcat(wchar_t *dest, const wxCStrData& src)
247 { return wxCRT_StrcatW(dest, src.AsWCharBuf()); }
248inline wchar_t *wxStrcat(wchar_t *dest, const wxWCharBuffer& src)
249 { return wxCRT_StrcatW(dest, src.data()); }
250inline char *wxStrcat(char *dest, const wchar_t *src)
251 { return wxCRT_StrcatA(dest, wxConvLibc.cWC2MB(src)); }
252inline wchar_t *wxStrcat(wchar_t *dest, const char *src)
253 { return wxCRT_StrcatW(dest, wxConvLibc.cMB2WC(src)); }
254
255inline char *wxStrncat(char *dest, const char *src, size_t n)
256 { return wxCRT_StrncatA(dest, src, n); }
257inline wchar_t *wxStrncat(wchar_t *dest, const wchar_t *src, size_t n)
258 { return wxCRT_StrncatW(dest, src, n); }
259inline char *wxStrncat(char *dest, const wxString& src, size_t n)
260 { return wxCRT_StrncatA(dest, src.mb_str(), n); }
261inline char *wxStrncat(char *dest, const wxCStrData& src, size_t n)
262 { return wxCRT_StrncatA(dest, src.AsCharBuf(), n); }
263inline char *wxStrncat(char *dest, const wxCharBuffer& src, size_t n)
264 { return wxCRT_StrncatA(dest, src.data(), n); }
265inline wchar_t *wxStrncat(wchar_t *dest, const wxString& src, size_t n)
266 { return wxCRT_StrncatW(dest, src.wc_str(), n); }
267inline wchar_t *wxStrncat(wchar_t *dest, const wxCStrData& src, size_t n)
268 { return wxCRT_StrncatW(dest, src.AsWCharBuf(), n); }
269inline wchar_t *wxStrncat(wchar_t *dest, const wxWCharBuffer& src, size_t n)
270 { return wxCRT_StrncatW(dest, src.data(), n); }
271inline char *wxStrncat(char *dest, const wchar_t *src, size_t n)
272 { return wxCRT_StrncatA(dest, wxConvLibc.cWC2MB(src), n); }
273inline wchar_t *wxStrncat(wchar_t *dest, const char *src, size_t n)
274 { return wxCRT_StrncatW(dest, wxConvLibc.cMB2WC(src), n); }
275
276
277#define WX_STR_DECL(name, T1, T2) name(T1 s1, T2 s2)
278#define WX_STR_CALL(func, a1, a2) func(a1, a2)
279
280// This macro defines string function for all possible variants of arguments,
281// except for those taking wxString or wxCStrData as second argument.
282// Parameters:
283// rettype - return type
284// name - name of the (overloaded) function to define
285// crtA - function to call for char* versions (takes two arguments)
286// crtW - ditto for wchar_t* function
287// forString - function to call when the *first* argument is wxString;
288// the second argument can be any string type, so this is
289// typically a template
290#define WX_STR_FUNC_NO_INVERT(rettype, name, crtA, crtW, forString) \
291 inline rettype WX_STR_DECL(name, const char *, const char *) \
292 { return WX_STR_CALL(crtA, s1, s2); } \
293 inline rettype WX_STR_DECL(name, const char *, const wchar_t *) \
294 { return WX_STR_CALL(forString, wxString(s1), wxString(s2)); } \
295 inline rettype WX_STR_DECL(name, const char *, const wxCharBuffer&) \
296 { return WX_STR_CALL(crtA, s1, s2.data()); } \
297 inline rettype WX_STR_DECL(name, const char *, const wxWCharBuffer&) \
298 { return WX_STR_CALL(forString, wxString(s1), s2.data()); } \
299 \
300 inline rettype WX_STR_DECL(name, const wchar_t *, const wchar_t *) \
301 { return WX_STR_CALL(crtW, s1, s2); } \
302 inline rettype WX_STR_DECL(name, const wchar_t *, const char *) \
303 { return WX_STR_CALL(forString, wxString(s1), wxString(s2)); } \
304 inline rettype WX_STR_DECL(name, const wchar_t *, const wxWCharBuffer&) \
305 { return WX_STR_CALL(crtW, s1, s2.data()); } \
306 inline rettype WX_STR_DECL(name, const wchar_t *, const wxCharBuffer&) \
307 { return WX_STR_CALL(forString, wxString(s1), s2.data()); } \
308 \
309 inline rettype WX_STR_DECL(name, const wxCharBuffer&, const char *) \
310 { return WX_STR_CALL(crtA, s1.data(), s2); } \
311 inline rettype WX_STR_DECL(name, const wxCharBuffer&, const wchar_t *) \
312 { return WX_STR_CALL(forString, wxString(s1), wxString(s2)); } \
313 inline rettype WX_STR_DECL(name, const wxCharBuffer&, const wxCharBuffer&)\
314 { return WX_STR_CALL(crtA, s1.data(), s2.data()); } \
49ec3b67 315 inline rettype WX_STR_DECL(name, const wxCharBuffer&, const wxWCharBuffer&) \
52de37c7
VS
316 { return WX_STR_CALL(forString, wxString(s1), wxString(s2)); } \
317 \
318 inline rettype WX_STR_DECL(name, const wxWCharBuffer&, const wchar_t *) \
319 { return WX_STR_CALL(crtW, s1.data(), s2); } \
320 inline rettype WX_STR_DECL(name, const wxWCharBuffer&, const char *) \
321 { return WX_STR_CALL(forString, wxString(s1), wxString(s2)); } \
49ec3b67 322 inline rettype WX_STR_DECL(name, const wxWCharBuffer&, const wxWCharBuffer&) \
52de37c7 323 { return WX_STR_CALL(crtW, s1.data(), s2.data()); } \
49ec3b67 324 inline rettype WX_STR_DECL(name, const wxWCharBuffer&, const wxCharBuffer&) \
52de37c7
VS
325 { return WX_STR_CALL(forString, wxString(s1), wxString(s2)); } \
326 \
327 inline rettype WX_STR_DECL(name, const wxString&, const char*) \
328 { return WX_STR_CALL(forString, s1, s2); } \
329 inline rettype WX_STR_DECL(name, const wxString&, const wchar_t*) \
330 { return WX_STR_CALL(forString, s1, s2); } \
331 inline rettype WX_STR_DECL(name, const wxString&, const wxCharBuffer&) \
332 { return WX_STR_CALL(forString, s1, s2); } \
333 inline rettype WX_STR_DECL(name, const wxString&, const wxWCharBuffer&) \
334 { return WX_STR_CALL(forString, s1, s2); } \
335 inline rettype WX_STR_DECL(name, const wxString&, const wxString&) \
336 { return WX_STR_CALL(forString, s1, s2); } \
337 inline rettype WX_STR_DECL(name, const wxString&, const wxCStrData&) \
338 { return WX_STR_CALL(forString, s1, s2); } \
339 \
340 inline rettype WX_STR_DECL(name, const wxCStrData&, const char*) \
341 { return WX_STR_CALL(forString, s1.AsString(), s2); } \
342 inline rettype WX_STR_DECL(name, const wxCStrData&, const wchar_t*) \
343 { return WX_STR_CALL(forString, s1.AsString(), s2); } \
344 inline rettype WX_STR_DECL(name, const wxCStrData&, const wxCharBuffer&) \
345 { return WX_STR_CALL(forString, s1.AsString(), s2); } \
346 inline rettype WX_STR_DECL(name, const wxCStrData&, const wxWCharBuffer&) \
347 { return WX_STR_CALL(forString, s1.AsString(), s2); } \
348 inline rettype WX_STR_DECL(name, const wxCStrData&, const wxString&) \
349 { return WX_STR_CALL(forString, s1.AsString(), s2); } \
350 inline rettype WX_STR_DECL(name, const wxCStrData&, const wxCStrData&) \
351 { return WX_STR_CALL(forString, s1.AsString(), s2); }
352
353// This defines strcmp-like function, i.e. one returning the result of
354// comparison; see WX_STR_FUNC_NO_INVERT for explanation of the arguments
355#define WX_STRCMP_FUNC(name, crtA, crtW, forString) \
356 WX_STR_FUNC_NO_INVERT(int, name, crtA, crtW, forString) \
357 \
358 inline int WX_STR_DECL(name, const char *, const wxCStrData&) \
359 { return -WX_STR_CALL(forString, s2.AsString(), s1); } \
360 inline int WX_STR_DECL(name, const char *, const wxString&) \
361 { return -WX_STR_CALL(forString, s2, s1); } \
362 \
363 inline int WX_STR_DECL(name, const wchar_t *, const wxCStrData&) \
364 { return -WX_STR_CALL(forString, s2.AsString(), s1); } \
365 inline int WX_STR_DECL(name, const wchar_t *, const wxString&) \
366 { return -WX_STR_CALL(forString, s2, s1); } \
367 \
368 inline int WX_STR_DECL(name, const wxCharBuffer&, const wxCStrData&) \
369 { return -WX_STR_CALL(forString, s2.AsString(), s1.data()); } \
370 inline int WX_STR_DECL(name, const wxCharBuffer&, const wxString&) \
371 { return -WX_STR_CALL(forString, s2, s1.data()); } \
372 \
373 inline int WX_STR_DECL(name, const wxWCharBuffer&, const wxCStrData&) \
374 { return -WX_STR_CALL(forString, s2.AsString(), s1.data()); } \
375 inline int WX_STR_DECL(name, const wxWCharBuffer&, const wxString&) \
376 { return -WX_STR_CALL(forString, s2, s1.data()); }
377
378
379// This defines a string function that is *not* strcmp-like, i.e. doesn't
380// return the result of comparison and so if the second argument is a string,
381// it has to be converted to char* or wchar_t*
382#define WX_STR_FUNC(rettype, name, crtA, crtW, forString) \
383 WX_STR_FUNC_NO_INVERT(rettype, name, crtA, crtW, forString) \
384 \
385 inline rettype WX_STR_DECL(name, const char *, const wxCStrData&) \
386 { return WX_STR_CALL(crtA, s1, s2.AsCharBuf()); } \
387 inline rettype WX_STR_DECL(name, const char *, const wxString&) \
388 { return WX_STR_CALL(crtA, s1, s2.mb_str()); } \
389 \
390 inline rettype WX_STR_DECL(name, const wchar_t *, const wxCStrData&) \
391 { return WX_STR_CALL(crtW, s1, s2.AsWCharBuf()); } \
392 inline rettype WX_STR_DECL(name, const wchar_t *, const wxString&) \
393 { return WX_STR_CALL(crtW, s1, s2.wc_str()); } \
394 \
395 inline rettype WX_STR_DECL(name, const wxCharBuffer&, const wxCStrData&) \
396 { return WX_STR_CALL(crtA, s1.data(), s2.AsCharBuf()); } \
397 inline rettype WX_STR_DECL(name, const wxCharBuffer&, const wxString&) \
398 { return WX_STR_CALL(crtA, s1.data(), s2.mb_str()); } \
399 \
400 inline rettype WX_STR_DECL(name, const wxWCharBuffer&, const wxCStrData&) \
401 { return WX_STR_CALL(crtW, s1.data(), s2.AsWCharBuf()); } \
402 inline rettype WX_STR_DECL(name, const wxWCharBuffer&, const wxString&) \
403 { return WX_STR_CALL(crtW, s1.data(), s2.wc_str()); }
404
405template<typename T>
406inline int wxStrcmp_String(const wxString& s1, const T& s2)
407 { return s1.compare(s2); }
408WX_STRCMP_FUNC(wxStrcmp, wxCRT_StrcmpA, wxCRT_StrcmpW, wxStrcmp_String)
409
410template<typename T>
411inline int wxStricmp_String(const wxString& s1, const T& s2)
412 { return s1.CmpNoCase(s2); }
413WX_STRCMP_FUNC(wxStricmp, wxCRT_StricmpA, wxCRT_StricmpW, wxStricmp_String)
414
d6f2a891 415#if defined(wxCRT_StrcollA) && defined(wxCRT_StrcollW)
ae51cebb 416
30f3757b
VS
417// GCC 3.3 and other compilers have a bug that causes it to fail compilation if
418// the template's implementation uses overloaded function declared later (see
419// the wxStrcoll() call in wxStrcoll_String<T>()), so we have to
420// forward-declare the template and implement it below WX_STRCMP_FUNC. OTOH,
a2c5db76
VS
421// this fails to compile with VC6, so don't do it for VC. It also causes
422// problems with GCC visibility in newer GCC versions.
423#if !(defined(__VISUALC__) || wxCHECK_GCC_VERSION(3,4))
ae51cebb
VS
424template<typename T>
425inline int wxStrcoll_String(const wxString& s1, const T& s2);
426WX_STRCMP_FUNC(wxStrcoll, wxCRT_StrcollA, wxCRT_StrcollW, wxStrcoll_String)
30f3757b 427#endif // !__VISUALC__
ae51cebb 428
52de37c7
VS
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
ae51cebb
VS
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);
52de37c7 438#else
ae51cebb 439 return wxStrcoll((const char*)s1.mb_str(), s2);
52de37c7
VS
440#endif
441}
ae51cebb 442
a2c5db76 443#if defined(__VISUALC__) || wxCHECK_GCC_VERSION(3,4)
ae51cebb 444// this is exactly the same WX_STRCMP_FUNC line as above wxStrcoll_String<>
52de37c7 445WX_STRCMP_FUNC(wxStrcoll, wxCRT_StrcollA, wxCRT_StrcollW, wxStrcoll_String)
ae51cebb
VS
446#endif
447
d6f2a891 448#endif // defined(wxCRT_Strcoll[AW])
52de37c7
VS
449
450template<typename T>
49ec3b67 451inline size_t wxStrspn_String(const wxString& s1, const T& s2)
52de37c7
VS
452{
453 size_t pos = s1.find_first_not_of(s2);
49ec3b67 454 return pos == wxString::npos ? s1.length() : pos;
52de37c7 455}
49ec3b67
VZ
456WX_STR_FUNC_NO_INVERT(size_t, wxStrspn,
457 wxCRT_StrspnA, wxCRT_StrspnW, wxStrspn_String)
52de37c7
VS
458
459template<typename T>
49ec3b67 460inline size_t wxStrcspn_String(const wxString& s1, const T& s2)
52de37c7
VS
461{
462 size_t pos = s1.find_first_of(s2);
49ec3b67 463 return pos == wxString::npos ? s1.length() : pos;
52de37c7 464}
49ec3b67
VZ
465WX_STR_FUNC_NO_INVERT(size_t, wxStrcspn,
466 wxCRT_StrcspnA, wxCRT_StrcspnW, wxStrcspn_String)
52de37c7
VS
467
468#undef WX_STR_DECL
469#undef WX_STR_CALL
470#define WX_STR_DECL(name, T1, T2) name(T1 s1, T2 s2, size_t n)
471#define WX_STR_CALL(func, a1, a2) func(a1, a2, n)
472
473template<typename T>
474inline int wxStrncmp_String(const wxString& s1, const T& s2, size_t n)
475 { return s1.compare(0, n, s2, 0, n); }
476WX_STRCMP_FUNC(wxStrncmp, wxCRT_StrncmpA, wxCRT_StrncmpW, wxStrncmp_String)
477
478template<typename T>
479inline int wxStrnicmp_String(const wxString& s1, const T& s2, size_t n)
480 { return s1.substr(0, n).CmpNoCase(wxString(s2).substr(0, n)); }
481WX_STRCMP_FUNC(wxStrnicmp, wxCRT_StrnicmpA, wxCRT_StrnicmpW, wxStrnicmp_String)
482
483#undef WX_STR_DECL
484#undef WX_STR_CALL
485#undef WX_STRCMP_FUNC
486#undef WX_STR_FUNC
487#undef WX_STR_FUNC_NO_INVERT
488
d6f2a891
VZ
489#if defined(wxCRT_StrxfrmA) && defined(wxCRT_StrxfrmW)
490
52de37c7
VS
491inline size_t wxStrxfrm(char *dest, const char *src, size_t n)
492 { return wxCRT_StrxfrmA(dest, src, n); }
493inline size_t wxStrxfrm(wchar_t *dest, const wchar_t *src, size_t n)
494 { return wxCRT_StrxfrmW(dest, src, n); }
495template<typename T>
496inline size_t wxStrxfrm(T *dest, const wxCharTypeBuffer<T>& src, size_t n)
497 { return wxStrxfrm(dest, src.data(), n); }
498inline size_t wxStrxfrm(char *dest, const wxString& src, size_t n)
499 { return wxCRT_StrxfrmA(dest, src.mb_str(), n); }
500inline size_t wxStrxfrm(wchar_t *dest, const wxString& src, size_t n)
501 { return wxCRT_StrxfrmW(dest, src.wc_str(), n); }
502inline size_t wxStrxfrm(char *dest, const wxCStrData& src, size_t n)
503 { return wxCRT_StrxfrmA(dest, src.AsCharBuf(), n); }
504inline size_t wxStrxfrm(wchar_t *dest, const wxCStrData& src, size_t n)
505 { return wxCRT_StrxfrmW(dest, src.AsWCharBuf(), n); }
506
d6f2a891
VZ
507#endif // defined(wxCRT_Strxfrm[AW])
508
52de37c7
VS
509inline char *wxStrtok(char *str, const char *delim, char **saveptr)
510 { return wxCRT_StrtokA(str, delim, saveptr); }
511inline wchar_t *wxStrtok(wchar_t *str, const wchar_t *delim, wchar_t **saveptr)
512 { return wxCRT_StrtokW(str, delim, saveptr); }
513template<typename T>
514inline T *wxStrtok(T *str, const wxCharTypeBuffer<T>& delim, T **saveptr)
515 { return wxStrtok(str, delim.data(), saveptr); }
516inline char *wxStrtok(char *str, const wxCStrData& delim, char **saveptr)
517 { return wxCRT_StrtokA(str, delim.AsCharBuf(), saveptr); }
518inline wchar_t *wxStrtok(wchar_t *str, const wxCStrData& delim, wchar_t **saveptr)
519 { return wxCRT_StrtokW(str, delim.AsWCharBuf(), saveptr); }
520inline char *wxStrtok(char *str, const wxString& delim, char **saveptr)
521 { return wxCRT_StrtokA(str, delim.mb_str(), saveptr); }
522inline wchar_t *wxStrtok(wchar_t *str, const wxString& delim, wchar_t **saveptr)
523 { return wxCRT_StrtokW(str, delim.wc_str(), saveptr); }
524
525inline const char *wxStrstr(const char *haystack, const char *needle)
526 { return wxCRT_StrstrA(haystack, needle); }
527inline const wchar_t *wxStrstr(const wchar_t *haystack, const wchar_t *needle)
528 { return wxCRT_StrstrW(haystack, needle); }
529inline const char *wxStrstr(const char *haystack, const wxString& needle)
530 { return wxCRT_StrstrA(haystack, needle.mb_str()); }
531inline const wchar_t *wxStrstr(const wchar_t *haystack, const wxString& needle)
532 { return wxCRT_StrstrW(haystack, needle.wc_str()); }
533// these functions return char* pointer into the non-temporary conversion buffer
534// used by c_str()'s implicit conversion to char*, for ANSI build compatibility
535inline const char *wxStrstr(const wxString& haystack, const wxString& needle)
536 { return wxCRT_StrstrA(haystack.c_str(), needle.mb_str()); }
537inline const char *wxStrstr(const wxCStrData& haystack, const wxString& needle)
538 { return wxCRT_StrstrA(haystack, needle.mb_str()); }
539inline const char *wxStrstr(const wxCStrData& haystack, const wxCStrData& needle)
540 { return wxCRT_StrstrA(haystack, needle.AsCharBuf()); }
541// if 'needle' is char/wchar_t, then the same is probably wanted as return value
542inline const char *wxStrstr(const wxString& haystack, const char *needle)
543 { return wxCRT_StrstrA(haystack.c_str(), needle); }
544inline const char *wxStrstr(const wxCStrData& haystack, const char *needle)
545 { return wxCRT_StrstrA(haystack, needle); }
546inline const wchar_t *wxStrstr(const wxString& haystack, const wchar_t *needle)
547 { return wxCRT_StrstrW(haystack.c_str(), needle); }
548inline const wchar_t *wxStrstr(const wxCStrData& haystack, const wchar_t *needle)
549 { return wxCRT_StrstrW(haystack, needle); }
550
551inline const char *wxStrchr(const char *s, char c)
552 { return wxCRT_StrchrA(s, c); }
553inline const wchar_t *wxStrchr(const wchar_t *s, wchar_t c)
554 { return wxCRT_StrchrW(s, c); }
555inline const char *wxStrrchr(const char *s, char c)
556 { return wxCRT_StrrchrA(s, c); }
557inline const wchar_t *wxStrrchr(const wchar_t *s, wchar_t c)
558 { return wxCRT_StrrchrW(s, c); }
01c0981e
VS
559inline const char *wxStrchr(const char *s, const wxUniChar& c)
560 { return wxCRT_StrchrA(s, (char)c); }
561inline const wchar_t *wxStrchr(const wchar_t *s, const wxUniChar& c)
562 { return wxCRT_StrchrW(s, (wchar_t)c); }
563inline const char *wxStrrchr(const char *s, const wxUniChar& c)
564 { return wxCRT_StrrchrA(s, (char)c); }
565inline const wchar_t *wxStrrchr(const wchar_t *s, const wxUniChar& c)
566 { return wxCRT_StrrchrW(s, (wchar_t)c); }
567inline const char *wxStrchr(const char *s, const wxUniCharRef& c)
568 { return wxCRT_StrchrA(s, (char)c); }
569inline const wchar_t *wxStrchr(const wchar_t *s, const wxUniCharRef& c)
570 { return wxCRT_StrchrW(s, (wchar_t)c); }
571inline const char *wxStrrchr(const char *s, const wxUniCharRef& c)
572 { return wxCRT_StrrchrA(s, (char)c); }
573inline const wchar_t *wxStrrchr(const wchar_t *s, const wxUniCharRef& c)
574 { return wxCRT_StrrchrW(s, (wchar_t)c); }
52de37c7
VS
575template<typename T>
576inline const T* wxStrchr(const wxCharTypeBuffer<T>& s, T c)
577 { return wxStrchr(s.data(), c); }
578template<typename T>
579inline const T* wxStrrchr(const wxCharTypeBuffer<T>& s, T c)
580 { return wxStrrchr(s.data(), c); }
01c0981e
VS
581template<typename T>
582inline const T* wxStrchr(const wxCharTypeBuffer<T>& s, const wxUniChar& c)
583 { return wxStrchr(s.data(), (T)c); }
584template<typename T>
585inline const T* wxStrrchr(const wxCharTypeBuffer<T>& s, const wxUniChar& c)
586 { return wxStrrchr(s.data(), (T)c); }
587template<typename T>
588inline const T* wxStrchr(const wxCharTypeBuffer<T>& s, const wxUniCharRef& c)
589 { return wxStrchr(s.data(), (T)c); }
590template<typename T>
591inline const T* wxStrrchr(const wxCharTypeBuffer<T>& s, const wxUniCharRef& c)
592 { return wxStrrchr(s.data(), (T)c); }
52de37c7
VS
593// these functions return char* pointer into the non-temporary conversion buffer
594// used by c_str()'s implicit conversion to char*, for ANSI build compatibility
595inline const char* wxStrchr(const wxString& s, char c)
596 { return wxCRT_StrchrA((const char*)s.c_str(), c); }
597inline const char* wxStrrchr(const wxString& s, char c)
598 { return wxCRT_StrrchrA((const char*)s.c_str(), c); }
01c0981e
VS
599inline const char* wxStrchr(const wxString& s, int c)
600 { return wxCRT_StrchrA((const char*)s.c_str(), c); }
601inline const char* wxStrrchr(const wxString& s, int c)
602 { return wxCRT_StrrchrA((const char*)s.c_str(), c); }
603inline const char* wxStrchr(const wxString& s, const wxUniChar& c)
604 { return wxCRT_StrchrA((const char*)s.c_str(), (char)c); }
605inline const char* wxStrrchr(const wxString& s, const wxUniChar& c)
606 { return wxCRT_StrrchrA((const char*)s.c_str(), (char)c); }
607inline const char* wxStrchr(const wxString& s, const wxUniCharRef& c)
608 { return wxCRT_StrchrA((const char*)s.c_str(), (char)c); }
609inline const char* wxStrrchr(const wxString& s, const wxUniCharRef& c)
610 { return wxCRT_StrrchrA((const char*)s.c_str(), (char)c); }
611inline const wchar_t* wxStrchr(const wxString& s, wchar_t c)
612 { return wxCRT_StrchrW((const wchar_t*)s.c_str(), c); }
613inline const wchar_t* wxStrrchr(const wxString& s, wchar_t c)
614 { return wxCRT_StrrchrW((const wchar_t*)s.c_str(), c); }
52de37c7 615inline const char* wxStrchr(const wxCStrData& s, char c)
01c0981e 616 { return wxCRT_StrchrA(s.AsChar(), c); }
52de37c7 617inline const char* wxStrrchr(const wxCStrData& s, char c)
01c0981e
VS
618 { return wxCRT_StrrchrA(s.AsChar(), c); }
619inline const char* wxStrchr(const wxCStrData& s, int c)
620 { return wxCRT_StrchrA(s.AsChar(), c); }
621inline const char* wxStrrchr(const wxCStrData& s, int c)
622 { return wxCRT_StrrchrA(s.AsChar(), c); }
623inline const char* wxStrchr(const wxCStrData& s, const wxUniChar& c)
624 { return wxCRT_StrchrA(s.AsChar(), (char)c); }
625inline const char* wxStrrchr(const wxCStrData& s, const wxUniChar& c)
626 { return wxCRT_StrrchrA(s.AsChar(), (char)c); }
627inline const char* wxStrchr(const wxCStrData& s, const wxUniCharRef& c)
628 { return wxCRT_StrchrA(s.AsChar(), (char)c); }
629inline const char* wxStrrchr(const wxCStrData& s, const wxUniCharRef& c)
630 { return wxCRT_StrrchrA(s.AsChar(), (char)c); }
631inline const wchar_t* wxStrchr(const wxCStrData& s, wchar_t c)
632 { return wxCRT_StrchrW(s.AsWChar(), c); }
633inline const wchar_t* wxStrrchr(const wxCStrData& s, wchar_t c)
634 { return wxCRT_StrrchrW(s.AsWChar(), c); }
52de37c7
VS
635
636inline const char *wxStrpbrk(const char *s, const char *accept)
637 { return wxCRT_StrpbrkA(s, accept); }
638inline const wchar_t *wxStrpbrk(const wchar_t *s, const wchar_t *accept)
639 { return wxCRT_StrpbrkW(s, accept); }
52de37c7
VS
640inline const char *wxStrpbrk(const char *s, const wxString& accept)
641 { return wxCRT_StrpbrkA(s, accept.mb_str()); }
642inline const char *wxStrpbrk(const char *s, const wxCStrData& accept)
643 { return wxCRT_StrpbrkA(s, accept.AsCharBuf()); }
52de37c7
VS
644inline const wchar_t *wxStrpbrk(const wchar_t *s, const wxString& accept)
645 { return wxCRT_StrpbrkW(s, accept.wc_str()); }
646inline const wchar_t *wxStrpbrk(const wchar_t *s, const wxCStrData& accept)
647 { return wxCRT_StrpbrkW(s, accept.AsWCharBuf()); }
648inline const char *wxStrpbrk(const wxString& s, const wxString& accept)
649 { return wxCRT_StrpbrkA(s.c_str(), accept.mb_str()); }
105260e8
VZ
650inline const char *wxStrpbrk(const wxString& s, const char *accept)
651 { return wxCRT_StrpbrkA(s.c_str(), accept); }
652inline const wchar_t *wxStrpbrk(const wxString& s, const wchar_t *accept)
653 { return wxCRT_StrpbrkW(s.wc_str(), accept); }
654inline const char *wxStrpbrk(const wxString& s, const wxCStrData& accept)
655 { return wxCRT_StrpbrkA(s.c_str(), accept.AsCharBuf()); }
52de37c7
VS
656inline const char *wxStrpbrk(const wxCStrData& s, const wxString& accept)
657 { return wxCRT_StrpbrkA(s.AsChar(), accept.mb_str()); }
105260e8
VZ
658inline const char *wxStrpbrk(const wxCStrData& s, const char *accept)
659 { return wxCRT_StrpbrkA(s.AsChar(), accept); }
660inline const wchar_t *wxStrpbrk(const wxCStrData& s, const wchar_t *accept)
661 { return wxCRT_StrpbrkW(s.AsWChar(), accept); }
662inline const char *wxStrpbrk(const wxCStrData& s, const wxCStrData& accept)
663 { return wxCRT_StrpbrkA(s.AsChar(), accept.AsCharBuf()); }
664template <typename S, typename T>
665inline const T *wxStrpbrk(const S& s, const wxCharTypeBuffer<T>& accept)
666 { return wxStrpbrk(s, accept.data()); }
52de37c7
VS
667
668
669/* inlined non-const versions */
670inline char *wxStrstr(char *haystack, const char *needle)
671 { return (char *)wxStrstr((const char *)haystack, needle); }
672inline wchar_t *wxStrstr(wchar_t *haystack, const wchar_t *needle)
673 { return (wchar_t *)wxStrstr((const wchar_t *)haystack, needle); }
674inline char *wxStrstr(char *haystack, const wxString& needle)
675 { return (char *)wxStrstr((const char *)haystack, needle); }
676inline wchar_t *wxStrstr(wchar_t *haystack, const wxString& needle)
677 { return (wchar_t *)wxStrstr((const wchar_t *)haystack, needle); }
678
679inline char * wxStrchr(char *s, char c)
680 { return (char *)wxStrchr((const char *)s, c); }
681inline char * wxStrrchr(char *s, char c)
682 { return (char *)wxStrrchr((const char *)s, c); }
683inline wchar_t * wxStrchr(wchar_t *s, wchar_t c)
684 { return (wchar_t *)wxStrchr((const wchar_t *)s, c); }
685inline wchar_t * wxStrrchr(wchar_t *s, wchar_t c)
686 { return (wchar_t *)wxStrrchr((const wchar_t *)s, c); }
687
688inline char * wxStrpbrk(char *s, const char *accept)
689 { return (char *)wxStrpbrk((const char *)s, accept); }
690inline wchar_t * wxStrpbrk(wchar_t *s, const wchar_t *accept)
691 { return (wchar_t *)wxStrpbrk((const wchar_t *)s, accept); }
692inline char * wxStrpbrk(char *s, const wxString& accept)
693 { return (char *)wxStrpbrk((const char *)s, accept); }
694inline wchar_t * wxStrpbrk(wchar_t *s, const wxString& accept)
695 { return (wchar_t *)wxStrpbrk((const wchar_t *)s, accept); }
696
697
698// ----------------------------------------------------------------------------
699// stdio.h functions
700// ----------------------------------------------------------------------------
701
702// NB: using fn_str() for mode is a hack to get the same type (char*/wchar_t*)
703// as needed, the conversion itself doesn't matter, it's ASCII
704inline FILE *wxFopen(const wxString& path, const wxString& mode)
705 { return wxCRT_Fopen(path.fn_str(), mode.fn_str()); }
706inline FILE *wxFreopen(const wxString& path, const wxString& mode, FILE *stream)
707 { return wxCRT_Freopen(path.fn_str(), mode.fn_str(), stream); }
708inline int wxRemove(const wxString& path)
709 { return wxCRT_Remove(path.fn_str()); }
710inline int wxRename(const wxString& oldpath, const wxString& newpath)
711 { return wxCRT_Rename(oldpath.fn_str(), newpath.fn_str()); }
712
52de37c7
VS
713extern WXDLLIMPEXP_BASE int wxPuts(const wxString& s);
714extern WXDLLIMPEXP_BASE int wxFputs(const wxString& s, FILE *stream);
715extern WXDLLIMPEXP_BASE void wxPerror(const wxString& s);
716
717extern WXDLLIMPEXP_BASE int wxFputc(const wxUniChar& c, FILE *stream);
718
719#define wxPutc(c, stream) wxFputc(c, stream)
720#define wxPutchar(c) wxFputc(c, stdout)
721#define wxFputchar(c) wxPutchar(c)
722
723// NB: We only provide ANSI version of fgets() because fgetws() interprets the
724// stream according to current locale, which is rarely what is desired.
725inline char *wxFgets(char *s, int size, FILE *stream)
726 { return wxCRT_FgetsA(s, size, stream); }
727// This version calls ANSI version and converts the string using wxConvLibc
728extern WXDLLIMPEXP_BASE wchar_t *wxFgets(wchar_t *s, int size, FILE *stream);
729
730#define wxGets(s) wxGets_is_insecure_and_dangerous_use_wxFgets_instead
731
732// NB: We only provide ANSI versions of this for the same reasons as in the
733// case of wxFgets() above
734inline int wxFgetc(FILE *stream) { return wxCRT_FgetcA(stream); }
735inline int wxUngetc(int c, FILE *stream) { return wxCRT_UngetcA(c, stream); }
736
737#define wxGetc(stream) wxFgetc(stream)
738#define wxGetchar() wxFgetc(stdin)
739#define wxFgetchar() wxGetchar()
740
741// ----------------------------------------------------------------------------
742// stdlib.h functions
743// ----------------------------------------------------------------------------
744
745#ifdef wxCRT_AtoiW
746inline int wxAtoi(const wxString& str) { return wxCRT_AtoiW(str.wc_str()); }
747#else
748inline int wxAtoi(const wxString& str) { return wxCRT_AtoiA(str.mb_str()); }
749#endif
750
751#ifdef wxCRT_AtolW
752inline long wxAtol(const wxString& str) { return wxCRT_AtolW(str.wc_str()); }
753#else
754inline long wxAtol(const wxString& str) { return wxCRT_AtolA(str.mb_str()); }
755#endif
756
757#ifdef wxCRT_AtofW
758inline double wxAtof(const wxString& str) { return wxCRT_AtofW(str.wc_str()); }
759#else
760inline double wxAtof(const wxString& str) { return wxCRT_AtofA(str.mb_str()); }
761#endif
762
763inline double wxStrtod(const char *nptr, char **endptr)
764 { return wxCRT_StrtodA(nptr, endptr); }
765inline double wxStrtod(const wchar_t *nptr, wchar_t **endptr)
766 { return wxCRT_StrtodW(nptr, endptr); }
767template<typename T>
768inline double wxStrtod(const wxCharTypeBuffer<T>& nptr, T **endptr)
769 { return wxStrtod(nptr.data(), endptr); }
770
771// We implement wxStrto*() like this so that the code compiles when NULL is
772// passed in - - if we had just char** and wchar_t** overloads for 'endptr', it
773// would be ambiguous. The solution is to use a template so that endptr can be
774// any type: when NULL constant is used, the type will be int and we can handle
775// that case specially. Otherwise, we infer the type that 'nptr' should be
776// converted to from the type of 'endptr'. We need wxStrtoxCharType<T> template
777// to make the code compile even for T=int (that's the case when it's not going
778// to be ever used, but it still has to compile).
779template<typename T> struct wxStrtoxCharType {};
780template<> struct wxStrtoxCharType<char**>
7dfe6f2a
VS
781{
782 typedef const char* Type;
783 static char** AsPointer(char **p) { return p; }
784};
52de37c7 785template<> struct wxStrtoxCharType<wchar_t**>
7dfe6f2a
VS
786{
787 typedef const wchar_t* Type;
788 static wchar_t** AsPointer(wchar_t **p) { return p; }
789};
52de37c7 790template<> struct wxStrtoxCharType<int>
7dfe6f2a
VS
791{
792 typedef const char* Type; /* this one is never used */
793 static char** AsPointer(int WXUNUSED_UNLESS_DEBUG(p))
794 {
795 wxASSERT_MSG( p == 0, "passing non-NULL int is invalid" );
796 return NULL;
797 }
798};
52de37c7
VS
799
800template<typename T>
801inline double wxStrtod(const wxString& nptr, T endptr)
802{
803 if ( endptr == 0 )
804 {
805 // when we don't care about endptr, use the string representation that
806 // doesn't require any conversion (it doesn't matter for this function
807 // even if its UTF-8):
808 return wxStrtod(nptr.wx_str(), (wxStringCharType**)NULL);
809 }
810 else
811 {
812 // note that it is important to use c_str() here and not mb_str() or
813 // wc_str(), because we store the pointer into (possibly converted)
814 // buffer in endptr and so it must be valid even when wxStrtod() returns
e9352368
VS
815 typedef typename wxStrtoxCharType<T>::Type CharType;
816 return wxStrtod((CharType)nptr.c_str(),
7dfe6f2a 817 wxStrtoxCharType<T>::AsPointer(endptr));
52de37c7
VS
818 }
819}
820template<typename T>
821inline double wxStrtod(const wxCStrData& nptr, T endptr)
822 { return wxStrtod(nptr.AsString(), endptr); }
823
824
825#define WX_STRTOX_FUNC(rettype, name, implA, implW) \
826 /* see wxStrtod() above for explanation of this code: */ \
827 inline rettype name(const char *nptr, char **endptr, int base) \
828 { return implA(nptr, endptr, base); } \
829 inline rettype name(const wchar_t *nptr, wchar_t **endptr, int base) \
830 { return implW(nptr, endptr, base); } \
831 template<typename T> \
832 inline rettype name(const wxCharTypeBuffer<T>& nptr, T **endptr, int base)\
833 { return name(nptr.data(), endptr); } \
834 template<typename T> \
835 inline rettype name(const wxString& nptr, T endptr, int base) \
836 { \
837 if ( endptr == 0 ) \
838 return name(nptr.wx_str(), (wxStringCharType**)NULL, base); \
839 else \
e9352368
VS
840 { \
841 typedef typename wxStrtoxCharType<T>::Type CharType; \
842 return name((CharType)nptr.c_str(), \
7dfe6f2a
VS
843 wxStrtoxCharType<T>::AsPointer(endptr), \
844 base); \
e9352368 845 } \
52de37c7
VS
846 } \
847 template<typename T> \
848 inline rettype name(const wxCStrData& nptr, T endptr, int base) \
849 { return name(nptr.AsString(), endptr, base); }
850
851WX_STRTOX_FUNC(long, wxStrtol, wxCRT_StrtolA, wxCRT_StrtolW)
852WX_STRTOX_FUNC(unsigned long, wxStrtoul, wxCRT_StrtoulA, wxCRT_StrtoulW)
bdcb2137 853#ifdef wxLongLong_t
52de37c7
VS
854WX_STRTOX_FUNC(wxLongLong_t, wxStrtoll, wxCRT_StrtollA, wxCRT_StrtollW)
855WX_STRTOX_FUNC(wxULongLong_t, wxStrtoull, wxCRT_StrtoullA, wxCRT_StrtoullW)
bdcb2137 856#endif // wxLongLong_t
52de37c7
VS
857
858#undef WX_STRTOX_FUNC
859
860
d6f2a891
VZ
861// there is no command interpreter under CE, hence no system()
862#ifndef __WXWINCE__
863
52de37c7
VS
864// mingw32 doesn't provide _tsystem() even though it provides other stdlib.h
865// functions in their wide versions
866#ifdef wxCRT_SystemW
867inline int wxSystem(const wxString& str) { return wxCRT_SystemW(str.wc_str()); }
868#else
869inline int wxSystem(const wxString& str) { return wxCRT_SystemA(str.mb_str()); }
870#endif
871
d6f2a891
VZ
872#endif // !__WXWINCE__/__WXWINCE__
873
52de37c7
VS
874inline char* wxGetenv(const char *name) { return wxCRT_GetenvA(name); }
875inline wchar_t* wxGetenv(const wchar_t *name) { return wxCRT_GetenvW(name); }
876inline char* wxGetenv(const wxString& name) { return wxCRT_GetenvA(name.mb_str()); }
877inline char* wxGetenv(const wxCStrData& name) { return wxCRT_GetenvA(name.AsCharBuf()); }
878inline char* wxGetenv(const wxCharBuffer& name) { return wxCRT_GetenvA(name.data()); }
879inline wchar_t* wxGetenv(const wxWCharBuffer& name) { return wxCRT_GetenvW(name.data()); }
880
52de37c7
VS
881// ----------------------------------------------------------------------------
882// time.h functions
883// ----------------------------------------------------------------------------
884
885inline size_t wxStrftime(char *s, size_t max,
886 const wxString& format, const struct tm *tm)
887 { return wxCRT_StrftimeA(s, max, format.mb_str(), tm); }
888
889inline size_t wxStrftime(wchar_t *s, size_t max,
890 const wxString& format, const struct tm *tm)
891 { return wxCRT_StrftimeW(s, max, format.wc_str(), tm); }
892
893// NB: we can't provide both char* and wchar_t* versions for obvious reasons
894// and returning wxString wouldn't work either (it would be immediately
895// destroyed and if assigned to char*/wchar_t*, the pointer would be
896// invalid), so we only keep ASCII version, because the returned value
897// is always ASCII anyway
898#define wxAsctime asctime
899#define wxCtime ctime
900
901
902// ----------------------------------------------------------------------------
903// ctype.h functions
904// ----------------------------------------------------------------------------
905
906// FIXME-UTF8: we'd be better off implementing these ourselves, as the CRT
907// version is locale-dependent
52de37c7
VS
908// FIXME-UTF8: these don't work when EOF is passed in because of wxUniChar,
909// is this OK or not?
910
80820772
VZ
911inline bool wxIsalnum(const wxUniChar& c) { return wxCRT_IsalnumW(c) != 0; }
912inline bool wxIsalpha(const wxUniChar& c) { return wxCRT_IsalphaW(c) != 0; }
913inline bool wxIscntrl(const wxUniChar& c) { return wxCRT_IscntrlW(c) != 0; }
914inline bool wxIsdigit(const wxUniChar& c) { return wxCRT_IsdigitW(c) != 0; }
915inline bool wxIsgraph(const wxUniChar& c) { return wxCRT_IsgraphW(c) != 0; }
916inline bool wxIslower(const wxUniChar& c) { return wxCRT_IslowerW(c) != 0; }
917inline bool wxIsprint(const wxUniChar& c) { return wxCRT_IsprintW(c) != 0; }
918inline bool wxIspunct(const wxUniChar& c) { return wxCRT_IspunctW(c) != 0; }
919inline bool wxIsspace(const wxUniChar& c) { return wxCRT_IsspaceW(c) != 0; }
920inline bool wxIsupper(const wxUniChar& c) { return wxCRT_IsupperW(c) != 0; }
921inline bool wxIsxdigit(const wxUniChar& c) { return wxCRT_IsxdigitW(c) != 0; }
52de37c7
VS
922
923inline wxUniChar wxTolower(const wxUniChar& c) { return wxCRT_TolowerW(c); }
924inline wxUniChar wxToupper(const wxUniChar& c) { return wxCRT_ToupperW(c); }
925
926#if WXWIN_COMPATIBILITY_2_8
927// we had goofed and defined wxIsctrl() instead of (correct) wxIscntrl() in the
928// initial versions of this header -- now it is too late to remove it so
929// although we fixed the function/macro name above, still provide the
930// backwards-compatible synonym.
931wxDEPRECATED( inline int wxIsctrl(const wxUniChar& c) );
932inline int wxIsctrl(const wxUniChar& c) { return wxIscntrl(c); }
933#endif // WXWIN_COMPATIBILITY_2_8
e3f6cbd9
VS
934
935#endif /* _WX_WXCRT_H_ */