1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/wxchar.cpp
3 // Purpose: wxChar implementation
5 // Modified by: Ron Lee
8 // Copyright: (c) wxWidgets copyright
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ===========================================================================
13 // headers, declarations, constants
14 // ===========================================================================
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
23 #define _ISOC9X_SOURCE 1 // to get vsscanf()
24 #define _BSD_SOURCE 1 // to still get strdup()
34 #include "wx/msw/wince/time.h"
38 #include "wx/wxchar.h"
39 #include "wx/string.h"
42 #include "wx/utils.h" // for wxMin and wxMax
44 #if defined(__WIN32__) && defined(wxNEED_WX_CTYPE_H)
51 #if defined(__MWERKS__) && __MSL__ >= 0x6000
57 size_t WXDLLEXPORT
wxMB2WC(wchar_t *buf
, const char *psz
, size_t n
)
59 // assume that we have mbsrtowcs() too if we have wcsrtombs()
62 memset(&mbstate
, 0, sizeof(mbstate_t));
67 if (n
) *buf
= wxT('\0');
71 return mbsrtowcs(buf
, &psz
, n
, &mbstate
);
73 return wxMbstowcs(buf
, psz
, n
);
77 // note that we rely on common (and required by Unix98 but unfortunately not
78 // C99) extension which allows to call mbs(r)towcs() with NULL output pointer
79 // to just get the size of the needed buffer -- this is needed as otherwise
80 // we have no idea about how much space we need and if the CRT doesn't
81 // support it (the only currently known example being Metrowerks, see
82 // wx/wxchar.h) we don't use its mbstowcs() at all
84 return mbsrtowcs((wchar_t *) NULL
, &psz
, 0, &mbstate
);
86 return wxMbstowcs((wchar_t *) NULL
, psz
, 0);
90 size_t WXDLLEXPORT
wxWC2MB(char *buf
, const wchar_t *pwz
, size_t n
)
94 memset(&mbstate
, 0, sizeof(mbstate_t));
99 // glibc2.1 chokes on null input
103 #ifdef HAVE_WCSRTOMBS
104 return wcsrtombs(buf
, &pwz
, n
, &mbstate
);
106 return wxWcstombs(buf
, pwz
, n
);
110 #ifdef HAVE_WCSRTOMBS
111 return wcsrtombs((char *) NULL
, &pwz
, 0, &mbstate
);
113 return wxWcstombs((char *) NULL
, pwz
, 0);
116 #endif // wxUSE_WCHAR_T
118 bool WXDLLEXPORT
wxOKlibc()
120 #if wxUSE_WCHAR_T && defined(__UNIX__) && defined(__GLIBC__) && !defined(__WINE__)
121 // glibc 2.0 uses UTF-8 even when it shouldn't
123 if ((MB_CUR_MAX
== 2) &&
124 (wxMB2WC(&res
, "\xdd\xa5", 1) == 1) &&
126 // this is UTF-8 allright, check whether that's what we want
127 char *cur_locale
= setlocale(LC_CTYPE
, NULL
);
128 if ((strlen(cur_locale
) < 4) ||
129 (strcasecmp(cur_locale
+ strlen(cur_locale
) - 4, "utf8")) ||
130 (strcasecmp(cur_locale
+ strlen(cur_locale
) - 5, "utf-8"))) {
131 // nope, don't use libc conversion
139 // ============================================================================
140 // printf() functions business
141 // ============================================================================
143 // special test mode: define all functions below even if we don't really need
144 // them to be able to test them
155 #define wxNEED_WPRINTF
157 int wxVfprintf( FILE *stream
, const wxChar
*format
, va_list argptr
);
160 // ----------------------------------------------------------------------------
161 // implement [v]snprintf() if the system doesn't provide a safe one
162 // or if the system's one does not support positional parameters
163 // (very useful for i18n purposes)
164 // ----------------------------------------------------------------------------
166 #if !defined(wxVsnprintf_)
168 // wxUSE_STRUTILS says our wxVsnprintf_ implementation to use or not to
169 // use wxStrlen and wxStrncpy functions over one-char processing loops.
171 // Some benchmarking revealed that wxUSE_STRUTILS == 1 has the following
174 // when in ANSI mode, this setting does not change almost anything
175 // when in Unicode mode, it gives ~ 50% of slowdown !
177 // both in ANSI and Unicode mode it gives ~ 60% of speedup !
179 #if defined(WIN32) && wxUSE_UNICODE
180 #define wxUSE_STRUTILS 0
182 #define wxUSE_STRUTILS 1
185 // some limits of our implementation
186 #define wxMAX_SVNPRINTF_ARGUMENTS 64
187 #define wxMAX_SVNPRINTF_FLAGBUFFER_LEN 32
189 // the conversion specifiers accepted by wxMyPosVsnprintf_
190 enum wxPrintfArgType
{
193 wxPAT_INT
, // %d, %i, %o, %u, %x, %X
194 wxPAT_LONGINT
, // %ld, etc
196 wxPAT_LONGLONGINT
, // %Ld, etc
198 wxPAT_SIZET
, // %Zd, etc
200 wxPAT_DOUBLE
, // %e, %E, %f, %g, %G
201 wxPAT_LONGDOUBLE
, // %le, etc
205 wxPAT_CHAR
, // %hc (in ANSI mode: %c, too)
206 wxPAT_WCHAR
, // %lc (in Unicode mode: %c, too)
208 wxPAT_PCHAR
, // %s (related to a char *)
209 wxPAT_PWCHAR
, // %s (related to a wchar_t *)
212 wxPAT_NSHORTINT
, // %hn
213 wxPAT_NLONGINT
// %ln
216 // an argument passed to wxMyPosVsnprintf_
218 int pad_int
; // %d, %i, %o, %u, %x, %X
219 long int pad_longint
; // %ld, etc
221 long long int pad_longlongint
; // %Ld, etc
223 size_t pad_sizet
; // %Zd, etc
225 double pad_double
; // %e, %E, %f, %g, %G
226 long double pad_longdouble
; // %le, etc
228 void *pad_pointer
; // %p
230 char pad_char
; // %hc (in ANSI mode: %c, too)
231 wchar_t pad_wchar
; // %lc (in Unicode mode: %c, too)
233 char *pad_pchar
; // %s (related to a char *)
234 wchar_t *pad_pwchar
; // %s (related to a wchar_t *)
237 short int *pad_nshortint
; // %hn
238 long int *pad_nlongint
; // %ln
242 // Contains parsed data relative to a conversion specifier given to
243 // wxMyPosVsnprintf_ and parsed from the format string
244 // NOTE: in C++ there is almost no difference between struct & classes thus
245 // there is no performance gain by using a struct here...
246 class wxPrintfConvSpec
250 // the position of the argument relative to this conversion specifier
253 // the type of this conversion specifier
254 wxPrintfArgType type
;
256 // the minimum and maximum width
257 // when one of this var is set to -1 it means: use the following argument
258 // in the stack as minimum/maximum width for this conversion specifier
259 int min_width
, max_width
;
261 // does the argument need to the be aligned to left ?
264 // pointer to the '%' of this conversion specifier in the format string
265 // NOTE: this points somewhere in the string given to the Parse() function -
266 // it's task of the caller ensure that memory is still valid !
267 const wxChar
*argpos
;
269 // pointer to the last character of this conversion specifier in the
271 // NOTE: this points somewhere in the string given to the Parse() function -
272 // it's task of the caller ensure that memory is still valid !
273 const wxChar
*argend
;
275 // a little buffer where formatting flags like #+\.hlqLZ are stored by Parse()
276 // for use in Process()
277 char szFlags
[wxMAX_SVNPRINTF_FLAGBUFFER_LEN
];
282 // we don't declare this as a constructor otherwise it would be called
283 // automatically and we don't want this: to be optimized, wxMyPosVsnprintf_
284 // calls this function only on really-used instances of this class.
287 // Parses the first conversion specifier in the given string, which must
288 // begin with a '%'. Returns false if the first '%' does not introduce a
289 // (valid) conversion specifier and thus should be ignored.
290 bool Parse(const wxChar
*format
);
292 // Process this conversion specifier and puts the result in the given
293 // buffer. Returns the number of characters written in 'buf' or -1 if
294 // there's not enough space.
295 int Process(wxChar
*buf
, size_t lenMax
, wxPrintfArg
*p
);
297 // Loads the argument of this conversion specifier from given va_list.
298 bool LoadArg(wxPrintfArg
*p
, va_list &argptr
);
301 // An helper function of LoadArg() which is used to handle the '*' flag
302 void ReplaceAsteriskWith(int w
);
305 void wxPrintfConvSpec::Init()
311 argpos
= argend
= NULL
;
312 type
= wxPAT_INVALID
;
313 szFlags
[0] = wxT('%');
316 bool wxPrintfConvSpec::Parse(const wxChar
*format
)
320 // temporary parse data
322 bool in_prec
, prec_dot
;
325 adj_left
= in_prec
= prec_dot
= false;
326 argpos
= argend
= format
;
330 if (in_prec && !prec_dot) \
332 szFlags[flagofs++] = '.'; \
337 const wxChar ch
= *(++argend
);
341 return false; // not really an argument
344 return false; // not really an argument
352 szFlags
[flagofs
++] = ch
;
358 szFlags
[flagofs
++] = ch
;
366 // dot will be auto-added to szFlags if non-negative
373 szFlags
[flagofs
++] = ch
;
379 szFlags
[flagofs
++] = ch
;
386 szFlags
[flagofs
++] = ch
;
392 szFlags
[flagofs
++] = ch
;
400 // tell Process() to use the next argument
401 // in the stack as maxwidth...
406 // tell Process() to use the next argument
407 // in the stack as minwidth...
411 // save the * in our formatting buffer...
412 // will be replaced later by Process()
413 szFlags
[flagofs
++] = ch
;
416 case wxT('1'): case wxT('2'): case wxT('3'):
417 case wxT('4'): case wxT('5'): case wxT('6'):
418 case wxT('7'): case wxT('8'): case wxT('9'):
422 while ( (*argend
>= wxT('0')) &&
423 (*argend
<= wxT('9')) )
425 szFlags
[flagofs
++] = *argend
;
426 len
= len
*10 + (*argend
- wxT('0'));
435 argend
--; // the main loop pre-increments n again
439 case wxT('$'): // a positional parameter (e.g. %2$s) ?
442 break; // ignore this formatting flag as no
443 // numbers are preceding it
445 // remove from szFlags all digits previously added
448 } while (szFlags
[flagofs
] >= '1' &&
449 szFlags
[flagofs
] <= '9');
451 // re-adjust the offset making it point to the
452 // next free char of szFlags
467 szFlags
[flagofs
++] = ch
;
468 szFlags
[flagofs
] = '\0';
472 // NB: 'short int' value passed through '...'
473 // is promoted to 'int', so we have to get
474 // an int from stack even if we need a short
477 type
= wxPAT_LONGINT
;
480 type
= wxPAT_LONGLONGINT
;
482 type
= wxPAT_LONGINT
;
483 #endif // long long/!long long
495 szFlags
[flagofs
++] = ch
;
496 szFlags
[flagofs
] = '\0';
498 type
= wxPAT_LONGDOUBLE
;
505 type
= wxPAT_POINTER
;
512 // in Unicode mode %hc == ANSI character
513 // and in ANSI mode, %hc == %c == ANSI...
518 // in ANSI mode %lc == Unicode character
519 // and in Unicode mode, %lc == %c == Unicode...
525 // in Unicode mode, %c == Unicode character
528 // in ANSI mode, %c == ANSI character
538 // Unicode mode wx extension: we'll let %hs mean non-Unicode
539 // strings (when in ANSI mode, %s == %hs == ANSI string)
544 // in Unicode mode, %ls == %s == Unicode string
545 // in ANSI mode, %ls == Unicode string
563 type
= wxPAT_NSHORTINT
;
565 type
= wxPAT_NLONGINT
;
570 // bad format, don't consider this an argument;
571 // leave it unchanged
577 return true; // parsing was successful
581 void wxPrintfConvSpec::ReplaceAsteriskWith(int w
)
583 char temp
[wxMAX_SVNPRINTF_FLAGBUFFER_LEN
];
585 // find the first * in our flag buffer
586 char *pwidth
= strchr(szFlags
, '*');
589 // save what follows the * (the +1 is to skip it!)
590 strcpy(temp
, pwidth
+1);
596 // replace * with the actual integer given as width
597 int offset
= ::sprintf(pwidth
,"%d",abs(w
));
599 // restore after the expanded * what was following it
600 strcpy(pwidth
+offset
, temp
);
603 bool wxPrintfConvSpec::LoadArg(wxPrintfArg
*p
, va_list &argptr
)
605 // did the '*' width/precision specifier was used ?
608 // take the maxwidth specifier from the stack
609 max_width
= va_arg(argptr
, int);
613 ReplaceAsteriskWith(max_width
);
618 // take the minwidth specifier from the stack
619 min_width
= va_arg(argptr
, int);
621 ReplaceAsteriskWith(min_width
);
624 adj_left
= !adj_left
;
625 min_width
= -min_width
;
631 p
->pad_int
= va_arg(argptr
, int);
634 p
->pad_longint
= va_arg(argptr
, long int);
637 case wxPAT_LONGLONGINT
:
638 p
->pad_longlongint
= va_arg(argptr
, long long int);
642 p
->pad_sizet
= va_arg(argptr
, size_t);
645 p
->pad_double
= va_arg(argptr
, double);
647 case wxPAT_LONGDOUBLE
:
648 p
->pad_longdouble
= va_arg(argptr
, long double);
651 p
->pad_pointer
= va_arg(argptr
, void *);
655 p
->pad_char
= va_arg(argptr
, int); // char is promoted to int when passed through '...'
658 p
->pad_wchar
= va_arg(argptr
, int); // char is promoted to int when passed through '...'
662 p
->pad_pchar
= va_arg(argptr
, char *);
665 p
->pad_pwchar
= va_arg(argptr
, wchar_t *);
669 p
->pad_nint
= va_arg(argptr
, int *);
671 case wxPAT_NSHORTINT
:
672 p
->pad_nshortint
= va_arg(argptr
, short int *);
675 p
->pad_nlongint
= va_arg(argptr
, long int *);
683 return true; // loading was successful
686 int wxPrintfConvSpec::Process(wxChar
*buf
, size_t lenMax
, wxPrintfArg
*p
)
688 // buffer to avoid dynamic memory allocation each time for small strings
689 static char szScratch
[1024];
692 #define APPEND_CH(ch) \
694 if ( lenCur == lenMax ) \
697 buf[lenCur++] = ch; \
700 #define APPEND_STR(s) \
702 for ( const wxChar *p = s; *p; p++ ) \
711 ::sprintf(szScratch
, szFlags
, p
->pad_int
);
715 ::sprintf(szScratch
, szFlags
, p
->pad_longint
);
719 case wxPAT_LONGLONGINT
:
720 ::sprintf(szScratch
, szFlags
, p
->pad_longlongint
);
722 #endif // SIZEOF_LONG_LONG
725 ::sprintf(szScratch
, szFlags
, p
->pad_sizet
);
728 case wxPAT_LONGDOUBLE
:
729 ::sprintf(szScratch
, szFlags
, p
->pad_longdouble
);
733 ::sprintf(szScratch
, szFlags
, p
->pad_double
);
737 ::sprintf(szScratch
, szFlags
, p
->pad_pointer
);
747 if (type
== wxPAT_CHAR
) {
748 // user passed a character explicitely indicated as ANSI...
749 const char buf
[2] = { p
->pad_char
, 0 };
750 val
= wxString(buf
, wxConvLibc
)[0u];
756 if (type
== wxPAT_WCHAR
) {
757 // user passed a character explicitely indicated as Unicode...
758 const wchar_t buf
[2] = { p
->pad_wchar
, 0 };
759 val
= wxString(buf
, wxConvLibc
)[0u];
767 for (i
= 1; i
< (size_t)min_width
; i
++)
773 for (i
= 1; i
< (size_t)min_width
; i
++)
786 if (type
== wxPAT_PCHAR
) {
787 // user passed a string explicitely indicated as ANSI...
788 val
= s
= wxString(p
->pad_pchar
, wxConvLibc
);
794 if (type
== wxPAT_PWCHAR
) {
795 // user passed a string explicitely indicated as Unicode...
796 val
= s
= wxString(p
->pad_pwchar
, wxConvLibc
);
805 // at this point we are sure that max_width is positive or null
806 // (see top of wxPrintfConvSpec::LoadArg)
807 len
= wxMin((unsigned int)max_width
, wxStrlen(val
));
809 for ( len
= 0; val
[len
] && (len
< max_width
); len
++ )
813 else if (max_width
>= 6)
828 for (i
= len
; i
< min_width
; i
++)
833 // at this point we are sure that max_width is positive or null
834 // (see top of wxPrintfConvSpec::LoadArg)
835 len
= wxMin((unsigned int)len
, lenMax
-lenCur
);
836 wxStrncpy(buf
+lenCur
, val
, len
);
839 for (i
= 0; i
< len
; i
++)
845 for (i
= len
; i
< min_width
; i
++)
852 *p
->pad_nint
= lenCur
;
855 case wxPAT_NSHORTINT
:
856 *p
->pad_nshortint
= lenCur
;
860 *p
->pad_nlongint
= lenCur
;
868 // if we used system's sprintf() then we now need to append the s_szScratch
869 // buffer to the given one...
875 case wxPAT_LONGLONGINT
:
878 case wxPAT_LONGDOUBLE
:
883 const wxMB2WXbuf tmp
= wxConvLibc
.cMB2WX(szScratch
);
884 size_t len
= wxMin(lenMax
, wxStrlen(tmp
));
885 wxStrncpy(buf
, tmp
, len
);
890 const wxMB2WXbuf tmp
=
891 wxConvLibc
.cMB2WX(szScratch
);
898 break; // all other cases were completed previously
904 int WXDLLEXPORT
wxVsnprintf_(wxChar
*buf
, size_t lenMax
,
905 const wxChar
*format
, va_list argptr
)
908 static wxPrintfConvSpec arg
[wxMAX_SVNPRINTF_ARGUMENTS
];
909 static wxPrintfArg argdata
[wxMAX_SVNPRINTF_ARGUMENTS
];
910 static wxPrintfConvSpec
*pspec
[wxMAX_SVNPRINTF_ARGUMENTS
] = { NULL
};
914 // number of characters in the buffer so far, must be less than lenMax
918 const wxChar
*toparse
= format
;
920 // parse the format string
921 bool posarg_present
= false, nonposarg_present
= false;
922 for (; *toparse
!= wxT('\0'); toparse
++)
924 if (*toparse
== wxT('%') )
928 // let's see if this is a (valid) conversion specifier...
929 if (arg
[nargs
].Parse(toparse
))
932 wxPrintfConvSpec
*current
= &arg
[nargs
];
934 // make toparse point to the end of this specifier
935 toparse
= current
->argend
;
937 if (current
->pos
> 0) {
938 // the positionals start from number 1... adjust the index
940 posarg_present
= true;
942 // not a positional argument...
943 current
->pos
= nargs
;
944 nonposarg_present
= true;
947 // this conversion specifier is tied to the pos-th argument...
948 pspec
[current
->pos
] = current
;
951 if (nargs
== wxMAX_SVNPRINTF_ARGUMENTS
)
952 break; // cannot handle any additional conv spec
957 if (posarg_present
&& nonposarg_present
)
958 return -1; // format strings with both positional and
959 // non-positional conversion specifier are unsupported !!
961 // on platforms where va_list is an array type, it is necessary to make a
962 // copy to be able to pass it to LoadArg as a reference.
965 wxVaCopy(ap
, argptr
);
967 // now load arguments from stack
968 for (i
=0; i
< nargs
&& ok
; i
++) {
969 // !pspec[i] if user forgot a positional parameter (e.g. %$1s %$3s) ?
970 // or LoadArg false if wxPrintfConvSpec::Parse failed to set its 'type'
971 // to a valid value...
972 ok
= pspec
[i
] && pspec
[i
]->LoadArg(&argdata
[i
], ap
);
980 // finally, process each conversion specifier with its own argument
982 for (i
=0; i
< nargs
; i
++)
984 // copy in the output buffer the portion of the format string between
985 // last specifier and the current one
986 size_t tocopy
= ( arg
[i
].argpos
- toparse
);
987 if (lenCur
+tocopy
>= lenMax
)
988 return -1; // not enough space in the output buffer !
990 wxStrncpy(buf
+lenCur
, toparse
, tocopy
);
993 // process this specifier directly in the output buffer
994 int n
= arg
[i
].Process(buf
+lenCur
, lenMax
- lenCur
, &argdata
[arg
[i
].pos
]);
996 return -1; // not enough space in the output buffer !
999 // the +1 is because wxPrintfConvSpec::argend points to the last character
1000 // of the format specifier, but we are not interested to it...
1001 toparse
= arg
[i
].argend
+ 1;
1004 // copy portion of the format string after last specifier
1005 // NOTE: toparse is pointing to the character just after the last processed
1006 // conversion specifier
1007 // NOTE2: the +1 is because we want to copy also the '\0'
1008 size_t tocopy
= wxStrlen(format
) + 1 - ( toparse
- format
) ;
1009 if (lenCur
+tocopy
>= lenMax
)
1010 return -1; // not enough space in the output buffer !
1011 wxStrncpy(buf
+lenCur
, toparse
, tocopy
);
1012 lenCur
+= tocopy
- 1; // the -1 is because of the '\0'
1014 // clean the static array portion used...
1015 // NOTE: other arrays do not need cleanup!
1016 memset(pspec
, 0, sizeof(wxPrintfConvSpec
*)*nargs
);
1018 wxASSERT(lenCur
== wxStrlen(buf
));
1026 #endif // !wxVsnprintfA
1028 #if !defined(wxSnprintf_)
1029 int WXDLLEXPORT
wxSnprintf_(wxChar
*buf
, size_t len
, const wxChar
*format
, ...)
1032 va_start(argptr
, format
);
1034 int iLen
= wxVsnprintf_(buf
, len
, format
, argptr
);
1040 #endif // wxSnprintf_
1042 #if defined(__DMC__)
1043 /* Digital Mars adds count to _stprintf (C99) so convert */
1045 int wxSprintf (wchar_t * __RESTRICT s
, const wchar_t * __RESTRICT format
, ... )
1049 va_start( arglist
, format
);
1050 int iLen
= swprintf ( s
, -1, format
, arglist
);
1055 #endif // wxUSE_UNICODE
1059 // ----------------------------------------------------------------------------
1060 // implement the standard IO functions for wide char if libc doesn't have them
1061 // ----------------------------------------------------------------------------
1064 int wxFputs(const wchar_t *ws
, FILE *stream
)
1066 // counting the number of wide characters written isn't worth the trouble,
1067 // simply distinguish between ok and error
1068 return fputs(wxConvLibc
.cWC2MB(ws
), stream
) == -1 ? -1 : 0;
1070 #endif // wxNEED_FPUTS
1073 int wxPuts(const wxChar
*ws
)
1075 int rc
= wxFputs(ws
, stdout
);
1078 if ( wxFputs(L
"\n", stdout
) == -1 )
1086 #endif // wxNEED_PUTS
1089 int /* not wint_t */ wxPutc(wchar_t wc
, FILE *stream
)
1091 wchar_t ws
[2] = { wc
, L
'\0' };
1093 return wxFputs(ws
, stream
);
1095 #endif // wxNEED_PUTC
1097 // NB: we only implement va_list functions here, the ones taking ... are
1098 // defined below for wxNEED_PRINTF_CONVERSION case anyhow and we reuse
1099 // the definitions there to avoid duplicating them here
1100 #ifdef wxNEED_WPRINTF
1102 // TODO: implement the scanf() functions
1103 int vwscanf(const wxChar
*format
, va_list argptr
)
1105 wxFAIL_MSG( _T("TODO") );
1110 int vswscanf(const wxChar
*ws
, const wxChar
*format
, va_list argptr
)
1112 // The best we can do without proper Unicode support in glibc is to
1113 // convert the strings into MB representation and run ANSI version
1114 // of the function. This doesn't work with %c and %s because of difference
1115 // in size of char and wchar_t, though.
1117 wxCHECK_MSG( wxStrstr(format
, _T("%s")) == NULL
, -1,
1118 _T("incomplete vswscanf implementation doesn't allow %s") );
1119 wxCHECK_MSG( wxStrstr(format
, _T("%c")) == NULL
, -1,
1120 _T("incomplete vswscanf implementation doesn't allow %c") );
1123 wxVaCopy(argcopy
, argptr
);
1124 return vsscanf(wxConvLibc
.cWX2MB(ws
), wxConvLibc
.cWX2MB(format
), argcopy
);
1127 int vfwscanf(FILE *stream
, const wxChar
*format
, va_list argptr
)
1129 wxFAIL_MSG( _T("TODO") );
1134 #define vswprintf wxVsnprintf_
1136 int vfwprintf(FILE *stream
, const wxChar
*format
, va_list argptr
)
1139 int rc
= s
.PrintfV(format
, argptr
);
1143 // we can't do much better without Unicode support in libc...
1144 if ( fprintf(stream
, "%s", (const char*)s
.mb_str() ) == -1 )
1151 int vwprintf(const wxChar
*format
, va_list argptr
)
1153 return wxVfprintf(stdout
, format
, argptr
);
1156 #endif // wxNEED_WPRINTF
1158 #ifdef wxNEED_PRINTF_CONVERSION
1160 // ----------------------------------------------------------------------------
1161 // wxFormatConverter: class doing the "%s" -> "%ls" conversion
1162 // ----------------------------------------------------------------------------
1165 Here are the gory details. We want to follow the Windows/MS conventions,
1170 format specifier results in
1171 -----------------------------------
1173 %lc, %C, %lC wchar_t
1177 format specifier results in
1178 -----------------------------------
1180 %c, %lc, %lC wchar_t
1183 while on POSIX systems we have %C identical to %lc and %c always means char
1184 (in any mode) while %lc always means wchar_t,
1186 So to use native functions in order to get our semantics we must do the
1187 following translations in Unicode mode (nothing to do in ANSI mode):
1189 wxWidgets specifier POSIX specifier
1190 ----------------------------------------
1196 And, of course, the same should be done for %s as well.
1199 class wxFormatConverter
1202 wxFormatConverter(const wxChar
*format
);
1204 // notice that we only translated the string if m_fmtOrig == NULL (as set
1205 // by CopyAllBefore()), otherwise we should simply use the original format
1206 operator const wxChar
*() const
1207 { return m_fmtOrig
? m_fmtOrig
: m_fmt
.c_str(); }
1210 // copy another character to the translated format: this function does the
1211 // copy if we are translating but doesn't do anything at all if we don't,
1212 // so we don't create the translated format string at all unless we really
1213 // need to (i.e. InsertFmtChar() is called)
1214 wxChar
CopyFmtChar(wxChar ch
)
1218 // we're translating, do copy
1223 // simply increase the count which should be copied by
1224 // CopyAllBefore() later if needed
1231 // insert an extra character
1232 void InsertFmtChar(wxChar ch
)
1236 // so far we haven't translated anything yet
1243 void CopyAllBefore()
1245 wxASSERT_MSG( m_fmtOrig
&& m_fmt
.empty(), _T("logic error") );
1247 m_fmt
= wxString(m_fmtOrig
, m_nCopied
);
1249 // we won't need it any longer
1253 static bool IsFlagChar(wxChar ch
)
1255 return ch
== _T('-') || ch
== _T('+') ||
1256 ch
== _T('0') || ch
== _T(' ') || ch
== _T('#');
1259 void SkipDigits(const wxChar
**ptpc
)
1261 while ( **ptpc
>= _T('0') && **ptpc
<= _T('9') )
1262 CopyFmtChar(*(*ptpc
)++);
1265 // the translated format
1268 // the original format
1269 const wxChar
*m_fmtOrig
;
1271 // the number of characters already copied
1275 wxFormatConverter::wxFormatConverter(const wxChar
*format
)
1282 if ( CopyFmtChar(*format
++) == _T('%') )
1285 while ( IsFlagChar(*format
) )
1286 CopyFmtChar(*format
++);
1288 // and possible width
1289 if ( *format
== _T('*') )
1290 CopyFmtChar(*format
++);
1292 SkipDigits(&format
);
1295 if ( *format
== _T('.') )
1297 CopyFmtChar(*format
++);
1298 if ( *format
== _T('*') )
1299 CopyFmtChar(*format
++);
1301 SkipDigits(&format
);
1304 // next we can have a size modifier
1320 // "ll" has a different meaning!
1321 if ( format
[1] != _T('l') )
1327 //else: fall through
1333 // and finally we should have the type
1338 // %C and %hC -> %c and %lC -> %lc
1340 CopyFmtChar(_T('l'));
1342 InsertFmtChar(*format
++ == _T('C') ? _T('c') : _T('s'));
1347 // %c -> %lc but %hc stays %hc and %lc is still %lc
1348 if ( size
== Default
)
1349 InsertFmtChar(_T('l'));
1353 // nothing special to do
1354 if ( size
!= Default
)
1355 CopyFmtChar(*(format
- 1));
1356 CopyFmtChar(*format
++);
1362 #else // !wxNEED_PRINTF_CONVERSION
1363 // no conversion necessary
1364 #define wxFormatConverter(x) (x)
1365 #endif // wxNEED_PRINTF_CONVERSION/!wxNEED_PRINTF_CONVERSION
1368 // For testing the format converter
1369 wxString
wxConvertFormat(const wxChar
*format
)
1371 return wxString(wxFormatConverter(format
));
1375 // ----------------------------------------------------------------------------
1376 // wxPrintf(), wxScanf() and relatives
1377 // ----------------------------------------------------------------------------
1379 #if defined(wxNEED_PRINTF_CONVERSION) || defined(wxNEED_WPRINTF)
1381 int wxScanf( const wxChar
*format
, ... )
1384 va_start(argptr
, format
);
1386 int ret
= vwscanf(wxFormatConverter(format
), argptr
);
1393 int wxSscanf( const wxChar
*str
, const wxChar
*format
, ... )
1396 va_start(argptr
, format
);
1398 int ret
= vswscanf( str
, wxFormatConverter(format
), argptr
);
1405 int wxFscanf( FILE *stream
, const wxChar
*format
, ... )
1408 va_start(argptr
, format
);
1409 int ret
= vfwscanf(stream
, wxFormatConverter(format
), argptr
);
1416 int wxPrintf( const wxChar
*format
, ... )
1419 va_start(argptr
, format
);
1421 int ret
= vwprintf( wxFormatConverter(format
), argptr
);
1429 int wxSnprintf( wxChar
*str
, size_t size
, const wxChar
*format
, ... )
1432 va_start(argptr
, format
);
1434 int ret
= vswprintf( str
, size
, wxFormatConverter(format
), argptr
);
1440 #endif // wxSnprintf
1442 int wxSprintf( wxChar
*str
, const wxChar
*format
, ... )
1445 va_start(argptr
, format
);
1447 // note that wxString::FormatV() uses wxVsnprintf(), not wxSprintf(), so
1448 // it's safe to implement this one in terms of it
1449 wxString
s(wxString::FormatV(format
, argptr
));
1457 int wxFprintf( FILE *stream
, const wxChar
*format
, ... )
1460 va_start( argptr
, format
);
1462 int ret
= vfwprintf( stream
, wxFormatConverter(format
), argptr
);
1469 int wxVsscanf( const wxChar
*str
, const wxChar
*format
, va_list argptr
)
1471 return vswscanf( str
, wxFormatConverter(format
), argptr
);
1474 int wxVfprintf( FILE *stream
, const wxChar
*format
, va_list argptr
)
1476 return vfwprintf( stream
, wxFormatConverter(format
), argptr
);
1479 int wxVprintf( const wxChar
*format
, va_list argptr
)
1481 return vwprintf( wxFormatConverter(format
), argptr
);
1485 int wxVsnprintf( wxChar
*str
, size_t size
, const wxChar
*format
, va_list argptr
)
1487 return vswprintf( str
, size
, wxFormatConverter(format
), argptr
);
1489 #endif // wxVsnprintf
1491 int wxVsprintf( wxChar
*str
, const wxChar
*format
, va_list argptr
)
1493 // same as for wxSprintf()
1494 return vswprintf(str
, INT_MAX
/ 4, wxFormatConverter(format
), argptr
);
1497 #endif // wxNEED_PRINTF_CONVERSION
1501 // ----------------------------------------------------------------------------
1502 // ctype.h stuff (currently unused)
1503 // ----------------------------------------------------------------------------
1505 #if defined(__WIN32__) && defined(wxNEED_WX_CTYPE_H)
1506 inline WORD
wxMSW_ctype(wxChar ch
)
1509 GetStringTypeEx(LOCALE_USER_DEFAULT
, CT_CTYPE1
, &ch
, 1, &ret
);
1513 WXDLLEXPORT
int wxIsalnum(wxChar ch
) { return IsCharAlphaNumeric(ch
); }
1514 WXDLLEXPORT
int wxIsalpha(wxChar ch
) { return IsCharAlpha(ch
); }
1515 WXDLLEXPORT
int wxIscntrl(wxChar ch
) { return wxMSW_ctype(ch
) & C1_CNTRL
; }
1516 WXDLLEXPORT
int wxIsdigit(wxChar ch
) { return wxMSW_ctype(ch
) & C1_DIGIT
; }
1517 WXDLLEXPORT
int wxIsgraph(wxChar ch
) { return wxMSW_ctype(ch
) & (C1_DIGIT
|C1_PUNCT
|C1_ALPHA
); }
1518 WXDLLEXPORT
int wxIslower(wxChar ch
) { return IsCharLower(ch
); }
1519 WXDLLEXPORT
int wxIsprint(wxChar ch
) { return wxMSW_ctype(ch
) & (C1_DIGIT
|C1_SPACE
|C1_PUNCT
|C1_ALPHA
); }
1520 WXDLLEXPORT
int wxIspunct(wxChar ch
) { return wxMSW_ctype(ch
) & C1_PUNCT
; }
1521 WXDLLEXPORT
int wxIsspace(wxChar ch
) { return wxMSW_ctype(ch
) & C1_SPACE
; }
1522 WXDLLEXPORT
int wxIsupper(wxChar ch
) { return IsCharUpper(ch
); }
1523 WXDLLEXPORT
int wxIsxdigit(wxChar ch
) { return wxMSW_ctype(ch
) & C1_XDIGIT
; }
1524 WXDLLEXPORT
int wxTolower(wxChar ch
) { return (wxChar
)CharLower((LPTSTR
)(ch
)); }
1525 WXDLLEXPORT
int wxToupper(wxChar ch
) { return (wxChar
)CharUpper((LPTSTR
)(ch
)); }
1528 #ifdef wxNEED_WX_MBSTOWCS
1530 WXDLLEXPORT
size_t wxMbstowcs (wchar_t * out
, const char * in
, size_t outlen
)
1540 const char* origin
= in
;
1542 while (outlen
-- && *in
)
1544 *out
++ = (wchar_t) *in
++;
1552 WXDLLEXPORT
size_t wxWcstombs (char * out
, const wchar_t * in
, size_t outlen
)
1562 const wchar_t* origin
= in
;
1564 while (outlen
-- && *in
)
1566 *out
++ = (char) *in
++;
1574 #endif // wxNEED_WX_MBSTOWCS
1576 #if defined(wxNEED_WX_CTYPE_H)
1578 #include <CoreFoundation/CoreFoundation.h>
1580 #define cfalnumset CFCharacterSetGetPredefined(kCFCharacterSetAlphaNumeric)
1581 #define cfalphaset CFCharacterSetGetPredefined(kCFCharacterSetLetter)
1582 #define cfcntrlset CFCharacterSetGetPredefined(kCFCharacterSetControl)
1583 #define cfdigitset CFCharacterSetGetPredefined(kCFCharacterSetDecimalDigit)
1584 //CFCharacterSetRef cfgraphset = kCFCharacterSetControl && !' '
1585 #define cflowerset CFCharacterSetGetPredefined(kCFCharacterSetLowercaseLetter)
1586 //CFCharacterSetRef cfprintset = !kCFCharacterSetControl
1587 #define cfpunctset CFCharacterSetGetPredefined(kCFCharacterSetPunctuation)
1588 #define cfspaceset CFCharacterSetGetPredefined(kCFCharacterSetWhitespaceAndNewline)
1589 #define cfupperset CFCharacterSetGetPredefined(kCFCharacterSetUppercaseLetter)
1591 WXDLLEXPORT
int wxIsalnum(wxChar ch
) { return CFCharacterSetIsCharacterMember(cfalnumset
, ch
); }
1592 WXDLLEXPORT
int wxIsalpha(wxChar ch
) { return CFCharacterSetIsCharacterMember(cfalphaset
, ch
); }
1593 WXDLLEXPORT
int wxIscntrl(wxChar ch
) { return CFCharacterSetIsCharacterMember(cfcntrlset
, ch
); }
1594 WXDLLEXPORT
int wxIsdigit(wxChar ch
) { return CFCharacterSetIsCharacterMember(cfdigitset
, ch
); }
1595 WXDLLEXPORT
int wxIsgraph(wxChar ch
) { return !CFCharacterSetIsCharacterMember(cfcntrlset
, ch
) && ch
!= ' '; }
1596 WXDLLEXPORT
int wxIslower(wxChar ch
) { return CFCharacterSetIsCharacterMember(cflowerset
, ch
); }
1597 WXDLLEXPORT
int wxIsprint(wxChar ch
) { return !CFCharacterSetIsCharacterMember(cfcntrlset
, ch
); }
1598 WXDLLEXPORT
int wxIspunct(wxChar ch
) { return CFCharacterSetIsCharacterMember(cfpunctset
, ch
); }
1599 WXDLLEXPORT
int wxIsspace(wxChar ch
) { return CFCharacterSetIsCharacterMember(cfspaceset
, ch
); }
1600 WXDLLEXPORT
int wxIsupper(wxChar ch
) { return CFCharacterSetIsCharacterMember(cfupperset
, ch
); }
1601 WXDLLEXPORT
int wxIsxdigit(wxChar ch
) { return wxIsdigit(ch
) || (ch
>='a' && ch
<='f') || (ch
>='A' && ch
<='F'); }
1602 WXDLLEXPORT
int wxTolower(wxChar ch
) { return (wxChar
)tolower((char)(ch
)); }
1603 WXDLLEXPORT
int wxToupper(wxChar ch
) { return (wxChar
)toupper((char)(ch
)); }
1605 #endif // wxNEED_WX_CTYPE_H
1609 WXDLLEXPORT
char *wxStrdupA(const char *s
)
1611 return strcpy((char *)malloc(strlen(s
) + 1), s
);
1618 WXDLLEXPORT
wchar_t * wxStrdupW(const wchar_t *pwz
)
1620 size_t size
= (wxWcslen(pwz
) + 1) * sizeof(wchar_t);
1621 wchar_t *ret
= (wchar_t *) malloc(size
);
1622 memcpy(ret
, pwz
, size
);
1629 int WXDLLEXPORT
wxStricmp(const wxChar
*psz1
, const wxChar
*psz2
)
1631 register wxChar c1
, c2
;
1633 c1
= wxTolower(*psz1
++);
1634 c2
= wxTolower(*psz2
++);
1635 } while ( c1
&& (c1
== c2
) );
1641 int WXDLLEXPORT
wxStrnicmp(const wxChar
*s1
, const wxChar
*s2
, size_t n
)
1643 // initialize the variables just to suppress stupid gcc warning
1644 register wxChar c1
= 0, c2
= 0;
1645 while (n
&& ((c1
= wxTolower(*s1
)) == (c2
= wxTolower(*s2
)) ) && c1
) n
--, s1
++, s2
++;
1647 if (c1
< c2
) return -1;
1648 if (c1
> c2
) return 1;
1655 WXDLLEXPORT wxWCharBuffer
wxSetlocale(int category
, const wxChar
*locale
)
1657 char *localeOld
= setlocale(category
, wxConvLibc
.cWX2MB(locale
));
1659 return wxWCharBuffer(wxConvLibc
.cMB2WC(localeOld
));
1663 #if wxUSE_WCHAR_T && !defined(HAVE_WCSLEN)
1664 WXDLLEXPORT
size_t wxWcslen(const wchar_t *s
)
1674 // ----------------------------------------------------------------------------
1675 // string.h functions
1676 // ----------------------------------------------------------------------------
1678 #ifdef wxNEED_WX_STRING_H
1680 // RN: These need to be c externed for the regex lib
1685 WXDLLEXPORT wxChar
* wxStrcat(wxChar
*dest
, const wxChar
*src
)
1688 while (*dest
) dest
++;
1689 while ((*dest
++ = *src
++));
1693 WXDLLEXPORT
const wxChar
* wxStrchr(const wxChar
*s
, wxChar c
)
1695 // be careful here as the terminating NUL makes part of the string
1705 WXDLLEXPORT
int wxStrcmp(const wxChar
*s1
, const wxChar
*s2
)
1707 while ((*s1
== *s2
) && *s1
) s1
++, s2
++;
1708 if ((wxUChar
)*s1
< (wxUChar
)*s2
) return -1;
1709 if ((wxUChar
)*s1
> (wxUChar
)*s2
) return 1;
1713 WXDLLEXPORT wxChar
* wxStrcpy(wxChar
*dest
, const wxChar
*src
)
1716 while ((*dest
++ = *src
++));
1720 WXDLLEXPORT
size_t wxStrlen_(const wxChar
*s
)
1730 WXDLLEXPORT wxChar
* wxStrncat(wxChar
*dest
, const wxChar
*src
, size_t n
)
1733 while (*dest
) dest
++;
1734 while (n
&& (*dest
++ = *src
++)) n
--;
1738 WXDLLEXPORT
int wxStrncmp(const wxChar
*s1
, const wxChar
*s2
, size_t n
)
1740 while (n
&& (*s1
== *s2
) && *s1
) n
--, s1
++, s2
++;
1742 if ((wxUChar
)*s1
< (wxUChar
)*s2
) return -1;
1743 if ((wxUChar
)*s1
> (wxUChar
)*s2
) return 1;
1748 WXDLLEXPORT wxChar
* wxStrncpy(wxChar
*dest
, const wxChar
*src
, size_t n
)
1751 while (n
&& (*dest
++ = *src
++)) n
--;
1752 while (n
) *dest
++=0, n
--; // the docs specify padding with zeroes
1756 WXDLLEXPORT
const wxChar
* wxStrpbrk(const wxChar
*s
, const wxChar
*accept
)
1758 while (*s
&& !wxStrchr(accept
, *s
))
1761 return *s
? s
: NULL
;
1764 WXDLLEXPORT
const wxChar
* wxStrrchr(const wxChar
*s
, wxChar c
)
1766 const wxChar
*ret
= NULL
;
1778 WXDLLEXPORT
size_t wxStrspn(const wxChar
*s
, const wxChar
*accept
)
1781 while (wxStrchr(accept
, *s
++)) len
++;
1785 WXDLLEXPORT
const wxChar
*wxStrstr(const wxChar
*haystack
, const wxChar
*needle
)
1787 wxASSERT_MSG( needle
!= NULL
, _T("NULL argument in wxStrstr") );
1789 // VZ: this is not exactly the most efficient string search algorithm...
1791 const size_t len
= wxStrlen(needle
);
1793 while ( const wxChar
*fnd
= wxStrchr(haystack
, *needle
) )
1795 if ( !wxStrncmp(fnd
, needle
, len
) )
1808 WXDLLEXPORT
double wxStrtod(const wxChar
*nptr
, wxChar
**endptr
)
1810 const wxChar
*start
= nptr
;
1812 // FIXME: only correct for C locale
1813 while (wxIsspace(*nptr
)) nptr
++;
1814 if (*nptr
== wxT('+') || *nptr
== wxT('-')) nptr
++;
1815 while (wxIsdigit(*nptr
)) nptr
++;
1816 if (*nptr
== wxT('.')) {
1818 while (wxIsdigit(*nptr
)) nptr
++;
1820 if (*nptr
== wxT('E') || *nptr
== wxT('e')) {
1822 if (*nptr
== wxT('+') || *nptr
== wxT('-')) nptr
++;
1823 while (wxIsdigit(*nptr
)) nptr
++;
1826 wxString
data(nptr
, nptr
-start
);
1827 wxWX2MBbuf dat
= data
.mb_str(wxConvLibc
);
1828 char *rdat
= wxMBSTRINGCAST dat
;
1829 double ret
= strtod(dat
, &rdat
);
1831 if (endptr
) *endptr
= (wxChar
*)(start
+ (rdat
- (const char *)dat
));
1836 WXDLLEXPORT
long int wxStrtol(const wxChar
*nptr
, wxChar
**endptr
, int base
)
1838 const wxChar
*start
= nptr
;
1840 // FIXME: only correct for C locale
1841 while (wxIsspace(*nptr
)) nptr
++;
1842 if (*nptr
== wxT('+') || *nptr
== wxT('-')) nptr
++;
1843 if (((base
== 0) || (base
== 16)) &&
1844 (nptr
[0] == wxT('0') && nptr
[1] == wxT('x'))) {
1848 else if ((base
== 0) && (nptr
[0] == wxT('0'))) base
= 8;
1849 else if (base
== 0) base
= 10;
1851 while ((wxIsdigit(*nptr
) && (*nptr
- wxT('0') < base
)) ||
1852 (wxIsalpha(*nptr
) && (wxToupper(*nptr
) - wxT('A') + 10 < base
))) nptr
++;
1854 wxString
data(start
, nptr
-start
);
1855 wxWX2MBbuf dat
= data
.mb_str(wxConvLibc
);
1856 char *rdat
= wxMBSTRINGCAST dat
;
1857 long int ret
= strtol(dat
, &rdat
, base
);
1859 if (endptr
) *endptr
= (wxChar
*)(start
+ (rdat
- (const char *)dat
));
1864 WXDLLEXPORT
unsigned long int wxStrtoul(const wxChar
*nptr
, wxChar
**endptr
, int base
)
1866 return (unsigned long int) wxStrtol(nptr
, endptr
, base
);
1869 #endif // wxNEED_WX_STRING_H
1871 #ifdef wxNEED_WX_STDIO_H
1872 WXDLLEXPORT
FILE * wxFopen(const wxChar
*path
, const wxChar
*mode
)
1874 char mode_buffer
[10];
1875 for (size_t i
= 0; i
< wxStrlen(mode
)+1; i
++)
1876 mode_buffer
[i
] = (char) mode
[i
];
1878 return fopen( wxConvFile
.cWX2MB(path
), mode_buffer
);
1881 WXDLLEXPORT
FILE * wxFreopen(const wxChar
*path
, const wxChar
*mode
, FILE *stream
)
1883 char mode_buffer
[10];
1884 for (size_t i
= 0; i
< wxStrlen(mode
)+1; i
++)
1885 mode_buffer
[i
] = (char) mode
[i
];
1887 return freopen( wxConvFile
.cWX2MB(path
), mode_buffer
, stream
);
1890 WXDLLEXPORT
int wxRemove(const wxChar
*path
)
1892 return remove( wxConvFile
.cWX2MB(path
) );
1895 WXDLLEXPORT
int wxRename(const wxChar
*oldpath
, const wxChar
*newpath
)
1897 return rename( wxConvFile
.cWX2MB(oldpath
), wxConvFile
.cWX2MB(newpath
) );
1902 double WXDLLEXPORT
wxAtof(const wxChar
*psz
)
1907 if (str
.ToDouble(& d
))
1912 return atof(wxConvLibc
.cWX2MB(psz
));
1917 #ifdef wxNEED_WX_STDLIB_H
1918 int WXDLLEXPORT
wxAtoi(const wxChar
*psz
)
1920 return atoi(wxConvLibc
.cWX2MB(psz
));
1923 long WXDLLEXPORT
wxAtol(const wxChar
*psz
)
1925 return atol(wxConvLibc
.cWX2MB(psz
));
1928 wxChar
* WXDLLEXPORT
wxGetenv(const wxChar
*name
)
1931 // NB: buffer returned by getenv() is allowed to be overwritten next
1932 // time getenv() is called, so it is OK to use static string
1933 // buffer to hold the data.
1934 static wxWCharBuffer
value((wxChar
*)NULL
);
1935 value
= wxConvLibc
.cMB2WX(getenv(wxConvLibc
.cWX2MB(name
)));
1936 return value
.data();
1938 return getenv(name
);
1942 int WXDLLEXPORT
wxSystem(const wxChar
*psz
)
1944 return system(wxConvLibc
.cWX2MB(psz
));
1947 #endif // wxNEED_WX_STDLIB_H
1949 #ifdef wxNEED_WX_TIME_H
1951 wxStrftime(wxChar
*s
, size_t maxsize
, const wxChar
*fmt
, const struct tm
*tm
)
1956 wxCharBuffer
buf(maxsize
);
1958 wxCharBuffer
bufFmt(wxConvLibc
.cWX2MB(fmt
));
1962 size_t ret
= strftime(buf
.data(), maxsize
, bufFmt
, tm
);
1966 wxWCharBuffer wbuf
= wxConvLibc
.cMB2WX(buf
);
1970 wxStrncpy(s
, wbuf
, maxsize
);
1973 #endif // wxNEED_WX_TIME_H
1976 WXDLLEXPORT wxChar
*wxCtime(const time_t *timep
)
1978 // normally the string is 26 chars but give one more in case some broken
1979 // DOS compiler decides to use "\r\n" instead of "\n" at the end
1980 static wxChar buf
[27];
1982 // ctime() is guaranteed to return a string containing only ASCII
1983 // characters, as its format is always the same for any locale
1984 wxStrncpy(buf
, wxString::FromAscii(ctime(timep
)), WXSIZEOF(buf
));
1985 buf
[WXSIZEOF(buf
) - 1] = _T('\0');
1991 #endif // wxUSE_WCHAR_T
1993 // ----------------------------------------------------------------------------
1994 // functions which we may need even if !wxUSE_WCHAR_T
1995 // ----------------------------------------------------------------------------
1999 WXDLLEXPORT wxChar
* wxStrtok(wxChar
*psz
, const wxChar
*delim
, wxChar
**save_ptr
)
2008 psz
+= wxStrspn(psz
, delim
);
2011 *save_ptr
= (wxChar
*)NULL
;
2012 return (wxChar
*)NULL
;
2016 psz
= wxStrpbrk(psz
, delim
);
2019 *save_ptr
= (wxChar
*)NULL
;
2024 *save_ptr
= psz
+ 1;
2032 // ----------------------------------------------------------------------------
2033 // missing C RTL functions
2034 // ----------------------------------------------------------------------------
2036 #ifdef wxNEED_STRDUP
2038 char *strdup(const char *s
)
2040 char *dest
= (char*) malloc( strlen( s
) + 1 ) ;
2042 strcpy( dest
, s
) ;
2045 #endif // wxNEED_STRDUP
2047 #if defined(__WXWINCE__) && (_WIN32_WCE <= 211)
2049 void *calloc( size_t num
, size_t size
)
2051 void** ptr
= (void **)malloc(num
* size
);
2052 memset( ptr
, 0, num
* size
);
2056 #endif // __WXWINCE__ <= 211
2060 int wxRemove(const wxChar
*path
)
2062 return ::DeleteFile(path
) == 0;