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 wchar_t/char overloads
186 #if defined(wxCRT_StrnlenA) && defined(wxCRT_StrnlenW)
187 inline size_t wxStrnlen(const char *str
, size_t maxlen
) { return wxCRT_StrnlenA(str
, maxlen
); }
188 inline size_t wxStrnlen(const wchar_t *str
, size_t maxlen
) { return wxCRT_StrnlenW(str
, maxlen
); }
190 // use unsafer wxStrlen:
191 inline size_t wxStrnlen(const char *str
, size_t maxlen
) { return wxCRT_StrlenA(str
); wxUnusedVar(maxlen
); }
192 inline size_t wxStrnlen(const wchar_t *str
, size_t maxlen
) { return wxCRT_StrlenW(str
); wxUnusedVar(maxlen
); }
195 // NB: these are defined in wxcrtbase.h, see the comment there
196 // inline char* wxStrdup(const char *s) { return wxStrdupA(s); }
197 // inline wchar_t* wxStrdup(const wchar_t *s) { return wxStrdupW(s); }
198 inline char* wxStrdup(const wxCharBuffer
& s
) { return wxStrdup(s
.data()); }
199 inline wchar_t* wxStrdup(const wxWCharBuffer
& s
) { return wxStrdup(s
.data()); }
200 inline char* wxStrdup(const wxString
& s
) { return wxStrdup(s
.mb_str()); }
201 inline char* wxStrdup(const wxCStrData
& s
) { return wxStrdup(s
.AsCharBuf()); }
203 inline char *wxStrcpy(char *dest
, const char *src
)
204 { return wxCRT_StrcpyA(dest
, src
); }
205 inline wchar_t *wxStrcpy(wchar_t *dest
, const wchar_t *src
)
206 { return wxCRT_StrcpyW(dest
, src
); }
207 inline char *wxStrcpy(char *dest
, const wxString
& src
)
208 { return wxCRT_StrcpyA(dest
, src
.mb_str()); }
209 inline char *wxStrcpy(char *dest
, const wxCStrData
& src
)
210 { return wxCRT_StrcpyA(dest
, src
.AsCharBuf()); }
211 inline char *wxStrcpy(char *dest
, const wxCharBuffer
& src
)
212 { return wxCRT_StrcpyA(dest
, src
.data()); }
213 inline wchar_t *wxStrcpy(wchar_t *dest
, const wxString
& src
)
214 { return wxCRT_StrcpyW(dest
, src
.wc_str()); }
215 inline wchar_t *wxStrcpy(wchar_t *dest
, const wxCStrData
& src
)
216 { return wxCRT_StrcpyW(dest
, src
.AsWCharBuf()); }
217 inline wchar_t *wxStrcpy(wchar_t *dest
, const wxWCharBuffer
& src
)
218 { return wxCRT_StrcpyW(dest
, src
.data()); }
219 inline char *wxStrcpy(char *dest
, const wchar_t *src
)
220 { return wxCRT_StrcpyA(dest
, wxConvLibc
.cWC2MB(src
)); }
221 inline wchar_t *wxStrcpy(wchar_t *dest
, const char *src
)
222 { return wxCRT_StrcpyW(dest
, wxConvLibc
.cMB2WC(src
)); }
224 inline char *wxStrncpy(char *dest
, const char *src
, size_t n
)
225 { return wxCRT_StrncpyA(dest
, src
, n
); }
226 inline wchar_t *wxStrncpy(wchar_t *dest
, const wchar_t *src
, size_t n
)
227 { return wxCRT_StrncpyW(dest
, src
, n
); }
228 inline char *wxStrncpy(char *dest
, const wxString
& src
, size_t n
)
229 { return wxCRT_StrncpyA(dest
, src
.mb_str(), n
); }
230 inline char *wxStrncpy(char *dest
, const wxCStrData
& src
, size_t n
)
231 { return wxCRT_StrncpyA(dest
, src
.AsCharBuf(), n
); }
232 inline char *wxStrncpy(char *dest
, const wxCharBuffer
& src
, size_t n
)
233 { return wxCRT_StrncpyA(dest
, src
.data(), n
); }
234 inline wchar_t *wxStrncpy(wchar_t *dest
, const wxString
& src
, size_t n
)
235 { return wxCRT_StrncpyW(dest
, src
.wc_str(), n
); }
236 inline wchar_t *wxStrncpy(wchar_t *dest
, const wxCStrData
& src
, size_t n
)
237 { return wxCRT_StrncpyW(dest
, src
.AsWCharBuf(), n
); }
238 inline wchar_t *wxStrncpy(wchar_t *dest
, const wxWCharBuffer
& src
, size_t n
)
239 { return wxCRT_StrncpyW(dest
, src
.data(), n
); }
240 inline char *wxStrncpy(char *dest
, const wchar_t *src
, size_t n
)
241 { return wxCRT_StrncpyA(dest
, wxConvLibc
.cWC2MB(src
), n
); }
242 inline wchar_t *wxStrncpy(wchar_t *dest
, const char *src
, size_t n
)
243 { return wxCRT_StrncpyW(dest
, wxConvLibc
.cMB2WC(src
), n
); }
245 // this is a function new in 2.9 so we don't care about backwards compatibility and
246 // so don't need to support wchar_t/char overloads
247 inline size_t wxStrlcpy(char *dest
, const char *src
, size_t n
)
249 const size_t len
= wxCRT_StrlenA(src
);
255 wxCRT_StrncpyA(dest
, src
, n
);
261 inline size_t wxStrlcpy(wchar_t *dest
, const wchar_t *src
, size_t n
)
263 const size_t len
= wxCRT_StrlenW(src
);
268 wxCRT_StrncpyW(dest
, src
, n
);
275 inline char *wxStrcat(char *dest
, const char *src
)
276 { return wxCRT_StrcatA(dest
, src
); }
277 inline wchar_t *wxStrcat(wchar_t *dest
, const wchar_t *src
)
278 { return wxCRT_StrcatW(dest
, src
); }
279 inline char *wxStrcat(char *dest
, const wxString
& src
)
280 { return wxCRT_StrcatA(dest
, src
.mb_str()); }
281 inline char *wxStrcat(char *dest
, const wxCStrData
& src
)
282 { return wxCRT_StrcatA(dest
, src
.AsCharBuf()); }
283 inline char *wxStrcat(char *dest
, const wxCharBuffer
& src
)
284 { return wxCRT_StrcatA(dest
, src
.data()); }
285 inline wchar_t *wxStrcat(wchar_t *dest
, const wxString
& src
)
286 { return wxCRT_StrcatW(dest
, src
.wc_str()); }
287 inline wchar_t *wxStrcat(wchar_t *dest
, const wxCStrData
& src
)
288 { return wxCRT_StrcatW(dest
, src
.AsWCharBuf()); }
289 inline wchar_t *wxStrcat(wchar_t *dest
, const wxWCharBuffer
& src
)
290 { return wxCRT_StrcatW(dest
, src
.data()); }
291 inline char *wxStrcat(char *dest
, const wchar_t *src
)
292 { return wxCRT_StrcatA(dest
, wxConvLibc
.cWC2MB(src
)); }
293 inline wchar_t *wxStrcat(wchar_t *dest
, const char *src
)
294 { return wxCRT_StrcatW(dest
, wxConvLibc
.cMB2WC(src
)); }
296 inline char *wxStrncat(char *dest
, const char *src
, size_t n
)
297 { return wxCRT_StrncatA(dest
, src
, n
); }
298 inline wchar_t *wxStrncat(wchar_t *dest
, const wchar_t *src
, size_t n
)
299 { return wxCRT_StrncatW(dest
, src
, n
); }
300 inline char *wxStrncat(char *dest
, const wxString
& src
, size_t n
)
301 { return wxCRT_StrncatA(dest
, src
.mb_str(), n
); }
302 inline char *wxStrncat(char *dest
, const wxCStrData
& src
, size_t n
)
303 { return wxCRT_StrncatA(dest
, src
.AsCharBuf(), n
); }
304 inline char *wxStrncat(char *dest
, const wxCharBuffer
& src
, size_t n
)
305 { return wxCRT_StrncatA(dest
, src
.data(), n
); }
306 inline wchar_t *wxStrncat(wchar_t *dest
, const wxString
& src
, size_t n
)
307 { return wxCRT_StrncatW(dest
, src
.wc_str(), n
); }
308 inline wchar_t *wxStrncat(wchar_t *dest
, const wxCStrData
& src
, size_t n
)
309 { return wxCRT_StrncatW(dest
, src
.AsWCharBuf(), n
); }
310 inline wchar_t *wxStrncat(wchar_t *dest
, const wxWCharBuffer
& src
, size_t n
)
311 { return wxCRT_StrncatW(dest
, src
.data(), n
); }
312 inline char *wxStrncat(char *dest
, const wchar_t *src
, size_t n
)
313 { return wxCRT_StrncatA(dest
, wxConvLibc
.cWC2MB(src
), n
); }
314 inline wchar_t *wxStrncat(wchar_t *dest
, const char *src
, size_t n
)
315 { return wxCRT_StrncatW(dest
, wxConvLibc
.cMB2WC(src
), n
); }
318 #define WX_STR_DECL(name, T1, T2) name(T1 s1, T2 s2)
319 #define WX_STR_CALL(func, a1, a2) func(a1, a2)
321 // This macro defines string function for all possible variants of arguments,
322 // except for those taking wxString or wxCStrData as second argument.
324 // rettype - return type
325 // name - name of the (overloaded) function to define
326 // crtA - function to call for char* versions (takes two arguments)
327 // crtW - ditto for wchar_t* function
328 // forString - function to call when the *first* argument is wxString;
329 // the second argument can be any string type, so this is
330 // typically a template
331 #define WX_STR_FUNC_NO_INVERT(rettype, name, crtA, crtW, forString) \
332 inline rettype WX_STR_DECL(name, const char *, const char *) \
333 { return WX_STR_CALL(crtA, s1, s2); } \
334 inline rettype WX_STR_DECL(name, const char *, const wchar_t *) \
335 { return WX_STR_CALL(forString, wxString(s1), wxString(s2)); } \
336 inline rettype WX_STR_DECL(name, const char *, const wxCharBuffer&) \
337 { return WX_STR_CALL(crtA, s1, s2.data()); } \
338 inline rettype WX_STR_DECL(name, const char *, const wxWCharBuffer&) \
339 { return WX_STR_CALL(forString, wxString(s1), s2.data()); } \
341 inline rettype WX_STR_DECL(name, const wchar_t *, const wchar_t *) \
342 { return WX_STR_CALL(crtW, s1, s2); } \
343 inline rettype WX_STR_DECL(name, const wchar_t *, const char *) \
344 { return WX_STR_CALL(forString, wxString(s1), wxString(s2)); } \
345 inline rettype WX_STR_DECL(name, const wchar_t *, const wxWCharBuffer&) \
346 { return WX_STR_CALL(crtW, s1, s2.data()); } \
347 inline rettype WX_STR_DECL(name, const wchar_t *, const wxCharBuffer&) \
348 { return WX_STR_CALL(forString, wxString(s1), s2.data()); } \
350 inline rettype WX_STR_DECL(name, const wxCharBuffer&, const char *) \
351 { return WX_STR_CALL(crtA, s1.data(), s2); } \
352 inline rettype WX_STR_DECL(name, const wxCharBuffer&, const wchar_t *) \
353 { return WX_STR_CALL(forString, wxString(s1), wxString(s2)); } \
354 inline rettype WX_STR_DECL(name, const wxCharBuffer&, const wxCharBuffer&)\
355 { return WX_STR_CALL(crtA, s1.data(), s2.data()); } \
356 inline rettype WX_STR_DECL(name, const wxCharBuffer&, const wxWCharBuffer&) \
357 { return WX_STR_CALL(forString, wxString(s1), wxString(s2)); } \
359 inline rettype WX_STR_DECL(name, const wxWCharBuffer&, const wchar_t *) \
360 { return WX_STR_CALL(crtW, s1.data(), s2); } \
361 inline rettype WX_STR_DECL(name, const wxWCharBuffer&, const char *) \
362 { return WX_STR_CALL(forString, wxString(s1), wxString(s2)); } \
363 inline rettype WX_STR_DECL(name, const wxWCharBuffer&, const wxWCharBuffer&) \
364 { return WX_STR_CALL(crtW, s1.data(), s2.data()); } \
365 inline rettype WX_STR_DECL(name, const wxWCharBuffer&, const wxCharBuffer&) \
366 { return WX_STR_CALL(forString, wxString(s1), wxString(s2)); } \
368 inline rettype WX_STR_DECL(name, const wxString&, const char*) \
369 { return WX_STR_CALL(forString, s1, s2); } \
370 inline rettype WX_STR_DECL(name, const wxString&, const wchar_t*) \
371 { return WX_STR_CALL(forString, s1, s2); } \
372 inline rettype WX_STR_DECL(name, const wxString&, const wxCharBuffer&) \
373 { return WX_STR_CALL(forString, s1, s2); } \
374 inline rettype WX_STR_DECL(name, const wxString&, const wxWCharBuffer&) \
375 { return WX_STR_CALL(forString, s1, s2); } \
376 inline rettype WX_STR_DECL(name, const wxString&, const wxString&) \
377 { return WX_STR_CALL(forString, s1, s2); } \
378 inline rettype WX_STR_DECL(name, const wxString&, const wxCStrData&) \
379 { return WX_STR_CALL(forString, s1, s2); } \
381 inline rettype WX_STR_DECL(name, const wxCStrData&, const char*) \
382 { return WX_STR_CALL(forString, s1.AsString(), s2); } \
383 inline rettype WX_STR_DECL(name, const wxCStrData&, const wchar_t*) \
384 { return WX_STR_CALL(forString, s1.AsString(), s2); } \
385 inline rettype WX_STR_DECL(name, const wxCStrData&, const wxCharBuffer&) \
386 { return WX_STR_CALL(forString, s1.AsString(), s2); } \
387 inline rettype WX_STR_DECL(name, const wxCStrData&, const wxWCharBuffer&) \
388 { return WX_STR_CALL(forString, s1.AsString(), s2); } \
389 inline rettype WX_STR_DECL(name, const wxCStrData&, const wxString&) \
390 { return WX_STR_CALL(forString, s1.AsString(), s2); } \
391 inline rettype WX_STR_DECL(name, const wxCStrData&, const wxCStrData&) \
392 { return WX_STR_CALL(forString, s1.AsString(), s2); }
394 // This defines strcmp-like function, i.e. one returning the result of
395 // comparison; see WX_STR_FUNC_NO_INVERT for explanation of the arguments
396 #define WX_STRCMP_FUNC(name, crtA, crtW, forString) \
397 WX_STR_FUNC_NO_INVERT(int, name, crtA, crtW, forString) \
399 inline int WX_STR_DECL(name, const char *, const wxCStrData&) \
400 { return -WX_STR_CALL(forString, s2.AsString(), s1); } \
401 inline int WX_STR_DECL(name, const char *, const wxString&) \
402 { return -WX_STR_CALL(forString, s2, s1); } \
404 inline int WX_STR_DECL(name, const wchar_t *, const wxCStrData&) \
405 { return -WX_STR_CALL(forString, s2.AsString(), s1); } \
406 inline int WX_STR_DECL(name, const wchar_t *, const wxString&) \
407 { return -WX_STR_CALL(forString, s2, s1); } \
409 inline int WX_STR_DECL(name, const wxCharBuffer&, const wxCStrData&) \
410 { return -WX_STR_CALL(forString, s2.AsString(), s1.data()); } \
411 inline int WX_STR_DECL(name, const wxCharBuffer&, const wxString&) \
412 { return -WX_STR_CALL(forString, s2, s1.data()); } \
414 inline int WX_STR_DECL(name, const wxWCharBuffer&, const wxCStrData&) \
415 { return -WX_STR_CALL(forString, s2.AsString(), s1.data()); } \
416 inline int WX_STR_DECL(name, const wxWCharBuffer&, const wxString&) \
417 { return -WX_STR_CALL(forString, s2, s1.data()); }
420 // This defines a string function that is *not* strcmp-like, i.e. doesn't
421 // return the result of comparison and so if the second argument is a string,
422 // it has to be converted to char* or wchar_t*
423 #define WX_STR_FUNC(rettype, name, crtA, crtW, forString) \
424 WX_STR_FUNC_NO_INVERT(rettype, name, crtA, crtW, forString) \
426 inline rettype WX_STR_DECL(name, const char *, const wxCStrData&) \
427 { return WX_STR_CALL(crtA, s1, s2.AsCharBuf()); } \
428 inline rettype WX_STR_DECL(name, const char *, const wxString&) \
429 { return WX_STR_CALL(crtA, s1, s2.mb_str()); } \
431 inline rettype WX_STR_DECL(name, const wchar_t *, const wxCStrData&) \
432 { return WX_STR_CALL(crtW, s1, s2.AsWCharBuf()); } \
433 inline rettype WX_STR_DECL(name, const wchar_t *, const wxString&) \
434 { return WX_STR_CALL(crtW, s1, s2.wc_str()); } \
436 inline rettype WX_STR_DECL(name, const wxCharBuffer&, const wxCStrData&) \
437 { return WX_STR_CALL(crtA, s1.data(), s2.AsCharBuf()); } \
438 inline rettype WX_STR_DECL(name, const wxCharBuffer&, const wxString&) \
439 { return WX_STR_CALL(crtA, s1.data(), s2.mb_str()); } \
441 inline rettype WX_STR_DECL(name, const wxWCharBuffer&, const wxCStrData&) \
442 { return WX_STR_CALL(crtW, s1.data(), s2.AsWCharBuf()); } \
443 inline rettype WX_STR_DECL(name, const wxWCharBuffer&, const wxString&) \
444 { return WX_STR_CALL(crtW, s1.data(), s2.wc_str()); }
447 inline int wxStrcmp_String(const wxString
& s1
, const T
& s2
)
448 { return s1
.compare(s2
); }
449 WX_STRCMP_FUNC(wxStrcmp
, wxCRT_StrcmpA
, wxCRT_StrcmpW
, wxStrcmp_String
)
452 inline int wxStricmp_String(const wxString
& s1
, const T
& s2
)
453 { return s1
.CmpNoCase(s2
); }
454 WX_STRCMP_FUNC(wxStricmp
, wxCRT_StricmpA
, wxCRT_StricmpW
, wxStricmp_String
)
456 #if defined(wxCRT_StrcollA) && defined(wxCRT_StrcollW)
458 // GCC 3.3 and other compilers have a bug that causes it to fail compilation if
459 // the template's implementation uses overloaded function declared later (see
460 // the wxStrcoll() call in wxStrcoll_String<T>()), so we have to
461 // forward-declare the template and implement it below WX_STRCMP_FUNC. OTOH,
462 // this fails to compile with VC6, so don't do it for VC. It also causes
463 // problems with GCC visibility in newer GCC versions.
464 #if !(defined(__VISUALC__) || wxCHECK_GCC_VERSION(3,4))
466 inline int wxStrcoll_String(const wxString
& s1
, const T
& s2
);
467 WX_STRCMP_FUNC(wxStrcoll
, wxCRT_StrcollA
, wxCRT_StrcollW
, wxStrcoll_String
)
468 #endif // !__VISUALC__
471 inline int wxStrcoll_String(const wxString
& s1
, const T
& s2
)
474 // NB: strcoll() doesn't work correctly on UTF-8 strings, so we have to use
475 // wc_str() even if wxUSE_UNICODE_UTF8; the (const wchar_t*) cast is
476 // there just as optimization to avoid going through
477 // wxStrcoll<wxWCharBuffer>:
478 return wxStrcoll((const wchar_t*)s1
.wc_str(), s2
);
480 return wxStrcoll((const char*)s1
.mb_str(), s2
);
484 #if defined(__VISUALC__) || wxCHECK_GCC_VERSION(3,4)
485 // this is exactly the same WX_STRCMP_FUNC line as above wxStrcoll_String<>
486 WX_STRCMP_FUNC(wxStrcoll
, wxCRT_StrcollA
, wxCRT_StrcollW
, wxStrcoll_String
)
489 #endif // defined(wxCRT_Strcoll[AW])
492 inline size_t wxStrspn_String(const wxString
& s1
, const T
& s2
)
494 size_t pos
= s1
.find_first_not_of(s2
);
495 return pos
== wxString::npos
? s1
.length() : pos
;
497 WX_STR_FUNC(size_t, wxStrspn
, wxCRT_StrspnA
, wxCRT_StrspnW
, wxStrspn_String
)
500 inline size_t wxStrcspn_String(const wxString
& s1
, const T
& s2
)
502 size_t pos
= s1
.find_first_of(s2
);
503 return pos
== wxString::npos
? s1
.length() : pos
;
505 WX_STR_FUNC(size_t, wxStrcspn
, wxCRT_StrcspnA
, wxCRT_StrcspnW
, wxStrcspn_String
)
509 #define WX_STR_DECL(name, T1, T2) name(T1 s1, T2 s2, size_t n)
510 #define WX_STR_CALL(func, a1, a2) func(a1, a2, n)
513 inline int wxStrncmp_String(const wxString
& s1
, const T
& s2
, size_t n
)
514 { return s1
.compare(0, n
, s2
, 0, n
); }
515 WX_STRCMP_FUNC(wxStrncmp
, wxCRT_StrncmpA
, wxCRT_StrncmpW
, wxStrncmp_String
)
518 inline int wxStrnicmp_String(const wxString
& s1
, const T
& s2
, size_t n
)
519 { return s1
.substr(0, n
).CmpNoCase(wxString(s2
).substr(0, n
)); }
520 WX_STRCMP_FUNC(wxStrnicmp
, wxCRT_StrnicmpA
, wxCRT_StrnicmpW
, wxStrnicmp_String
)
524 #undef WX_STRCMP_FUNC
526 #undef WX_STR_FUNC_NO_INVERT
528 #if defined(wxCRT_StrxfrmA) && defined(wxCRT_StrxfrmW)
530 inline size_t wxStrxfrm(char *dest
, const char *src
, size_t n
)
531 { return wxCRT_StrxfrmA(dest
, src
, n
); }
532 inline size_t wxStrxfrm(wchar_t *dest
, const wchar_t *src
, size_t n
)
533 { return wxCRT_StrxfrmW(dest
, src
, n
); }
535 inline size_t wxStrxfrm(T
*dest
, const wxCharTypeBuffer
<T
>& src
, size_t n
)
536 { return wxStrxfrm(dest
, src
.data(), n
); }
537 inline size_t wxStrxfrm(char *dest
, const wxString
& src
, size_t n
)
538 { return wxCRT_StrxfrmA(dest
, src
.mb_str(), n
); }
539 inline size_t wxStrxfrm(wchar_t *dest
, const wxString
& src
, size_t n
)
540 { return wxCRT_StrxfrmW(dest
, src
.wc_str(), n
); }
541 inline size_t wxStrxfrm(char *dest
, const wxCStrData
& src
, size_t n
)
542 { return wxCRT_StrxfrmA(dest
, src
.AsCharBuf(), n
); }
543 inline size_t wxStrxfrm(wchar_t *dest
, const wxCStrData
& src
, size_t n
)
544 { return wxCRT_StrxfrmW(dest
, src
.AsWCharBuf(), n
); }
546 #endif // defined(wxCRT_Strxfrm[AW])
548 inline char *wxStrtok(char *str
, const char *delim
, char **saveptr
)
549 { return wxCRT_StrtokA(str
, delim
, saveptr
); }
550 inline wchar_t *wxStrtok(wchar_t *str
, const wchar_t *delim
, wchar_t **saveptr
)
551 { return wxCRT_StrtokW(str
, delim
, saveptr
); }
553 inline T
*wxStrtok(T
*str
, const wxCharTypeBuffer
<T
>& delim
, T
**saveptr
)
554 { return wxStrtok(str
, delim
.data(), saveptr
); }
555 inline char *wxStrtok(char *str
, const wxCStrData
& delim
, char **saveptr
)
556 { return wxCRT_StrtokA(str
, delim
.AsCharBuf(), saveptr
); }
557 inline wchar_t *wxStrtok(wchar_t *str
, const wxCStrData
& delim
, wchar_t **saveptr
)
558 { return wxCRT_StrtokW(str
, delim
.AsWCharBuf(), saveptr
); }
559 inline char *wxStrtok(char *str
, const wxString
& delim
, char **saveptr
)
560 { return wxCRT_StrtokA(str
, delim
.mb_str(), saveptr
); }
561 inline wchar_t *wxStrtok(wchar_t *str
, const wxString
& delim
, wchar_t **saveptr
)
562 { return wxCRT_StrtokW(str
, delim
.wc_str(), saveptr
); }
564 inline const char *wxStrstr(const char *haystack
, const char *needle
)
565 { return wxCRT_StrstrA(haystack
, needle
); }
566 inline const wchar_t *wxStrstr(const wchar_t *haystack
, const wchar_t *needle
)
567 { return wxCRT_StrstrW(haystack
, needle
); }
568 inline const char *wxStrstr(const char *haystack
, const wxString
& needle
)
569 { return wxCRT_StrstrA(haystack
, needle
.mb_str()); }
570 inline const wchar_t *wxStrstr(const wchar_t *haystack
, const wxString
& needle
)
571 { return wxCRT_StrstrW(haystack
, needle
.wc_str()); }
572 // these functions return char* pointer into the non-temporary conversion buffer
573 // used by c_str()'s implicit conversion to char*, for ANSI build compatibility
574 inline const char *wxStrstr(const wxString
& haystack
, const wxString
& needle
)
575 { return wxCRT_StrstrA(haystack
.c_str(), needle
.mb_str()); }
576 inline const char *wxStrstr(const wxCStrData
& haystack
, const wxString
& needle
)
577 { return wxCRT_StrstrA(haystack
, needle
.mb_str()); }
578 inline const char *wxStrstr(const wxCStrData
& haystack
, const wxCStrData
& needle
)
579 { return wxCRT_StrstrA(haystack
, needle
.AsCharBuf()); }
580 // if 'needle' is char/wchar_t, then the same is probably wanted as return value
581 inline const char *wxStrstr(const wxString
& haystack
, const char *needle
)
582 { return wxCRT_StrstrA(haystack
.c_str(), needle
); }
583 inline const char *wxStrstr(const wxCStrData
& haystack
, const char *needle
)
584 { return wxCRT_StrstrA(haystack
, needle
); }
585 inline const wchar_t *wxStrstr(const wxString
& haystack
, const wchar_t *needle
)
586 { return wxCRT_StrstrW(haystack
.c_str(), needle
); }
587 inline const wchar_t *wxStrstr(const wxCStrData
& haystack
, const wchar_t *needle
)
588 { return wxCRT_StrstrW(haystack
, needle
); }
590 inline const char *wxStrchr(const char *s
, char c
)
591 { return wxCRT_StrchrA(s
, c
); }
592 inline const wchar_t *wxStrchr(const wchar_t *s
, wchar_t c
)
593 { return wxCRT_StrchrW(s
, c
); }
594 inline const char *wxStrrchr(const char *s
, char c
)
595 { return wxCRT_StrrchrA(s
, c
); }
596 inline const wchar_t *wxStrrchr(const wchar_t *s
, wchar_t c
)
597 { return wxCRT_StrrchrW(s
, c
); }
598 inline const char *wxStrchr(const char *s
, const wxUniChar
& c
)
599 { return wxCRT_StrchrA(s
, (char)c
); }
600 inline const wchar_t *wxStrchr(const wchar_t *s
, const wxUniChar
& c
)
601 { return wxCRT_StrchrW(s
, (wchar_t)c
); }
602 inline const char *wxStrrchr(const char *s
, const wxUniChar
& c
)
603 { return wxCRT_StrrchrA(s
, (char)c
); }
604 inline const wchar_t *wxStrrchr(const wchar_t *s
, const wxUniChar
& c
)
605 { return wxCRT_StrrchrW(s
, (wchar_t)c
); }
606 inline const char *wxStrchr(const char *s
, const wxUniCharRef
& c
)
607 { return wxCRT_StrchrA(s
, (char)c
); }
608 inline const wchar_t *wxStrchr(const wchar_t *s
, const wxUniCharRef
& c
)
609 { return wxCRT_StrchrW(s
, (wchar_t)c
); }
610 inline const char *wxStrrchr(const char *s
, const wxUniCharRef
& c
)
611 { return wxCRT_StrrchrA(s
, (char)c
); }
612 inline const wchar_t *wxStrrchr(const wchar_t *s
, const wxUniCharRef
& c
)
613 { return wxCRT_StrrchrW(s
, (wchar_t)c
); }
615 inline const T
* wxStrchr(const wxCharTypeBuffer
<T
>& s
, T c
)
616 { return wxStrchr(s
.data(), c
); }
618 inline const T
* wxStrrchr(const wxCharTypeBuffer
<T
>& s
, T c
)
619 { return wxStrrchr(s
.data(), c
); }
621 inline const T
* wxStrchr(const wxCharTypeBuffer
<T
>& s
, const wxUniChar
& c
)
622 { return wxStrchr(s
.data(), (T
)c
); }
624 inline const T
* wxStrrchr(const wxCharTypeBuffer
<T
>& s
, const wxUniChar
& c
)
625 { return wxStrrchr(s
.data(), (T
)c
); }
627 inline const T
* wxStrchr(const wxCharTypeBuffer
<T
>& s
, const wxUniCharRef
& c
)
628 { return wxStrchr(s
.data(), (T
)c
); }
630 inline const T
* wxStrrchr(const wxCharTypeBuffer
<T
>& s
, const wxUniCharRef
& c
)
631 { return wxStrrchr(s
.data(), (T
)c
); }
632 // these functions return char* pointer into the non-temporary conversion buffer
633 // used by c_str()'s implicit conversion to char*, for ANSI build compatibility
634 inline const char* wxStrchr(const wxString
& s
, char c
)
635 { return wxCRT_StrchrA((const char*)s
.c_str(), c
); }
636 inline const char* wxStrrchr(const wxString
& s
, char c
)
637 { return wxCRT_StrrchrA((const char*)s
.c_str(), c
); }
638 inline const char* wxStrchr(const wxString
& s
, int c
)
639 { return wxCRT_StrchrA((const char*)s
.c_str(), c
); }
640 inline const char* wxStrrchr(const wxString
& s
, int c
)
641 { return wxCRT_StrrchrA((const char*)s
.c_str(), c
); }
642 inline const char* wxStrchr(const wxString
& s
, const wxUniChar
& c
)
643 { return wxCRT_StrchrA((const char*)s
.c_str(), (char)c
); }
644 inline const char* wxStrrchr(const wxString
& s
, const wxUniChar
& c
)
645 { return wxCRT_StrrchrA((const char*)s
.c_str(), (char)c
); }
646 inline const char* wxStrchr(const wxString
& s
, const wxUniCharRef
& c
)
647 { return wxCRT_StrchrA((const char*)s
.c_str(), (char)c
); }
648 inline const char* wxStrrchr(const wxString
& s
, const wxUniCharRef
& c
)
649 { return wxCRT_StrrchrA((const char*)s
.c_str(), (char)c
); }
650 inline const wchar_t* wxStrchr(const wxString
& s
, wchar_t c
)
651 { return wxCRT_StrchrW((const wchar_t*)s
.c_str(), c
); }
652 inline const wchar_t* wxStrrchr(const wxString
& s
, wchar_t c
)
653 { return wxCRT_StrrchrW((const wchar_t*)s
.c_str(), c
); }
654 inline const char* wxStrchr(const wxCStrData
& s
, char c
)
655 { return wxCRT_StrchrA(s
.AsChar(), c
); }
656 inline const char* wxStrrchr(const wxCStrData
& s
, char c
)
657 { return wxCRT_StrrchrA(s
.AsChar(), c
); }
658 inline const char* wxStrchr(const wxCStrData
& s
, int c
)
659 { return wxCRT_StrchrA(s
.AsChar(), c
); }
660 inline const char* wxStrrchr(const wxCStrData
& s
, int c
)
661 { return wxCRT_StrrchrA(s
.AsChar(), c
); }
662 inline const char* wxStrchr(const wxCStrData
& s
, const wxUniChar
& c
)
663 { return wxCRT_StrchrA(s
.AsChar(), (char)c
); }
664 inline const char* wxStrrchr(const wxCStrData
& s
, const wxUniChar
& c
)
665 { return wxCRT_StrrchrA(s
.AsChar(), (char)c
); }
666 inline const char* wxStrchr(const wxCStrData
& s
, const wxUniCharRef
& c
)
667 { return wxCRT_StrchrA(s
.AsChar(), (char)c
); }
668 inline const char* wxStrrchr(const wxCStrData
& s
, const wxUniCharRef
& c
)
669 { return wxCRT_StrrchrA(s
.AsChar(), (char)c
); }
670 inline const wchar_t* wxStrchr(const wxCStrData
& s
, wchar_t c
)
671 { return wxCRT_StrchrW(s
.AsWChar(), c
); }
672 inline const wchar_t* wxStrrchr(const wxCStrData
& s
, wchar_t c
)
673 { return wxCRT_StrrchrW(s
.AsWChar(), c
); }
675 inline const char *wxStrpbrk(const char *s
, const char *accept
)
676 { return wxCRT_StrpbrkA(s
, accept
); }
677 inline const wchar_t *wxStrpbrk(const wchar_t *s
, const wchar_t *accept
)
678 { return wxCRT_StrpbrkW(s
, accept
); }
679 inline const char *wxStrpbrk(const char *s
, const wxString
& accept
)
680 { return wxCRT_StrpbrkA(s
, accept
.mb_str()); }
681 inline const char *wxStrpbrk(const char *s
, const wxCStrData
& accept
)
682 { return wxCRT_StrpbrkA(s
, accept
.AsCharBuf()); }
683 inline const wchar_t *wxStrpbrk(const wchar_t *s
, const wxString
& accept
)
684 { return wxCRT_StrpbrkW(s
, accept
.wc_str()); }
685 inline const wchar_t *wxStrpbrk(const wchar_t *s
, const wxCStrData
& accept
)
686 { return wxCRT_StrpbrkW(s
, accept
.AsWCharBuf()); }
687 inline const char *wxStrpbrk(const wxString
& s
, const wxString
& accept
)
688 { return wxCRT_StrpbrkA(s
.c_str(), accept
.mb_str()); }
689 inline const char *wxStrpbrk(const wxString
& s
, const char *accept
)
690 { return wxCRT_StrpbrkA(s
.c_str(), accept
); }
691 inline const wchar_t *wxStrpbrk(const wxString
& s
, const wchar_t *accept
)
692 { return wxCRT_StrpbrkW(s
.wc_str(), accept
); }
693 inline const char *wxStrpbrk(const wxString
& s
, const wxCStrData
& accept
)
694 { return wxCRT_StrpbrkA(s
.c_str(), accept
.AsCharBuf()); }
695 inline const char *wxStrpbrk(const wxCStrData
& s
, const wxString
& accept
)
696 { return wxCRT_StrpbrkA(s
.AsChar(), accept
.mb_str()); }
697 inline const char *wxStrpbrk(const wxCStrData
& s
, const char *accept
)
698 { return wxCRT_StrpbrkA(s
.AsChar(), accept
); }
699 inline const wchar_t *wxStrpbrk(const wxCStrData
& s
, const wchar_t *accept
)
700 { return wxCRT_StrpbrkW(s
.AsWChar(), accept
); }
701 inline const char *wxStrpbrk(const wxCStrData
& s
, const wxCStrData
& accept
)
702 { return wxCRT_StrpbrkA(s
.AsChar(), accept
.AsCharBuf()); }
703 template <typename S
, typename T
>
704 inline const T
*wxStrpbrk(const S
& s
, const wxCharTypeBuffer
<T
>& accept
)
705 { return wxStrpbrk(s
, accept
.data()); }
708 /* inlined non-const versions */
709 inline char *wxStrstr(char *haystack
, const char *needle
)
710 { return (char *)wxStrstr((const char *)haystack
, needle
); }
711 inline wchar_t *wxStrstr(wchar_t *haystack
, const wchar_t *needle
)
712 { return (wchar_t *)wxStrstr((const wchar_t *)haystack
, needle
); }
713 inline char *wxStrstr(char *haystack
, const wxString
& needle
)
714 { return (char *)wxStrstr((const char *)haystack
, needle
); }
715 inline wchar_t *wxStrstr(wchar_t *haystack
, const wxString
& needle
)
716 { return (wchar_t *)wxStrstr((const wchar_t *)haystack
, needle
); }
718 inline char * wxStrchr(char *s
, char c
)
719 { return (char *)wxStrchr((const char *)s
, c
); }
720 inline char * wxStrrchr(char *s
, char c
)
721 { return (char *)wxStrrchr((const char *)s
, c
); }
722 inline wchar_t * wxStrchr(wchar_t *s
, wchar_t c
)
723 { return (wchar_t *)wxStrchr((const wchar_t *)s
, c
); }
724 inline wchar_t * wxStrrchr(wchar_t *s
, wchar_t c
)
725 { return (wchar_t *)wxStrrchr((const wchar_t *)s
, c
); }
727 inline char * wxStrpbrk(char *s
, const char *accept
)
728 { return (char *)wxStrpbrk((const char *)s
, accept
); }
729 inline wchar_t * wxStrpbrk(wchar_t *s
, const wchar_t *accept
)
730 { return (wchar_t *)wxStrpbrk((const wchar_t *)s
, accept
); }
731 inline char * wxStrpbrk(char *s
, const wxString
& accept
)
732 { return (char *)wxStrpbrk((const char *)s
, accept
); }
733 inline wchar_t * wxStrpbrk(wchar_t *s
, const wxString
& accept
)
734 { return (wchar_t *)wxStrpbrk((const wchar_t *)s
, accept
); }
737 // ----------------------------------------------------------------------------
739 // ----------------------------------------------------------------------------
741 // NB: using fn_str() for mode is a hack to get the same type (char*/wchar_t*)
742 // as needed, the conversion itself doesn't matter, it's ASCII
743 inline FILE *wxFopen(const wxString
& path
, const wxString
& mode
)
744 { return wxCRT_Fopen(path
.fn_str(), mode
.fn_str()); }
745 inline FILE *wxFreopen(const wxString
& path
, const wxString
& mode
, FILE *stream
)
746 { return wxCRT_Freopen(path
.fn_str(), mode
.fn_str(), stream
); }
747 inline int wxRemove(const wxString
& path
)
748 { return wxCRT_Remove(path
.fn_str()); }
749 inline int wxRename(const wxString
& oldpath
, const wxString
& newpath
)
750 { return wxCRT_Rename(oldpath
.fn_str(), newpath
.fn_str()); }
752 extern WXDLLIMPEXP_BASE
int wxPuts(const wxString
& s
);
753 extern WXDLLIMPEXP_BASE
int wxFputs(const wxString
& s
, FILE *stream
);
754 extern WXDLLIMPEXP_BASE
void wxPerror(const wxString
& s
);
756 extern WXDLLIMPEXP_BASE
int wxFputc(const wxUniChar
& c
, FILE *stream
);
758 #define wxPutc(c, stream) wxFputc(c, stream)
759 #define wxPutchar(c) wxFputc(c, stdout)
760 #define wxFputchar(c) wxPutchar(c)
762 // NB: We only provide ANSI version of fgets() because fgetws() interprets the
763 // stream according to current locale, which is rarely what is desired.
764 inline char *wxFgets(char *s
, int size
, FILE *stream
)
765 { return wxCRT_FgetsA(s
, size
, stream
); }
766 // This version calls ANSI version and converts the string using wxConvLibc
767 extern WXDLLIMPEXP_BASE
wchar_t *wxFgets(wchar_t *s
, int size
, FILE *stream
);
769 #define wxGets(s) wxGets_is_insecure_and_dangerous_use_wxFgets_instead
771 // NB: We only provide ANSI versions of this for the same reasons as in the
772 // case of wxFgets() above
773 inline int wxFgetc(FILE *stream
) { return wxCRT_FgetcA(stream
); }
774 inline int wxUngetc(int c
, FILE *stream
) { return wxCRT_UngetcA(c
, stream
); }
776 #define wxGetc(stream) wxFgetc(stream)
777 #define wxGetchar() wxFgetc(stdin)
778 #define wxFgetchar() wxGetchar()
780 // ----------------------------------------------------------------------------
781 // stdlib.h functions
782 // ----------------------------------------------------------------------------
785 inline int wxAtoi(const wxString
& str
) { return wxCRT_AtoiW(str
.wc_str()); }
787 inline int wxAtoi(const wxString
& str
) { return wxCRT_AtoiA(str
.mb_str()); }
791 inline long wxAtol(const wxString
& str
) { return wxCRT_AtolW(str
.wc_str()); }
793 inline long wxAtol(const wxString
& str
) { return wxCRT_AtolA(str
.mb_str()); }
797 inline double wxAtof(const wxString
& str
) { return wxCRT_AtofW(str
.wc_str()); }
799 inline double wxAtof(const wxString
& str
) { return wxCRT_AtofA(str
.mb_str()); }
802 inline double wxStrtod(const char *nptr
, char **endptr
)
803 { return wxCRT_StrtodA(nptr
, endptr
); }
804 inline double wxStrtod(const wchar_t *nptr
, wchar_t **endptr
)
805 { return wxCRT_StrtodW(nptr
, endptr
); }
807 inline double wxStrtod(const wxCharTypeBuffer
<T
>& nptr
, T
**endptr
)
808 { return wxStrtod(nptr
.data(), endptr
); }
810 // We implement wxStrto*() like this so that the code compiles when NULL is
811 // passed in - - if we had just char** and wchar_t** overloads for 'endptr', it
812 // would be ambiguous. The solution is to use a template so that endptr can be
813 // any type: when NULL constant is used, the type will be int and we can handle
814 // that case specially. Otherwise, we infer the type that 'nptr' should be
815 // converted to from the type of 'endptr'. We need wxStrtoxCharType<T> template
816 // to make the code compile even for T=int (that's the case when it's not going
817 // to be ever used, but it still has to compile).
818 template<typename T
> struct wxStrtoxCharType
{};
819 template<> struct wxStrtoxCharType
<char**>
821 typedef const char* Type
;
822 static char** AsPointer(char **p
) { return p
; }
824 template<> struct wxStrtoxCharType
<wchar_t**>
826 typedef const wchar_t* Type
;
827 static wchar_t** AsPointer(wchar_t **p
) { return p
; }
829 template<> struct wxStrtoxCharType
<int>
831 typedef const char* Type
; /* this one is never used */
832 static char** AsPointer(int WXUNUSED_UNLESS_DEBUG(p
))
834 wxASSERT_MSG( p
== 0, "passing non-NULL int is invalid" );
840 inline double wxStrtod(const wxString
& nptr
, T endptr
)
844 // when we don't care about endptr, use the string representation that
845 // doesn't require any conversion (it doesn't matter for this function
846 // even if its UTF-8):
847 return wxStrtod(nptr
.wx_str(), (wxStringCharType
**)NULL
);
851 // note that it is important to use c_str() here and not mb_str() or
852 // wc_str(), because we store the pointer into (possibly converted)
853 // buffer in endptr and so it must be valid even when wxStrtod() returns
854 typedef typename wxStrtoxCharType
<T
>::Type CharType
;
855 return wxStrtod((CharType
)nptr
.c_str(),
856 wxStrtoxCharType
<T
>::AsPointer(endptr
));
860 inline double wxStrtod(const wxCStrData
& nptr
, T endptr
)
861 { return wxStrtod(nptr
.AsString(), endptr
); }
864 #define WX_STRTOX_FUNC(rettype, name, implA, implW) \
865 /* see wxStrtod() above for explanation of this code: */ \
866 inline rettype name(const char *nptr, char **endptr, int base) \
867 { return implA(nptr, endptr, base); } \
868 inline rettype name(const wchar_t *nptr, wchar_t **endptr, int base) \
869 { return implW(nptr, endptr, base); } \
870 template<typename T> \
871 inline rettype name(const wxCharTypeBuffer<T>& nptr, T **endptr, int base)\
872 { return name(nptr.data(), endptr); } \
873 template<typename T> \
874 inline rettype name(const wxString& nptr, T endptr, int base) \
877 return name(nptr.wx_str(), (wxStringCharType**)NULL, base); \
880 typedef typename wxStrtoxCharType<T>::Type CharType; \
881 return name((CharType)nptr.c_str(), \
882 wxStrtoxCharType<T>::AsPointer(endptr), \
886 template<typename T> \
887 inline rettype name(const wxCStrData& nptr, T endptr, int base) \
888 { return name(nptr.AsString(), endptr, base); }
890 WX_STRTOX_FUNC(long, wxStrtol
, wxCRT_StrtolA
, wxCRT_StrtolW
)
891 WX_STRTOX_FUNC(unsigned long, wxStrtoul
, wxCRT_StrtoulA
, wxCRT_StrtoulW
)
893 WX_STRTOX_FUNC(wxLongLong_t
, wxStrtoll
, wxCRT_StrtollA
, wxCRT_StrtollW
)
894 WX_STRTOX_FUNC(wxULongLong_t
, wxStrtoull
, wxCRT_StrtoullA
, wxCRT_StrtoullW
)
895 #endif // wxLongLong_t
897 #undef WX_STRTOX_FUNC
900 // there is no command interpreter under CE, hence no system()
903 // mingw32 doesn't provide _tsystem() even though it provides other stdlib.h
904 // functions in their wide versions
906 inline int wxSystem(const wxString
& str
) { return wxCRT_SystemW(str
.wc_str()); }
908 inline int wxSystem(const wxString
& str
) { return wxCRT_SystemA(str
.mb_str()); }
911 #endif // !__WXWINCE__/__WXWINCE__
913 inline char* wxGetenv(const char *name
) { return wxCRT_GetenvA(name
); }
914 inline wchar_t* wxGetenv(const wchar_t *name
) { return wxCRT_GetenvW(name
); }
915 inline char* wxGetenv(const wxString
& name
) { return wxCRT_GetenvA(name
.mb_str()); }
916 inline char* wxGetenv(const wxCStrData
& name
) { return wxCRT_GetenvA(name
.AsCharBuf()); }
917 inline char* wxGetenv(const wxCharBuffer
& name
) { return wxCRT_GetenvA(name
.data()); }
918 inline wchar_t* wxGetenv(const wxWCharBuffer
& name
) { return wxCRT_GetenvW(name
.data()); }
920 // ----------------------------------------------------------------------------
922 // ----------------------------------------------------------------------------
924 inline size_t wxStrftime(char *s
, size_t max
,
925 const wxString
& format
, const struct tm
*tm
)
926 { return wxCRT_StrftimeA(s
, max
, format
.mb_str(), tm
); }
928 inline size_t wxStrftime(wchar_t *s
, size_t max
,
929 const wxString
& format
, const struct tm
*tm
)
930 { return wxCRT_StrftimeW(s
, max
, format
.wc_str(), tm
); }
932 // NB: we can't provide both char* and wchar_t* versions for obvious reasons
933 // and returning wxString wouldn't work either (it would be immediately
934 // destroyed and if assigned to char*/wchar_t*, the pointer would be
935 // invalid), so we only keep ASCII version, because the returned value
936 // is always ASCII anyway
937 #define wxAsctime asctime
938 #define wxCtime ctime
941 // ----------------------------------------------------------------------------
943 // ----------------------------------------------------------------------------
945 // FIXME-UTF8: we'd be better off implementing these ourselves, as the CRT
946 // version is locale-dependent
947 // FIXME-UTF8: these don't work when EOF is passed in because of wxUniChar,
948 // is this OK or not?
950 inline bool wxIsalnum(const wxUniChar
& c
) { return wxCRT_IsalnumW(c
) != 0; }
951 inline bool wxIsalpha(const wxUniChar
& c
) { return wxCRT_IsalphaW(c
) != 0; }
952 inline bool wxIscntrl(const wxUniChar
& c
) { return wxCRT_IscntrlW(c
) != 0; }
953 inline bool wxIsdigit(const wxUniChar
& c
) { return wxCRT_IsdigitW(c
) != 0; }
954 inline bool wxIsgraph(const wxUniChar
& c
) { return wxCRT_IsgraphW(c
) != 0; }
955 inline bool wxIslower(const wxUniChar
& c
) { return wxCRT_IslowerW(c
) != 0; }
956 inline bool wxIsprint(const wxUniChar
& c
) { return wxCRT_IsprintW(c
) != 0; }
957 inline bool wxIspunct(const wxUniChar
& c
) { return wxCRT_IspunctW(c
) != 0; }
958 inline bool wxIsspace(const wxUniChar
& c
) { return wxCRT_IsspaceW(c
) != 0; }
959 inline bool wxIsupper(const wxUniChar
& c
) { return wxCRT_IsupperW(c
) != 0; }
960 inline bool wxIsxdigit(const wxUniChar
& c
) { return wxCRT_IsxdigitW(c
) != 0; }
962 inline wxUniChar
wxTolower(const wxUniChar
& c
) { return wxCRT_TolowerW(c
); }
963 inline wxUniChar
wxToupper(const wxUniChar
& c
) { return wxCRT_ToupperW(c
); }
965 #if WXWIN_COMPATIBILITY_2_8
966 // we had goofed and defined wxIsctrl() instead of (correct) wxIscntrl() in the
967 // initial versions of this header -- now it is too late to remove it so
968 // although we fixed the function/macro name above, still provide the
969 // backwards-compatible synonym.
970 wxDEPRECATED( inline int wxIsctrl(const wxUniChar
& c
) );
971 inline int wxIsctrl(const wxUniChar
& c
) { return wxIscntrl(c
); }
972 #endif // WXWIN_COMPATIBILITY_2_8
974 #endif /* _WX_WXCRT_H_ */