]> git.saurik.com Git - wxWidgets.git/blob - include/wx/wxchar.h
added test for wxFileConfig::DeleteEntry
[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
6 // Created: 1998/06/12
7 // RCS-ID: $Id$
8 // Copyright: (c) 1998-2002 wxWindows dev team
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_WXCHAR_H_
13 #define _WX_WXCHAR_H_
14
15 #if defined(__GNUG__) && !defined(__APPLE__)
16 #pragma interface "wxchar.h"
17 #endif
18
19 // ----------------------------------------------------------------------------
20 // first deal with Unicode setting: wxUSE_UNICODE should be defined as 0 or 1
21 // and is used by wxWindows, _UNICODE and/or UNICODE may be defined or used by
22 // the system headers so bring these settings in sync
23 // ----------------------------------------------------------------------------
24
25 // set wxUSE_UNICODE to 1 if UNICODE or _UNICODE is defined
26 #if defined(_UNICODE) || defined(UNICODE)
27 #undef wxUSE_UNICODE
28 #define wxUSE_UNICODE 1
29 #else
30 #ifndef wxUSE_UNICODE
31 #define wxUSE_UNICODE 0
32 #endif
33 #endif // Unicode
34
35 // and vice versa: define UNICODE and _UNICODE if wxUSE_UNICODE is 1...
36 #if wxUSE_UNICODE
37 #ifndef _UNICODE
38 #define _UNICODE
39 #endif
40 #ifndef UNICODE
41 #define UNICODE
42 #endif
43 #endif // Unicode
44
45 // check whether we have wchar_t
46 #if !defined(wxUSE_WCHAR_T)
47 #if defined(__WIN16__)
48 // no wchar_t under Win16 regadrless of compiler used
49 #define wxUSE_WCHAR_T 0
50 #elif defined(__UNIX__)
51 #if defined(HAVE_WCSTR_H) || defined(HAVE_WCHAR_H) || defined(__FreeBSD__) || defined(__DARWIN__)
52 #define wxUSE_WCHAR_T 1
53 #else
54 #define wxUSE_WCHAR_T 0
55 #endif
56 #elif defined(__GNUWIN32__) && !defined(__MINGW32__)
57 #define wxUSE_WCHAR_T 0
58 #elif defined(__WATCOMC__)
59 #define wxUSE_WCHAR_T 0
60 #elif defined(__VISAGECPP__) && (__IBMCPP__ < 400)
61 #define wxUSE_WCHAR_T 0
62 #else
63 // add additional compiler checks if this fails
64 #define wxUSE_WCHAR_T 1
65 #endif
66 #endif // !defined(wxUSE_WCHAR_T)
67
68 // Unicode support requires wchar_t
69 #if wxUSE_UNICODE && !wxUSE_WCHAR_T
70 #error "wchar_t must be available in Unicode build"
71 #endif // Unicode
72
73 // ----------------------------------------------------------------------------
74 // standard headers we need here
75 //
76 // NB: don't include any wxWindows headers here because almost of them include
77 // this one!
78 // ----------------------------------------------------------------------------
79
80 // Required for wxPrintf() etc
81 #include <stdarg.h>
82
83 // Almost all compiler have strdup(), but not quite all: CodeWarrior under Mac
84 // and VC++ for Windows CE don't provide it
85 #if !(defined(__MWERKS__) && defined(__WXMAC__)) && !defined(__WXWINCE__)
86 // use #define, not inline wrapper, as it is tested with #ifndef below
87 #define wxStrdupA strdup
88 #endif
89
90 // non Unix compilers which do have wchar.h (but not tchar.h which is included
91 // below and which includes wchar.h anyhow).
92 // Actually MinGW has tchar.h, but it does not include wchar.h
93 #if defined(__MWERKS__) || defined(__VISAGECPP__) || defined(__MINGW32__)
94 #ifndef HAVE_WCHAR_H
95 #define HAVE_WCHAR_H
96 #endif
97 #endif
98
99 #if wxUSE_WCHAR_T
100 #ifdef HAVE_WCHAR_H
101 // the current (as of Nov 2002) version of cygwin has a bug in its
102 // wchar.h -- there is no extern "C" around the declarations in it and
103 // this results in linking errors later; also, at least on some
104 // Cygwin versions, wchar.h requires sys/types.h
105 #ifdef __CYGWIN__
106 #include <sys/types.h>
107 extern "C" {
108 #endif // Cygwin
109 #include <wchar.h>
110 #ifdef __CYGWIN__
111 }
112 #endif // Cygwin
113 #elif defined(HAVE_WCSTR_H)
114 // old compilers have relevant declarations here
115 #include <wcstr.h>
116 #elif defined(__FreeBSD__) || defined(__DARWIN__) || defined(__EMX__)
117 // include stdlib.h for wchar_t
118 #include <stdlib.h>
119 #endif // HAVE_WCHAR_H
120 #endif // wxUSE_WCHAR_T
121
122 // ----------------------------------------------------------------------------
123 // define wxHAVE_TCHAR_SUPPORT for the compilers which support the TCHAR type
124 // mapped to either char or wchar_t depending on the ASCII/Unicode mode and have
125 // the function mapping _tfoo() -> foo() or wfoo()
126 // ----------------------------------------------------------------------------
127
128 // VC++ and BC++ starting with 5.2 have TCHAR support
129 #ifdef __VISUALC__
130 #define wxHAVE_TCHAR_SUPPORT
131 #elif defined(__BORLANDC__) && (__BORLANDC__ >= 0x520)
132 #define wxHAVE_TCHAR_SUPPORT
133 #include <ctype.h>
134 #elif defined(__MINGW32__) && wxCHECK_W32API_VERSION( 1, 0 )
135 #define wxHAVE_TCHAR_SUPPORT
136 #include <stddef.h>
137 #include <string.h>
138 #include <ctype.h>
139 #elif 0 && defined(__VISAGECPP__) && (__IBMCPP__ >= 400)
140 // VZ: the old VisualAge definitions were completely wrong and had no
141 // chance at all to work in Unicode build anyhow so let's pretend that
142 // VisualAge does _not_ support TCHAR for the moment (as indicated by
143 // "0 &&" above) until someone really has time to delve into Unicode
144 // issues under OS/2
145
146 // VisualAge 4.0+ supports TCHAR
147 #define wxHAVE_TCHAR_SUPPORT
148 #endif // compilers with (good) TCHAR support
149
150 #ifdef wxHAVE_TCHAR_SUPPORT
151 // get TCHAR definition if we've got it
152 #include <tchar.h>
153
154 // we surely do have wchar_t if we have TCHAR
155 #ifndef wxUSE_WCHAR_T
156 #define wxUSE_WCHAR_T 1
157 #endif // !defined(wxUSE_WCHAR_T)
158
159 // and we also do have wcslen()
160 #ifndef HAVE_WCSLEN
161 #define HAVE_WCSLEN
162 #endif
163 #endif // wxHAVE_TCHAR_SUPPORT
164
165 // ----------------------------------------------------------------------------
166 // define wxChar type
167 // ----------------------------------------------------------------------------
168
169 // TODO: define wxCharInt to be equal to either int or wint_t?
170
171 #if !wxUSE_UNICODE
172 typedef char wxChar;
173 typedef signed char wxSChar;
174 typedef unsigned char wxUChar;
175 #else // Unicode
176 // VZ: note that VC++ defines _T[SU]CHAR simply as wchar_t and not as
177 // signed/unsigned version of it which (a) makes sense to me (unlike
178 // char wchar_t is always unsigned) and (b) was how the previous
179 // definitions worked so keep it like this
180
181 // GNU libc has __WCHAR_TYPE__ which requires special treatment, see
182 // comment below
183 #if !defined(__WCHAR_TYPE__) || \
184 (!defined(__GNUC__) || wxCHECK_GCC_VERSION(2, 96))
185 // standard case
186 typedef wchar_t wxChar;
187 typedef wchar_t wxSChar;
188 typedef wchar_t wxUChar;
189 #else // __WCHAR_TYPE__ and gcc < 2.96
190 // VS: wxWindows used to define wxChar as __WCHAR_TYPE__ here. However,
191 // this doesn't work with new GCC 3.x compilers because wchar_t is
192 // C++'s builtin type in the new standard. OTOH, old compilers (GCC
193 // 2.x) won't accept new definition of wx{S,U}Char, therefore we
194 // have to define wxChar conditionally depending on detected
195 // compiler & compiler version.
196 // with old definition of wxChar.
197 typedef __WCHAR_TYPE__ wxChar;
198 typedef __WCHAR_TYPE__ wxSChar;
199 typedef __WCHAR_TYPE__ wxUChar;
200 #endif // __WCHAR_TYPE__
201 #endif // ASCII/Unicode
202
203 // ----------------------------------------------------------------------------
204 // define _T() and related macros
205 // ----------------------------------------------------------------------------
206
207 // BSD systems define _T() to be something different in ctype.h, override it
208 #if defined(__FreeBSD__) || defined(__DARWIN__)
209 #include <ctype.h>
210 #undef _T
211 #endif
212
213 // could already be defined by tchar.h (it's quasi standard)
214 #ifndef _T
215 #if !wxUSE_UNICODE
216 #define _T(x) x
217 #else // Unicode
218 #define _T(x) L ## x
219 #endif // ASCII/Unicode
220 #endif // !defined(_T)
221
222 // although global macros with such names are normally bad, we want to have
223 // another name for _T() which should be used to avoid confusion between _T()
224 // and _() in wxWindows sources
225 #define wxT(x) _T(x)
226
227 // Unicode-friendly __FILE__, __DATE__ and __TIME__ analogs
228 #ifndef __TFILE__
229 #define __XFILE__(x) wxT(x)
230 #define __TFILE__ __XFILE__(__FILE__)
231 #endif
232
233 #ifndef __TDATE__
234 #define __XDATE__(x) wxT(x)
235 #define __TDATE__ __XDATE__(__DATE__)
236 #endif
237
238 #ifndef __TTIME__
239 #define __XTIME__(x) wxT(x)
240 #define __TTIME__ __XTIME__(__TIME__)
241 #endif
242
243 // ----------------------------------------------------------------------------
244 // define wxFoo() function for each standard foo() function whose signature
245 // (exceptionally including the return type) includes any mention of char:
246 // wxFoo() is going to be a Unicode-friendly version of foo(), i.e. will have
247 // the same signature but with char replaced by wxChar which allows us to use
248 // it in Unicode build as well
249 // ----------------------------------------------------------------------------
250
251 #ifdef wxHAVE_TCHAR_SUPPORT
252 #include <ctype.h>
253
254 // ctype.h functions
255 #define wxIsalnum _istalnum
256 #define wxIsalpha _istalpha
257 #define wxIsctrl _istctrl
258 #define wxIsdigit _istdigit
259 #define wxIsgraph _istgraph
260 #define wxIslower _istlower
261 #define wxIsprint _istprint
262 #define wxIspunct _istpunct
263 #define wxIsspace _istspace
264 #define wxIsupper _istupper
265 #define wxIsxdigit _istxdigit
266 #define wxTolower _totlower
267 #define wxToupper _totupper
268
269 // locale.h functons
270 #define wxSetlocale _tsetlocale
271
272 // string.h functions
273 #define wxStrcat _tcscat
274 #define wxStrchr _tcschr
275 #define wxStrcmp _tcscmp
276 #define wxStrcoll _tcscoll
277 #define wxStrcpy _tcscpy
278 #define wxStrcspn _tcscspn
279 #define wxStrdupW _wcsdup // notice the 'W'!
280 #define wxStrftime _tcsftime
281 #define wxStricmp _tcsicmp
282 #define wxStrnicmp _tcsnicmp
283 #define wxStrlen_ _tcslen // used in wxStrlen inline function
284 #define wxStrncat _tcsncat
285 #define wxStrncmp _tcsncmp
286 #define wxStrncpy _tcsncpy
287 #define wxStrpbrk _tcspbrk
288 #define wxStrrchr _tcsrchr
289 #define wxStrspn _tcsspn
290 #define wxStrstr _tcsstr
291 #define wxStrtod _tcstod
292 #define wxStrtol _tcstol
293 #define wxStrtoul _tcstoul
294 #define wxStrxfrm _tcsxfrm
295
296 // stdio.h functions
297 #define wxFgetc _fgettc
298 #define wxFgetchar _fgettchar
299 #define wxFgets _fgetts
300 #define wxFopen _tfopen
301 #define wxFputc _fputtc
302 #define wxFputchar _fputtchar
303 #define wxFprintf _ftprintf
304 #define wxFputs _fputts
305 #define wxFreopen _tfreopen
306 #define wxFscanf _ftscanf
307 #define wxGetc _gettc
308 #define wxGetchar _gettchar
309 #define wxGets _getts
310 #define wxPerror _tperror
311 #define wxPrintf _tprintf
312 #define wxPutc _puttc
313 #define wxPutchar _puttchar
314 #define wxPuts _putts
315 #define wxScanf _tscanf
316 #define wxSprintf _stprintf
317 #define wxSscanf _stscanf
318 #define wxTmpnam _ttmpnam
319 #define wxUngetc _tungetc
320 #define wxVfprintf _vftprintf
321 #define wxVprintf _vtprintf
322 #define wxVsscanf _vstscanf
323 #define wxVsprintf _vstprintf
324
325 // special case: not all TCHAR-aware compilers have those
326 #if defined(__VISUALC__) || \
327 (defined(__BORLANDC__) && __BORLANDC__ >= 0x540)
328 #define wxVsnprintf_ _vsntprintf
329 #define wxSnprintf_ _sntprintf
330 #endif
331
332 // special case: these functions are missing under Win9x with Unicows so we
333 // have to implement them ourselves
334 #if wxUSE_UNICODE_MSLU
335 #define wxRemove wxMSLU__tremove
336 #define wxRename wxMSLU__trename
337 #else
338 #define wxRemove _tremove
339 #define wxRename _trename
340 #endif
341
342 // stdlib.h functions
343 #define wxAtoi _ttoi
344 #define wxAtol _ttol
345 // #define wxAtof _tttof -- notice that there is no such thing (why?)
346 #define wxGetenv _tgetenv
347 #define wxSystem _tsystem
348
349 // time.h functions
350 #define wxAsctime _tasctime
351 #define wxCtime _tctime
352 #else // !TCHAR-aware compilers
353 #if wxUSE_UNICODE
354 #include <wctype.h>
355
356 // this is probably glibc-specific
357 #if defined(__WCHAR_TYPE__)
358 // ctype.h functions (wctype.h)
359 #define wxIsalnum iswalnum
360 #define wxIsalpha iswalpha
361 #define wxIsctrl iswcntrl
362 #define wxIsdigit iswdigit
363 #define wxIsgraph iswgraph
364 #define wxIslower iswlower
365 #define wxIsprint iswprint
366 #define wxIspunct iswpunct
367 #define wxIsspace iswspace
368 #define wxIsupper iswupper
369 #define wxIsxdigit iswxdigit
370
371 #if defined(__GLIBC__) && (__GLIBC__ == 2) && (__GLIBC_MINOR__ == 0)
372 // /usr/include/wctype.h incorrectly declares translations
373 // tables which provokes tons of compile-time warnings -- try
374 // to correct this
375 #define wxTolower(wc) towctrans((wc), (wctrans_t)__ctype_tolower)
376 #define wxToupper(wc) towctrans((wc), (wctrans_t)__ctype_toupper)
377 #else // !glibc 2.0
378 #define wxTolower towlower
379 #define wxToupper towupper
380 #endif // gcc/!gcc
381
382 // string.h functions (wchar.h)
383 #define wxStrcat wcscat
384 #define wxStrchr wcschr
385 #define wxStrcmp wcscmp
386 #define wxStrcoll wcscoll
387 #define wxStrcpy wcscpy
388 #define wxStrcspn wcscspn
389 #define wxStrlen_ wxWcslen // wxStrlen_() is used in wxStrlen()
390 #define wxStrncat wcsncat
391 #define wxStrncmp wcsncmp
392 #define wxStrncpy wcsncpy
393 #define wxStrpbrk wcspbrk
394 #define wxStrrchr wcsrchr
395 #define wxStrspn wcsspn
396 #define wxStrstr wcsstr
397 #define wxStrtod wcstod
398 #define wxStrtol wcstol
399 #define wxStrtoul wcstoul
400 #define wxStrxfrm wcsxfrm
401
402 #define wxFgetc fgetwc
403 #define wxFgetchar fgetwchar
404 #define wxFgets fgetws
405 #define wxFputc fputwc
406 #define wxFputchar fputwchar
407 #define wxGetc getwc
408 #define wxGetchar getwchar
409 #define wxGets getws
410 #define wxUngetc ungetwc
411
412 #ifdef HAVE_FPUTWC
413 #define wxPutc wputc
414 #define wxPutchar wputchar
415 #define wxPuts putws
416 #define wxFputs fputws
417 #else
418 #define wxNEED_FPUTWC
419
420 #include <stdio.h>
421
422 int wxFputs(const wxChar *ch, FILE *stream);
423 int wxPutc(wxChar ch, FILE *stream);
424
425 #define wxPuts(ws) wxFputs(ws, stdout)
426 #define wxPutchar(wch) wxPutc(wch, stdout)
427 #endif
428
429 // we need %s to %ls conversion for printf and scanf etc
430 #define wxNEED_PRINTF_CONVERSION
431
432 // glibc doesn't have wide char equivalents of the other stuff so
433 // use our own versions
434 #define wxNEED_WX_STDIO_H
435 #define wxNEED_WX_STDLIB_H
436 #define wxNEED_WX_TIME_H
437 #elif defined(__MWERKS__) && defined(macintosh)
438 // ctype.h functions (wctype.h)
439 #define wxIsalnum iswalnum
440 #define wxIsalpha iswalpha
441 #define wxIsctrl iswcntrl
442 #define wxIsdigit iswdigit
443 #define wxIsgraph iswgraph
444 #define wxIslower iswlower
445 #define wxIsprint iswprint
446 #define wxIspunct iswpunct
447 #define wxIsspace iswspace
448 #define wxIsupper iswupper
449 #define wxIsxdigit iswxdigit
450 #define wxTolower towlower
451 #define wxToupper towupper
452
453 // string.h functions (wchar.h)
454 #define wxStrcat wcscat
455 #define wxStrchr wcschr
456 #define wxStrcmp wcscmp
457 #define wxStrcoll wcscoll
458 #define wxStrcpy wcscpy
459 #define wxStrcspn wcscspn
460 #define wxStrlen_ wxWcslen // wxStrlen_() is used in wxStrlen()
461 #define wxStrncat wcsncat
462 #define wxStrncmp wcsncmp
463 #define wxStrncpy wcsncpy
464 #define wxStrpbrk wcspbrk
465 #define wxStrrchr wcsrchr
466 #define wxStrspn wcsspn
467 #define wxStrstr wcsstr
468 #define wxStrtod wcstod
469 #define wxStrtol wcstol
470 #define wxStrtoul wcstoul
471 #define wxStrxfrm wcsxfrm
472
473 #define wxFgetc fgetwc
474 #define wxFgetchar fgetwchar
475 #define wxFgets fgetws
476 #define wxFputc fputwc
477 #define wxFputchar fputwchar
478 #define wxGetc getwc
479 #define wxGetchar getwchar
480 #define wxGets getws
481 #define wxUngetc ungetwc
482
483 #define wxNEED_FPUTWC
484
485 #include <stdio.h>
486
487 int wxFputs(const wxChar *ch, FILE *stream);
488 int wxPutc(wxChar ch, FILE *stream);
489
490 #define wxPuts(ws) wxFputs(ws, stdout)
491 #define wxPutchar(wch) wxPutc(wch, stdout)
492
493 // we need %s to %ls conversion for printf and scanf etc
494 #define wxNEED_PRINTF_CONVERSION
495 // glibc doesn't have wide char equivalents of the other stuff so
496 // use our own versions
497 #define wxNEED_WX_STDIO_H
498 #define wxNEED_WX_STDLIB_H
499 #define wxNEED_WX_TIME_H
500 #else // !metrowerks for apple
501 #error "Please define wide character functions for your environment"
502 #endif
503 #else // ASCII
504 #include <ctype.h>
505 #include <string.h>
506
507 // ctype.h functions
508 #define wxIsalnum isalnum
509 #define wxIsalpha isalpha
510 #define wxIsctrl isctrl
511 #define wxIsdigit isdigit
512 #define wxIsgraph isgraph
513 #define wxIslower islower
514 #define wxIsprint isprint
515 #define wxIspunct ispunct
516 #define wxIsspace isspace
517 #define wxIsupper isupper
518 #define wxIsxdigit isxdigit
519 #define wxTolower tolower
520 #define wxToupper toupper
521
522 // locale.h functons
523 #define wxSetlocale setlocale
524
525 // string.h functions
526 #define wxStrcat strcat
527 #define wxStrchr strchr
528 #define wxStrcmp strcmp
529 #define wxStrcoll strcoll
530 #define wxStrcpy strcpy
531 #define wxStrcspn strcspn
532
533 // wxStricmp and wxStrnicmp are defined below
534 #define wxStrlen_ strlen // used in wxStrlen inline function
535 #define wxStrncat strncat
536 #define wxStrncmp strncmp
537 #define wxStrncpy strncpy
538 #define wxStrpbrk strpbrk
539 #define wxStrrchr strrchr
540 #define wxStrspn strspn
541 #define wxStrstr strstr
542 #define wxStrtod strtod
543 #ifdef HAVE_STRTOK_R
544 #define wxStrtok(str, sep, last) strtok_r(str, sep, last)
545 #endif
546 #define wxStrtol strtol
547 #define wxStrtoul strtoul
548 #define wxStrxfrm strxfrm
549
550 // stdio.h functions
551 #define wxFopen fopen
552 #define wxFreopen freopen
553 #define wxPerror perror
554 #define wxRemove remove
555 #define wxRename rename
556 #define wxTmpnam tmpnam
557
558 #define wxFgetc fgetc
559 #define wxFgetchar fgetchar
560 #define wxFgets fgets
561 #define wxFputc fputc
562 #define wxFputchar fputchar
563 #define wxFprintf fprintf
564 #define wxFscanf fscanf
565 #define wxGetc getc
566 #define wxGetchar getchar
567 #define wxGets gets
568 #define wxPrintf printf
569 #define wxPutc putc
570 #define wxPutchar putchar
571 #define wxPuts puts
572 #define wxScanf scanf
573 #define wxSprintf sprintf
574 #define wxSscanf sscanf
575 #define wxUngetc ungetc
576 #define wxVfprintf vfprintf
577 #define wxVprintf vprintf
578 #define wxVsscanf vsscanf
579 #define wxVsprintf vsprintf
580
581 // stdlib.h functions
582 #define wxAtof atof
583 #define wxAtoi atoi
584 #define wxAtol atol
585 #define wxGetenv getenv
586 #define wxSystem system
587
588 // time.h functions
589 #define wxAsctime asctime
590 #define wxCtime ctime
591 #define wxStrftime strftime
592 #endif // Unicode/ASCII
593 #endif // TCHAR-aware compilers/the others
594
595 // ----------------------------------------------------------------------------
596 // various special cases
597 // ----------------------------------------------------------------------------
598
599 // define wxStricmp and wxStrnicmp for various compilers
600 //
601 // note that in Unicode mode we definitely are going to need our own version
602 #if !defined(wxStricmp) && !wxUSE_UNICODE
603 #if defined(__BORLANDC__) || defined(__WATCOMC__) || \
604 defined(__SALFORDC__) || defined(__VISAGECPP__) || \
605 defined(__EMX__) || defined(__DJGPP__)
606 #define wxStricmp stricmp
607 #define wxStrnicmp strnicmp
608 #elif defined(__SC__) || defined(__VISUALC__) || \
609 (defined(__MWERKS__) && defined(__INTEL__))
610 #define wxStricmp _stricmp
611 #define wxStrnicmp _strnicmp
612 #elif defined(__UNIX__) || defined(__GNUWIN32__)
613 #define wxStricmp strcasecmp
614 #define wxStrnicmp strncasecmp
615 // #else -- use wxWindows implementation
616 #endif
617 #endif // !defined(wxStricmp)
618
619 // define wxWcslen() which should be always available if wxUSE_WCHAR_T == 1 (as
620 // it's used in wx/buffer.h -- and also might be used just below by wxStrlen()
621 // when wxStrlen_() is #define'd as wxWcslen so do it before defining wxStrlen)
622 #if wxUSE_WCHAR_T
623 #ifdef HAVE_WCSLEN
624 #define wxWcslen wcslen
625 #else
626 inline size_t wxWcslen(const wchar_t *s)
627 {
628 size_t n = 0;
629 while ( *s++ )
630 n++;
631
632 return n;
633 }
634 #endif
635 #endif // wxUSE_WCHAR_T
636
637 // checks whether the passed in pointer is NULL and if the string is empty
638 inline bool wxIsEmpty(const wxChar *p) { return !p || !*p; }
639
640 // safe version of strlen() (returns 0 if passed NULL pointer)
641 inline size_t wxStrlen(const wxChar *psz) { return psz ? wxStrlen_(psz) : 0; }
642
643 // each of strdup() and wcsdup() may or may not be available but we need both
644 // of them anyhow for wx/buffer.h so we define the missing one(s) in
645 // wxchar.cpp and so we should always have both wxStrdupA and wxStrdupW
646 // defined -- if this is somehow not the case in some situations, please
647 // correct that and not the lines here
648 #if wxUSE_UNICODE
649 #define wxStrdup wxStrdupW
650 #else
651 #define wxStrdup wxStrdupA
652 #endif
653
654 WXDLLEXPORT bool wxOKlibc(); // for internal use
655
656 // ----------------------------------------------------------------------------
657 // printf() family saga
658 // ----------------------------------------------------------------------------
659
660 /*
661 For some systems vsnprintf() exists in the system libraries but not in the
662 headers, so we need to declare it ourselves to be able to use it.
663 */
664 #if defined(HAVE_VSNPRINTF) && !defined(HAVE_VSNPRINTF_DECL)
665 extern "C"
666 int vsnprintf(char *str, size_t size, const char *format, va_list ap);
667 #endif // !HAVE_VSNPRINTF_DECL
668
669 /*
670 First of all, we always want to define safe snprintf() function to be used
671 instead of sprintf(). Some compilers already have it (or rather vsnprintf()
672 which we really need...), otherwise we implement it using our own printf()
673 code.
674
675 We define function with a trailing underscore here because the real one is a
676 wrapper around it as explained below
677 */
678 #ifndef wxVsnprintf_
679 #if wxUSE_UNICODE
680 #if defined(HAVE__VSNWPRINTF)
681 #define wxVsnprintf_ _vsnwprintf
682 /* MinGW?MSVCRT has the wrong vswprintf */
683 #elif defined(HAVE_VSWPRINTF) && !defined(__MINGW32__)
684 #define wxVsnprintf_ vswprintf
685 #endif
686 #else // ASCII
687 // all versions of CodeWarrior supported by wxWindows apparently have
688 // vsnprintf()
689 #if defined(HAVE_VSNPRINTF) || defined(__MWERKS__)
690 // assume we have snprintf() too if we have vsnprintf()
691 #define wxVsnprintf_ vsnprintf
692 #define wxSnprintf_ snprintf
693 #endif
694 #endif
695 #endif // wxVsnprintf_ not defined yet
696
697 #ifndef wxSnprintf_
698 // no [v]snprintf(), cook our own
699 WXDLLEXPORT int wxSnprintf_(wxChar *buf, size_t len, const wxChar *format,
700 ...) ATTRIBUTE_PRINTF_3;
701 #endif
702 #ifndef wxVsnprintf_
703 WXDLLEXPORT int wxVsnprintf_(wxChar *buf, size_t len, const wxChar *format,
704 va_list argptr);
705 #endif
706
707 /*
708 In Unicode mode we need to have all standard functions such as wprintf() and
709 so on but not all systems have them so use our own implementations in this
710 case.
711 */
712 #if wxUSE_UNICODE && !defined(wxHAVE_TCHAR_SUPPORT) && !defined(HAVE_WPRINTF)
713 #define wxNEED_WPRINTF
714 #endif
715
716 /*
717 More Unicode complications: although both ANSI C and C++ define a number of
718 wide character functions such as wprintf(), not all environments have them.
719 Worse, those which do have different behaviours: under Windows, %s format
720 specifier changes its meaning in Unicode build and expects a Unicode string
721 while under Unix/POSIX it still means an ASCII string even for wprintf() and
722 %ls has to be used for wide strings.
723
724 We choose to always emulate Windows behaviour as more useful for us so even
725 if we have wprintf() we still must wrap it in a non trivial wxPrintf().
726
727 However, if we don't have any vswprintf() at all we don't need to redefine
728 anything as our own wxVsnprintf_() already behaves as needed.
729 */
730 #ifndef wxVsnprintf_
731 #undef wxNEED_PRINTF_CONVERSION
732 #endif
733
734 #if defined(wxNEED_PRINTF_CONVERSION) || defined(wxNEED_WPRINTF)
735 // we need to implement all wide character printf and scanf functions
736 // either because we don't have them at all or because they don't have the
737 // semantics we need
738
739 #include <stdio.h> // for FILE
740
741 int wxScanf( const wxChar *format, ... ) ATTRIBUTE_PRINTF_1;
742 int wxSscanf( const wxChar *str, const wxChar *format, ... ) ATTRIBUTE_PRINTF_2;
743 int wxFscanf( FILE *stream, const wxChar *format, ... ) ATTRIBUTE_PRINTF_2;
744 int wxVsscanf( const wxChar *str, const wxChar *format, va_list ap );
745 int wxPrintf( const wxChar *format, ... ) ATTRIBUTE_PRINTF_1;
746 int wxSprintf( wxChar *str, const wxChar *format, ... ) ATTRIBUTE_PRINTF_2;
747 int wxFprintf( FILE *stream, const wxChar *format, ... ) ATTRIBUTE_PRINTF_2;
748 int wxVfprintf( FILE *stream, const wxChar *format, va_list ap );
749 int wxVprintf( const wxChar *format, va_list ap );
750 int wxVsprintf( wxChar *str, const wxChar *format, va_list ap );
751 #endif // wxNEED_PRINTF_CONVERSION
752
753 // these 2 can be simply mapped to the versions with underscore at the end
754 // if we don't have to do the conversion
755 #ifdef wxNEED_PRINTF_CONVERSION
756 int wxSnprintf( wxChar *str, size_t size, const wxChar *format, ... ) ATTRIBUTE_PRINTF_3;
757 int wxVsnprintf( wxChar *str, size_t size, const wxChar *format, va_list ap );
758 #else
759 #define wxSnprintf wxSnprintf_
760 #define wxVsnprintf wxVsnprintf_
761 #endif
762
763 // ----------------------------------------------------------------------------
764 // various functions which might not be available in libc and for which we
765 // provide our own replacements in wxchar.cpp
766 // ----------------------------------------------------------------------------
767
768 // ctype.h functions
769 //
770 // VZ: note that this is never defined currently
771 #ifdef wxNEED_WX_CTYPE_H
772 WXDLLEXPORT int wxIsalnum(wxChar ch);
773 WXDLLEXPORT int wxIsalpha(wxChar ch);
774 WXDLLEXPORT int wxIsctrl(wxChar ch);
775 WXDLLEXPORT int wxIsdigit(wxChar ch);
776 WXDLLEXPORT int wxIsgraph(wxChar ch);
777 WXDLLEXPORT int wxIslower(wxChar ch);
778 WXDLLEXPORT int wxIsprint(wxChar ch);
779 WXDLLEXPORT int wxIspunct(wxChar ch);
780 WXDLLEXPORT int wxIsspace(wxChar ch);
781 WXDLLEXPORT int wxIsupper(wxChar ch);
782 WXDLLEXPORT int wxIsxdigit(wxChar ch);
783 WXDLLEXPORT int wxTolower(wxChar ch);
784 WXDLLEXPORT int wxToupper(wxChar ch);
785 #endif // wxNEED_WX_CTYPE_H
786
787 // under VC++ 6.0 isspace() returns 1 for 8 bit chars which completely breaks
788 // the file parsing -- this may be true for 5.0 as well, update #ifdef then
789 #if defined(__VISUALC__) && (__VISUALC__ >= 1200) && !wxUSE_UNICODE
790 #undef wxIsspace
791 #define wxIsspace(c) ((((unsigned)c) < 128) && isspace(c))
792 #endif // VC++
793
794
795 // string.h functions
796 //
797 // VZ: this is never defined neither currently
798 #ifdef wxNEED_WX_STRING_H
799 WXDLLEXPORT wxChar * wxStrcat(wxChar *dest, const wxChar *src);
800 WXDLLEXPORT const wxChar * wxStrchr(const wxChar *s, wxChar c);
801 WXDLLEXPORT wxChar * wxStrchr(wxChar *s, wxChar c)
802 { return (wxChar *)wxStrchr((const wxChar *)s, c); }
803 WXDLLEXPORT int wxStrcmp(const wxChar *s1, const wxChar *s2);
804 WXDLLEXPORT int wxStrcoll(const wxChar *s1, const wxChar *s2);
805 WXDLLEXPORT wxChar * wxStrcpy(wxChar *dest, const wxChar *src);
806 WXDLLEXPORT size_t wxStrcspn(const wxChar *s, const wxChar *reject);
807 WXDLLEXPORT size_t wxStrlen(const wxChar *s);
808 WXDLLEXPORT wxChar * wxStrncat(wxChar *dest, const wxChar *src, size_t n);
809 WXDLLEXPORT int wxStrncmp(const wxChar *s1, const wxChar *s2, size_t n);
810 WXDLLEXPORT wxChar * wxStrncpy(wxChar *dest, const wxChar *src, size_t n);
811 WXDLLEXPORT const wxChar * wxStrpbrk(const wxChar *s, const wxChar *accept);
812 WXDLLEXPORT wxChar * wxStrpbrk(wxChar *s, const wxChar *accept)
813 { return (wxChar *)wxStrpbrk((const wxChar *)s, accept); }
814 WXDLLEXPORT const wxChar * wxStrrchr(const wxChar *s, wxChar c);
815 WXDLLEXPORT wxChar * wxStrrchr(wxChar *s, wxChar c)
816 { return (wxChar *)wxStrrchr((const wxChar *)s, c); }
817 WXDLLEXPORT size_t wxStrspn(const wxChar *s, const wxChar *accept);
818 WXDLLEXPORT const wxChar * wxStrstr(const wxChar *haystack, const wxChar *needle);
819 WXDLLEXPORT wxChar *wxStrstr(wxChar *haystack, const wxChar *needle)
820 { return (wxChar *)wxStrstr((const wxChar *)haystack, needle); }
821 WXDLLEXPORT double wxStrtod(const wxChar *nptr, wxChar **endptr);
822 WXDLLEXPORT long int wxStrtol(const wxChar *nptr, wxChar **endptr, int base);
823 WXDLLEXPORT unsigned long int wxStrtoul(const wxChar *nptr, wxChar **endptr, int base);
824 WXDLLEXPORT size_t wxStrxfrm(wxChar *dest, const wxChar *src, size_t n);
825 #endif // wxNEED_WX_STRING_H
826
827 #ifndef wxStrdupA
828 WXDLLEXPORT char *wxStrdupA(const char *psz);
829 #endif
830
831 #ifndef wxStrdupW
832 WXDLLEXPORT wchar_t *wxStrdupW(const wchar_t *pwz);
833 #endif
834
835 #ifndef wxStricmp
836 WXDLLEXPORT int wxStricmp(const wxChar *psz1, const wxChar *psz2);
837 #endif
838
839 #ifndef wxStrnicmp
840 WXDLLEXPORT int wxStrnicmp(const wxChar *psz1, const wxChar *psz2, size_t len);
841 #endif
842
843 #ifndef wxStrtok
844 WXDLLEXPORT wxChar * wxStrtok(wxChar *psz, const wxChar *delim, wxChar **save_ptr);
845 #endif
846
847 #ifndef wxSetlocale
848 class WXDLLEXPORT wxWCharBuffer;
849 WXDLLEXPORT wxWCharBuffer wxSetlocale(int category, const wxChar *locale);
850 #endif
851
852 // stdio.h functions
853 #ifdef wxNEED_WX_STDIO_H
854 #include <stdio.h>
855 WXDLLEXPORT FILE * wxFopen(const wxChar *path, const wxChar *mode);
856 WXDLLEXPORT FILE * wxFreopen(const wxChar *path, const wxChar *mode, FILE *stream);
857 WXDLLEXPORT int wxRemove(const wxChar *path);
858 WXDLLEXPORT int wxRename(const wxChar *oldpath, const wxChar *newpath);
859
860 // *printf() family is handled separately
861 #endif // wxNEED_WX_STDIO_H
862
863
864 // stdlib.h functions
865 #ifndef wxAtof
866 WXDLLEXPORT double wxAtof(const wxChar *psz);
867 #endif
868
869 #ifdef wxNEED_WX_STDLIB_H
870 WXDLLEXPORT int wxAtoi(const wxChar *psz);
871 WXDLLEXPORT long wxAtol(const wxChar *psz);
872 WXDLLEXPORT wxChar * wxGetenv(const wxChar *name);
873 WXDLLEXPORT int wxSystem(const wxChar *psz);
874 #endif
875
876
877 // time.h functions
878 #ifdef wxNEED_WX_TIME_H
879 #if defined(__MWERKS__) && defined(macintosh)
880 #include <time.h>
881 #endif
882 WXDLLEXPORT size_t wxStrftime(wxChar *s, size_t max,
883 const wxChar *fmt, const struct tm *tm);
884 #endif // wxNEED_WX_TIME_H
885
886 // ----------------------------------------------------------------------------
887 // multibyte to wide char conversion functions and macros
888 // ----------------------------------------------------------------------------
889
890 #if wxUSE_WCHAR_T
891 // multibyte<->widechar conversion
892 WXDLLEXPORT size_t wxMB2WC(wchar_t *buf, const char *psz, size_t n);
893 WXDLLEXPORT size_t wxWC2MB(char *buf, const wchar_t *psz, size_t n);
894
895 #if wxUSE_UNICODE
896 #define wxMB2WX wxMB2WC
897 #define wxWX2MB wxWC2MB
898 #define wxWC2WX wxStrncpy
899 #define wxWX2WC wxStrncpy
900 #else
901 #define wxMB2WX wxStrncpy
902 #define wxWX2MB wxStrncpy
903 #define wxWC2WX wxWC2MB
904 #define wxWX2WC wxMB2WC
905 #endif
906 #else // !wxUSE_UNICODE
907 // No wxUSE_WCHAR_T: we have to do something (JACS)
908 #define wxMB2WC wxStrncpy
909 #define wxWC2MB wxStrncpy
910 #define wxMB2WX wxStrncpy
911 #define wxWX2MB wxStrncpy
912 #define wxWC2WX wxWC2MB
913 #define wxWX2WC wxMB2WC
914 #endif
915
916 #endif //_WX_WXCHAR_H_
917