1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: Type-safe ANSI and Unicode builds compatible wrappers for
5 // Author: Joel Farley, Ove Kaaven
6 // Modified by: Vadim Zeitlin, Robert Roebling, Ron Lee, Vaclav Slavik
9 // Copyright: (c) 1998-2006 wxWidgets dev team
10 // Licence: wxWindows licence
11 ///////////////////////////////////////////////////////////////////////////////
16 // NB: User code should include wx/crt.h instead of including this
19 #include "wx/wxcrtbase.h"
20 #include "wx/string.h"
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
29 // ============================================================================
31 // ============================================================================
33 /* checks whether the passed in pointer is NULL and if the string is empty */
34 inline bool wxIsEmpty(const char *s
) { return !s
|| !*s
; }
35 inline bool wxIsEmpty(const wchar_t *s
) { return !s
|| !*s
; }
36 inline bool wxIsEmpty(const wxCharBuffer
& s
) { return wxIsEmpty(s
.data()); }
37 inline bool wxIsEmpty(const wxWCharBuffer
& s
) { return wxIsEmpty(s
.data()); }
38 inline bool wxIsEmpty(const wxString
& s
) { return s
.empty(); }
39 inline bool wxIsEmpty(const wxCStrData
& s
) { return s
.AsString().empty(); }
43 /* multibyte to wide char conversion functions and macros */
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
);
51 #define wxMB2WX wxMB2WC
52 #define wxWX2MB wxWC2MB
53 #define wxWC2WX wxStrncpy
54 #define wxWX2WC wxStrncpy
56 #define wxMB2WX wxStrncpy
57 #define wxWX2MB wxStrncpy
58 #define wxWC2WX wxWC2MB
59 #define wxWX2WC wxMB2WC
61 #else /* !wxUSE_UNICODE */
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
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
82 //implement our own wmem variants
83 inline wxChar
* wxTmemchr(const wxChar
* s
, wxChar c
, size_t l
)
85 for(;l
&& *s
!= c
;--l
, ++s
) {}
92 inline int wxTmemcmp(const wxChar
* sz1
, const wxChar
* sz2
, size_t len
)
94 for(; *sz1
== *sz2
&& len
; --len
, ++sz1
, ++sz2
) {}
97 return *sz1
< *sz2
? -1 : *sz1
> *sz2
;
102 inline wxChar
* wxTmemcpy(wxChar
* szOut
, const wxChar
* szIn
, size_t len
)
104 return (wxChar
*) memcpy(szOut
, szIn
, len
* sizeof(wxChar
));
107 inline wxChar
* wxTmemmove(wxChar
* szOut
, const wxChar
* szIn
, size_t len
)
109 return (wxChar
*) memmove(szOut
, szIn
, len
* sizeof(wxChar
));
112 inline wxChar
* wxTmemset(wxChar
* szOut
, const wxChar cIn
, size_t len
)
114 wxChar
* szRet
= szOut
;
121 #endif /* wxUSE_UNICODE */
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):
126 inline char* wxTmemchr(const char* s
, char c
, size_t len
)
127 { return (char*)memchr(s
, c
, len
); }
128 inline int wxTmemcmp(const char* sz1
, const char* sz2
, size_t len
)
129 { return memcmp(sz1
, sz2
, len
); }
130 inline char* wxTmemcpy(char* szOut
, const char* szIn
, size_t len
)
131 { return (char*)memcpy(szOut
, szIn
, len
); }
132 inline char* wxTmemmove(char* szOut
, const char* szIn
, size_t len
)
133 { return (char*)memmove(szOut
, szIn
, len
); }
134 inline char* wxTmemset(char* szOut
, const char cIn
, size_t len
)
135 { return (char*)memset(szOut
, cIn
, len
); }
138 // ============================================================================
139 // wx wrappers for CRT functions in both char* and wchar_t* versions
140 // ============================================================================
142 // A few notes on implementation of these wrappers:
144 // We need both char* and wchar_t* versions of functions like wxStrlen() for
145 // compatibility with both ANSI and Unicode builds.
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
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*.
156 // ----------------------------------------------------------------------------
158 // ----------------------------------------------------------------------------
160 // NB: we can't provide const wchar_t* (= wxChar*) overload, because calling
161 // wxSetlocale(category, NULL) -- which is a common thing to do -- would be
163 WXDLLIMPEXP_BASE
char* wxSetlocale(int category
, const char *locale
);
164 inline char* wxSetlocale(int category
, const wxCharBuffer
& locale
)
165 { return wxSetlocale(category
, locale
.data()); }
166 inline char* wxSetlocale(int category
, const wxString
& locale
)
167 { return wxSetlocale(category
, locale
.mb_str()); }
168 inline char* wxSetlocale(int category
, const wxCStrData
& locale
)
169 { return wxSetlocale(category
, locale
.AsCharBuf()); }
171 // ----------------------------------------------------------------------------
173 // ----------------------------------------------------------------------------
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; }
179 inline size_t wxStrlen(const wxCharBuffer
& s
) { return wxStrlen(s
.data()); }
180 inline size_t wxStrlen(const wxWCharBuffer
& s
) { return wxStrlen(s
.data()); }
181 inline size_t wxStrlen(const wxString
& s
) { return s
.length(); }
182 inline size_t wxStrlen(const wxCStrData
& s
) { return s
.AsString().length(); }
184 // this is a function new in 2.9 so we don't care about backwards compatibility and
185 // so don't need to support wxCharBuffer/wxWCharBuffer overloads
186 #if defined(wxCRT_StrnlenA)
187 inline size_t wxStrnlen(const char *str
, size_t maxlen
) { return wxCRT_StrnlenA(str
, maxlen
); }
189 inline size_t wxStrnlen(const char *str
, size_t maxlen
)
192 for ( n
= 0; n
< maxlen
; n
++ )
200 #if defined(wxCRT_StrnlenW)
201 inline size_t wxStrnlen(const wchar_t *str
, size_t maxlen
) { return wxCRT_StrnlenW(str
, maxlen
); }
203 inline size_t wxStrnlen(const wchar_t *str
, size_t maxlen
)
206 for ( n
= 0; n
< maxlen
; n
++ )
214 // NB: these are defined in wxcrtbase.h, see the comment there
215 // inline char* wxStrdup(const char *s) { return wxStrdupA(s); }
216 // inline wchar_t* wxStrdup(const wchar_t *s) { return wxStrdupW(s); }
217 inline char* wxStrdup(const wxCharBuffer
& s
) { return wxStrdup(s
.data()); }
218 inline wchar_t* wxStrdup(const wxWCharBuffer
& s
) { return wxStrdup(s
.data()); }
219 inline char* wxStrdup(const wxString
& s
) { return wxStrdup(s
.mb_str()); }
220 inline char* wxStrdup(const wxCStrData
& s
) { return wxStrdup(s
.AsCharBuf()); }
222 inline char *wxStrcpy(char *dest
, const char *src
)
223 { return wxCRT_StrcpyA(dest
, src
); }
224 inline wchar_t *wxStrcpy(wchar_t *dest
, const wchar_t *src
)
225 { return wxCRT_StrcpyW(dest
, src
); }
226 inline char *wxStrcpy(char *dest
, const wxString
& src
)
227 { return wxCRT_StrcpyA(dest
, src
.mb_str()); }
228 inline char *wxStrcpy(char *dest
, const wxCStrData
& src
)
229 { return wxCRT_StrcpyA(dest
, src
.AsCharBuf()); }
230 inline char *wxStrcpy(char *dest
, const wxCharBuffer
& src
)
231 { return wxCRT_StrcpyA(dest
, src
.data()); }
232 inline wchar_t *wxStrcpy(wchar_t *dest
, const wxString
& src
)
233 { return wxCRT_StrcpyW(dest
, src
.wc_str()); }
234 inline wchar_t *wxStrcpy(wchar_t *dest
, const wxCStrData
& src
)
235 { return wxCRT_StrcpyW(dest
, src
.AsWCharBuf()); }
236 inline wchar_t *wxStrcpy(wchar_t *dest
, const wxWCharBuffer
& src
)
237 { return wxCRT_StrcpyW(dest
, src
.data()); }
238 inline char *wxStrcpy(char *dest
, const wchar_t *src
)
239 { return wxCRT_StrcpyA(dest
, wxConvLibc
.cWC2MB(src
)); }
240 inline wchar_t *wxStrcpy(wchar_t *dest
, const char *src
)
241 { return wxCRT_StrcpyW(dest
, wxConvLibc
.cMB2WC(src
)); }
243 inline char *wxStrncpy(char *dest
, const char *src
, size_t n
)
244 { return wxCRT_StrncpyA(dest
, src
, n
); }
245 inline wchar_t *wxStrncpy(wchar_t *dest
, const wchar_t *src
, size_t n
)
246 { return wxCRT_StrncpyW(dest
, src
, n
); }
247 inline char *wxStrncpy(char *dest
, const wxString
& src
, size_t n
)
248 { return wxCRT_StrncpyA(dest
, src
.mb_str(), n
); }
249 inline char *wxStrncpy(char *dest
, const wxCStrData
& src
, size_t n
)
250 { return wxCRT_StrncpyA(dest
, src
.AsCharBuf(), n
); }
251 inline char *wxStrncpy(char *dest
, const wxCharBuffer
& src
, size_t n
)
252 { return wxCRT_StrncpyA(dest
, src
.data(), n
); }
253 inline wchar_t *wxStrncpy(wchar_t *dest
, const wxString
& src
, size_t n
)
254 { return wxCRT_StrncpyW(dest
, src
.wc_str(), n
); }
255 inline wchar_t *wxStrncpy(wchar_t *dest
, const wxCStrData
& src
, size_t n
)
256 { return wxCRT_StrncpyW(dest
, src
.AsWCharBuf(), n
); }
257 inline wchar_t *wxStrncpy(wchar_t *dest
, const wxWCharBuffer
& src
, size_t n
)
258 { return wxCRT_StrncpyW(dest
, src
.data(), n
); }
259 inline char *wxStrncpy(char *dest
, const wchar_t *src
, size_t n
)
260 { return wxCRT_StrncpyA(dest
, wxConvLibc
.cWC2MB(src
), n
); }
261 inline wchar_t *wxStrncpy(wchar_t *dest
, const char *src
, size_t n
)
262 { return wxCRT_StrncpyW(dest
, wxConvLibc
.cMB2WC(src
), n
); }
264 // this is a function new in 2.9 so we don't care about backwards compatibility and
265 // so don't need to support wchar_t/char overloads
266 inline size_t wxStrlcpy(char *dest
, const char *src
, size_t n
)
268 const size_t len
= wxCRT_StrlenA(src
);
274 wxCRT_StrncpyA(dest
, src
, n
);
280 inline size_t wxStrlcpy(wchar_t *dest
, const wchar_t *src
, size_t n
)
282 const size_t len
= wxCRT_StrlenW(src
);
287 wxCRT_StrncpyW(dest
, src
, n
);
294 inline char *wxStrcat(char *dest
, const char *src
)
295 { return wxCRT_StrcatA(dest
, src
); }
296 inline wchar_t *wxStrcat(wchar_t *dest
, const wchar_t *src
)
297 { return wxCRT_StrcatW(dest
, src
); }
298 inline char *wxStrcat(char *dest
, const wxString
& src
)
299 { return wxCRT_StrcatA(dest
, src
.mb_str()); }
300 inline char *wxStrcat(char *dest
, const wxCStrData
& src
)
301 { return wxCRT_StrcatA(dest
, src
.AsCharBuf()); }
302 inline char *wxStrcat(char *dest
, const wxCharBuffer
& src
)
303 { return wxCRT_StrcatA(dest
, src
.data()); }
304 inline wchar_t *wxStrcat(wchar_t *dest
, const wxString
& src
)
305 { return wxCRT_StrcatW(dest
, src
.wc_str()); }
306 inline wchar_t *wxStrcat(wchar_t *dest
, const wxCStrData
& src
)
307 { return wxCRT_StrcatW(dest
, src
.AsWCharBuf()); }
308 inline wchar_t *wxStrcat(wchar_t *dest
, const wxWCharBuffer
& src
)
309 { return wxCRT_StrcatW(dest
, src
.data()); }
310 inline char *wxStrcat(char *dest
, const wchar_t *src
)
311 { return wxCRT_StrcatA(dest
, wxConvLibc
.cWC2MB(src
)); }
312 inline wchar_t *wxStrcat(wchar_t *dest
, const char *src
)
313 { return wxCRT_StrcatW(dest
, wxConvLibc
.cMB2WC(src
)); }
315 inline char *wxStrncat(char *dest
, const char *src
, size_t n
)
316 { return wxCRT_StrncatA(dest
, src
, n
); }
317 inline wchar_t *wxStrncat(wchar_t *dest
, const wchar_t *src
, size_t n
)
318 { return wxCRT_StrncatW(dest
, src
, n
); }
319 inline char *wxStrncat(char *dest
, const wxString
& src
, size_t n
)
320 { return wxCRT_StrncatA(dest
, src
.mb_str(), n
); }
321 inline char *wxStrncat(char *dest
, const wxCStrData
& src
, size_t n
)
322 { return wxCRT_StrncatA(dest
, src
.AsCharBuf(), n
); }
323 inline char *wxStrncat(char *dest
, const wxCharBuffer
& src
, size_t n
)
324 { return wxCRT_StrncatA(dest
, src
.data(), n
); }
325 inline wchar_t *wxStrncat(wchar_t *dest
, const wxString
& src
, size_t n
)
326 { return wxCRT_StrncatW(dest
, src
.wc_str(), n
); }
327 inline wchar_t *wxStrncat(wchar_t *dest
, const wxCStrData
& src
, size_t n
)
328 { return wxCRT_StrncatW(dest
, src
.AsWCharBuf(), n
); }
329 inline wchar_t *wxStrncat(wchar_t *dest
, const wxWCharBuffer
& src
, size_t n
)
330 { return wxCRT_StrncatW(dest
, src
.data(), n
); }
331 inline char *wxStrncat(char *dest
, const wchar_t *src
, size_t n
)
332 { return wxCRT_StrncatA(dest
, wxConvLibc
.cWC2MB(src
), n
); }
333 inline wchar_t *wxStrncat(wchar_t *dest
, const char *src
, size_t n
)
334 { return wxCRT_StrncatW(dest
, wxConvLibc
.cMB2WC(src
), n
); }
337 #define WX_STR_DECL(name, T1, T2) name(T1 s1, T2 s2)
338 #define WX_STR_CALL(func, a1, a2) func(a1, a2)
340 // This macro defines string function for all possible variants of arguments,
341 // except for those taking wxString or wxCStrData as second argument.
343 // rettype - return type
344 // name - name of the (overloaded) function to define
345 // crtA - function to call for char* versions (takes two arguments)
346 // crtW - ditto for wchar_t* function
347 // forString - function to call when the *first* argument is wxString;
348 // the second argument can be any string type, so this is
349 // typically a template
350 #define WX_STR_FUNC_NO_INVERT(rettype, name, crtA, crtW, forString) \
351 inline rettype WX_STR_DECL(name, const char *, const char *) \
352 { return WX_STR_CALL(crtA, s1, s2); } \
353 inline rettype WX_STR_DECL(name, const char *, const wchar_t *) \
354 { return WX_STR_CALL(forString, wxString(s1), wxString(s2)); } \
355 inline rettype WX_STR_DECL(name, const char *, const wxCharBuffer&) \
356 { return WX_STR_CALL(crtA, s1, s2.data()); } \
357 inline rettype WX_STR_DECL(name, const char *, const wxWCharBuffer&) \
358 { return WX_STR_CALL(forString, wxString(s1), s2.data()); } \
360 inline rettype WX_STR_DECL(name, const wchar_t *, const wchar_t *) \
361 { return WX_STR_CALL(crtW, s1, s2); } \
362 inline rettype WX_STR_DECL(name, const wchar_t *, const char *) \
363 { return WX_STR_CALL(forString, wxString(s1), wxString(s2)); } \
364 inline rettype WX_STR_DECL(name, const wchar_t *, const wxWCharBuffer&) \
365 { return WX_STR_CALL(crtW, s1, s2.data()); } \
366 inline rettype WX_STR_DECL(name, const wchar_t *, const wxCharBuffer&) \
367 { return WX_STR_CALL(forString, wxString(s1), s2.data()); } \
369 inline rettype WX_STR_DECL(name, const wxCharBuffer&, const char *) \
370 { return WX_STR_CALL(crtA, s1.data(), s2); } \
371 inline rettype WX_STR_DECL(name, const wxCharBuffer&, const wchar_t *) \
372 { return WX_STR_CALL(forString, wxString(s1), wxString(s2)); } \
373 inline rettype WX_STR_DECL(name, const wxCharBuffer&, const wxCharBuffer&)\
374 { return WX_STR_CALL(crtA, s1.data(), s2.data()); } \
375 inline rettype WX_STR_DECL(name, const wxCharBuffer&, const wxWCharBuffer&) \
376 { return WX_STR_CALL(forString, wxString(s1), wxString(s2)); } \
378 inline rettype WX_STR_DECL(name, const wxWCharBuffer&, const wchar_t *) \
379 { return WX_STR_CALL(crtW, s1.data(), s2); } \
380 inline rettype WX_STR_DECL(name, const wxWCharBuffer&, const char *) \
381 { return WX_STR_CALL(forString, wxString(s1), wxString(s2)); } \
382 inline rettype WX_STR_DECL(name, const wxWCharBuffer&, const wxWCharBuffer&) \
383 { return WX_STR_CALL(crtW, s1.data(), s2.data()); } \
384 inline rettype WX_STR_DECL(name, const wxWCharBuffer&, const wxCharBuffer&) \
385 { return WX_STR_CALL(forString, wxString(s1), wxString(s2)); } \
387 inline rettype WX_STR_DECL(name, const wxString&, const char*) \
388 { return WX_STR_CALL(forString, s1, s2); } \
389 inline rettype WX_STR_DECL(name, const wxString&, const wchar_t*) \
390 { return WX_STR_CALL(forString, s1, s2); } \
391 inline rettype WX_STR_DECL(name, const wxString&, const wxCharBuffer&) \
392 { return WX_STR_CALL(forString, s1, s2); } \
393 inline rettype WX_STR_DECL(name, const wxString&, const wxWCharBuffer&) \
394 { return WX_STR_CALL(forString, s1, s2); } \
395 inline rettype WX_STR_DECL(name, const wxString&, const wxString&) \
396 { return WX_STR_CALL(forString, s1, s2); } \
397 inline rettype WX_STR_DECL(name, const wxString&, const wxCStrData&) \
398 { return WX_STR_CALL(forString, s1, s2); } \
400 inline rettype WX_STR_DECL(name, const wxCStrData&, const char*) \
401 { return WX_STR_CALL(forString, s1.AsString(), s2); } \
402 inline rettype WX_STR_DECL(name, const wxCStrData&, const wchar_t*) \
403 { return WX_STR_CALL(forString, s1.AsString(), s2); } \
404 inline rettype WX_STR_DECL(name, const wxCStrData&, const wxCharBuffer&) \
405 { return WX_STR_CALL(forString, s1.AsString(), s2); } \
406 inline rettype WX_STR_DECL(name, const wxCStrData&, const wxWCharBuffer&) \
407 { return WX_STR_CALL(forString, s1.AsString(), s2); } \
408 inline rettype WX_STR_DECL(name, const wxCStrData&, const wxString&) \
409 { return WX_STR_CALL(forString, s1.AsString(), s2); } \
410 inline rettype WX_STR_DECL(name, const wxCStrData&, const wxCStrData&) \
411 { return WX_STR_CALL(forString, s1.AsString(), s2); }
413 // This defines strcmp-like function, i.e. one returning the result of
414 // comparison; see WX_STR_FUNC_NO_INVERT for explanation of the arguments
415 #define WX_STRCMP_FUNC(name, crtA, crtW, forString) \
416 WX_STR_FUNC_NO_INVERT(int, name, crtA, crtW, forString) \
418 inline int WX_STR_DECL(name, const char *, const wxCStrData&) \
419 { return -WX_STR_CALL(forString, s2.AsString(), s1); } \
420 inline int WX_STR_DECL(name, const char *, const wxString&) \
421 { return -WX_STR_CALL(forString, s2, s1); } \
423 inline int WX_STR_DECL(name, const wchar_t *, const wxCStrData&) \
424 { return -WX_STR_CALL(forString, s2.AsString(), s1); } \
425 inline int WX_STR_DECL(name, const wchar_t *, const wxString&) \
426 { return -WX_STR_CALL(forString, s2, s1); } \
428 inline int WX_STR_DECL(name, const wxCharBuffer&, const wxCStrData&) \
429 { return -WX_STR_CALL(forString, s2.AsString(), s1.data()); } \
430 inline int WX_STR_DECL(name, const wxCharBuffer&, const wxString&) \
431 { return -WX_STR_CALL(forString, s2, s1.data()); } \
433 inline int WX_STR_DECL(name, const wxWCharBuffer&, const wxCStrData&) \
434 { return -WX_STR_CALL(forString, s2.AsString(), s1.data()); } \
435 inline int WX_STR_DECL(name, const wxWCharBuffer&, const wxString&) \
436 { return -WX_STR_CALL(forString, s2, s1.data()); }
439 // This defines a string function that is *not* strcmp-like, i.e. doesn't
440 // return the result of comparison and so if the second argument is a string,
441 // it has to be converted to char* or wchar_t*
442 #define WX_STR_FUNC(rettype, name, crtA, crtW, forString) \
443 WX_STR_FUNC_NO_INVERT(rettype, name, crtA, crtW, forString) \
445 inline rettype WX_STR_DECL(name, const char *, const wxCStrData&) \
446 { return WX_STR_CALL(crtA, s1, s2.AsCharBuf()); } \
447 inline rettype WX_STR_DECL(name, const char *, const wxString&) \
448 { return WX_STR_CALL(crtA, s1, s2.mb_str()); } \
450 inline rettype WX_STR_DECL(name, const wchar_t *, const wxCStrData&) \
451 { return WX_STR_CALL(crtW, s1, s2.AsWCharBuf()); } \
452 inline rettype WX_STR_DECL(name, const wchar_t *, const wxString&) \
453 { return WX_STR_CALL(crtW, s1, s2.wc_str()); } \
455 inline rettype WX_STR_DECL(name, const wxCharBuffer&, const wxCStrData&) \
456 { return WX_STR_CALL(crtA, s1.data(), s2.AsCharBuf()); } \
457 inline rettype WX_STR_DECL(name, const wxCharBuffer&, const wxString&) \
458 { return WX_STR_CALL(crtA, s1.data(), s2.mb_str()); } \
460 inline rettype WX_STR_DECL(name, const wxWCharBuffer&, const wxCStrData&) \
461 { return WX_STR_CALL(crtW, s1.data(), s2.AsWCharBuf()); } \
462 inline rettype WX_STR_DECL(name, const wxWCharBuffer&, const wxString&) \
463 { return WX_STR_CALL(crtW, s1.data(), s2.wc_str()); }
466 inline int wxStrcmp_String(const wxString
& s1
, const T
& s2
)
467 { return s1
.compare(s2
); }
468 WX_STRCMP_FUNC(wxStrcmp
, wxCRT_StrcmpA
, wxCRT_StrcmpW
, wxStrcmp_String
)
471 inline int wxStricmp_String(const wxString
& s1
, const T
& s2
)
472 { return s1
.CmpNoCase(s2
); }
473 WX_STRCMP_FUNC(wxStricmp
, wxCRT_StricmpA
, wxCRT_StricmpW
, wxStricmp_String
)
475 #if defined(wxCRT_StrcollA) && defined(wxCRT_StrcollW)
477 // GCC 3.3 and other compilers have a bug that causes it to fail compilation if
478 // the template's implementation uses overloaded function declared later (see
479 // the wxStrcoll() call in wxStrcoll_String<T>()), so we have to
480 // forward-declare the template and implement it below WX_STRCMP_FUNC. OTOH,
481 // this fails to compile with VC6, so don't do it for VC. It also causes
482 // problems with GCC visibility in newer GCC versions.
483 #if !(defined(__VISUALC__) || wxCHECK_GCC_VERSION(3,4))
485 inline int wxStrcoll_String(const wxString
& s1
, const T
& s2
);
486 WX_STRCMP_FUNC(wxStrcoll
, wxCRT_StrcollA
, wxCRT_StrcollW
, wxStrcoll_String
)
487 #endif // !__VISUALC__
490 inline int wxStrcoll_String(const wxString
& s1
, const T
& s2
)
493 // NB: strcoll() doesn't work correctly on UTF-8 strings, so we have to use
494 // wc_str() even if wxUSE_UNICODE_UTF8; the (const wchar_t*) cast is
495 // there just as optimization to avoid going through
496 // wxStrcoll<wxWCharBuffer>:
497 return wxStrcoll((const wchar_t*)s1
.wc_str(), s2
);
499 return wxStrcoll((const char*)s1
.mb_str(), s2
);
503 #if defined(__VISUALC__) || wxCHECK_GCC_VERSION(3,4)
504 // this is exactly the same WX_STRCMP_FUNC line as above wxStrcoll_String<>
505 WX_STRCMP_FUNC(wxStrcoll
, wxCRT_StrcollA
, wxCRT_StrcollW
, wxStrcoll_String
)
508 #endif // defined(wxCRT_Strcoll[AW])
511 inline size_t wxStrspn_String(const wxString
& s1
, const T
& s2
)
513 size_t pos
= s1
.find_first_not_of(s2
);
514 return pos
== wxString::npos
? s1
.length() : pos
;
516 WX_STR_FUNC(size_t, wxStrspn
, wxCRT_StrspnA
, wxCRT_StrspnW
, wxStrspn_String
)
519 inline size_t wxStrcspn_String(const wxString
& s1
, const T
& s2
)
521 size_t pos
= s1
.find_first_of(s2
);
522 return pos
== wxString::npos
? s1
.length() : pos
;
524 WX_STR_FUNC(size_t, wxStrcspn
, wxCRT_StrcspnA
, wxCRT_StrcspnW
, wxStrcspn_String
)
528 #define WX_STR_DECL(name, T1, T2) name(T1 s1, T2 s2, size_t n)
529 #define WX_STR_CALL(func, a1, a2) func(a1, a2, n)
532 inline int wxStrncmp_String(const wxString
& s1
, const T
& s2
, size_t n
)
533 { return s1
.compare(0, n
, s2
, 0, n
); }
534 WX_STRCMP_FUNC(wxStrncmp
, wxCRT_StrncmpA
, wxCRT_StrncmpW
, wxStrncmp_String
)
537 inline int wxStrnicmp_String(const wxString
& s1
, const T
& s2
, size_t n
)
538 { return s1
.substr(0, n
).CmpNoCase(wxString(s2
).substr(0, n
)); }
539 WX_STRCMP_FUNC(wxStrnicmp
, wxCRT_StrnicmpA
, wxCRT_StrnicmpW
, wxStrnicmp_String
)
543 #undef WX_STRCMP_FUNC
545 #undef WX_STR_FUNC_NO_INVERT
547 #if defined(wxCRT_StrxfrmA) && defined(wxCRT_StrxfrmW)
549 inline size_t wxStrxfrm(char *dest
, const char *src
, size_t n
)
550 { return wxCRT_StrxfrmA(dest
, src
, n
); }
551 inline size_t wxStrxfrm(wchar_t *dest
, const wchar_t *src
, size_t n
)
552 { return wxCRT_StrxfrmW(dest
, src
, n
); }
554 inline size_t wxStrxfrm(T
*dest
, const wxCharTypeBuffer
<T
>& src
, size_t n
)
555 { return wxStrxfrm(dest
, src
.data(), n
); }
556 inline size_t wxStrxfrm(char *dest
, const wxString
& src
, size_t n
)
557 { return wxCRT_StrxfrmA(dest
, src
.mb_str(), n
); }
558 inline size_t wxStrxfrm(wchar_t *dest
, const wxString
& src
, size_t n
)
559 { return wxCRT_StrxfrmW(dest
, src
.wc_str(), n
); }
560 inline size_t wxStrxfrm(char *dest
, const wxCStrData
& src
, size_t n
)
561 { return wxCRT_StrxfrmA(dest
, src
.AsCharBuf(), n
); }
562 inline size_t wxStrxfrm(wchar_t *dest
, const wxCStrData
& src
, size_t n
)
563 { return wxCRT_StrxfrmW(dest
, src
.AsWCharBuf(), n
); }
565 #endif // defined(wxCRT_Strxfrm[AW])
567 inline char *wxStrtok(char *str
, const char *delim
, char **saveptr
)
568 { return wxCRT_StrtokA(str
, delim
, saveptr
); }
569 inline wchar_t *wxStrtok(wchar_t *str
, const wchar_t *delim
, wchar_t **saveptr
)
570 { return wxCRT_StrtokW(str
, delim
, saveptr
); }
572 inline T
*wxStrtok(T
*str
, const wxCharTypeBuffer
<T
>& delim
, T
**saveptr
)
573 { return wxStrtok(str
, delim
.data(), saveptr
); }
574 inline char *wxStrtok(char *str
, const wxCStrData
& delim
, char **saveptr
)
575 { return wxCRT_StrtokA(str
, delim
.AsCharBuf(), saveptr
); }
576 inline wchar_t *wxStrtok(wchar_t *str
, const wxCStrData
& delim
, wchar_t **saveptr
)
577 { return wxCRT_StrtokW(str
, delim
.AsWCharBuf(), saveptr
); }
578 inline char *wxStrtok(char *str
, const wxString
& delim
, char **saveptr
)
579 { return wxCRT_StrtokA(str
, delim
.mb_str(), saveptr
); }
580 inline wchar_t *wxStrtok(wchar_t *str
, const wxString
& delim
, wchar_t **saveptr
)
581 { return wxCRT_StrtokW(str
, delim
.wc_str(), saveptr
); }
583 inline const char *wxStrstr(const char *haystack
, const char *needle
)
584 { return wxCRT_StrstrA(haystack
, needle
); }
585 inline const wchar_t *wxStrstr(const wchar_t *haystack
, const wchar_t *needle
)
586 { return wxCRT_StrstrW(haystack
, needle
); }
587 inline const char *wxStrstr(const char *haystack
, const wxString
& needle
)
588 { return wxCRT_StrstrA(haystack
, needle
.mb_str()); }
589 inline const wchar_t *wxStrstr(const wchar_t *haystack
, const wxString
& needle
)
590 { return wxCRT_StrstrW(haystack
, needle
.wc_str()); }
591 // these functions return char* pointer into the non-temporary conversion buffer
592 // used by c_str()'s implicit conversion to char*, for ANSI build compatibility
593 inline const char *wxStrstr(const wxString
& haystack
, const wxString
& needle
)
594 { return wxCRT_StrstrA(haystack
.c_str(), needle
.mb_str()); }
595 inline const char *wxStrstr(const wxCStrData
& haystack
, const wxString
& needle
)
596 { return wxCRT_StrstrA(haystack
, needle
.mb_str()); }
597 inline const char *wxStrstr(const wxCStrData
& haystack
, const wxCStrData
& needle
)
598 { return wxCRT_StrstrA(haystack
, needle
.AsCharBuf()); }
599 // if 'needle' is char/wchar_t, then the same is probably wanted as return value
600 inline const char *wxStrstr(const wxString
& haystack
, const char *needle
)
601 { return wxCRT_StrstrA(haystack
.c_str(), needle
); }
602 inline const char *wxStrstr(const wxCStrData
& haystack
, const char *needle
)
603 { return wxCRT_StrstrA(haystack
, needle
); }
604 inline const wchar_t *wxStrstr(const wxString
& haystack
, const wchar_t *needle
)
605 { return wxCRT_StrstrW(haystack
.c_str(), needle
); }
606 inline const wchar_t *wxStrstr(const wxCStrData
& haystack
, const wchar_t *needle
)
607 { return wxCRT_StrstrW(haystack
, needle
); }
609 inline const char *wxStrchr(const char *s
, char c
)
610 { return wxCRT_StrchrA(s
, c
); }
611 inline const wchar_t *wxStrchr(const wchar_t *s
, wchar_t c
)
612 { return wxCRT_StrchrW(s
, c
); }
613 inline const char *wxStrrchr(const char *s
, char c
)
614 { return wxCRT_StrrchrA(s
, c
); }
615 inline const wchar_t *wxStrrchr(const wchar_t *s
, wchar_t c
)
616 { return wxCRT_StrrchrW(s
, c
); }
617 inline const char *wxStrchr(const char *s
, const wxUniChar
& c
)
618 { return wxCRT_StrchrA(s
, (char)c
); }
619 inline const wchar_t *wxStrchr(const wchar_t *s
, const wxUniChar
& c
)
620 { return wxCRT_StrchrW(s
, (wchar_t)c
); }
621 inline const char *wxStrrchr(const char *s
, const wxUniChar
& c
)
622 { return wxCRT_StrrchrA(s
, (char)c
); }
623 inline const wchar_t *wxStrrchr(const wchar_t *s
, const wxUniChar
& c
)
624 { return wxCRT_StrrchrW(s
, (wchar_t)c
); }
625 inline const char *wxStrchr(const char *s
, const wxUniCharRef
& c
)
626 { return wxCRT_StrchrA(s
, (char)c
); }
627 inline const wchar_t *wxStrchr(const wchar_t *s
, const wxUniCharRef
& c
)
628 { return wxCRT_StrchrW(s
, (wchar_t)c
); }
629 inline const char *wxStrrchr(const char *s
, const wxUniCharRef
& c
)
630 { return wxCRT_StrrchrA(s
, (char)c
); }
631 inline const wchar_t *wxStrrchr(const wchar_t *s
, const wxUniCharRef
& c
)
632 { return wxCRT_StrrchrW(s
, (wchar_t)c
); }
634 inline const T
* wxStrchr(const wxCharTypeBuffer
<T
>& s
, T c
)
635 { return wxStrchr(s
.data(), c
); }
637 inline const T
* wxStrrchr(const wxCharTypeBuffer
<T
>& s
, T c
)
638 { return wxStrrchr(s
.data(), c
); }
640 inline const T
* wxStrchr(const wxCharTypeBuffer
<T
>& s
, const wxUniChar
& c
)
641 { return wxStrchr(s
.data(), (T
)c
); }
643 inline const T
* wxStrrchr(const wxCharTypeBuffer
<T
>& s
, const wxUniChar
& c
)
644 { return wxStrrchr(s
.data(), (T
)c
); }
646 inline const T
* wxStrchr(const wxCharTypeBuffer
<T
>& s
, const wxUniCharRef
& c
)
647 { return wxStrchr(s
.data(), (T
)c
); }
649 inline const T
* wxStrrchr(const wxCharTypeBuffer
<T
>& s
, const wxUniCharRef
& c
)
650 { return wxStrrchr(s
.data(), (T
)c
); }
651 // these functions return char* pointer into the non-temporary conversion buffer
652 // used by c_str()'s implicit conversion to char*, for ANSI build compatibility
653 inline const char* wxStrchr(const wxString
& s
, char c
)
654 { return wxCRT_StrchrA((const char*)s
.c_str(), c
); }
655 inline const char* wxStrrchr(const wxString
& s
, char c
)
656 { return wxCRT_StrrchrA((const char*)s
.c_str(), c
); }
657 inline const char* wxStrchr(const wxString
& s
, int c
)
658 { return wxCRT_StrchrA((const char*)s
.c_str(), c
); }
659 inline const char* wxStrrchr(const wxString
& s
, int c
)
660 { return wxCRT_StrrchrA((const char*)s
.c_str(), c
); }
661 inline const char* wxStrchr(const wxString
& s
, const wxUniChar
& c
)
662 { return wxCRT_StrchrA((const char*)s
.c_str(), (char)c
); }
663 inline const char* wxStrrchr(const wxString
& s
, const wxUniChar
& c
)
664 { return wxCRT_StrrchrA((const char*)s
.c_str(), (char)c
); }
665 inline const char* wxStrchr(const wxString
& s
, const wxUniCharRef
& c
)
666 { return wxCRT_StrchrA((const char*)s
.c_str(), (char)c
); }
667 inline const char* wxStrrchr(const wxString
& s
, const wxUniCharRef
& c
)
668 { return wxCRT_StrrchrA((const char*)s
.c_str(), (char)c
); }
669 inline const wchar_t* wxStrchr(const wxString
& s
, wchar_t c
)
670 { return wxCRT_StrchrW((const wchar_t*)s
.c_str(), c
); }
671 inline const wchar_t* wxStrrchr(const wxString
& s
, wchar_t c
)
672 { return wxCRT_StrrchrW((const wchar_t*)s
.c_str(), c
); }
673 inline const char* wxStrchr(const wxCStrData
& s
, char c
)
674 { return wxCRT_StrchrA(s
.AsChar(), c
); }
675 inline const char* wxStrrchr(const wxCStrData
& s
, char c
)
676 { return wxCRT_StrrchrA(s
.AsChar(), c
); }
677 inline const char* wxStrchr(const wxCStrData
& s
, int c
)
678 { return wxCRT_StrchrA(s
.AsChar(), c
); }
679 inline const char* wxStrrchr(const wxCStrData
& s
, int c
)
680 { return wxCRT_StrrchrA(s
.AsChar(), c
); }
681 inline const char* wxStrchr(const wxCStrData
& s
, const wxUniChar
& c
)
682 { return wxCRT_StrchrA(s
.AsChar(), (char)c
); }
683 inline const char* wxStrrchr(const wxCStrData
& s
, const wxUniChar
& c
)
684 { return wxCRT_StrrchrA(s
.AsChar(), (char)c
); }
685 inline const char* wxStrchr(const wxCStrData
& s
, const wxUniCharRef
& c
)
686 { return wxCRT_StrchrA(s
.AsChar(), (char)c
); }
687 inline const char* wxStrrchr(const wxCStrData
& s
, const wxUniCharRef
& c
)
688 { return wxCRT_StrrchrA(s
.AsChar(), (char)c
); }
689 inline const wchar_t* wxStrchr(const wxCStrData
& s
, wchar_t c
)
690 { return wxCRT_StrchrW(s
.AsWChar(), c
); }
691 inline const wchar_t* wxStrrchr(const wxCStrData
& s
, wchar_t c
)
692 { return wxCRT_StrrchrW(s
.AsWChar(), c
); }
694 inline const char *wxStrpbrk(const char *s
, const char *accept
)
695 { return wxCRT_StrpbrkA(s
, accept
); }
696 inline const wchar_t *wxStrpbrk(const wchar_t *s
, const wchar_t *accept
)
697 { return wxCRT_StrpbrkW(s
, accept
); }
698 inline const char *wxStrpbrk(const char *s
, const wxString
& accept
)
699 { return wxCRT_StrpbrkA(s
, accept
.mb_str()); }
700 inline const char *wxStrpbrk(const char *s
, const wxCStrData
& accept
)
701 { return wxCRT_StrpbrkA(s
, accept
.AsCharBuf()); }
702 inline const wchar_t *wxStrpbrk(const wchar_t *s
, const wxString
& accept
)
703 { return wxCRT_StrpbrkW(s
, accept
.wc_str()); }
704 inline const wchar_t *wxStrpbrk(const wchar_t *s
, const wxCStrData
& accept
)
705 { return wxCRT_StrpbrkW(s
, accept
.AsWCharBuf()); }
706 inline const char *wxStrpbrk(const wxString
& s
, const wxString
& accept
)
707 { return wxCRT_StrpbrkA(s
.c_str(), accept
.mb_str()); }
708 inline const char *wxStrpbrk(const wxString
& s
, const char *accept
)
709 { return wxCRT_StrpbrkA(s
.c_str(), accept
); }
710 inline const wchar_t *wxStrpbrk(const wxString
& s
, const wchar_t *accept
)
711 { return wxCRT_StrpbrkW(s
.wc_str(), accept
); }
712 inline const char *wxStrpbrk(const wxString
& s
, const wxCStrData
& accept
)
713 { return wxCRT_StrpbrkA(s
.c_str(), accept
.AsCharBuf()); }
714 inline const char *wxStrpbrk(const wxCStrData
& s
, const wxString
& accept
)
715 { return wxCRT_StrpbrkA(s
.AsChar(), accept
.mb_str()); }
716 inline const char *wxStrpbrk(const wxCStrData
& s
, const char *accept
)
717 { return wxCRT_StrpbrkA(s
.AsChar(), accept
); }
718 inline const wchar_t *wxStrpbrk(const wxCStrData
& s
, const wchar_t *accept
)
719 { return wxCRT_StrpbrkW(s
.AsWChar(), accept
); }
720 inline const char *wxStrpbrk(const wxCStrData
& s
, const wxCStrData
& accept
)
721 { return wxCRT_StrpbrkA(s
.AsChar(), accept
.AsCharBuf()); }
722 template <typename S
, typename T
>
723 inline const T
*wxStrpbrk(const S
& s
, const wxCharTypeBuffer
<T
>& accept
)
724 { return wxStrpbrk(s
, accept
.data()); }
727 /* inlined non-const versions */
728 inline char *wxStrstr(char *haystack
, const char *needle
)
729 { return (char *)wxStrstr((const char *)haystack
, needle
); }
730 inline wchar_t *wxStrstr(wchar_t *haystack
, const wchar_t *needle
)
731 { return (wchar_t *)wxStrstr((const wchar_t *)haystack
, needle
); }
732 inline char *wxStrstr(char *haystack
, const wxString
& needle
)
733 { return (char *)wxStrstr((const char *)haystack
, needle
); }
734 inline wchar_t *wxStrstr(wchar_t *haystack
, const wxString
& needle
)
735 { return (wchar_t *)wxStrstr((const wchar_t *)haystack
, needle
); }
737 inline char * wxStrchr(char *s
, char c
)
738 { return (char *)wxStrchr((const char *)s
, c
); }
739 inline char * wxStrrchr(char *s
, char c
)
740 { return (char *)wxStrrchr((const char *)s
, c
); }
741 inline wchar_t * wxStrchr(wchar_t *s
, wchar_t c
)
742 { return (wchar_t *)wxStrchr((const wchar_t *)s
, c
); }
743 inline wchar_t * wxStrrchr(wchar_t *s
, wchar_t c
)
744 { return (wchar_t *)wxStrrchr((const wchar_t *)s
, c
); }
746 inline char * wxStrpbrk(char *s
, const char *accept
)
747 { return (char *)wxStrpbrk((const char *)s
, accept
); }
748 inline wchar_t * wxStrpbrk(wchar_t *s
, const wchar_t *accept
)
749 { return (wchar_t *)wxStrpbrk((const wchar_t *)s
, accept
); }
750 inline char * wxStrpbrk(char *s
, const wxString
& accept
)
751 { return (char *)wxStrpbrk((const char *)s
, accept
); }
752 inline wchar_t * wxStrpbrk(wchar_t *s
, const wxString
& accept
)
753 { return (wchar_t *)wxStrpbrk((const wchar_t *)s
, accept
); }
756 // ----------------------------------------------------------------------------
758 // ----------------------------------------------------------------------------
760 // NB: using fn_str() for mode is a hack to get the same type (char*/wchar_t*)
761 // as needed, the conversion itself doesn't matter, it's ASCII
762 inline FILE *wxFopen(const wxString
& path
, const wxString
& mode
)
763 { return wxCRT_Fopen(path
.fn_str(), mode
.fn_str()); }
764 inline FILE *wxFreopen(const wxString
& path
, const wxString
& mode
, FILE *stream
)
765 { return wxCRT_Freopen(path
.fn_str(), mode
.fn_str(), stream
); }
766 inline int wxRemove(const wxString
& path
)
767 { return wxCRT_Remove(path
.fn_str()); }
768 inline int wxRename(const wxString
& oldpath
, const wxString
& newpath
)
769 { return wxCRT_Rename(oldpath
.fn_str(), newpath
.fn_str()); }
771 extern WXDLLIMPEXP_BASE
int wxPuts(const wxString
& s
);
772 extern WXDLLIMPEXP_BASE
int wxFputs(const wxString
& s
, FILE *stream
);
773 extern WXDLLIMPEXP_BASE
void wxPerror(const wxString
& s
);
775 extern WXDLLIMPEXP_BASE
int wxFputc(const wxUniChar
& c
, FILE *stream
);
777 #define wxPutc(c, stream) wxFputc(c, stream)
778 #define wxPutchar(c) wxFputc(c, stdout)
779 #define wxFputchar(c) wxPutchar(c)
781 // NB: We only provide ANSI version of fgets() because fgetws() interprets the
782 // stream according to current locale, which is rarely what is desired.
783 inline char *wxFgets(char *s
, int size
, FILE *stream
)
784 { return wxCRT_FgetsA(s
, size
, stream
); }
785 // This version calls ANSI version and converts the string using wxConvLibc
786 extern WXDLLIMPEXP_BASE
wchar_t *wxFgets(wchar_t *s
, int size
, FILE *stream
);
788 #define wxGets(s) wxGets_is_insecure_and_dangerous_use_wxFgets_instead
790 // NB: We only provide ANSI versions of this for the same reasons as in the
791 // case of wxFgets() above
792 inline int wxFgetc(FILE *stream
) { return wxCRT_FgetcA(stream
); }
793 inline int wxUngetc(int c
, FILE *stream
) { return wxCRT_UngetcA(c
, stream
); }
795 #define wxGetc(stream) wxFgetc(stream)
796 #define wxGetchar() wxFgetc(stdin)
797 #define wxFgetchar() wxGetchar()
799 // ----------------------------------------------------------------------------
800 // stdlib.h functions
801 // ----------------------------------------------------------------------------
804 inline int wxAtoi(const wxString
& str
) { return wxCRT_AtoiW(str
.wc_str()); }
806 inline int wxAtoi(const wxString
& str
) { return wxCRT_AtoiA(str
.mb_str()); }
810 inline long wxAtol(const wxString
& str
) { return wxCRT_AtolW(str
.wc_str()); }
812 inline long wxAtol(const wxString
& str
) { return wxCRT_AtolA(str
.mb_str()); }
816 inline double wxAtof(const wxString
& str
) { return wxCRT_AtofW(str
.wc_str()); }
818 inline double wxAtof(const wxString
& str
) { return wxCRT_AtofA(str
.mb_str()); }
821 inline double wxStrtod(const char *nptr
, char **endptr
)
822 { return wxCRT_StrtodA(nptr
, endptr
); }
823 inline double wxStrtod(const wchar_t *nptr
, wchar_t **endptr
)
824 { return wxCRT_StrtodW(nptr
, endptr
); }
826 inline double wxStrtod(const wxCharTypeBuffer
<T
>& nptr
, T
**endptr
)
827 { return wxStrtod(nptr
.data(), endptr
); }
829 // We implement wxStrto*() like this so that the code compiles when NULL is
830 // passed in - - if we had just char** and wchar_t** overloads for 'endptr', it
831 // would be ambiguous. The solution is to use a template so that endptr can be
832 // any type: when NULL constant is used, the type will be int and we can handle
833 // that case specially. Otherwise, we infer the type that 'nptr' should be
834 // converted to from the type of 'endptr'. We need wxStrtoxCharType<T> template
835 // to make the code compile even for T=int (that's the case when it's not going
836 // to be ever used, but it still has to compile).
837 template<typename T
> struct wxStrtoxCharType
{};
838 template<> struct wxStrtoxCharType
<char**>
840 typedef const char* Type
;
841 static char** AsPointer(char **p
) { return p
; }
843 template<> struct wxStrtoxCharType
<wchar_t**>
845 typedef const wchar_t* Type
;
846 static wchar_t** AsPointer(wchar_t **p
) { return p
; }
848 template<> struct wxStrtoxCharType
<int>
850 typedef const char* Type
; /* this one is never used */
851 static char** AsPointer(int WXUNUSED_UNLESS_DEBUG(p
))
853 wxASSERT_MSG( p
== 0, "passing non-NULL int is invalid" );
859 inline double wxStrtod(const wxString
& nptr
, T endptr
)
863 // when we don't care about endptr, use the string representation that
864 // doesn't require any conversion (it doesn't matter for this function
865 // even if its UTF-8):
866 return wxStrtod(nptr
.wx_str(), (wxStringCharType
**)NULL
);
870 // note that it is important to use c_str() here and not mb_str() or
871 // wc_str(), because we store the pointer into (possibly converted)
872 // buffer in endptr and so it must be valid even when wxStrtod() returns
873 typedef typename wxStrtoxCharType
<T
>::Type CharType
;
874 return wxStrtod((CharType
)nptr
.c_str(),
875 wxStrtoxCharType
<T
>::AsPointer(endptr
));
879 inline double wxStrtod(const wxCStrData
& nptr
, T endptr
)
880 { return wxStrtod(nptr
.AsString(), endptr
); }
883 #define WX_STRTOX_FUNC(rettype, name, implA, implW) \
884 /* see wxStrtod() above for explanation of this code: */ \
885 inline rettype name(const char *nptr, char **endptr, int base) \
886 { return implA(nptr, endptr, base); } \
887 inline rettype name(const wchar_t *nptr, wchar_t **endptr, int base) \
888 { return implW(nptr, endptr, base); } \
889 template<typename T> \
890 inline rettype name(const wxCharTypeBuffer<T>& nptr, T **endptr, int base)\
891 { return name(nptr.data(), endptr); } \
892 template<typename T> \
893 inline rettype name(const wxString& nptr, T endptr, int base) \
896 return name(nptr.wx_str(), (wxStringCharType**)NULL, base); \
899 typedef typename wxStrtoxCharType<T>::Type CharType; \
900 return name((CharType)nptr.c_str(), \
901 wxStrtoxCharType<T>::AsPointer(endptr), \
905 template<typename T> \
906 inline rettype name(const wxCStrData& nptr, T endptr, int base) \
907 { return name(nptr.AsString(), endptr, base); }
909 WX_STRTOX_FUNC(long, wxStrtol
, wxCRT_StrtolA
, wxCRT_StrtolW
)
910 WX_STRTOX_FUNC(unsigned long, wxStrtoul
, wxCRT_StrtoulA
, wxCRT_StrtoulW
)
912 WX_STRTOX_FUNC(wxLongLong_t
, wxStrtoll
, wxCRT_StrtollA
, wxCRT_StrtollW
)
913 WX_STRTOX_FUNC(wxULongLong_t
, wxStrtoull
, wxCRT_StrtoullA
, wxCRT_StrtoullW
)
914 #endif // wxLongLong_t
916 #undef WX_STRTOX_FUNC
919 // there is no command interpreter under CE, hence no system()
922 // mingw32 doesn't provide _tsystem() even though it provides other stdlib.h
923 // functions in their wide versions
925 inline int wxSystem(const wxString
& str
) { return wxCRT_SystemW(str
.wc_str()); }
927 inline int wxSystem(const wxString
& str
) { return wxCRT_SystemA(str
.mb_str()); }
930 #endif // !__WXWINCE__/__WXWINCE__
932 inline char* wxGetenv(const char *name
) { return wxCRT_GetenvA(name
); }
933 inline wchar_t* wxGetenv(const wchar_t *name
) { return wxCRT_GetenvW(name
); }
934 inline char* wxGetenv(const wxString
& name
) { return wxCRT_GetenvA(name
.mb_str()); }
935 inline char* wxGetenv(const wxCStrData
& name
) { return wxCRT_GetenvA(name
.AsCharBuf()); }
936 inline char* wxGetenv(const wxCharBuffer
& name
) { return wxCRT_GetenvA(name
.data()); }
937 inline wchar_t* wxGetenv(const wxWCharBuffer
& name
) { return wxCRT_GetenvW(name
.data()); }
939 // ----------------------------------------------------------------------------
941 // ----------------------------------------------------------------------------
943 inline size_t wxStrftime(char *s
, size_t max
,
944 const wxString
& format
, const struct tm
*tm
)
945 { return wxCRT_StrftimeA(s
, max
, format
.mb_str(), tm
); }
947 inline size_t wxStrftime(wchar_t *s
, size_t max
,
948 const wxString
& format
, const struct tm
*tm
)
949 { return wxCRT_StrftimeW(s
, max
, format
.wc_str(), tm
); }
951 // NB: we can't provide both char* and wchar_t* versions for obvious reasons
952 // and returning wxString wouldn't work either (it would be immediately
953 // destroyed and if assigned to char*/wchar_t*, the pointer would be
954 // invalid), so we only keep ASCII version, because the returned value
955 // is always ASCII anyway
956 #define wxAsctime asctime
957 #define wxCtime ctime
960 // ----------------------------------------------------------------------------
962 // ----------------------------------------------------------------------------
964 // FIXME-UTF8: we'd be better off implementing these ourselves, as the CRT
965 // version is locale-dependent
966 // FIXME-UTF8: these don't work when EOF is passed in because of wxUniChar,
967 // is this OK or not?
969 inline bool wxIsalnum(const wxUniChar
& c
) { return wxCRT_IsalnumW(c
) != 0; }
970 inline bool wxIsalpha(const wxUniChar
& c
) { return wxCRT_IsalphaW(c
) != 0; }
971 inline bool wxIscntrl(const wxUniChar
& c
) { return wxCRT_IscntrlW(c
) != 0; }
972 inline bool wxIsdigit(const wxUniChar
& c
) { return wxCRT_IsdigitW(c
) != 0; }
973 inline bool wxIsgraph(const wxUniChar
& c
) { return wxCRT_IsgraphW(c
) != 0; }
974 inline bool wxIslower(const wxUniChar
& c
) { return wxCRT_IslowerW(c
) != 0; }
975 inline bool wxIsprint(const wxUniChar
& c
) { return wxCRT_IsprintW(c
) != 0; }
976 inline bool wxIspunct(const wxUniChar
& c
) { return wxCRT_IspunctW(c
) != 0; }
977 inline bool wxIsspace(const wxUniChar
& c
) { return wxCRT_IsspaceW(c
) != 0; }
978 inline bool wxIsupper(const wxUniChar
& c
) { return wxCRT_IsupperW(c
) != 0; }
979 inline bool wxIsxdigit(const wxUniChar
& c
) { return wxCRT_IsxdigitW(c
) != 0; }
981 inline wxUniChar
wxTolower(const wxUniChar
& c
) { return wxCRT_TolowerW(c
); }
982 inline wxUniChar
wxToupper(const wxUniChar
& c
) { return wxCRT_ToupperW(c
); }
984 #if WXWIN_COMPATIBILITY_2_8
985 // we had goofed and defined wxIsctrl() instead of (correct) wxIscntrl() in the
986 // initial versions of this header -- now it is too late to remove it so
987 // although we fixed the function/macro name above, still provide the
988 // backwards-compatible synonym.
989 wxDEPRECATED( inline int wxIsctrl(const wxUniChar
& c
) );
990 inline int wxIsctrl(const wxUniChar
& c
) { return wxIscntrl(c
); }
991 #endif // WXWIN_COMPATIBILITY_2_8
993 #endif /* _WX_WXCRT_H_ */