]>
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
; }
72 DECLARE_DYNAMIC_CLASS(wxStrConvModule
)
75 IMPLEMENT_DYNAMIC_CLASS(wxStrConvModule
, wxModule
)
78 // ----------------------------------------------------------------------------
80 // ----------------------------------------------------------------------------
92 #include "wx/encconv.h"
93 #include "wx/fontmap.h"
95 // ----------------------------------------------------------------------------
97 // ----------------------------------------------------------------------------
99 #define BSWAP_UCS4(str, len) { unsigned _c; for (_c=0; _c<len; _c++) str[_c]=wxUINT32_SWAP_ALWAYS(str[_c]); }
100 #define BSWAP_UTF16(str, len) { unsigned _c; for (_c=0; _c<len; _c++) str[_c]=wxUINT16_SWAP_ALWAYS(str[_c]); }
102 // under Unix SIZEOF_WCHAR_T is defined by configure, but under other platforms
103 // it might be not defined - assume the most common value
104 #ifndef SIZEOF_WCHAR_T
105 #define SIZEOF_WCHAR_T 2
106 #endif // !defined(SIZEOF_WCHAR_T)
108 #if SIZEOF_WCHAR_T == 4
109 #define WC_NAME "UCS4"
110 #define WC_BSWAP BSWAP_UCS4
111 #ifdef WORDS_BIGENDIAN
112 #define WC_NAME_BEST "UCS-4BE"
114 #define WC_NAME_BEST "UCS-4LE"
116 #elif SIZEOF_WCHAR_T == 2
117 #define WC_NAME "UTF16"
118 #define WC_BSWAP BSWAP_UTF16
120 #ifdef WORDS_BIGENDIAN
121 #define WC_NAME_BEST "UTF-16BE"
123 #define WC_NAME_BEST "UTF-16LE"
125 #else // sizeof(wchar_t) != 2 nor 4
126 // I don't know what to do about this
127 #error "Weird sizeof(wchar_t): please report your platform details to wx-users mailing list"
130 // ============================================================================
132 // ============================================================================
134 // ----------------------------------------------------------------------------
135 // UTF-16 en/decoding
136 // ----------------------------------------------------------------------------
140 static size_t encode_utf16(wxUint32 input
, wchar_t *output
)
144 if (output
) *output
++ = (wchar_t) input
;
147 else if (input
>=0x110000)
155 *output
++ = (wchar_t) ((input
>> 10)+0xd7c0);
156 *output
++ = (wchar_t) ((input
&0x3ff)+0xdc00);
162 static size_t decode_utf16(const wchar_t* input
, wxUint32
& output
)
164 if ((*input
<0xd800) || (*input
>0xdfff))
169 else if ((input
[1]<0xdc00) || (input
[1]>=0xdfff))
176 output
= ((input
[0] - 0xd7c0) << 10) + (input
[1] - 0xdc00);
183 // ----------------------------------------------------------------------------
185 // ----------------------------------------------------------------------------
187 size_t wxMBConv::MB2WC(wchar_t *buf
, const char *psz
, size_t n
) const
189 return wxMB2WC(buf
, psz
, n
);
192 size_t wxMBConv::WC2MB(char *buf
, const wchar_t *psz
, size_t n
) const
194 return wxWC2MB(buf
, psz
, n
);
197 const wxWCharBuffer
wxMBConv::cMB2WC(const char *psz
) const
201 size_t nLen
= MB2WC((wchar_t *) NULL
, psz
, 0);
202 if (nLen
== (size_t)-1)
203 return wxWCharBuffer((wchar_t *) NULL
);
204 wxWCharBuffer
buf(nLen
);
205 MB2WC((wchar_t *)(const wchar_t *) buf
, psz
, nLen
);
209 return wxWCharBuffer((wchar_t *) NULL
);
212 const wxCharBuffer
wxMBConv::cWC2MB(const wchar_t *psz
) const
216 size_t nLen
= WC2MB((char *) NULL
, psz
, 0);
217 if (nLen
== (size_t)-1)
218 return wxCharBuffer((char *) NULL
);
219 wxCharBuffer
buf(nLen
);
220 WC2MB((char *)(const char *) buf
, psz
, nLen
);
224 return wxCharBuffer((char *) NULL
);
227 // ----------------------------------------------------------------------------
228 // standard file conversion
229 // ----------------------------------------------------------------------------
231 WXDLLEXPORT_DATA(wxMBConvFile
) wxConvFile
;
233 // just use the libc conversion for now
234 size_t wxMBConvFile::MB2WC(wchar_t *buf
, const char *psz
, size_t n
) const
236 return wxMB2WC(buf
, psz
, n
);
239 size_t wxMBConvFile::WC2MB(char *buf
, const wchar_t *psz
, size_t n
) const
241 return wxWC2MB(buf
, psz
, n
);
244 // ----------------------------------------------------------------------------
245 // standard gdk conversion
246 // ----------------------------------------------------------------------------
250 WXDLLEXPORT_DATA(wxMBConvGdk
) wxConvGdk
;
254 size_t wxMBConvGdk::MB2WC(wchar_t *buf
, const char *psz
, size_t n
) const
258 return gdk_mbstowcs((GdkWChar
*)buf
, psz
, n
);
262 GdkWChar
*nbuf
= new GdkWChar
[n
=strlen(psz
)];
263 size_t len
= gdk_mbstowcs(nbuf
, psz
, n
);
269 size_t wxMBConvGdk::WC2MB(char *buf
, const wchar_t *psz
, size_t n
) const
271 char *mbstr
= gdk_wcstombs((GdkWChar
*)psz
);
272 size_t len
= mbstr
? strlen(mbstr
) : 0;
277 memcpy(buf
, psz
, len
);
286 // ----------------------------------------------------------------------------
288 // ----------------------------------------------------------------------------
290 WXDLLEXPORT_DATA(wxMBConvUTF7
) wxConvUTF7
;
293 static char utf7_setD
[]="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
294 "abcdefghijklmnopqrstuvwxyz"
295 "0123456789'(),-./:?";
296 static char utf7_setO
[]="!\"#$%&*;<=>@[]^_`{|}";
297 static char utf7_setB
[]="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
298 "abcdefghijklmnopqrstuvwxyz"
302 // TODO: write actual implementations of UTF-7 here
303 size_t wxMBConvUTF7::MB2WC(wchar_t * WXUNUSED(buf
),
304 const char * WXUNUSED(psz
),
305 size_t WXUNUSED(n
)) const
310 size_t wxMBConvUTF7::WC2MB(char * WXUNUSED(buf
),
311 const wchar_t * WXUNUSED(psz
),
312 size_t WXUNUSED(n
)) const
317 // ----------------------------------------------------------------------------
319 // ----------------------------------------------------------------------------
321 WXDLLEXPORT_DATA(wxMBConvUTF8
) wxConvUTF8
;
323 static wxUint32 utf8_max
[]=
324 { 0x7f, 0x7ff, 0xffff, 0x1fffff, 0x3ffffff, 0x7fffffff, 0xffffffff };
326 size_t wxMBConvUTF8::MB2WC(wchar_t *buf
, const char *psz
, size_t n
) const
330 while (*psz
&& ((!buf
) || (len
< n
)))
332 unsigned char cc
= *psz
++, fc
= cc
;
334 for (cnt
= 0; fc
& 0x80; cnt
++)
348 // invalid UTF-8 sequence
353 unsigned ocnt
= cnt
- 1;
354 wxUint32 res
= cc
& (0x3f >> cnt
);
358 if ((cc
& 0xC0) != 0x80)
360 // invalid UTF-8 sequence
363 res
= (res
<< 6) | (cc
& 0x3f);
365 if (res
<= utf8_max
[ocnt
])
367 // illegal UTF-8 encoding
371 size_t pa
= encode_utf16(res
, buf
);
372 if (pa
== (size_t)-1)
381 #endif // WC_UTF16/!WC_UTF16
385 if (buf
&& (len
< n
))
390 size_t wxMBConvUTF8::WC2MB(char *buf
, const wchar_t *psz
, size_t n
) const
394 while (*psz
&& ((!buf
) || (len
< n
)))
398 size_t pa
= decode_utf16(psz
, cc
);
399 psz
+= (pa
== (size_t)-1) ? 1 : pa
;
401 cc
=(*psz
++) & 0x7fffffff;
404 for (cnt
= 0; cc
> utf8_max
[cnt
]; cnt
++) {}
418 *buf
++ = (char) ((-128 >> cnt
) | ((cc
>> (cnt
* 6)) & (0x3f >> cnt
)));
420 *buf
++ = (char) (0x80 | ((cc
>> (cnt
* 6)) & 0x3f));
425 if (buf
&& (len
<n
)) *buf
= 0;
429 // ============================================================================
430 // wxCharacterSet and derived classes
431 // ============================================================================
433 // ----------------------------------------------------------------------------
434 // wxCharacterSet is the ABC for the classes below
435 // ----------------------------------------------------------------------------
440 wxCharacterSet(const wxChar
*name
) : cname(name
) {}
441 virtual ~wxCharacterSet() {}
442 virtual size_t MB2WC(wchar_t *buf
, const char *psz
, size_t n
) = 0;
443 virtual size_t WC2MB(char *buf
, const wchar_t *psz
, size_t n
) = 0;
444 virtual bool usable() const = 0;
449 // ----------------------------------------------------------------------------
450 // ID_CharSet: implementation of wxCharacterSet using an existing wxMBConv
451 // ----------------------------------------------------------------------------
453 class ID_CharSet
: public wxCharacterSet
456 ID_CharSet(const wxChar
*name
, wxMBConv
*cnv
)
457 : wxCharacterSet(name
), work(cnv
) {}
459 size_t MB2WC(wchar_t *buf
, const char *psz
, size_t n
)
460 { return work
? work
->MB2WC(buf
,psz
,n
) : (size_t)-1; }
462 size_t WC2MB(char *buf
, const wchar_t *psz
, size_t n
)
463 { return work
? work
->WC2MB(buf
,psz
,n
) : (size_t)-1; }
466 { return work
!=NULL
; }
472 // ============================================================================
473 // The classes doing conversion using the iconv_xxx() functions
474 // ============================================================================
478 // VS: glibc 2.1.3 is broken in that iconv() conversion to/from UCS4 fails with E2BIG
479 // if output buffer is _exactly_ as big as needed. Such case is (unless there's
480 // yet another bug in glibc) the only case when iconv() returns with (size_t)-1
481 // (which means error) and says there are 0 bytes left in the input buffer --
482 // when _real_ error occurs, bytes-left-in-input buffer is non-zero. Hence,
483 // this alternative test for iconv() failure.
484 // [This bug does not appear in glibc 2.2.]
485 #if defined(__GLIBC__) && __GLIBC__ == 2 && __GLIBC_MINOR__ <= 1
486 #define ICONV_FAILED(cres, bufLeft) ((cres == (size_t)-1) && \
487 (errno != E2BIG || bufLeft != 0))
489 #define ICONV_FAILED(cres, bufLeft) (cres == (size_t)-1)
492 #define ICONV_CHAR_CAST(x) ((ICONV_CONST char **)(x))
494 // ----------------------------------------------------------------------------
495 // IC_CharSet: encapsulates an iconv character set
496 // ----------------------------------------------------------------------------
498 class IC_CharSet
: public wxCharacterSet
501 IC_CharSet(const wxChar
*name
);
502 virtual ~IC_CharSet();
504 virtual size_t MB2WC(wchar_t *buf
, const char *psz
, size_t n
);
505 virtual size_t WC2MB(char *buf
, const wchar_t *psz
, size_t n
);
508 { return (m2w
!= (iconv_t
)-1) && (w2m
!= (iconv_t
)-1); }
511 // the iconv handlers used to translate from multibyte to wide char and in
512 // the other direction
517 // the name (for iconv_open()) of a wide char charset - if none is
518 // available on this machine, it will remain NULL
519 static const char *ms_wcCharsetName
;
521 // true if the wide char encoding we use (i.e. ms_wcCharsetName) has
522 // different endian-ness than the native one
523 static bool ms_wcNeedsSwap
;
526 const char *IC_CharSet::ms_wcCharsetName
= NULL
;
527 bool IC_CharSet::ms_wcNeedsSwap
= FALSE
;
529 IC_CharSet::IC_CharSet(const wxChar
*name
)
530 : wxCharacterSet(name
)
532 // check for charset that represents wchar_t:
533 if (ms_wcCharsetName
== NULL
)
535 ms_wcNeedsSwap
= FALSE
;
537 // try charset with explicit bytesex info (e.g. "UCS-4LE"):
538 ms_wcCharsetName
= WC_NAME_BEST
;
539 m2w
= iconv_open(ms_wcCharsetName
, wxConvLibc
.cWX2MB(name
));
541 if (m2w
== (iconv_t
)-1)
543 // try charset w/o bytesex info (e.g. "UCS4")
544 // and check for bytesex ourselves:
545 ms_wcCharsetName
= WC_NAME
;
546 m2w
= iconv_open(ms_wcCharsetName
, wxConvLibc
.cWX2MB(name
));
548 // last bet, try if it knows WCHAR_T pseudo-charset
549 if (m2w
== (iconv_t
)-1)
551 ms_wcCharsetName
= "WCHAR_T";
552 m2w
= iconv_open(ms_wcCharsetName
, wxConvLibc
.cWX2MB(name
));
555 if (m2w
!= (iconv_t
)-1)
557 char buf
[2], *bufPtr
;
558 wchar_t wbuf
[2], *wbufPtr
;
566 outsz
= SIZEOF_WCHAR_T
* 2;
570 res
= iconv(m2w
, ICONV_CHAR_CAST(&bufPtr
), &insz
,
571 (char**)&wbufPtr
, &outsz
);
573 if (ICONV_FAILED(res
, insz
))
575 ms_wcCharsetName
= NULL
;
576 wxLogLastError(wxT("iconv"));
577 wxLogError(_("Convertion to charset '%s' doesn't work."), name
);
581 ms_wcNeedsSwap
= wbuf
[0] != (wchar_t)buf
[0];
586 ms_wcCharsetName
= NULL
;
588 // VS: we must not output an error here, since wxWindows will safely
589 // fall back to using wxEncodingConverter.
590 wxLogTrace(wxT("strconv"), wxT("Impossible to convert to/from charset '%s' with iconv, falling back to wxEncodingConverter."), name
);
594 wxLogTrace(wxT("strconv"), wxT("wchar_t charset is '%s', needs swap: %i"), ms_wcCharsetName
, ms_wcNeedsSwap
);
596 else // we already have ms_wcCharsetName
598 m2w
= iconv_open(ms_wcCharsetName
, wxConvLibc
.cWX2MB(name
));
601 // NB: don't ever pass NULL to iconv_open(), it may crash!
602 if ( ms_wcCharsetName
)
604 w2m
= iconv_open(wxConvLibc
.cWX2MB(name
), ms_wcCharsetName
);
612 IC_CharSet::~IC_CharSet()
614 if ( m2w
!= (iconv_t
)-1 )
616 if ( w2m
!= (iconv_t
)-1 )
620 size_t IC_CharSet::MB2WC(wchar_t *buf
, const char *psz
, size_t n
)
622 size_t inbuf
= strlen(psz
);
623 size_t outbuf
= n
* SIZEOF_WCHAR_T
;
625 // VS: Use these instead of psz, buf because iconv() modifies its arguments:
626 wchar_t *bufPtr
= buf
;
627 const char *pszPtr
= psz
;
631 // have destination buffer, convert there
633 ICONV_CHAR_CAST(&pszPtr
), &inbuf
,
634 (char**)&bufPtr
, &outbuf
);
635 res
= n
- (outbuf
/ SIZEOF_WCHAR_T
);
639 // convert to native endianness
640 WC_BSWAP(buf
/* _not_ bufPtr */, res
)
645 // no destination buffer... convert using temp buffer
646 // to calculate destination buffer requirement
651 outbuf
= 8*SIZEOF_WCHAR_T
;
654 ICONV_CHAR_CAST(&pszPtr
), &inbuf
,
655 (char**)&bufPtr
, &outbuf
);
657 res
+= 8-(outbuf
/SIZEOF_WCHAR_T
);
658 } while ((cres
==(size_t)-1) && (errno
==E2BIG
));
661 if (ICONV_FAILED(cres
, inbuf
))
663 //VS: it is ok if iconv fails, hence trace only
664 wxLogTrace(wxT("strconv"), wxT("iconv failed: %s"), wxSysErrorMsg(wxSysErrorCode()));
671 size_t IC_CharSet::WC2MB(char *buf
, const wchar_t *psz
, size_t n
)
673 #if defined(__BORLANDC__) && (__BORLANDC__ > 0x530)
674 size_t inbuf
= std::wcslen(psz
) * SIZEOF_WCHAR_T
;
676 size_t inbuf
= ::wcslen(psz
) * SIZEOF_WCHAR_T
;
685 // need to copy to temp buffer to switch endianness
686 // this absolutely doesn't rock!
687 // (no, doing WC_BSWAP twice on the original buffer won't help, as it
688 // could be in read-only memory, or be accessed in some other thread)
689 tmpbuf
=(wchar_t*)malloc((inbuf
+1)*SIZEOF_WCHAR_T
);
690 memcpy(tmpbuf
,psz
,(inbuf
+1)*SIZEOF_WCHAR_T
);
691 WC_BSWAP(tmpbuf
, inbuf
)
697 // have destination buffer, convert there
698 cres
= iconv( w2m
, ICONV_CHAR_CAST(&psz
), &inbuf
, &buf
, &outbuf
);
704 // no destination buffer... convert using temp buffer
705 // to calculate destination buffer requirement
709 buf
= tbuf
; outbuf
= 16;
711 cres
= iconv( w2m
, ICONV_CHAR_CAST(&psz
), &inbuf
, &buf
, &outbuf
);
714 } while ((cres
==(size_t)-1) && (errno
==E2BIG
));
722 if (ICONV_FAILED(cres
, inbuf
))
724 //VS: it is ok if iconv fails, hence trace only
725 wxLogTrace(wxT("strconv"), wxT("iconv failed: %s"), wxSysErrorMsg(wxSysErrorCode()));
734 // ============================================================================
735 // Win32 conversion classes
736 // ============================================================================
738 #if defined(__WIN32__) && !defined(__WXMICROWIN__)
740 extern long wxCharsetToCodepage(const wxChar
*charset
); // from utils.cpp
742 class CP_CharSet
: public wxCharacterSet
745 CP_CharSet(const wxChar
* name
)
746 : wxCharacterSet(name
)
748 m_CodePage
= wxCharsetToCodepage(name
);
751 size_t MB2WC(wchar_t *buf
, const char *psz
, size_t n
)
754 MultiByteToWideChar(m_CodePage
, 0, psz
, -1, buf
, buf
? n
: 0);
755 //VS: returns # of written chars for buf!=NULL and *size*
756 // needed buffer for buf==NULL
757 return len
? (buf
? len
: len
-1) : (size_t)-1;
760 size_t WC2MB(char *buf
, const wchar_t *psz
, size_t n
)
762 size_t len
= WideCharToMultiByte(m_CodePage
, 0, psz
, -1, buf
,
763 buf
? n
: 0, NULL
, NULL
);
764 //VS: returns # of written chars for buf!=NULL and *size*
765 // needed buffer for buf==NULL
766 return len
? (buf
? len
: len
-1) : (size_t)-1;
770 { return m_CodePage
!= -1; }
777 // ============================================================================
778 // wxEncodingConverter based conversion classes
779 // ============================================================================
783 class EC_CharSet
: public wxCharacterSet
786 // temporarily just use wxEncodingConverter stuff,
787 // so that it works while a better implementation is built
788 EC_CharSet(const wxChar
* name
) : wxCharacterSet(name
),
789 enc(wxFONTENCODING_SYSTEM
)
792 enc
= wxTheFontMapper
->CharsetToEncoding(name
, FALSE
);
794 m_ok
= m2w
.Init(enc
, wxFONTENCODING_UNICODE
) &&
795 w2m
.Init(wxFONTENCODING_UNICODE
, enc
);
798 size_t MB2WC(wchar_t *buf
, const char *psz
, size_t WXUNUSED(n
))
800 size_t inbuf
= strlen(psz
);
802 m2w
.Convert(psz
,buf
);
806 size_t WC2MB(char *buf
, const wchar_t *psz
, size_t WXUNUSED(n
))
808 #if ( defined(__BORLANDC__) && (__BORLANDC__ > 0x530) ) \
809 || ( defined(__MWERKS__) && defined(__WXMSW__) )
810 size_t inbuf
= std::wcslen(psz
);
812 size_t inbuf
= ::wcslen(psz
);
815 w2m
.Convert(psz
,buf
);
820 bool usable() const { return m_ok
; }
824 wxEncodingConverter m2w
, w2m
;
826 // were we initialized successfully?
830 #endif // wxUSE_FONTMAP
832 // ----------------------------------------------------------------------------
833 // the function creating the wxCharacterSet for the specified charset on the
834 // current system, trying all possibilities
835 // ----------------------------------------------------------------------------
837 static wxCharacterSet
*wxGetCharacterSet(const wxChar
*name
)
839 // check for the special case of ASCII charset
841 if ( wxTheFontMapper
->CharsetToEncoding(name
) == wxFONTENCODING_DEFAULT
)
842 #else // wxUSE_FONTMAP
844 #endif // wxUSE_FONTMAP/!wxUSE_FONTMAP
846 // don't convert at all
850 // the test above must have taken care of this case
851 wxCHECK_MSG( name
, NULL
, _T("NULL name must be wxFONTENCODING_DEFAULT") );
853 wxCharacterSet
*cset
;
855 if ( wxStricmp(name
, wxT("UTF8")) == 0 || wxStricmp(name
, wxT("UTF-8")) == 0)
857 cset
= new ID_CharSet(name
, &wxConvUTF8
);
862 cset
= new IC_CharSet(name
);
865 #endif // HAVE_ICONV/!HAVE_ICONV
868 // it can only be NULL in this case
871 #endif // !HAVE_ICONV
873 if ( cset
->usable() )
880 #if defined(__WIN32__) && !defined(__WXMICROWIN__)
881 cset
= new CP_CharSet(name
);
882 if ( cset
->usable() )
890 cset
= new EC_CharSet(name
);
891 if ( cset
->usable() )
896 #endif // wxUSE_FONTMAP
898 wxLogError(_("Cannot convert from encoding '%s'!"), name
);
903 // ============================================================================
904 // wxCSConv implementation
905 // ============================================================================
907 wxCSConv::wxCSConv(const wxChar
*charset
)
909 m_name
= (wxChar
*)NULL
;
910 m_cset
= (wxCharacterSet
*) NULL
;
916 wxCSConv::~wxCSConv()
921 void wxCSConv::Clear()
931 void wxCSConv::SetName(const wxChar
*charset
)
935 m_name
= wxStrdup(charset
);
940 void wxCSConv::LoadNow()
946 wxString name
= wxLocale::GetSystemEncodingName();
951 // wxGetCharacterSet() complains about NULL name
952 m_cset
= m_name
? wxGetCharacterSet(m_name
) : NULL
;
957 size_t wxCSConv::MB2WC(wchar_t *buf
, const char *psz
, size_t n
) const
959 ((wxCSConv
*)this)->LoadNow(); // discard constness
962 return m_cset
->MB2WC(buf
, psz
, n
);
965 size_t len
= strlen(psz
);
969 for (size_t c
= 0; c
<= len
; c
++)
970 buf
[c
] = (unsigned char)(psz
[c
]);
976 size_t wxCSConv::WC2MB(char *buf
, const wchar_t *psz
, size_t n
) const
978 ((wxCSConv
*)this)->LoadNow(); // discard constness
981 return m_cset
->WC2MB(buf
, psz
, n
);
984 #if ( defined(__BORLANDC__) && (__BORLANDC__ > 0x530) ) \
985 || ( defined(__MWERKS__) && defined(__WXMSW__) )
986 size_t len
=std::wcslen(psz
);
988 size_t len
=::wcslen(psz
);
992 for (size_t c
= 0; c
<= len
; c
++)
993 buf
[c
] = (psz
[c
] > 0xff) ? '?' : psz
[c
];
999 #endif // wxUSE_WCHAR_T