]>
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/module.h"
46 #include "wx/strconv.h"
48 // ----------------------------------------------------------------------------
50 // ----------------------------------------------------------------------------
53 WXDLLEXPORT_DATA(wxMBConv
) wxConvLibc
;
54 WXDLLEXPORT_DATA(wxCSConv
) wxConvLocal((const wxChar
*)NULL
);
56 // stand-ins in absence of wchar_t
57 WXDLLEXPORT_DATA(wxMBConv
) wxConvLibc
, wxConvFile
;
58 #endif // wxUSE_WCHAR_T
60 WXDLLEXPORT_DATA(wxMBConv
*) wxConvCurrent
= &wxConvLibc
;
62 class wxStrConvModule
: public wxModule
65 wxStrConvModule() : wxModule() { }
66 virtual bool OnInit() { return TRUE
; }
74 DECLARE_DYNAMIC_CLASS(wxStrConvModule
)
77 IMPLEMENT_DYNAMIC_CLASS(wxStrConvModule
, wxModule
)
80 // ----------------------------------------------------------------------------
82 // ----------------------------------------------------------------------------
94 #include "wx/encconv.h"
95 #include "wx/fontmap.h"
97 // ----------------------------------------------------------------------------
99 // ----------------------------------------------------------------------------
101 #define BSWAP_UCS4(str, len) { unsigned _c; for (_c=0; _c<len; _c++) str[_c]=wxUINT32_SWAP_ALWAYS(str[_c]); }
102 #define BSWAP_UTF16(str, len) { unsigned _c; for (_c=0; _c<len; _c++) str[_c]=wxUINT16_SWAP_ALWAYS(str[_c]); }
104 // under Unix SIZEOF_WCHAR_T is defined by configure, but under other platforms
105 // it might be not defined - assume the most common value
106 #ifndef SIZEOF_WCHAR_T
107 #define SIZEOF_WCHAR_T 2
108 #endif // !defined(SIZEOF_WCHAR_T)
110 #if SIZEOF_WCHAR_T == 4
111 #define WC_NAME "UCS4"
112 #define WC_BSWAP BSWAP_UCS4
113 #ifdef WORDS_BIGENDIAN
114 #define WC_NAME_BEST "UCS-4BE"
116 #define WC_NAME_BEST "UCS-4LE"
118 #elif SIZEOF_WCHAR_T == 2
119 #define WC_NAME "UTF16"
120 #define WC_BSWAP BSWAP_UTF16
122 #ifdef WORDS_BIGENDIAN
123 #define WC_NAME_BEST "UTF-16BE"
125 #define WC_NAME_BEST "UTF-16LE"
127 #else // sizeof(wchar_t) != 2 nor 4
128 // I don't know what to do about this
129 #error "Weird sizeof(wchar_t): please report your platform details to wx-users mailing list"
132 // ============================================================================
134 // ============================================================================
136 // ----------------------------------------------------------------------------
137 // UTF-16 en/decoding
138 // ----------------------------------------------------------------------------
142 static size_t encode_utf16(wxUint32 input
, wchar_t *output
)
146 if (output
) *output
++ = (wchar_t) input
;
149 else if (input
>=0x110000)
157 *output
++ = (wchar_t) ((input
>> 10)+0xd7c0);
158 *output
++ = (wchar_t) ((input
&0x3ff)+0xdc00);
164 static size_t decode_utf16(const wchar_t* input
, wxUint32
& output
)
166 if ((*input
<0xd800) || (*input
>0xdfff))
171 else if ((input
[1]<0xdc00) || (input
[1]>=0xdfff))
178 output
= ((input
[0] - 0xd7c0) << 10) + (input
[1] - 0xdc00);
185 // ----------------------------------------------------------------------------
187 // ----------------------------------------------------------------------------
189 size_t wxMBConv::MB2WC(wchar_t *buf
, const char *psz
, size_t n
) const
191 return wxMB2WC(buf
, psz
, n
);
194 size_t wxMBConv::WC2MB(char *buf
, const wchar_t *psz
, size_t n
) const
196 return wxWC2MB(buf
, psz
, n
);
199 const wxWCharBuffer
wxMBConv::cMB2WC(const char *psz
) const
203 size_t nLen
= MB2WC((wchar_t *) NULL
, psz
, 0);
204 if (nLen
== (size_t)-1)
205 return wxWCharBuffer((wchar_t *) NULL
);
206 wxWCharBuffer
buf(nLen
);
207 MB2WC((wchar_t *)(const wchar_t *) buf
, psz
, nLen
);
211 return wxWCharBuffer((wchar_t *) NULL
);
214 const wxCharBuffer
wxMBConv::cWC2MB(const wchar_t *psz
) const
218 size_t nLen
= WC2MB((char *) NULL
, psz
, 0);
219 if (nLen
== (size_t)-1)
220 return wxCharBuffer((char *) NULL
);
221 wxCharBuffer
buf(nLen
);
222 WC2MB((char *)(const char *) buf
, psz
, nLen
);
226 return wxCharBuffer((char *) NULL
);
229 // ----------------------------------------------------------------------------
230 // standard file conversion
231 // ----------------------------------------------------------------------------
233 WXDLLEXPORT_DATA(wxMBConvFile
) wxConvFile
;
235 // just use the libc conversion for now
236 size_t wxMBConvFile::MB2WC(wchar_t *buf
, const char *psz
, size_t n
) const
238 return wxMB2WC(buf
, psz
, n
);
241 size_t wxMBConvFile::WC2MB(char *buf
, const wchar_t *psz
, size_t n
) const
243 return wxWC2MB(buf
, psz
, n
);
246 // ----------------------------------------------------------------------------
247 // standard gdk conversion
248 // ----------------------------------------------------------------------------
252 WXDLLEXPORT_DATA(wxMBConvGdk
) wxConvGdk
;
256 size_t wxMBConvGdk::MB2WC(wchar_t *buf
, const char *psz
, size_t n
) const
260 return gdk_mbstowcs((GdkWChar
*)buf
, psz
, n
);
264 GdkWChar
*nbuf
= new GdkWChar
[n
=strlen(psz
)];
265 size_t len
= gdk_mbstowcs(nbuf
, psz
, n
);
271 size_t wxMBConvGdk::WC2MB(char *buf
, const wchar_t *psz
, size_t n
) const
273 char *mbstr
= gdk_wcstombs((GdkWChar
*)psz
);
274 size_t len
= mbstr
? strlen(mbstr
) : 0;
279 memcpy(buf
, psz
, len
);
288 // ----------------------------------------------------------------------------
290 // ----------------------------------------------------------------------------
292 WXDLLEXPORT_DATA(wxMBConvUTF7
) wxConvUTF7
;
295 static char utf7_setD
[]="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
296 "abcdefghijklmnopqrstuvwxyz"
297 "0123456789'(),-./:?";
298 static char utf7_setO
[]="!\"#$%&*;<=>@[]^_`{|}";
299 static char utf7_setB
[]="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
300 "abcdefghijklmnopqrstuvwxyz"
304 // TODO: write actual implementations of UTF-7 here
305 size_t wxMBConvUTF7::MB2WC(wchar_t * WXUNUSED(buf
),
306 const char * WXUNUSED(psz
),
307 size_t WXUNUSED(n
)) const
312 size_t wxMBConvUTF7::WC2MB(char * WXUNUSED(buf
),
313 const wchar_t * WXUNUSED(psz
),
314 size_t WXUNUSED(n
)) const
319 // ----------------------------------------------------------------------------
321 // ----------------------------------------------------------------------------
323 WXDLLEXPORT_DATA(wxMBConvUTF8
) wxConvUTF8
;
325 static wxUint32 utf8_max
[]=
326 { 0x7f, 0x7ff, 0xffff, 0x1fffff, 0x3ffffff, 0x7fffffff, 0xffffffff };
328 size_t wxMBConvUTF8::MB2WC(wchar_t *buf
, const char *psz
, size_t n
) const
332 while (*psz
&& ((!buf
) || (len
< n
)))
334 unsigned char cc
= *psz
++, fc
= cc
;
336 for (cnt
= 0; fc
& 0x80; cnt
++)
350 // invalid UTF-8 sequence
355 unsigned ocnt
= cnt
- 1;
356 wxUint32 res
= cc
& (0x3f >> cnt
);
360 if ((cc
& 0xC0) != 0x80)
362 // invalid UTF-8 sequence
365 res
= (res
<< 6) | (cc
& 0x3f);
367 if (res
<= utf8_max
[ocnt
])
369 // illegal UTF-8 encoding
373 size_t pa
= encode_utf16(res
, buf
);
374 if (pa
== (size_t)-1)
383 #endif // WC_UTF16/!WC_UTF16
387 if (buf
&& (len
< n
))
392 size_t wxMBConvUTF8::WC2MB(char *buf
, const wchar_t *psz
, size_t n
) const
396 while (*psz
&& ((!buf
) || (len
< n
)))
400 size_t pa
= decode_utf16(psz
, cc
);
401 psz
+= (pa
== (size_t)-1) ? 1 : pa
;
403 cc
=(*psz
++) & 0x7fffffff;
406 for (cnt
= 0; cc
> utf8_max
[cnt
]; cnt
++) {}
420 *buf
++ = (char) ((-128 >> cnt
) | ((cc
>> (cnt
* 6)) & (0x3f >> cnt
)));
422 *buf
++ = (char) (0x80 | ((cc
>> (cnt
* 6)) & 0x3f));
427 if (buf
&& (len
<n
)) *buf
= 0;
431 // ============================================================================
432 // wxCharacterSet and derived classes
433 // ============================================================================
435 // ----------------------------------------------------------------------------
436 // wxCharacterSet is the ABC for the classes below
437 // ----------------------------------------------------------------------------
442 wxCharacterSet(const wxChar
*name
) : cname(name
) {}
443 virtual ~wxCharacterSet() {}
444 virtual size_t MB2WC(wchar_t *buf
, const char *psz
, size_t n
) = 0;
445 virtual size_t WC2MB(char *buf
, const wchar_t *psz
, size_t n
) = 0;
446 virtual bool usable() const = 0;
451 // ----------------------------------------------------------------------------
452 // ID_CharSet: implementation of wxCharacterSet using an existing wxMBConv
453 // ----------------------------------------------------------------------------
455 class ID_CharSet
: public wxCharacterSet
458 ID_CharSet(const wxChar
*name
, wxMBConv
*cnv
)
459 : wxCharacterSet(name
), work(cnv
) {}
461 size_t MB2WC(wchar_t *buf
, const char *psz
, size_t n
)
462 { return work
? work
->MB2WC(buf
,psz
,n
) : (size_t)-1; }
464 size_t WC2MB(char *buf
, const wchar_t *psz
, size_t n
)
465 { return work
? work
->WC2MB(buf
,psz
,n
) : (size_t)-1; }
468 { return work
!=NULL
; }
474 // ============================================================================
475 // The classes doing conversion using the iconv_xxx() functions
476 // ============================================================================
480 // VS: glibc 2.1.3 is broken in that iconv() conversion to/from UCS4 fails with E2BIG
481 // if output buffer is _exactly_ as big as needed. Such case is (unless there's
482 // yet another bug in glibc) the only case when iconv() returns with (size_t)-1
483 // (which means error) and says there are 0 bytes left in the input buffer --
484 // when _real_ error occurs, bytes-left-in-input buffer is non-zero. Hence,
485 // this alternative test for iconv() failure.
486 // [This bug does not appear in glibc 2.2.]
487 #if defined(__GLIBC__) && __GLIBC__ == 2 && __GLIBC_MINOR__ <= 1
488 #define ICONV_FAILED(cres, bufLeft) ((cres == (size_t)-1) && \
489 (errno != E2BIG || bufLeft != 0))
491 #define ICONV_FAILED(cres, bufLeft) (cres == (size_t)-1)
494 #define ICONV_CHAR_CAST(x) ((ICONV_CONST char **)(x))
496 // ----------------------------------------------------------------------------
497 // IC_CharSet: encapsulates an iconv character set
498 // ----------------------------------------------------------------------------
500 class IC_CharSet
: public wxCharacterSet
503 IC_CharSet(const wxChar
*name
);
504 virtual ~IC_CharSet();
506 virtual size_t MB2WC(wchar_t *buf
, const char *psz
, size_t n
);
507 virtual size_t WC2MB(char *buf
, const wchar_t *psz
, size_t n
);
510 { return (m2w
!= (iconv_t
)-1) && (w2m
!= (iconv_t
)-1); }
513 // the iconv handlers used to translate from multibyte to wide char and in
514 // the other direction
519 // the name (for iconv_open()) of a wide char charset - if none is
520 // available on this machine, it will remain NULL
521 static const char *ms_wcCharsetName
;
523 // true if the wide char encoding we use (i.e. ms_wcCharsetName) has
524 // different endian-ness than the native one
525 static bool ms_wcNeedsSwap
;
528 const char *IC_CharSet::ms_wcCharsetName
= NULL
;
529 bool IC_CharSet::ms_wcNeedsSwap
= FALSE
;
531 IC_CharSet::IC_CharSet(const wxChar
*name
)
532 : wxCharacterSet(name
)
534 // check for charset that represents wchar_t:
535 if (ms_wcCharsetName
== NULL
)
537 ms_wcNeedsSwap
= FALSE
;
539 // try charset with explicit bytesex info (e.g. "UCS-4LE"):
540 ms_wcCharsetName
= WC_NAME_BEST
;
541 m2w
= iconv_open(ms_wcCharsetName
, wxConvLibc
.cWX2MB(name
));
543 if (m2w
== (iconv_t
)-1)
545 // try charset w/o bytesex info (e.g. "UCS4")
546 // and check for bytesex ourselves:
547 ms_wcCharsetName
= WC_NAME
;
548 m2w
= iconv_open(ms_wcCharsetName
, wxConvLibc
.cWX2MB(name
));
550 // last bet, try if it knows WCHAR_T pseudo-charset
551 if (m2w
== (iconv_t
)-1)
553 ms_wcCharsetName
= "WCHAR_T";
554 m2w
= iconv_open(ms_wcCharsetName
, wxConvLibc
.cWX2MB(name
));
557 if (m2w
!= (iconv_t
)-1)
559 char buf
[2], *bufPtr
;
560 wchar_t wbuf
[2], *wbufPtr
;
568 outsz
= SIZEOF_WCHAR_T
* 2;
572 res
= iconv(m2w
, ICONV_CHAR_CAST(&bufPtr
), &insz
,
573 (char**)&wbufPtr
, &outsz
);
575 if (ICONV_FAILED(res
, insz
))
577 ms_wcCharsetName
= NULL
;
578 wxLogLastError(wxT("iconv"));
579 wxLogError(_("Convertion to charset '%s' doesn't work."), name
);
583 ms_wcNeedsSwap
= wbuf
[0] != (wchar_t)buf
[0];
588 ms_wcCharsetName
= NULL
;
590 // VS: we must not output an error here, since wxWindows will safely
591 // fall back to using wxEncodingConverter.
592 wxLogTrace(wxT("strconv"), wxT("Impossible to convert to/from charset '%s' with iconv, falling back to wxEncodingConverter."), name
);
596 wxLogTrace(wxT("strconv"), wxT("wchar_t charset is '%s', needs swap: %i"), ms_wcCharsetName
, ms_wcNeedsSwap
);
598 else // we already have ms_wcCharsetName
600 m2w
= iconv_open(ms_wcCharsetName
, wxConvLibc
.cWX2MB(name
));
603 // NB: don't ever pass NULL to iconv_open(), it may crash!
604 if ( ms_wcCharsetName
)
606 w2m
= iconv_open(wxConvLibc
.cWX2MB(name
), ms_wcCharsetName
);
614 IC_CharSet::~IC_CharSet()
616 if ( m2w
!= (iconv_t
)-1 )
618 if ( w2m
!= (iconv_t
)-1 )
622 size_t IC_CharSet::MB2WC(wchar_t *buf
, const char *psz
, size_t n
)
624 size_t inbuf
= strlen(psz
);
625 size_t outbuf
= n
* SIZEOF_WCHAR_T
;
627 // VS: Use these instead of psz, buf because iconv() modifies its arguments:
628 wchar_t *bufPtr
= buf
;
629 const char *pszPtr
= psz
;
633 // have destination buffer, convert there
635 ICONV_CHAR_CAST(&pszPtr
), &inbuf
,
636 (char**)&bufPtr
, &outbuf
);
637 res
= n
- (outbuf
/ SIZEOF_WCHAR_T
);
641 // convert to native endianness
642 WC_BSWAP(buf
/* _not_ bufPtr */, res
)
647 // no destination buffer... convert using temp buffer
648 // to calculate destination buffer requirement
653 outbuf
= 8*SIZEOF_WCHAR_T
;
656 ICONV_CHAR_CAST(&pszPtr
), &inbuf
,
657 (char**)&bufPtr
, &outbuf
);
659 res
+= 8-(outbuf
/SIZEOF_WCHAR_T
);
660 } while ((cres
==(size_t)-1) && (errno
==E2BIG
));
663 if (ICONV_FAILED(cres
, inbuf
))
665 //VS: it is ok if iconv fails, hence trace only
666 wxLogTrace(wxT("strconv"), wxT("iconv failed: %s"), wxSysErrorMsg(wxSysErrorCode()));
673 size_t IC_CharSet::WC2MB(char *buf
, const wchar_t *psz
, size_t n
)
675 #if defined(__BORLANDC__) && (__BORLANDC__ > 0x530)
676 size_t inbuf
= std::wcslen(psz
) * SIZEOF_WCHAR_T
;
678 size_t inbuf
= ::wcslen(psz
) * SIZEOF_WCHAR_T
;
687 // need to copy to temp buffer to switch endianness
688 // this absolutely doesn't rock!
689 // (no, doing WC_BSWAP twice on the original buffer won't help, as it
690 // could be in read-only memory, or be accessed in some other thread)
691 tmpbuf
=(wchar_t*)malloc((inbuf
+1)*SIZEOF_WCHAR_T
);
692 memcpy(tmpbuf
,psz
,(inbuf
+1)*SIZEOF_WCHAR_T
);
693 WC_BSWAP(tmpbuf
, inbuf
)
699 // have destination buffer, convert there
700 cres
= iconv( w2m
, ICONV_CHAR_CAST(&psz
), &inbuf
, &buf
, &outbuf
);
706 // no destination buffer... convert using temp buffer
707 // to calculate destination buffer requirement
711 buf
= tbuf
; outbuf
= 16;
713 cres
= iconv( w2m
, ICONV_CHAR_CAST(&psz
), &inbuf
, &buf
, &outbuf
);
716 } while ((cres
==(size_t)-1) && (errno
==E2BIG
));
724 if (ICONV_FAILED(cres
, inbuf
))
726 //VS: it is ok if iconv fails, hence trace only
727 wxLogTrace(wxT("strconv"), wxT("iconv failed: %s"), wxSysErrorMsg(wxSysErrorCode()));
736 // ============================================================================
737 // Win32 conversion classes
738 // ============================================================================
740 #if defined(__WIN32__) && !defined(__WXMICROWIN__)
742 extern long wxCharsetToCodepage(const wxChar
*charset
); // from utils.cpp
744 class CP_CharSet
: public wxCharacterSet
747 CP_CharSet(const wxChar
* name
)
748 : wxCharacterSet(name
)
750 m_CodePage
= wxCharsetToCodepage(name
);
753 size_t MB2WC(wchar_t *buf
, const char *psz
, size_t n
)
756 MultiByteToWideChar(m_CodePage
, 0, psz
, -1, buf
, buf
? n
: 0);
757 //VS: returns # of written chars for buf!=NULL and *size*
758 // needed buffer for buf==NULL
759 return len
? (buf
? len
: len
-1) : (size_t)-1;
762 size_t WC2MB(char *buf
, const wchar_t *psz
, size_t n
)
764 size_t len
= WideCharToMultiByte(m_CodePage
, 0, psz
, -1, buf
,
765 buf
? n
: 0, NULL
, NULL
);
766 //VS: returns # of written chars for buf!=NULL and *size*
767 // needed buffer for buf==NULL
768 return len
? (buf
? len
: len
-1) : (size_t)-1;
772 { return m_CodePage
!= -1; }
779 // ============================================================================
780 // wxEncodingConverter based conversion classes
781 // ============================================================================
785 class EC_CharSet
: public wxCharacterSet
788 // temporarily just use wxEncodingConverter stuff,
789 // so that it works while a better implementation is built
790 EC_CharSet(const wxChar
* name
) : wxCharacterSet(name
),
791 enc(wxFONTENCODING_SYSTEM
)
794 enc
= wxFontMapper::Get()->CharsetToEncoding(name
, FALSE
);
796 m_ok
= m2w
.Init(enc
, wxFONTENCODING_UNICODE
) &&
797 w2m
.Init(wxFONTENCODING_UNICODE
, enc
);
800 size_t MB2WC(wchar_t *buf
, const char *psz
, size_t WXUNUSED(n
))
802 size_t inbuf
= strlen(psz
);
804 m2w
.Convert(psz
,buf
);
808 size_t WC2MB(char *buf
, const wchar_t *psz
, size_t WXUNUSED(n
))
810 #if ( defined(__BORLANDC__) && (__BORLANDC__ > 0x530) ) \
811 || ( defined(__MWERKS__) && defined(__WXMSW__) )
812 size_t inbuf
= std::wcslen(psz
);
814 size_t inbuf
= ::wcslen(psz
);
817 w2m
.Convert(psz
,buf
);
822 bool usable() const { return m_ok
; }
826 wxEncodingConverter m2w
, w2m
;
828 // were we initialized successfully?
832 #endif // wxUSE_FONTMAP
834 // ----------------------------------------------------------------------------
835 // the function creating the wxCharacterSet for the specified charset on the
836 // current system, trying all possibilities
837 // ----------------------------------------------------------------------------
839 static wxCharacterSet
*wxGetCharacterSet(const wxChar
*name
)
841 // check for the special case of ASCII charset
843 if ( wxFontMapper::Get()->CharsetToEncoding(name
) == wxFONTENCODING_DEFAULT
)
844 #else // wxUSE_FONTMAP
846 #endif // wxUSE_FONTMAP/!wxUSE_FONTMAP
848 // don't convert at all
852 // the test above must have taken care of this case
853 wxCHECK_MSG( name
, NULL
, _T("NULL name must be wxFONTENCODING_DEFAULT") );
855 wxCharacterSet
*cset
;
857 if ( wxStricmp(name
, wxT("UTF8")) == 0 || wxStricmp(name
, wxT("UTF-8")) == 0)
859 cset
= new ID_CharSet(name
, &wxConvUTF8
);
864 cset
= new IC_CharSet(name
);
867 #endif // HAVE_ICONV/!HAVE_ICONV
870 // it can only be NULL in this case
873 #endif // !HAVE_ICONV
875 if ( cset
->usable() )
882 #if defined(__WIN32__) && !defined(__WXMICROWIN__)
883 cset
= new CP_CharSet(name
);
884 if ( cset
->usable() )
892 cset
= new EC_CharSet(name
);
893 if ( cset
->usable() )
898 #endif // wxUSE_FONTMAP
900 wxLogError(_("Cannot convert from encoding '%s'!"), name
);
905 // ============================================================================
906 // wxCSConv implementation
907 // ============================================================================
909 wxCSConv::wxCSConv(const wxChar
*charset
)
911 m_name
= (wxChar
*)NULL
;
912 m_cset
= (wxCharacterSet
*) NULL
;
918 wxCSConv::~wxCSConv()
923 void wxCSConv::Clear()
933 void wxCSConv::SetName(const wxChar
*charset
)
937 m_name
= wxStrdup(charset
);
942 void wxCSConv::LoadNow()
948 wxString name
= wxLocale::GetSystemEncodingName();
953 // wxGetCharacterSet() complains about NULL name
954 m_cset
= m_name
? wxGetCharacterSet(m_name
) : NULL
;
959 size_t wxCSConv::MB2WC(wchar_t *buf
, const char *psz
, size_t n
) const
961 ((wxCSConv
*)this)->LoadNow(); // discard constness
964 return m_cset
->MB2WC(buf
, psz
, n
);
967 size_t len
= strlen(psz
);
971 for (size_t c
= 0; c
<= len
; c
++)
972 buf
[c
] = (unsigned char)(psz
[c
]);
978 size_t wxCSConv::WC2MB(char *buf
, const wchar_t *psz
, size_t n
) const
980 ((wxCSConv
*)this)->LoadNow(); // discard constness
983 return m_cset
->WC2MB(buf
, psz
, n
);
986 #if ( defined(__BORLANDC__) && (__BORLANDC__ > 0x530) ) \
987 || ( defined(__MWERKS__) && defined(__WXMSW__) )
988 size_t len
=std::wcslen(psz
);
990 size_t len
=::wcslen(psz
);
994 for (size_t c
= 0; c
<= len
; c
++)
995 buf
[c
] = (psz
[c
] > 0xff) ? '?' : psz
[c
];
1001 #endif // wxUSE_WCHAR_T