]>
git.saurik.com Git - wxWidgets.git/blob - src/common/strconv.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Unicode conversion classes
4 // Author: Ove Kaaven, Robert Roebling, Vadim Zeitlin, Vaclav Slavik
8 // Copyright: (c) 1999 Ove Kaaven, Robert Roebling, Vadim Zeitlin, Vaclav Slavik
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation "strconv.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
37 #include "wx/msw/private.h"
45 #include "wx/strconv.h"
47 // ----------------------------------------------------------------------------
49 // ----------------------------------------------------------------------------
52 WXDLLEXPORT_DATA(wxMBConv
) wxConvLibc
;
53 WXDLLEXPORT_DATA(wxCSConv
) wxConvLocal((const wxChar
*)NULL
);
55 // stand-ins in absence of wchar_t
56 WXDLLEXPORT_DATA(wxMBConv
) wxConvLibc
, wxConvFile
;
57 #endif // wxUSE_WCHAR_T
59 WXDLLEXPORT_DATA(wxMBConv
*) wxConvCurrent
= &wxConvLibc
;
61 // ----------------------------------------------------------------------------
63 // ----------------------------------------------------------------------------
75 #include "wx/encconv.h"
76 #include "wx/fontmap.h"
78 // ----------------------------------------------------------------------------
80 // ----------------------------------------------------------------------------
82 #define BSWAP_UCS4(str, len) { unsigned _c; for (_c=0; _c<len; _c++) str[_c]=wxUINT32_SWAP_ALWAYS(str[_c]); }
83 #define BSWAP_UTF16(str, len) { unsigned _c; for (_c=0; _c<len; _c++) str[_c]=wxUINT16_SWAP_ALWAYS(str[_c]); }
85 // under Unix SIZEOF_WCHAR_T is defined by configure, but under other platforms
86 // it might be not defined - assume the most common value
87 #ifndef SIZEOF_WCHAR_T
88 #define SIZEOF_WCHAR_T 2
89 #endif // !defined(SIZEOF_WCHAR_T)
91 #if SIZEOF_WCHAR_T == 4
92 #define WC_NAME "UCS4"
93 #define WC_BSWAP BSWAP_UCS4
94 #ifdef WORDS_BIGENDIAN
95 #define WC_NAME_BEST "UCS-4BE"
97 #define WC_NAME_BEST "UCS-4LE"
99 #elif SIZEOF_WCHAR_T == 2
100 #define WC_NAME "UTF16"
101 #define WC_BSWAP BSWAP_UTF16
103 #ifdef WORDS_BIGENDIAN
104 #define WC_NAME_BEST "UTF-16BE"
106 #define WC_NAME_BEST "UTF-16LE"
108 #else // sizeof(wchar_t) != 2 nor 4
109 // I don't know what to do about this
110 #error "Weird sizeof(wchar_t): please report your platform details to wx-users mailing list"
113 // ============================================================================
115 // ============================================================================
117 // ----------------------------------------------------------------------------
118 // UTF-16 en/decoding
119 // ----------------------------------------------------------------------------
123 static size_t encode_utf16(wxUint32 input
, wchar_t *output
)
127 if (output
) *output
++ = (wchar_t) input
;
130 else if (input
>=0x110000)
138 *output
++ = (wchar_t) ((input
>> 10)+0xd7c0);
139 *output
++ = (wchar_t) ((input
&0x3ff)+0xdc00);
145 static size_t decode_utf16(const wchar_t* input
, wxUint32
& output
)
147 if ((*input
<0xd800) || (*input
>0xdfff))
152 else if ((input
[1]<0xdc00) || (input
[1]>=0xdfff))
159 output
= ((input
[0] - 0xd7c0) << 10) + (input
[1] - 0xdc00);
166 // ----------------------------------------------------------------------------
168 // ----------------------------------------------------------------------------
170 size_t wxMBConv::MB2WC(wchar_t *buf
, const char *psz
, size_t n
) const
172 return wxMB2WC(buf
, psz
, n
);
175 size_t wxMBConv::WC2MB(char *buf
, const wchar_t *psz
, size_t n
) const
177 return wxWC2MB(buf
, psz
, n
);
180 const wxWCharBuffer
wxMBConv::cMB2WC(const char *psz
) const
184 size_t nLen
= MB2WC((wchar_t *) NULL
, psz
, 0);
185 if (nLen
== (size_t)-1)
186 return wxWCharBuffer((wchar_t *) NULL
);
187 wxWCharBuffer
buf(nLen
);
188 MB2WC((wchar_t *)(const wchar_t *) buf
, psz
, nLen
);
192 return wxWCharBuffer((wchar_t *) NULL
);
195 const wxCharBuffer
wxMBConv::cWC2MB(const wchar_t *psz
) const
199 size_t nLen
= WC2MB((char *) NULL
, psz
, 0);
200 if (nLen
== (size_t)-1)
201 return wxCharBuffer((char *) NULL
);
202 wxCharBuffer
buf(nLen
);
203 WC2MB((char *)(const char *) buf
, psz
, nLen
);
207 return wxCharBuffer((char *) NULL
);
210 // ----------------------------------------------------------------------------
211 // standard file conversion
212 // ----------------------------------------------------------------------------
214 WXDLLEXPORT_DATA(wxMBConvFile
) wxConvFile
;
216 // just use the libc conversion for now
217 size_t wxMBConvFile::MB2WC(wchar_t *buf
, const char *psz
, size_t n
) const
219 return wxMB2WC(buf
, psz
, n
);
222 size_t wxMBConvFile::WC2MB(char *buf
, const wchar_t *psz
, size_t n
) const
224 return wxWC2MB(buf
, psz
, n
);
227 // ----------------------------------------------------------------------------
228 // standard gdk conversion
229 // ----------------------------------------------------------------------------
233 WXDLLEXPORT_DATA(wxMBConvGdk
) wxConvGdk
;
237 size_t wxMBConvGdk::MB2WC(wchar_t *buf
, const char *psz
, size_t n
) const
241 return gdk_mbstowcs((GdkWChar
*)buf
, psz
, n
);
245 GdkWChar
*nbuf
= new GdkWChar
[n
=strlen(psz
)];
246 size_t len
= gdk_mbstowcs(nbuf
, psz
, n
);
252 size_t wxMBConvGdk::WC2MB(char *buf
, const wchar_t *psz
, size_t n
) const
254 char *mbstr
= gdk_wcstombs((GdkWChar
*)psz
);
255 size_t len
= mbstr
? strlen(mbstr
) : 0;
260 memcpy(buf
, psz
, len
);
269 // ----------------------------------------------------------------------------
271 // ----------------------------------------------------------------------------
273 WXDLLEXPORT_DATA(wxMBConvUTF7
) wxConvUTF7
;
276 static char utf7_setD
[]="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
277 "abcdefghijklmnopqrstuvwxyz"
278 "0123456789'(),-./:?";
279 static char utf7_setO
[]="!\"#$%&*;<=>@[]^_`{|}";
280 static char utf7_setB
[]="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
281 "abcdefghijklmnopqrstuvwxyz"
285 // TODO: write actual implementations of UTF-7 here
286 size_t wxMBConvUTF7::MB2WC(wchar_t * WXUNUSED(buf
),
287 const char * WXUNUSED(psz
),
288 size_t WXUNUSED(n
)) const
293 size_t wxMBConvUTF7::WC2MB(char * WXUNUSED(buf
),
294 const wchar_t * WXUNUSED(psz
),
295 size_t WXUNUSED(n
)) const
300 // ----------------------------------------------------------------------------
302 // ----------------------------------------------------------------------------
304 WXDLLEXPORT_DATA(wxMBConvUTF8
) wxConvUTF8
;
306 static wxUint32 utf8_max
[]=
307 { 0x7f, 0x7ff, 0xffff, 0x1fffff, 0x3ffffff, 0x7fffffff, 0xffffffff };
309 size_t wxMBConvUTF8::MB2WC(wchar_t *buf
, const char *psz
, size_t n
) const
313 while (*psz
&& ((!buf
) || (len
< n
)))
315 unsigned char cc
= *psz
++, fc
= cc
;
317 for (cnt
= 0; fc
& 0x80; cnt
++)
331 // invalid UTF-8 sequence
336 unsigned ocnt
= cnt
- 1;
337 wxUint32 res
= cc
& (0x3f >> cnt
);
341 if ((cc
& 0xC0) != 0x80)
343 // invalid UTF-8 sequence
346 res
= (res
<< 6) | (cc
& 0x3f);
348 if (res
<= utf8_max
[ocnt
])
350 // illegal UTF-8 encoding
354 size_t pa
= encode_utf16(res
, buf
);
355 if (pa
== (size_t)-1)
364 #endif // WC_UTF16/!WC_UTF16
368 if (buf
&& (len
< n
))
373 size_t wxMBConvUTF8::WC2MB(char *buf
, const wchar_t *psz
, size_t n
) const
377 while (*psz
&& ((!buf
) || (len
< n
)))
381 size_t pa
= decode_utf16(psz
, cc
);
382 psz
+= (pa
== (size_t)-1) ? 1 : pa
;
384 cc
=(*psz
++) & 0x7fffffff;
387 for (cnt
= 0; cc
> utf8_max
[cnt
]; cnt
++) {}
401 *buf
++ = (char) ((-128 >> cnt
) | ((cc
>> (cnt
* 6)) & (0x3f >> cnt
)));
403 *buf
++ = (char) (0x80 | ((cc
>> (cnt
* 6)) & 0x3f));
408 if (buf
&& (len
<n
)) *buf
= 0;
412 // ============================================================================
413 // wxCharacterSet and derived classes
414 // ============================================================================
416 // ----------------------------------------------------------------------------
417 // wxCharacterSet is the ABC for the classes below
418 // ----------------------------------------------------------------------------
423 wxCharacterSet(const wxChar
*name
) : cname(name
) {}
424 virtual ~wxCharacterSet() {}
425 virtual size_t MB2WC(wchar_t *buf
, const char *psz
, size_t n
) = 0;
426 virtual size_t WC2MB(char *buf
, const wchar_t *psz
, size_t n
) = 0;
427 virtual bool usable() const = 0;
432 // ----------------------------------------------------------------------------
433 // ID_CharSet: implementation of wxCharacterSet using an existing wxMBConv
434 // ----------------------------------------------------------------------------
436 class ID_CharSet
: public wxCharacterSet
439 ID_CharSet(const wxChar
*name
, wxMBConv
*cnv
)
440 : wxCharacterSet(name
), work(cnv
) {}
442 size_t MB2WC(wchar_t *buf
, const char *psz
, size_t n
)
443 { return work
? work
->MB2WC(buf
,psz
,n
) : (size_t)-1; }
445 size_t WC2MB(char *buf
, const wchar_t *psz
, size_t n
)
446 { return work
? work
->WC2MB(buf
,psz
,n
) : (size_t)-1; }
449 { return work
!=NULL
; }
455 // ============================================================================
456 // The classes doing conversion using the iconv_xxx() functions
457 // ============================================================================
461 // VS: glibc 2.1.3 is broken in that iconv() conversion to/from UCS4 fails with E2BIG
462 // if output buffer is _exactly_ as big as needed. Such case is (unless there's
463 // yet another bug in glibc) the only case when iconv() returns with (size_t)-1
464 // (which means error) and says there are 0 bytes left in the input buffer --
465 // when _real_ error occurs, bytes-left-in-input buffer is non-zero. Hence,
466 // this alternative test for iconv() failure.
467 // [This bug does not appear in glibc 2.2.]
468 #if defined(__GLIBC__) && __GLIBC__ == 2 && __GLIBC_MINOR__ <= 1
469 #define ICONV_FAILED(cres, bufLeft) ((cres == (size_t)-1) && \
470 (errno != E2BIG || bufLeft != 0))
472 #define ICONV_FAILED(cres, bufLeft) (cres == (size_t)-1)
475 #define ICONV_CHAR_CAST(x) ((ICONV_CONST char **)(x))
477 // ----------------------------------------------------------------------------
478 // IC_CharSet: encapsulates an iconv character set
479 // ----------------------------------------------------------------------------
481 class IC_CharSet
: public wxCharacterSet
484 IC_CharSet(const wxChar
*name
);
485 virtual ~IC_CharSet();
487 virtual size_t MB2WC(wchar_t *buf
, const char *psz
, size_t n
);
488 virtual size_t WC2MB(char *buf
, const wchar_t *psz
, size_t n
);
491 { return (m2w
!= (iconv_t
)-1) && (w2m
!= (iconv_t
)-1); }
494 // the iconv handlers used to translate from multibyte to wide char and in
495 // the other direction
500 // the name (for iconv_open()) of a wide char charset - if none is
501 // available on this machine, it will remain NULL
502 static const char *ms_wcCharsetName
;
504 // true if the wide char encoding we use (i.e. ms_wcCharsetName) has
505 // different endian-ness than the native one
506 static bool ms_wcNeedsSwap
;
509 const char *IC_CharSet::ms_wcCharsetName
= NULL
;
510 bool IC_CharSet::ms_wcNeedsSwap
= FALSE
;
512 IC_CharSet::IC_CharSet(const wxChar
*name
)
513 : wxCharacterSet(name
)
515 // check for charset that represents wchar_t:
516 if (ms_wcCharsetName
== NULL
)
518 ms_wcNeedsSwap
= FALSE
;
520 // try charset with explicit bytesex info (e.g. "UCS-4LE"):
521 ms_wcCharsetName
= WC_NAME_BEST
;
522 m2w
= iconv_open(ms_wcCharsetName
, wxConvLibc
.cWX2MB(name
));
524 if (m2w
== (iconv_t
)-1)
526 // try charset w/o bytesex info (e.g. "UCS4")
527 // and check for bytesex ourselves:
528 ms_wcCharsetName
= WC_NAME
;
529 m2w
= iconv_open(ms_wcCharsetName
, wxConvLibc
.cWX2MB(name
));
531 // last bet, try if it knows WCHAR_T pseudo-charset
532 if (m2w
== (iconv_t
)-1)
534 ms_wcCharsetName
= "WCHAR_T";
535 m2w
= iconv_open(ms_wcCharsetName
, wxConvLibc
.cWX2MB(name
));
538 if (m2w
!= (iconv_t
)-1)
540 char buf
[2], *bufPtr
;
541 wchar_t wbuf
[2], *wbufPtr
;
549 outsz
= SIZEOF_WCHAR_T
* 2;
553 res
= iconv(m2w
, ICONV_CHAR_CAST(&bufPtr
), &insz
,
554 (char**)&wbufPtr
, &outsz
);
556 if (ICONV_FAILED(res
, insz
))
558 ms_wcCharsetName
= NULL
;
559 wxLogLastError(wxT("iconv"));
560 wxLogError(_("Convertion to charset '%s' doesn't work."), name
);
564 ms_wcNeedsSwap
= wbuf
[0] != (wchar_t)buf
[0];
569 ms_wcCharsetName
= NULL
;
571 // VS: we must not output an error here, since wxWindows will safely
572 // fall back to using wxEncodingConverter.
573 wxLogTrace(wxT("strconv"), wxT("Impossible to convert to/from charset '%s' with iconv, falling back to wxEncodingConverter."), name
);
577 wxLogTrace(wxT("strconv"), wxT("wchar_t charset is '%s', needs swap: %i"), ms_wcCharsetName
, ms_wcNeedsSwap
);
579 else // we already have ms_wcCharsetName
581 m2w
= iconv_open(ms_wcCharsetName
, wxConvLibc
.cWX2MB(name
));
584 // NB: don't ever pass NULL to iconv_open(), it may crash!
585 if ( ms_wcCharsetName
)
587 w2m
= iconv_open(wxConvLibc
.cWX2MB(name
), ms_wcCharsetName
);
595 IC_CharSet::~IC_CharSet()
597 if ( m2w
!= (iconv_t
)-1 )
599 if ( w2m
!= (iconv_t
)-1 )
603 size_t IC_CharSet::MB2WC(wchar_t *buf
, const char *psz
, size_t n
)
605 size_t inbuf
= strlen(psz
);
606 size_t outbuf
= n
* SIZEOF_WCHAR_T
;
608 // VS: Use these instead of psz, buf because iconv() modifies its arguments:
609 wchar_t *bufPtr
= buf
;
610 const char *pszPtr
= psz
;
614 // have destination buffer, convert there
616 ICONV_CHAR_CAST(&pszPtr
), &inbuf
,
617 (char**)&bufPtr
, &outbuf
);
618 res
= n
- (outbuf
/ SIZEOF_WCHAR_T
);
622 // convert to native endianness
623 WC_BSWAP(buf
/* _not_ bufPtr */, res
)
628 // no destination buffer... convert using temp buffer
629 // to calculate destination buffer requirement
634 outbuf
= 8*SIZEOF_WCHAR_T
;
637 ICONV_CHAR_CAST(&pszPtr
), &inbuf
,
638 (char**)&bufPtr
, &outbuf
);
640 res
+= 8-(outbuf
/SIZEOF_WCHAR_T
);
641 } while ((cres
==(size_t)-1) && (errno
==E2BIG
));
644 if (ICONV_FAILED(cres
, inbuf
))
646 //VS: it is ok if iconv fails, hence trace only
647 wxLogTrace(wxT("strconv"), wxT("iconv failed: %s"), wxSysErrorMsg(wxSysErrorCode()));
654 size_t IC_CharSet::WC2MB(char *buf
, const wchar_t *psz
, size_t n
)
656 #if defined(__BORLANDC__) && (__BORLANDC__ > 0x530)
657 size_t inbuf
= std::wcslen(psz
) * SIZEOF_WCHAR_T
;
659 size_t inbuf
= ::wcslen(psz
) * SIZEOF_WCHAR_T
;
668 // need to copy to temp buffer to switch endianness
669 // this absolutely doesn't rock!
670 // (no, doing WC_BSWAP twice on the original buffer won't help, as it
671 // could be in read-only memory, or be accessed in some other thread)
672 tmpbuf
=(wchar_t*)malloc((inbuf
+1)*SIZEOF_WCHAR_T
);
673 memcpy(tmpbuf
,psz
,(inbuf
+1)*SIZEOF_WCHAR_T
);
674 WC_BSWAP(tmpbuf
, inbuf
)
680 // have destination buffer, convert there
681 cres
= iconv( w2m
, ICONV_CHAR_CAST(&psz
), &inbuf
, &buf
, &outbuf
);
687 // no destination buffer... convert using temp buffer
688 // to calculate destination buffer requirement
692 buf
= tbuf
; outbuf
= 16;
694 cres
= iconv( w2m
, ICONV_CHAR_CAST(&psz
), &inbuf
, &buf
, &outbuf
);
697 } while ((cres
==(size_t)-1) && (errno
==E2BIG
));
705 if (ICONV_FAILED(cres
, inbuf
))
707 //VS: it is ok if iconv fails, hence trace only
708 wxLogTrace(wxT("strconv"), wxT("iconv failed: %s"), wxSysErrorMsg(wxSysErrorCode()));
717 // ============================================================================
718 // Win32 conversion classes
719 // ============================================================================
721 #if defined(__WIN32__) && !defined(__WXMICROWIN__)
723 extern long wxCharsetToCodepage(const wxChar
*charset
); // from utils.cpp
725 class CP_CharSet
: public wxCharacterSet
728 CP_CharSet(const wxChar
* name
)
729 : wxCharacterSet(name
)
731 m_CodePage
= wxCharsetToCodepage(name
);
734 size_t MB2WC(wchar_t *buf
, const char *psz
, size_t n
)
737 MultiByteToWideChar(m_CodePage
, 0, psz
, -1, buf
, buf
? n
: 0);
738 //VS: returns # of written chars for buf!=NULL and *size*
739 // needed buffer for buf==NULL
740 return len
? (buf
? len
: len
-1) : (size_t)-1;
743 size_t WC2MB(char *buf
, const wchar_t *psz
, size_t n
)
745 size_t len
= WideCharToMultiByte(m_CodePage
, 0, psz
, -1, buf
,
746 buf
? n
: 0, NULL
, NULL
);
747 //VS: returns # of written chars for buf!=NULL and *size*
748 // needed buffer for buf==NULL
749 return len
? (buf
? len
: len
-1) : (size_t)-1;
753 { return m_CodePage
!= -1; }
760 // ============================================================================
761 // wxEncodingConverter based conversion classes
762 // ============================================================================
766 class EC_CharSet
: public wxCharacterSet
769 // temporarily just use wxEncodingConverter stuff,
770 // so that it works while a better implementation is built
771 EC_CharSet(const wxChar
* name
) : wxCharacterSet(name
),
772 enc(wxFONTENCODING_SYSTEM
)
775 enc
= wxTheFontMapper
->CharsetToEncoding(name
, FALSE
);
777 m_ok
= m2w
.Init(enc
, wxFONTENCODING_UNICODE
) &&
778 w2m
.Init(wxFONTENCODING_UNICODE
, enc
);
781 size_t MB2WC(wchar_t *buf
, const char *psz
, size_t WXUNUSED(n
))
783 size_t inbuf
= strlen(psz
);
785 m2w
.Convert(psz
,buf
);
789 size_t WC2MB(char *buf
, const wchar_t *psz
, size_t WXUNUSED(n
))
791 #if ( defined(__BORLANDC__) && (__BORLANDC__ > 0x530) ) \
792 || ( defined(__MWERKS__) && defined(__WXMSW__) )
793 size_t inbuf
= std::wcslen(psz
);
795 size_t inbuf
= ::wcslen(psz
);
798 w2m
.Convert(psz
,buf
);
803 bool usable() const { return m_ok
; }
807 wxEncodingConverter m2w
, w2m
;
809 // were we initialized successfully?
813 #endif // wxUSE_FONTMAP
815 // ----------------------------------------------------------------------------
816 // the function creating the wxCharacterSet for the specified charset on the
817 // current system, trying all possibilities
818 // ----------------------------------------------------------------------------
820 static wxCharacterSet
*wxGetCharacterSet(const wxChar
*name
)
822 // check for the special case of ASCII charset
824 if ( wxTheFontMapper
->CharsetToEncoding(name
) == wxFONTENCODING_DEFAULT
)
825 #else // wxUSE_FONTMAP
827 #endif // wxUSE_FONTMAP/!wxUSE_FONTMAP
829 // don't convert at all
833 // the test above must have taken care of this case
834 wxCHECK_MSG( name
, NULL
, _T("NULL name must be wxFONTENCODING_DEFAULT") );
836 wxCharacterSet
*cset
;
838 if ( wxStricmp(name
, wxT("UTF8")) == 0 || wxStricmp(name
, wxT("UTF-8")) == 0)
840 cset
= new ID_CharSet(name
, &wxConvUTF8
);
845 cset
= new IC_CharSet(name
);
848 #endif // HAVE_ICONV/!HAVE_ICONV
851 // it can only be NULL in this case
854 #endif // !HAVE_ICONV
856 if ( cset
->usable() )
863 #if defined(__WIN32__) && !defined(__WXMICROWIN__)
864 cset
= new CP_CharSet(name
);
865 if ( cset
->usable() )
873 cset
= new EC_CharSet(name
);
874 if ( cset
->usable() )
879 #endif // wxUSE_FONTMAP
881 wxLogError(_("Cannot convert from encoding '%s'!"), name
);
886 // ============================================================================
887 // wxCSConv implementation
888 // ============================================================================
890 wxCSConv::wxCSConv(const wxChar
*charset
)
892 m_name
= (wxChar
*)NULL
;
893 m_cset
= (wxCharacterSet
*) NULL
;
899 wxCSConv::~wxCSConv()
905 void wxCSConv::SetName(const wxChar
*charset
)
909 m_name
= wxStrdup(charset
);
914 void wxCSConv::LoadNow()
920 wxString name
= wxLocale::GetSystemEncodingName();
925 // wxGetCharacterSet() complains about NULL name
926 m_cset
= m_name
? wxGetCharacterSet(m_name
) : NULL
;
931 size_t wxCSConv::MB2WC(wchar_t *buf
, const char *psz
, size_t n
) const
933 ((wxCSConv
*)this)->LoadNow(); // discard constness
936 return m_cset
->MB2WC(buf
, psz
, n
);
939 size_t len
= strlen(psz
);
943 for (size_t c
= 0; c
<= len
; c
++)
944 buf
[c
] = (unsigned char)(psz
[c
]);
950 size_t wxCSConv::WC2MB(char *buf
, const wchar_t *psz
, size_t n
) const
952 ((wxCSConv
*)this)->LoadNow(); // discard constness
955 return m_cset
->WC2MB(buf
, psz
, n
);
958 #if ( defined(__BORLANDC__) && (__BORLANDC__ > 0x530) ) \
959 || ( defined(__MWERKS__) && defined(__WXMSW__) )
960 size_t len
=std::wcslen(psz
);
962 size_t len
=::wcslen(psz
);
966 for (size_t c
= 0; c
<= len
; c
++)
967 buf
[c
] = (psz
[c
] > 0xff) ? '?' : psz
[c
];
973 #endif // wxUSE_WCHAR_T