]> git.saurik.com Git - wxWidgets.git/blob - include/wx/wxchar.h
Native spline drawing.
[wxWidgets.git] / include / wx / wxchar.h
1 /*
2 * Name: wx/wxchar.h
3 * Purpose: Declarations common to wx char/wchar_t usage (wide chars)
4 * Author: Joel Farley, Ove Kåven
5 * Modified by: Vadim Zeitlin, Robert Roebling, Ron Lee
6 * Created: 1998/06/12
7 * RCS-ID: $Id$
8 * Copyright: (c) 1998-2002 Joel Farley, Ove Kåven, Robert Roebling, Ron Lee
9 * Licence: wxWindows licence
10 */
11
12 /* THIS IS A C FILE, DON'T USE C++ FEATURES (IN PARTICULAR COMMENTS) IN IT */
13
14 #ifndef _WX_WXCHAR_H_
15 #define _WX_WXCHAR_H_
16
17 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
18 #pragma interface "wxchar.h"
19 #endif
20
21 #include "wx/defs.h" /* for wxUSE_UNICODE */
22
23 #if defined(HAVE_STRTOK_R) && defined(__DARWIN__) && defined(_MSL_USING_MW_C_HEADERS) && _MSL_USING_MW_C_HEADERS
24 char *strtok_r(char *, const char *, char **);
25 #endif
26
27 /* check whether we have wchar_t and which size it is if we do */
28 #if !defined(wxUSE_WCHAR_T)
29 #if defined(__UNIX__)
30 #if defined(HAVE_WCSTR_H) || defined(HAVE_WCHAR_H) || defined(__FreeBSD__) || defined(__DARWIN__)
31 #define wxUSE_WCHAR_T 1
32 #else
33 #define wxUSE_WCHAR_T 0
34 #endif
35 #elif defined(__GNUWIN32__) && !defined(__MINGW32__)
36 #define wxUSE_WCHAR_T 0
37 #elif defined(__WATCOMC__)
38 #define wxUSE_WCHAR_T 0
39 #elif defined(__VISAGECPP__) && (__IBMCPP__ < 400)
40 #define wxUSE_WCHAR_T 0
41 #else
42 /* add additional compiler checks if this fails */
43 #define wxUSE_WCHAR_T 1
44 #endif
45 #endif /* !defined(wxUSE_WCHAR_T) */
46
47 /* Unicode support requires wchar_t */
48 #if wxUSE_UNICODE && !wxUSE_WCHAR_T
49 #error "wchar_t must be available in Unicode build"
50 #endif /* Unicode */
51
52 /*
53 Standard headers we need here.
54
55 NB: don't include any wxWidgets headers here because almost of them include
56 this one!
57 */
58
59 /* Required for wxPrintf() etc */
60 #include <stdarg.h>
61
62 /* Almost all compiler have strdup(), but not quite all: CodeWarrior under Mac */
63 /* and VC++ for Windows CE don't provide it */
64 #if !(defined(__MWERKS__) && defined(__WXMAC__)) && !defined(__WXWINCE__)
65 /* use #define, not inline wrapper, as it is tested with #ifndef below */
66 #define wxStrdupA strdup
67 #endif
68
69 /*
70 non Unix compilers which do have wchar.h (but not tchar.h which is included
71 below and which includes wchar.h anyhow).
72
73 Actually MinGW has tchar.h, but it does not include wchar.h
74 */
75 #if defined(__MWERKS__) || defined(__VISAGECPP__) || defined(__MINGW32__) || defined(__WATCOMC__)
76 #ifndef HAVE_WCHAR_H
77 #define HAVE_WCHAR_H
78 #endif
79 #endif
80 #if defined(__MWERKS__) && !defined(__MACH__)
81 #ifndef HAVE_WCSLEN
82 #define HAVE_WCSLEN
83 #endif
84 #endif
85
86 #if wxUSE_WCHAR_T
87 #ifdef HAVE_WCHAR_H
88 /* the current (as of Nov 2002) version of cygwin has a bug in its */
89 /* wchar.h -- there is no extern "C" around the declarations in it and */
90 /* this results in linking errors later; also, at least on some */
91 /* Cygwin versions, wchar.h requires sys/types.h */
92 #ifdef __CYGWIN__
93 #include <sys/types.h>
94 #ifdef __cplusplus
95 extern "C" {
96 #endif
97 #endif /* Cygwin */
98
99 #include <wchar.h>
100
101 #if defined(__CYGWIN__) && defined(__cplusplus)
102 }
103 #endif /* Cygwin and C++ */
104
105 #elif defined(HAVE_WCSTR_H)
106 /* old compilers have relevant declarations here */
107 #include <wcstr.h>
108 #elif defined(__FreeBSD__) || defined(__DARWIN__) || defined(__EMX__)
109 /* include stdlib.h for wchar_t */
110 #include <stdlib.h>
111 #endif /* HAVE_WCHAR_H */
112 #endif /* wxUSE_WCHAR_T */
113
114 /* ---------------------------------------------------------------------------- */
115 /* define wxHAVE_TCHAR_SUPPORT for the compilers which support the TCHAR type */
116 /* mapped to either char or wchar_t depending on the ASCII/Unicode mode and have */
117 /* the function mapping _tfoo() -> foo() or wfoo() */
118 /* ---------------------------------------------------------------------------- */
119
120 /* VC++ and BC++ starting with 5.2 have TCHAR support */
121 #ifdef __VISUALC__
122 #define wxHAVE_TCHAR_SUPPORT
123 #elif defined(__BORLANDC__) && (__BORLANDC__ >= 0x520)
124 #define wxHAVE_TCHAR_SUPPORT
125 #include <ctype.h>
126 #elif defined(__WATCOMC__)
127 #define wxHAVE_TCHAR_SUPPORT
128 #elif defined(__DMC__)
129 #define wxHAVE_TCHAR_SUPPORT
130 #elif defined(__WXPALMOS__)
131 #include <stddef.h>
132 #elif defined(__MINGW32__) && wxCHECK_W32API_VERSION( 1, 0 )
133 #define wxHAVE_TCHAR_SUPPORT
134 #include <stddef.h>
135 #include <string.h>
136 #include <ctype.h>
137 #elif 0 && defined(__VISAGECPP__) && (__IBMCPP__ >= 400)
138 /* VZ: the old VisualAge definitions were completely wrong and had no */
139 /* chance at all to work in Unicode build anyhow so let's pretend that */
140 /* VisualAge does _not_ support TCHAR for the moment (as indicated by */
141 /* "0 &&" above) until someone really has time to delve into Unicode */
142 /* issues under OS/2 */
143
144 /* VisualAge 4.0+ supports TCHAR */
145 #define wxHAVE_TCHAR_SUPPORT
146 #endif /* compilers with (good) TCHAR support */
147
148 #ifdef __MWERKS__
149 #define HAVE_WPRINTF
150 #endif
151
152 #ifdef wxHAVE_TCHAR_SUPPORT
153 /* get TCHAR definition if we've got it */
154 #include <tchar.h>
155
156 /* we surely do have wchar_t if we have TCHAR */
157 #ifndef wxUSE_WCHAR_T
158 #define wxUSE_WCHAR_T 1
159 #endif /* !defined(wxUSE_WCHAR_T) */
160
161 /* and we also do have wcslen() */
162 #ifndef HAVE_WCSLEN
163 #define HAVE_WCSLEN
164 #endif
165 #endif /* wxHAVE_TCHAR_SUPPORT */
166
167 /* ---------------------------------------------------------------------------- */
168 /* define wxChar type */
169 /* ---------------------------------------------------------------------------- */
170
171 /* TODO: define wxCharInt to be equal to either int or wint_t? */
172
173 #if !wxUSE_UNICODE
174 typedef char wxChar;
175 typedef signed char wxSChar;
176 typedef unsigned char wxUChar;
177 #else /* Unicode */
178 /* VZ: note that VC++ defines _T[SU]CHAR simply as wchar_t and not as */
179 /* signed/unsigned version of it which (a) makes sense to me (unlike */
180 /* char wchar_t is always unsigned) and (b) was how the previous */
181 /* definitions worked so keep it like this */
182
183 /* GNU libc has __WCHAR_TYPE__ which requires special treatment, see */
184 /* comment below */
185 #if !defined(__WCHAR_TYPE__) || \
186 (!defined(__GNUC__) || wxCHECK_GCC_VERSION(2, 96))
187 /* standard case */
188 typedef wchar_t wxChar;
189 typedef wchar_t wxSChar;
190 typedef wchar_t wxUChar;
191 #else /* __WCHAR_TYPE__ and gcc < 2.96 */
192 /* VS: wxWidgets used to define wxChar as __WCHAR_TYPE__ here. However, */
193 /* this doesn't work with new GCC 3.x compilers because wchar_t is */
194 /* C++'s builtin type in the new standard. OTOH, old compilers (GCC */
195 /* 2.x) won't accept new definition of wx{S,U}Char, therefore we */
196 /* have to define wxChar conditionally depending on detected */
197 /* compiler & compiler version. */
198 /* with old definition of wxChar. */
199 typedef __WCHAR_TYPE__ wxChar;
200 typedef __WCHAR_TYPE__ wxSChar;
201 typedef __WCHAR_TYPE__ wxUChar;
202 #endif /* __WCHAR_TYPE__ */
203 #endif /* ASCII/Unicode */
204
205 /* ---------------------------------------------------------------------------- */
206 /* define _T() and related macros */
207 /* ---------------------------------------------------------------------------- */
208
209 /* BSD systems define _T() to be something different in ctype.h, override it */
210 #if defined(__FreeBSD__) || defined(__DARWIN__)
211 #include <ctype.h>
212 #undef _T
213 #endif
214
215 /* could already be defined by tchar.h (it's quasi standard) */
216 #ifndef _T
217 #if !wxUSE_UNICODE
218 #define _T(x) x
219 #else /* Unicode */
220 #define _T(x) L ## x
221 #endif /* ASCII/Unicode */
222 #endif /* !defined(_T) */
223
224 /* although global macros with such names are normally bad, we want to have */
225 /* another name for _T() which should be used to avoid confusion between _T() */
226 /* and _() in wxWidgets sources */
227 #define wxT(x) _T(x)
228
229 /* Unicode-friendly __FILE__, __DATE__ and __TIME__ analogs */
230 #ifndef __TFILE__
231 #define __XFILE__(x) wxT(x)
232 #define __TFILE__ __XFILE__(__FILE__)
233 #endif
234
235 #ifndef __TDATE__
236 #define __XDATE__(x) wxT(x)
237 #define __TDATE__ __XDATE__(__DATE__)
238 #endif
239
240 #ifndef __TTIME__
241 #define __XTIME__(x) wxT(x)
242 #define __TTIME__ __XTIME__(__TIME__)
243 #endif
244
245 /*
246 define wxFoo() function for each standard foo() function whose signature
247 (exceptionally including the return type) includes any mention of char:
248 wxFoo() is going to be a Unicode-friendly version of foo(), i.e. will have
249 the same signature but with char replaced by wxChar which allows us to use
250 it in Unicode build as well
251 */
252
253 #ifdef wxHAVE_TCHAR_SUPPORT
254 #include <ctype.h>
255
256 #if defined(__WATCOMC__) && defined(UNICODE)
257 #define WXWCHAR_T_CAST(c) (wint_t)(c)
258 #else
259 #define WXWCHAR_T_CAST(c) c
260 #endif
261
262 /* ctype.h functions */
263 #define wxIsalnum(c) _istalnum(WXWCHAR_T_CAST(c))
264 #define wxIsalpha(c) _istalpha(WXWCHAR_T_CAST(c))
265 #define wxIscntrl(c) _istcntrl(WXWCHAR_T_CAST(c))
266 #define wxIsdigit(c) _istdigit(WXWCHAR_T_CAST(c))
267 #define wxIsgraph(c) _istgraph(WXWCHAR_T_CAST(c))
268 #define wxIslower(c) _istlower(WXWCHAR_T_CAST(c))
269 #define wxIsprint(c) _istprint(WXWCHAR_T_CAST(c))
270 #define wxIspunct(c) _istpunct(WXWCHAR_T_CAST(c))
271 #define wxIsspace(c) _istspace(WXWCHAR_T_CAST(c))
272 #define wxIsupper(c) _istupper(WXWCHAR_T_CAST(c))
273 #define wxIsxdigit(c) _istxdigit(WXWCHAR_T_CAST(c))
274
275 /*
276 There is a bug in VC6 C RTL: toxxx() functions dosn't do anything with
277 signed chars < 0, so "fix" it here.
278 */
279 #define wxTolower(c) _totlower((wxUChar)(c))
280 #define wxToupper(c) _totupper((wxUChar)(c))
281
282 /* locale.h functons */
283 #define wxSetlocale _tsetlocale
284
285 /* string.h functions */
286 #define wxStrcat _tcscat
287 #define wxStrchr _tcschr
288 #define wxStrcmp _tcscmp
289 #define wxStrcoll _tcscoll
290 #define wxStrcpy _tcscpy
291 #define wxStrcspn _tcscspn
292 #define wxStrdupW _wcsdup /* notice the 'W'! */
293 #define wxStrftime _tcsftime
294 #define wxStricmp _tcsicmp
295 #define wxStrnicmp _tcsnicmp
296 #define wxStrlen_ _tcslen /* used in wxStrlen inline function */
297 #define wxStrncat _tcsncat
298 #define wxStrncmp _tcsncmp
299 #define wxStrncpy _tcsncpy
300 #define wxStrpbrk _tcspbrk
301 #define wxStrrchr _tcsrchr
302 #define wxStrspn _tcsspn
303 #define wxStrstr _tcsstr
304 #define wxStrtod _tcstod
305 #define wxStrtol _tcstol
306 #define wxStrtoul _tcstoul
307 #define wxStrxfrm _tcsxfrm
308
309 /* stdio.h functions */
310 #define wxFgetc _fgettc
311 #define wxFgetchar _fgettchar
312 #define wxFgets _fgetts
313 #if wxUSE_UNICODE_MSLU
314 #define wxFopen wxMSLU__tfopen
315 #else
316 #define wxFopen _tfopen
317 #endif
318 #define wxFputc _fputtc
319 #define wxFputchar _fputtchar
320 #define wxFprintf _ftprintf
321 #define wxFputs _fputts
322 #define wxFreopen _tfreopen
323 #define wxFscanf _ftscanf
324 #define wxGetc _gettc
325 #define wxGetchar _gettchar
326 #define wxGets _getts
327 #define wxPerror _tperror
328 #define wxPrintf _tprintf
329 #define wxPutc(c,f) _puttc(WXWCHAR_T_CAST(c),f)
330 #define wxPutchar _puttchar
331 #define wxPuts _putts
332 #define wxScanf _tscanf
333 #if defined(__DMC__)
334 #if wxUSE_UNICODE
335 /* Digital Mars adds count to _stprintf (C99) so prototype conversion see wxchar.cpp */
336 int wxSprintf (wchar_t * __RESTRICT s, const wchar_t * __RESTRICT format, ... ) ;
337 #else
338 /* and there is a bug in D Mars tchar.h prior to 8.39.4n, so define as sprintf */
339 #define wxSprintf sprintf
340 #endif
341 #else
342 #define wxSprintf _stprintf
343 #endif
344
345 #define wxSscanf _stscanf
346 #define wxTmpnam _ttmpnam
347 #define wxUngetc _tungetc
348 #define wxVfprintf _vftprintf
349 #define wxVprintf _vtprintf
350 #define wxVsscanf _vstscanf
351 #define wxVsprintf _vstprintf
352
353 /* special case: not all TCHAR-aware compilers have those */
354 #if defined(__VISUALC__) || \
355 (defined(__BORLANDC__) && __BORLANDC__ >= 0x540)
356 #define wxVsnprintf_ _vsntprintf
357 #define wxSnprintf_ _sntprintf
358 #endif
359
360 /* special case: these functions are missing under Win9x with Unicows so we */
361 /* have to implement them ourselves */
362 #if wxUSE_UNICODE_MSLU
363 #define wxRemove wxMSLU__tremove
364 #define wxRename wxMSLU__trename
365 #else
366 #ifdef __WXWINCE__
367 /* carefully: wxRemove() must return 0 on success while DeleteFile()
368 returns 0 on error, so don't just define one as the other */
369 int wxRemove(const wxChar *path);
370 #else
371 #define wxRemove _tremove
372 #define wxRename _trename
373 #endif
374 #endif
375
376 /* stdlib.h functions */
377 #define wxAtoi _ttoi
378 #define wxAtol _ttol
379 /* #define wxAtof _tttof -- notice that there is no such thing (why?) */
380 /* there are no env vars at all under CE, so no _tgetenv neither */
381 #ifdef __WXWINCE__
382 /* can't define as inline function as this is a C file... */
383 #define wxGetenv(name) ((wxChar *)NULL)
384 #else
385 #define wxGetenv _tgetenv
386 #endif
387 #define wxSystem _tsystem
388
389 /* time.h functions */
390 #define wxAsctime _tasctime
391 #define wxCtime _tctime
392
393 #define wxMbstowcs mbstowcs
394 #define wxWcstombs wcstombs
395 #else /* !TCHAR-aware compilers */
396
397 #if !defined(__MWERKS__) && defined(__DARWIN__) && ( MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_2 )
398 /* even though they are defined and "implemented", they are bad and just
399 stubs so we need our own - we need these even in ANSI builds!! */
400 WXDLLIMPEXP_BASE size_t wxMbstowcs (wchar_t *, const char *, size_t);
401 WXDLLIMPEXP_BASE size_t wxWcstombs (char *, const wchar_t *, size_t);
402 #else
403 #define wxMbstowcs mbstowcs
404 #define wxWcstombs wcstombs
405 #endif
406
407 /* No UNICODE in the c library except wchar_t typedef on mac OSX 10.2 and less - roll our own */
408 #if !defined(__MWERKS__) && wxUSE_UNICODE && defined(__DARWIN__) && ( MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_2 )
409
410 /* we need everything! */
411 #define wxNEED_WX_STRING_H
412 #define wxNEED_WX_CTYPE_H
413
414 #define wxFgetchar(c) wxFgetc(c, stdin)
415 #define wxFputc wxPutc
416 #define wxFputchar(c) wxPutc(c, stdout)
417 #define wxGetc wxFgetc
418 #define wxGetchar(c) wxFgetc(c, stdin)
419
420 #include <stdio.h>
421
422 #define wxNEED_FGETC
423 #define wxNEED_FGETS
424 #define wxNEED_GETS
425 #define wxNEED_UNGETC
426
427 #define wxNEED_FPUTS
428 #define wxNEED_PUTS
429 #define wxNEED_PUTC
430
431 int wxFputs(const wxChar *ch, FILE *stream);
432 int wxPuts(const wxChar *ws);
433 int wxPutc(wxChar ch, FILE *stream);
434
435 #ifdef __cplusplus
436 extern "C" {
437 #endif
438 WXDLLIMPEXP_BASE size_t wxStrlen_(const wxChar *s);
439 #ifdef __cplusplus
440 }
441 #endif
442
443 #define wxPutchar(wch) wxPutc(wch, stdout)
444
445 #define wxNEED_PRINTF_CONVERSION
446 #define wxNEED_WX_STDIO_H
447 #define wxNEED_WX_STDLIB_H
448 #define wxNEED_WX_TIME_H
449
450 #elif wxUSE_UNICODE
451 #include <wctype.h>
452
453 /* this is probably glibc-specific */
454 #if defined(__WCHAR_TYPE__) && !defined(__MWERKS__)
455 /* ctype.h functions (wctype.h) */
456 #define wxIsalnum iswalnum
457 #define wxIsalpha iswalpha
458 #define wxIscntrl iswcntrl
459 #define wxIsdigit iswdigit
460 #define wxIsgraph iswgraph
461 #define wxIslower iswlower
462 #define wxIsprint iswprint
463 #define wxIspunct iswpunct
464 #define wxIsspace iswspace
465 #define wxIsupper iswupper
466 #define wxIsxdigit iswxdigit
467
468 #if defined(__GLIBC__) && (__GLIBC__ == 2) && (__GLIBC_MINOR__ == 0)
469 /* /usr/include/wctype.h incorrectly declares translations */
470 /* tables which provokes tons of compile-time warnings -- try */
471 /* to correct this */
472 #define wxTolower(wc) towctrans((wc), (wctrans_t)__ctype_tolower)
473 #define wxToupper(wc) towctrans((wc), (wctrans_t)__ctype_toupper)
474 #else /* !glibc 2.0 */
475 #define wxTolower towlower
476 #define wxToupper towupper
477 #endif /* gcc/!gcc */
478
479 /* string.h functions (wchar.h) */
480 #define wxStrcat wcscat
481 #define wxStrchr wcschr
482 #define wxStrcmp wcscmp
483 #define wxStrcoll wcscoll
484 #define wxStrcpy wcscpy
485 #define wxStrcspn wcscspn
486 #define wxStrlen_ wxWcslen /* wxStrlen_() is used in wxStrlen() */
487 #define wxStrncat wcsncat
488 #define wxStrncmp wcsncmp
489 #define wxStrncpy wcsncpy
490 #define wxStrpbrk wcspbrk
491 #define wxStrrchr wcsrchr
492 #define wxStrspn wcsspn
493 #define wxStrstr wcsstr
494 #define wxStrtod wcstod
495 #define wxStrtol wcstol
496 #define wxStrtoul wcstoul
497 #define wxStrxfrm wcsxfrm
498
499 #define wxFgetc fgetwc
500 #define wxFgetchar fgetwchar
501 #define wxFgets fgetws
502 #define wxFputc fputwc
503 #define wxFputchar fputwchar
504 #define wxGetc getwc
505 #define wxGetchar getwchar
506 #define wxGets getws
507 #define wxUngetc ungetwc
508
509 #ifdef HAVE_FPUTWS
510 #define wxFputs fputws
511 #else
512 #define wxNEED_FPUTS
513 #include <stdio.h>
514 int wxFputs(const wxChar *ch, FILE *stream);
515 #endif
516
517 #ifdef HAVE_WPUTC
518 #define wxPutc wputc
519 #else
520 #define wxNEED_PUTC
521 #include <stdio.h>
522 int wxPutc(wxChar ch, FILE *stream);
523 #endif
524
525 #ifdef HAVE_WPUTCHAR
526 #define wxPutchar wputchar
527 #else
528 #define wxPutchar(wch) wxPutc(wch, stdout)
529 #endif
530
531 #ifdef HAVE_PUTWS
532 #define wxPuts putws
533 #else
534 #define wxNEED_PUTS
535 int wxPuts(const wxChar *ws);
536 #endif
537
538 /* we need %s to %ls conversion for printf and scanf etc */
539 #define wxNEED_PRINTF_CONVERSION
540
541 /* glibc doesn't have wide char equivalents of the other stuff so */
542 /* use our own versions */
543 #define wxNEED_WX_STDIO_H
544 #define wxNEED_WX_STDLIB_H
545 #define wxNEED_WX_TIME_H
546 #elif defined(__MWERKS__) && ( defined(__MSL__) || defined(__MACH__) )
547 /* ctype.h functions (wctype.h) */
548 #define wxIsalnum iswalnum
549 #define wxIsalpha iswalpha
550 #define wxIscntrl iswcntrl
551 #define wxIsdigit iswdigit
552 #define wxIsgraph iswgraph
553 #define wxIslower iswlower
554 #define wxIsprint iswprint
555 #define wxIspunct iswpunct
556 #define wxIsspace iswspace
557 #define wxIsupper iswupper
558 #define wxIsxdigit iswxdigit
559 #define wxTolower towlower
560 #define wxToupper towupper
561
562 /* string.h functions (wchar.h) */
563 #define wxStrcat wcscat
564 #define wxStrchr wcschr
565 #define wxStrcmp wcscmp
566 #define wxStrcoll wcscoll
567 #define wxStrcpy wcscpy
568 #define wxStrcspn wcscspn
569 #define wxStrlen_ wxWcslen /* wxStrlen_() is used in wxStrlen() */
570 #define wxStrncat wcsncat
571 #define wxStrncmp wcsncmp
572 #define wxStrncpy wcsncpy
573 #define wxStrpbrk wcspbrk
574 #define wxStrrchr wcsrchr
575 #define wxStrspn wcsspn
576 #define wxStrstr wcsstr
577 #define wxStrtod wcstod
578 #define wxStrtol wcstol
579 #define wxStrtoul wcstoul
580 #define wxStrxfrm wcsxfrm
581
582 #define wxFgetc fgetwc
583 #define wxFgetchar fgetwchar
584 #define wxFgets fgetws
585 #define wxFputc fputwc
586 #define wxFputchar fputwchar
587 #define wxGetc getwc
588 #define wxGetchar getwchar
589 #define wxGets getws
590 #define wxUngetc ungetwc
591
592 #define wxNEED_PRINTF_CONVERSION
593
594 #define wxPutc putwc
595 #define wxPutchar putwchar
596 #define wxFputs fputws
597
598 /* stdio.h functions */
599
600 #define wxNEED_WX_STDIO_H
601
602 /* stdlib.h functions */
603 #ifdef __MACH__
604 #define wxNEED_WX_STDLIB_H
605 #else
606 #define wxAtof watof
607 #define wxAtoi watoi
608 #define wxAtol watol
609 #define wxGetenv(a) ((wxChar*)NULL)
610 #define wxSystem(a) ((int)NULL)
611 #endif
612 /* time.h functions */
613 #define wxAsctime wasciitime
614 #define wxCtime wctime
615 /* #define wxStrftime wcsftime */
616
617 #define wxNEED_WX_TIME_H
618 #else /* !metrowerks for apple */
619 #error "Please define wide character functions for your environment"
620 #endif
621 #else /* ASCII */
622 #include <ctype.h>
623 #include <string.h>
624
625 /* ctype.h functions */
626 #define wxIsalnum isalnum
627 #define wxIsalpha isalpha
628 #define wxIscntrl iscntrl
629 #define wxIsdigit isdigit
630 #define wxIsgraph isgraph
631 #define wxIslower islower
632 #define wxIsprint isprint
633 #define wxIspunct ispunct
634 #define wxIsspace isspace
635 #define wxIsupper isupper
636 #define wxIsxdigit isxdigit
637 #define wxTolower tolower
638 #define wxToupper toupper
639
640 /* locale.h functons */
641 #define wxSetlocale setlocale
642
643 /* string.h functions */
644 #define wxStrcat strcat
645 #define wxStrchr strchr
646 #define wxStrcmp strcmp
647 #define wxStrcoll strcoll
648 #define wxStrcpy strcpy
649 #define wxStrcspn strcspn
650
651 /* wxStricmp and wxStrnicmp are defined below */
652 #define wxStrlen_ strlen /* used in wxStrlen inline function */
653 #define wxStrncat strncat
654 #define wxStrncmp strncmp
655 #define wxStrncpy strncpy
656 #define wxStrpbrk strpbrk
657 #define wxStrrchr strrchr
658 #define wxStrspn strspn
659 #define wxStrstr strstr
660 #define wxStrtod strtod
661 #ifdef HAVE_STRTOK_R
662 #define wxStrtok(str, sep, last) strtok_r(str, sep, last)
663 #endif
664 #define wxStrtol strtol
665 #define wxStrtoul strtoul
666 #define wxStrxfrm strxfrm
667
668 /* stdio.h functions */
669 #define wxFopen fopen
670 #define wxFreopen freopen
671 #define wxRemove remove
672 #define wxRename rename
673
674 #define wxPerror perror
675 #define wxTmpnam tmpnam
676
677 #define wxFgetc fgetc
678 #define wxFgetchar fgetchar
679 #define wxFgets fgets
680 #define wxFputc fputc
681 #define wxFputs fputs
682 #define wxFputchar fputchar
683 #define wxFprintf fprintf
684 #define wxFscanf fscanf
685 #define wxGetc getc
686 #define wxGetchar getchar
687 #define wxGets gets
688 #define wxPrintf printf
689 #define wxPutc putc
690 #define wxPutchar putchar
691 #define wxPuts puts
692 #define wxScanf scanf
693 #define wxSprintf sprintf
694 #define wxSscanf sscanf
695 #define wxUngetc ungetc
696 #define wxVfprintf vfprintf
697 #define wxVprintf vprintf
698 #define wxVsscanf vsscanf
699 #define wxVsprintf vsprintf
700
701 /* stdlib.h functions */
702 #define wxAtof atof
703 #define wxAtoi atoi
704 #define wxAtol atol
705 #define wxGetenv getenv
706 #define wxSystem system
707
708 /* time.h functions */
709 #define wxAsctime asctime
710 #define wxCtime ctime
711 #define wxStrftime strftime
712 #endif /* Unicode/ASCII */
713 #endif /* TCHAR-aware compilers/the others */
714
715 /*
716 various special cases
717 */
718
719 /* define wxStricmp and wxStrnicmp for various compilers */
720
721 /* note that in Unicode mode we definitely are going to need our own version */
722 #if !defined(wxStricmp) && !wxUSE_UNICODE
723 #if defined(__BORLANDC__) || defined(__WATCOMC__) || \
724 defined(__SALFORDC__) || defined(__VISAGECPP__) || \
725 defined(__EMX__) || defined(__DJGPP__)
726 #define wxStricmp stricmp
727 #define wxStrnicmp strnicmp
728 #elif defined(__WXPALMOS__)
729 /* FIXME: There is no equivalent to strnicmp in the Palm OS API. This
730 * quick hack should do until one can be written.
731 */
732 #define wxStricmp StrCaselessCompare
733 #define wxStrnicmp strnicmp
734 #elif defined(__SYMANTEC__) || defined(__VISUALC__) || \
735 (defined(__MWERKS__) && defined(__INTEL__))
736 #define wxStricmp _stricmp
737 #define wxStrnicmp _strnicmp
738 #elif defined(__UNIX__) || defined(__GNUWIN32__)
739 #define wxStricmp strcasecmp
740 #define wxStrnicmp strncasecmp
741 /* #else -- use wxWidgets implementation */
742 #endif
743 #endif /* !defined(wxStricmp) */
744
745 /* define wxWcslen() which should be always available if wxUSE_WCHAR_T == 1 (as */
746 /* it's used in wx/buffer.h -- and also might be used just below by wxStrlen() */
747 /* when wxStrlen_() is #define'd as wxWcslen so do it before defining wxStrlen) */
748 #if wxUSE_WCHAR_T
749 #ifdef HAVE_WCSLEN
750 #define wxWcslen wcslen
751 #else
752 WXDLLIMPEXP_BASE size_t wxWcslen(const wchar_t *s);
753 #endif
754 #endif /* wxUSE_WCHAR_T */
755
756 #ifdef __cplusplus
757 /* checks whether the passed in pointer is NULL and if the string is empty */
758 inline bool wxIsEmpty(const wxChar *p) { return !p || !*p; }
759
760 /* safe version of strlen() (returns 0 if passed NULL pointer) */
761 inline size_t wxStrlen(const wxChar *psz) { return psz ? wxStrlen_(psz) : 0; }
762 #endif
763
764 /*
765 each of strdup() and wcsdup() may or may not be available but we need both
766 of them anyhow for wx/buffer.h so we define the missing one(s) in
767 wxchar.cpp and so we should always have both wxStrdupA and wxStrdupW
768 defined -- if this is somehow not the case in some situations, please
769 correct that and not the lines here
770 */
771 #if wxUSE_UNICODE
772 #define wxStrdup wxStrdupW
773 #else
774 #define wxStrdup wxStrdupA
775 #endif
776
777 #ifdef __cplusplus
778 WXDLLIMPEXP_BASE bool wxOKlibc(); /* for internal use */
779 #endif
780
781 /* printf() family saga */
782
783 /*
784 For some systems [v]snprintf() exists in the system libraries but not in the
785 headers, so we need to declare it ourselves to be able to use it.
786 */
787 #if defined(HAVE_VSNPRINTF) && !defined(HAVE_VSNPRINTF_DECL)
788 #ifdef __cplusplus
789 extern "C"
790 #else
791 extern
792 #endif
793 int vsnprintf(char *str, size_t size, const char *format, va_list ap);
794 #endif /* !HAVE_VSNPRINTF_DECL */
795
796 #if defined(HAVE_SNPRINTF) && !defined(HAVE_SNPRINTF_DECL)
797 #ifdef __cplusplus
798 extern "C"
799 #else
800 extern
801 #endif
802 int snprintf(char *str, size_t size, const char *format, ...);
803 #endif /* !HAVE_SNPRINTF_DECL */
804
805 /* Wrapper for vsnprintf if it's 3rd parameter is non-const. Note: the
806 * same isn't done for snprintf below, the builtin wxSnprintf_ is used
807 * instead since it's already a simple wrapper */
808 #if defined __cplusplus && defined HAVE_BROKEN_VSNPRINTF_DECL
809 inline int wx_fixed_vsnprintf(char *str, size_t size, const char *format, va_list ap)
810 {
811 return vsnprintf(str, size, (char*)format, ap);
812 }
813 #endif
814
815 /*
816 First of all, we always want to define safe snprintf() function to be used
817 instead of sprintf(). Some compilers already have it (or rather vsnprintf()
818 which we really need...), otherwise we implement it using our own printf()
819 code.
820
821 We define function with a trailing underscore here because the real one is a
822 wrapper around it as explained below
823 */
824 #ifndef wxVsnprintf_
825 #if wxUSE_UNICODE
826 #if defined(__MWERKS__)
827 #define HAVE_WCSRTOMBS 1
828 #define HAVE_VSWPRINTF 1
829 #endif
830 #if defined(__WATCOMC__)
831 #define wxVsnprintf_ _vsnwprintf
832 #define wxSnprintf_ _snwprintf
833 #endif
834 #if defined(HAVE__VSNWPRINTF)
835 #define wxVsnprintf_ _vsnwprintf
836 /* MinGW?MSVCRT has the wrong vswprintf */
837 #elif defined(HAVE_VSWPRINTF) && !defined(__MINGW32__)
838 #define wxVsnprintf_ vswprintf
839 #endif
840 #else /* ASCII */
841 /* all versions of CodeWarrior supported by wxWidgets apparently have */
842 /* both snprintf() and vsnprintf() */
843 #if defined(HAVE_SNPRINTF) || defined(__MWERKS__) || defined(__WATCOMC__)
844 #ifndef HAVE_BROKEN_SNPRINTF_DECL
845 #define wxSnprintf_ snprintf
846 #endif
847 #endif
848 #if defined(HAVE_VSNPRINTF) || defined(__MWERKS__) || defined(__WATCOMC__)
849 #if defined __cplusplus && defined HAVE_BROKEN_VSNPRINTF_DECL
850 #define wxVsnprintf_ wx_fixed_vsnprintf
851 #else
852 #define wxVsnprintf_ vsnprintf
853 #endif
854 #endif
855 #endif
856 #endif /* wxVsnprintf_ not defined yet */
857
858 #ifndef wxSnprintf_
859 /* no [v]snprintf(), cook our own */
860 WXDLLIMPEXP_BASE int wxSnprintf_(wxChar *buf, size_t len, const wxChar *format,
861 ...) ATTRIBUTE_PRINTF_3;
862 #endif
863 #ifndef wxVsnprintf_
864 WXDLLIMPEXP_BASE int wxVsnprintf_(wxChar *buf, size_t len, const wxChar *format,
865 va_list argptr);
866 #endif
867
868 /*
869 In Unicode mode we need to have all standard functions such as wprintf() and
870 so on but not all systems have them so use our own implementations in this
871 case.
872 */
873 #if wxUSE_UNICODE && !defined(wxHAVE_TCHAR_SUPPORT) && !defined(HAVE_WPRINTF)
874 #define wxNEED_WPRINTF
875 #endif
876
877 /*
878 More Unicode complications: although both ANSI C and C++ define a number of
879 wide character functions such as wprintf(), not all environments have them.
880 Worse, those which do have different behaviours: under Windows, %s format
881 specifier changes its meaning in Unicode build and expects a Unicode string
882 while under Unix/POSIX it still means an ASCII string even for wprintf() and
883 %ls has to be used for wide strings.
884
885 We choose to always emulate Windows behaviour as more useful for us so even
886 if we have wprintf() we still must wrap it in a non trivial wxPrintf().
887
888 */
889
890 #if defined(wxNEED_PRINTF_CONVERSION) || defined(wxNEED_WPRINTF)
891 /*
892 we need to implement all wide character printf and scanf functions
893 either because we don't have them at all or because they don't have the
894 semantics we need
895 */
896
897 #include <stdio.h> /* for FILE */
898
899 int wxScanf( const wxChar *format, ... ) ATTRIBUTE_PRINTF_1;
900 int wxSscanf( const wxChar *str, const wxChar *format, ... ) ATTRIBUTE_PRINTF_2;
901 int wxFscanf( FILE *stream, const wxChar *format, ... ) ATTRIBUTE_PRINTF_2;
902 int wxVsscanf( const wxChar *str, const wxChar *format, va_list ap );
903 int wxPrintf( const wxChar *format, ... ) ATTRIBUTE_PRINTF_1;
904 int wxSprintf( wxChar *str, const wxChar *format, ... ) ATTRIBUTE_PRINTF_2;
905 int wxFprintf( FILE *stream, const wxChar *format, ... ) ATTRIBUTE_PRINTF_2;
906 int wxVfprintf( FILE *stream, const wxChar *format, va_list ap );
907 int wxVprintf( const wxChar *format, va_list ap );
908 int wxVsprintf( wxChar *str, const wxChar *format, va_list ap );
909 #endif /* wxNEED_PRINTF_CONVERSION */
910
911 /* these 2 can be simply mapped to the versions with underscore at the end */
912 /* if we don't have to do the conversion */
913 /*
914 However, if we don't have any vswprintf() at all we don't need to redefine
915 anything as our own wxVsnprintf_() already behaves as needed.
916 */
917 #if defined(wxNEED_PRINTF_CONVERSION) && defined(wxVsnprintf_)
918 int wxSnprintf( wxChar *str, size_t size, const wxChar *format, ... ) ATTRIBUTE_PRINTF_3;
919 int wxVsnprintf( wxChar *str, size_t size, const wxChar *format, va_list ap );
920 #else
921 #define wxSnprintf wxSnprintf_
922 #define wxVsnprintf wxVsnprintf_
923 #endif
924
925 /*
926 various functions which might not be available in libc and for which we
927 provide our own replacements in wxchar.cpp
928 */
929
930 /* ctype.h functions */
931
932 /* RN: Used only under OSX <= 10.2 currently */
933 #ifdef wxNEED_WX_CTYPE_H
934 WXDLLIMPEXP_BASE int wxIsalnum(wxChar ch);
935 WXDLLIMPEXP_BASE int wxIsalpha(wxChar ch);
936 WXDLLIMPEXP_BASE int wxIscntrl(wxChar ch);
937 WXDLLIMPEXP_BASE int wxIsdigit(wxChar ch);
938 WXDLLIMPEXP_BASE int wxIsgraph(wxChar ch);
939 WXDLLIMPEXP_BASE int wxIslower(wxChar ch);
940 WXDLLIMPEXP_BASE int wxIsprint(wxChar ch);
941 WXDLLIMPEXP_BASE int wxIspunct(wxChar ch);
942 WXDLLIMPEXP_BASE int wxIsspace(wxChar ch);
943 WXDLLIMPEXP_BASE int wxIsupper(wxChar ch);
944 WXDLLIMPEXP_BASE int wxIsxdigit(wxChar ch);
945 WXDLLIMPEXP_BASE int wxTolower(wxChar ch);
946 WXDLLIMPEXP_BASE int wxToupper(wxChar ch);
947 #endif /* wxNEED_WX_CTYPE_H */
948
949 /* under VC++ 6.0 isspace() returns 1 for 8 bit chars which completely breaks */
950 /* the file parsing -- this may be true for 5.0 as well, update #ifdef then */
951 #if defined(__VISUALC__) && (__VISUALC__ >= 1200) && !wxUSE_UNICODE
952 #undef wxIsspace
953 #define wxIsspace(c) ((((unsigned)c) < 128) && isspace(c))
954 #endif /* VC++ */
955
956 /*
957 a few compilers don't have the (non standard but common) isascii function,
958 define it ourselves for them
959 */
960 #ifndef isascii
961 #if defined(__MWERKS__)
962 #define wxNEED_ISASCII
963 #elif defined(_WIN32_WCE)
964 #if _WIN32_WCE <= 211
965 #define wxNEED_ISASCII
966 #endif
967 #endif
968 #endif /* isascii */
969
970 #ifdef wxNEED_ISASCII
971 inline int isascii(int c) { return (unsigned)c < 0x80; }
972 #endif
973
974 #ifdef _WIN32_WCE
975 #if _WIN32_WCE <= 211
976 #define isspace(c) ((c) == _T(' ') || (c) == _T('\t'))
977 #endif
978 #endif /* _WIN32_WCE */
979
980 /*
981 we had goofed and defined wxIsctrl() instead of (correct) wxIscntrl() in the
982 initial versions of this header -- now it is too late to remove it so
983 although we fixed the function/macro name above, still provide the
984 backwards-compatible synonym.
985 */
986 #define wxIsctrl wxIscntrl
987
988 /* string.h functions */
989 #ifndef strdup
990 #if defined(__MWERKS__) && !defined(__MACH__) && (__MSL__ < 0x00008000)
991 #define wxNEED_STRDUP
992 #elif defined(__WXWINCE__)
993 #if _WIN32_WCE <= 211
994 #define wxNEED_STRDUP
995 #endif
996 #endif
997 #endif /* strdup */
998
999 #ifdef wxNEED_STRDUP
1000 WXDLLIMPEXP_BASE char *strdup(const char* s);
1001 #endif
1002
1003 /* RN: Used only under OSX <= 10.2 currently
1004 The __cplusplus ifdefs are messy, but they are required to build
1005 the regex library, since c does not support function overloading
1006 */
1007 #ifdef wxNEED_WX_STRING_H
1008 # ifdef __cplusplus
1009 extern "C" {
1010 # endif
1011 WXDLLIMPEXP_BASE wxChar * wxStrcat(wxChar *dest, const wxChar *src);
1012 WXDLLIMPEXP_BASE const wxChar * wxStrchr(const wxChar *s, wxChar c);
1013 WXDLLIMPEXP_BASE int wxStrcmp(const wxChar *s1, const wxChar *s2);
1014 WXDLLIMPEXP_BASE int wxStrcoll(const wxChar *s1, const wxChar *s2);
1015 WXDLLIMPEXP_BASE wxChar * wxStrcpy(wxChar *dest, const wxChar *src);
1016 WXDLLIMPEXP_BASE size_t wxStrcspn(const wxChar *s, const wxChar *reject);
1017 WXDLLIMPEXP_BASE wxChar * wxStrncat(wxChar *dest, const wxChar *src, size_t n);
1018 WXDLLIMPEXP_BASE int wxStrncmp(const wxChar *s1, const wxChar *s2, size_t n);
1019 WXDLLIMPEXP_BASE wxChar * wxStrncpy(wxChar *dest, const wxChar *src, size_t n);
1020 WXDLLIMPEXP_BASE const wxChar * wxStrpbrk(const wxChar *s, const wxChar *accept);
1021 WXDLLIMPEXP_BASE const wxChar * wxStrrchr(const wxChar *s, wxChar c);
1022 WXDLLIMPEXP_BASE size_t wxStrspn(const wxChar *s, const wxChar *accept);
1023 WXDLLIMPEXP_BASE const wxChar * wxStrstr(const wxChar *haystack, const wxChar *needle);
1024 # ifdef __cplusplus
1025 }
1026 # endif
1027
1028 /* These functions use C++, so we can't c extern them */
1029 WXDLLIMPEXP_BASE double wxStrtod(const wxChar *nptr, wxChar **endptr);
1030 WXDLLIMPEXP_BASE long int wxStrtol(const wxChar *nptr, wxChar **endptr, int base);
1031 WXDLLIMPEXP_BASE unsigned long int wxStrtoul(const wxChar *nptr, wxChar **endptr, int base);
1032 WXDLLIMPEXP_BASE size_t wxStrxfrm(wxChar *dest, const wxChar *src, size_t n);
1033
1034 /* inlined versions */
1035 #ifdef __cplusplus
1036 inline wxChar * wxStrchr(wxChar *s, wxChar c)
1037 { return (wxChar *)wxStrchr((const wxChar *)s, c); }
1038 inline wxChar * wxStrpbrk(wxChar *s, const wxChar *accept)
1039 { return (wxChar *)wxStrpbrk((const wxChar *)s, accept); }
1040 inline wxChar * wxStrrchr(wxChar *s, wxChar c)
1041 { return (wxChar *)wxStrrchr((const wxChar *)s, c); }
1042 inline wxChar *wxStrstr(wxChar *haystack, const wxChar *needle)
1043 { return (wxChar *)wxStrstr((const wxChar *)haystack, needle); }
1044 #endif
1045
1046 #endif /* wxNEED_WX_STRING_H */
1047
1048 #ifndef wxStrdupA
1049 WXDLLIMPEXP_BASE char *wxStrdupA(const char *psz);
1050 #endif
1051
1052 #ifndef wxStrdupW
1053 WXDLLIMPEXP_BASE wchar_t *wxStrdupW(const wchar_t *pwz);
1054 #endif
1055
1056 #ifndef wxStricmp
1057 WXDLLIMPEXP_BASE int wxStricmp(const wxChar *psz1, const wxChar *psz2);
1058 #endif
1059
1060 #ifndef wxStrnicmp
1061 WXDLLIMPEXP_BASE int wxStrnicmp(const wxChar *psz1, const wxChar *psz2, size_t len);
1062 #endif
1063
1064 #ifndef wxStrtok
1065 WXDLLIMPEXP_BASE wxChar * wxStrtok(wxChar *psz, const wxChar *delim, wxChar **save_ptr);
1066 #endif
1067
1068 #ifdef __cplusplus
1069 #ifndef wxSetlocale
1070 class WXDLLIMPEXP_BASE wxWCharBuffer;
1071 WXDLLIMPEXP_BASE wxWCharBuffer wxSetlocale(int category, const wxChar *locale);
1072 #endif
1073 #endif
1074
1075 /* stdio.h functions */
1076 #ifdef wxNEED_WX_STDIO_H
1077 #include <stdio.h>
1078 WXDLLIMPEXP_BASE FILE * wxFopen(const wxChar *path, const wxChar *mode);
1079 WXDLLIMPEXP_BASE FILE * wxFreopen(const wxChar *path, const wxChar *mode, FILE *stream);
1080 WXDLLIMPEXP_BASE int wxRemove(const wxChar *path);
1081 WXDLLIMPEXP_BASE int wxRename(const wxChar *oldpath, const wxChar *newpath);
1082
1083 /* *printf() family is handled separately */
1084 #endif /* wxNEED_WX_STDIO_H */
1085
1086
1087 /* stdlib.h functions */
1088 #ifndef wxAtof
1089 WXDLLIMPEXP_BASE double wxAtof(const wxChar *psz);
1090 #endif
1091
1092 #ifdef wxNEED_WX_STDLIB_H
1093 WXDLLIMPEXP_BASE int wxAtoi(const wxChar *psz);
1094 WXDLLIMPEXP_BASE long wxAtol(const wxChar *psz);
1095 WXDLLIMPEXP_BASE wxChar * wxGetenv(const wxChar *name);
1096 WXDLLIMPEXP_BASE int wxSystem(const wxChar *psz);
1097 #endif
1098
1099
1100 /* time.h functions */
1101 #ifdef wxNEED_WX_TIME_H
1102 #if defined(__MWERKS__) && defined(macintosh)
1103 #include <time.h>
1104 #endif
1105 /*silent gabby compilers*/
1106 struct tm;
1107 WXDLLIMPEXP_BASE size_t wxStrftime(wxChar *s, size_t max,
1108 const wxChar *fmt, const struct tm *tm);
1109 #endif /* wxNEED_WX_TIME_H */
1110
1111 #ifndef wxCtime
1112 #include <time.h>
1113 WXDLLIMPEXP_BASE wxChar *wxCtime(const time_t *timep);
1114 #endif
1115
1116
1117 /* missing functions in some WinCE versions */
1118 #ifdef _WIN32_WCE
1119 #if (_WIN32_WCE < 300)
1120 WXDLLIMPEXP_BASE void *calloc( size_t num, size_t size );
1121 #endif
1122 #endif /* _WIN32_WCE */
1123
1124 /* multibyte to wide char conversion functions and macros */
1125
1126 #if wxUSE_WCHAR_T
1127 /* multibyte<->widechar conversion */
1128 WXDLLIMPEXP_BASE size_t wxMB2WC(wchar_t *buf, const char *psz, size_t n);
1129 WXDLLIMPEXP_BASE size_t wxWC2MB(char *buf, const wchar_t *psz, size_t n);
1130
1131 #if wxUSE_UNICODE
1132 #define wxMB2WX wxMB2WC
1133 #define wxWX2MB wxWC2MB
1134 #define wxWC2WX wxStrncpy
1135 #define wxWX2WC wxStrncpy
1136 #else
1137 #define wxMB2WX wxStrncpy
1138 #define wxWX2MB wxStrncpy
1139 #define wxWC2WX wxWC2MB
1140 #define wxWX2WC wxMB2WC
1141 #endif
1142 #else /* !wxUSE_UNICODE */
1143 /* Why is this here?
1144 #error ha */
1145 /* No wxUSE_WCHAR_T: we have to do something (JACS) */
1146 #define wxMB2WC wxStrncpy
1147 #define wxWC2MB wxStrncpy
1148 #define wxMB2WX wxStrncpy
1149 #define wxWX2MB wxStrncpy
1150 #define wxWC2WX wxWC2MB
1151 #define wxWX2WC wxMB2WC
1152 #endif
1153
1154 /*
1155 RN: The following are not normal versions of memcpy et al., rather
1156 these are either char or widechar versions depending on
1157 if unicode is used or not.
1158 */
1159
1160 #ifdef __cplusplus
1161
1162 //
1163 // RN: We could do the usual tricky compiler detection here,
1164 // and use their variant (such as wmemchr, etc.). The problem
1165 // is that these functions are quite rare, even though they are
1166 // part of the current POSIX standard. In addition, most compilers
1167 // (including even MSC) inline them just like we do right in their
1168 // headers.
1169 //
1170 #if wxUSE_UNICODE
1171 #include <string.h> //for mem funcs
1172
1173 //implement our own wmem variants
1174 inline wxChar* wxTmemchr(const wxChar* s, wxChar c, size_t l)
1175 {
1176 for(;l && *s != c;--l, ++s) {}
1177
1178 if(l)
1179 return (wxChar*)s;
1180 return NULL;
1181 }
1182
1183 inline int wxTmemcmp(const wxChar* sz1, const wxChar* sz2, size_t len)
1184 {
1185 for(; *sz1 == *sz2 && len; --len, ++sz1, ++sz2) {}
1186
1187 if(len)
1188 return *sz1 < *sz2 ? -1 : *sz1 > *sz2;
1189 else
1190 return 0;
1191 }
1192
1193 inline wxChar* wxTmemcpy(wxChar* szOut, const wxChar* szIn, size_t len)
1194 {
1195 return (wxChar*) memcpy(szOut, szIn, len * sizeof(wxChar));
1196 }
1197
1198 inline wxChar* wxTmemmove(wxChar* szOut, const wxChar* szIn, size_t len)
1199 {
1200 return (wxChar*) memmove(szOut, szIn, len * sizeof(wxChar));
1201 }
1202
1203 inline wxChar* wxTmemset(wxChar* szOut, const wxChar cIn, size_t len)
1204 {
1205 wxChar* szRet = szOut;
1206
1207 while (len--)
1208 *szOut++ = cIn;
1209
1210 return szRet;
1211 }
1212
1213 #else //!wxUSE_UNICODE
1214 # define wxTmemchr memchr
1215 # define wxTmemcmp memcmp
1216 # define wxTmemcpy memcpy
1217 # define wxTmemmove memmove
1218 # define wxTmemset memset
1219 #endif
1220
1221 #endif /*__cplusplus*/
1222
1223
1224 #endif /* _WX_WXCHAR_H_ */
1225