]>
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 licence
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 WXDLLIMPEXP_DATA_BASE(wxMBConv
) wxConvLibc
;
54 WXDLLIMPEXP_DATA_BASE(wxCSConv
) wxConvLocal((const wxChar
*)NULL
);
55 WXDLLIMPEXP_DATA_BASE(wxCSConv
) wxConvISO8859_1(_T("iso-8859-1"));
57 // stand-ins in absence of wchar_t
58 WXDLLIMPEXP_DATA_BASE(wxMBConv
) wxConvLibc
,
63 #endif // wxUSE_WCHAR_T
65 WXDLLIMPEXP_DATA_BASE(wxMBConv
*) wxConvCurrent
= &wxConvLibc
;
67 class wxStrConvModule
: public wxModule
70 wxStrConvModule() : wxModule() { }
71 virtual bool OnInit() { return TRUE
; }
76 wxConvISO8859_1
.Clear();
80 DECLARE_DYNAMIC_CLASS(wxStrConvModule
)
83 IMPLEMENT_DYNAMIC_CLASS(wxStrConvModule
, wxModule
)
86 // ----------------------------------------------------------------------------
88 // ----------------------------------------------------------------------------
100 #include "wx/encconv.h"
101 #include "wx/fontmap.h"
103 // ----------------------------------------------------------------------------
105 // ----------------------------------------------------------------------------
107 #define BSWAP_UCS4(str, len) { unsigned _c; for (_c=0; _c<len; _c++) str[_c]=wxUINT32_SWAP_ALWAYS(str[_c]); }
108 #define BSWAP_UTF16(str, len) { unsigned _c; for (_c=0; _c<len; _c++) str[_c]=wxUINT16_SWAP_ALWAYS(str[_c]); }
110 // under Unix SIZEOF_WCHAR_T is defined by configure, but under other platforms
111 // it might be not defined - assume the most common value
112 #ifndef SIZEOF_WCHAR_T
113 #define SIZEOF_WCHAR_T 2
114 #endif // !defined(SIZEOF_WCHAR_T)
116 #if SIZEOF_WCHAR_T == 4
117 #define WC_NAME "UCS4"
118 #define WC_BSWAP BSWAP_UCS4
119 #ifdef WORDS_BIGENDIAN
120 #define WC_NAME_BEST "UCS-4BE"
122 #define WC_NAME_BEST "UCS-4LE"
124 #elif SIZEOF_WCHAR_T == 2
125 #define WC_NAME "UTF16"
126 #define WC_BSWAP BSWAP_UTF16
128 #ifdef WORDS_BIGENDIAN
129 #define WC_NAME_BEST "UTF-16BE"
131 #define WC_NAME_BEST "UTF-16LE"
133 #else // sizeof(wchar_t) != 2 nor 4
134 // I don't know what to do about this
135 #error "Weird sizeof(wchar_t): please report your platform details to wx-users mailing list"
138 // ============================================================================
140 // ============================================================================
142 // ----------------------------------------------------------------------------
143 // UTF-16 en/decoding
144 // ----------------------------------------------------------------------------
148 static size_t encode_utf16(wxUint32 input
, wchar_t *output
)
152 if (output
) *output
++ = (wchar_t) input
;
155 else if (input
>=0x110000)
163 *output
++ = (wchar_t) ((input
>> 10)+0xd7c0);
164 *output
++ = (wchar_t) ((input
&0x3ff)+0xdc00);
170 static size_t decode_utf16(const wchar_t* input
, wxUint32
& output
)
172 if ((*input
<0xd800) || (*input
>0xdfff))
177 else if ((input
[1]<0xdc00) || (input
[1]>=0xdfff))
184 output
= ((input
[0] - 0xd7c0) << 10) + (input
[1] - 0xdc00);
191 // ----------------------------------------------------------------------------
193 // ----------------------------------------------------------------------------
195 #define IGNORE_LIBC 0
197 wxMBConv::~wxMBConv()
199 // nothing to do here
202 size_t wxMBConv::MB2WC(wchar_t *buf
, const char *psz
, size_t n
) const
207 for (size_t i
= 0; i
< strlen( psz
)+1; i
++)
208 buf
[i
] = (wchar_t) psz
[i
];
209 return strlen( psz
);
213 return strlen( psz
);
216 return wxMB2WC(buf
, psz
, n
);
220 size_t wxMBConv::WC2MB(char *buf
, const wchar_t *psz
, size_t n
) const
225 for (size_t i
= 0; i
< wxStrlen( psz
)+1; i
++)
226 buf
[i
] = (char) psz
[i
];
227 return wxStrlen( psz
);
231 return wxStrlen( psz
);
234 return wxWC2MB(buf
, psz
, n
);
238 const wxWCharBuffer
wxMBConv::cMB2WC(const char *psz
) const
242 // calculate the length of the buffer needed first
243 size_t nLen
= MB2WC(NULL
, psz
, 0);
244 if ( nLen
!= (size_t)-1 )
246 // now do the actual conversion
247 wxWCharBuffer
buf(nLen
);
248 MB2WC(buf
.data(), psz
, nLen
+ 1); // with the trailing NUL
254 wxWCharBuffer
buf((wchar_t *)NULL
);
259 const wxCharBuffer
wxMBConv::cWC2MB(const wchar_t *pwz
) const
263 size_t nLen
= WC2MB(NULL
, pwz
, 0);
264 if ( nLen
!= (size_t)-1 )
266 wxCharBuffer
buf(nLen
);
267 WC2MB(buf
.data(), pwz
, nLen
+ 1);
273 wxCharBuffer
buf((char *)NULL
);
278 // ----------------------------------------------------------------------------
280 // ----------------------------------------------------------------------------
282 WXDLLIMPEXP_DATA_BASE(wxMBConvUTF7
) wxConvUTF7
;
285 static char utf7_setD
[]="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
286 "abcdefghijklmnopqrstuvwxyz"
287 "0123456789'(),-./:?";
288 static char utf7_setO
[]="!\"#$%&*;<=>@[]^_`{|}";
289 static char utf7_setB
[]="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
290 "abcdefghijklmnopqrstuvwxyz"
294 // TODO: write actual implementations of UTF-7 here
295 size_t wxMBConvUTF7::MB2WC(wchar_t * WXUNUSED(buf
),
296 const char * WXUNUSED(psz
),
297 size_t WXUNUSED(n
)) const
302 size_t wxMBConvUTF7::WC2MB(char * WXUNUSED(buf
),
303 const wchar_t * WXUNUSED(psz
),
304 size_t WXUNUSED(n
)) const
309 // ----------------------------------------------------------------------------
311 // ----------------------------------------------------------------------------
313 WXDLLIMPEXP_DATA_BASE(wxMBConvUTF8
) wxConvUTF8
;
315 static wxUint32 utf8_max
[]=
316 { 0x7f, 0x7ff, 0xffff, 0x1fffff, 0x3ffffff, 0x7fffffff, 0xffffffff };
318 size_t wxMBConvUTF8::MB2WC(wchar_t *buf
, const char *psz
, size_t n
) const
322 while (*psz
&& ((!buf
) || (len
< n
)))
324 unsigned char cc
= *psz
++, fc
= cc
;
326 for (cnt
= 0; fc
& 0x80; cnt
++)
340 // invalid UTF-8 sequence
345 unsigned ocnt
= cnt
- 1;
346 wxUint32 res
= cc
& (0x3f >> cnt
);
350 if ((cc
& 0xC0) != 0x80)
352 // invalid UTF-8 sequence
355 res
= (res
<< 6) | (cc
& 0x3f);
357 if (res
<= utf8_max
[ocnt
])
359 // illegal UTF-8 encoding
363 size_t pa
= encode_utf16(res
, buf
);
364 if (pa
== (size_t)-1)
373 #endif // WC_UTF16/!WC_UTF16
377 if (buf
&& (len
< n
))
382 size_t wxMBConvUTF8::WC2MB(char *buf
, const wchar_t *psz
, size_t n
) const
386 while (*psz
&& ((!buf
) || (len
< n
)))
390 size_t pa
= decode_utf16(psz
, cc
);
391 psz
+= (pa
== (size_t)-1) ? 1 : pa
;
393 cc
=(*psz
++) & 0x7fffffff;
396 for (cnt
= 0; cc
> utf8_max
[cnt
]; cnt
++) {}
410 *buf
++ = (char) ((-128 >> cnt
) | ((cc
>> (cnt
* 6)) & (0x3f >> cnt
)));
412 *buf
++ = (char) (0x80 | ((cc
>> (cnt
* 6)) & 0x3f));
417 if (buf
&& (len
<n
)) *buf
= 0;
422 // ============================================================================
423 // wxCharacterSet and derived classes
424 // ============================================================================
426 // ----------------------------------------------------------------------------
427 // wxCharacterSet is the ABC for the classes below
428 // ----------------------------------------------------------------------------
433 wxCharacterSet(const wxChar
*name
) : cname(name
) {}
434 virtual ~wxCharacterSet() {}
435 virtual size_t MB2WC(wchar_t *buf
, const char *psz
, size_t n
) = 0;
436 virtual size_t WC2MB(char *buf
, const wchar_t *psz
, size_t n
) = 0;
437 virtual bool usable() const = 0;
442 // ----------------------------------------------------------------------------
443 // ID_CharSet: implementation of wxCharacterSet using an existing wxMBConv
444 // ----------------------------------------------------------------------------
446 class ID_CharSet
: public wxCharacterSet
449 ID_CharSet(const wxChar
*name
, wxMBConv
*cnv
)
450 : wxCharacterSet(name
), work(cnv
) {}
452 size_t MB2WC(wchar_t *buf
, const char *psz
, size_t n
)
453 { return work
? work
->MB2WC(buf
,psz
,n
) : (size_t)-1; }
455 size_t WC2MB(char *buf
, const wchar_t *psz
, size_t n
)
456 { return work
? work
->WC2MB(buf
,psz
,n
) : (size_t)-1; }
459 { return work
!=NULL
; }
465 // ============================================================================
466 // The classes doing conversion using the iconv_xxx() functions
467 // ============================================================================
471 // VS: glibc 2.1.3 is broken in that iconv() conversion to/from UCS4 fails with E2BIG
472 // if output buffer is _exactly_ as big as needed. Such case is (unless there's
473 // yet another bug in glibc) the only case when iconv() returns with (size_t)-1
474 // (which means error) and says there are 0 bytes left in the input buffer --
475 // when _real_ error occurs, bytes-left-in-input buffer is non-zero. Hence,
476 // this alternative test for iconv() failure.
477 // [This bug does not appear in glibc 2.2.]
478 #if defined(__GLIBC__) && __GLIBC__ == 2 && __GLIBC_MINOR__ <= 1
479 #define ICONV_FAILED(cres, bufLeft) ((cres == (size_t)-1) && \
480 (errno != E2BIG || bufLeft != 0))
482 #define ICONV_FAILED(cres, bufLeft) (cres == (size_t)-1)
485 #define ICONV_CHAR_CAST(x) ((ICONV_CONST char **)(x))
487 // ----------------------------------------------------------------------------
488 // IC_CharSet: encapsulates an iconv character set
489 // ----------------------------------------------------------------------------
491 class IC_CharSet
: public wxCharacterSet
494 IC_CharSet(const wxChar
*name
);
495 virtual ~IC_CharSet();
497 virtual size_t MB2WC(wchar_t *buf
, const char *psz
, size_t n
);
498 virtual size_t WC2MB(char *buf
, const wchar_t *psz
, size_t n
);
501 { return (m2w
!= (iconv_t
)-1) && (w2m
!= (iconv_t
)-1); }
504 // the iconv handlers used to translate from multibyte to wide char and in
505 // the other direction
510 // the name (for iconv_open()) of a wide char charset - if none is
511 // available on this machine, it will remain NULL
512 static const char *ms_wcCharsetName
;
514 // true if the wide char encoding we use (i.e. ms_wcCharsetName) has
515 // different endian-ness than the native one
516 static bool ms_wcNeedsSwap
;
519 const char *IC_CharSet::ms_wcCharsetName
= NULL
;
520 bool IC_CharSet::ms_wcNeedsSwap
= FALSE
;
522 IC_CharSet::IC_CharSet(const wxChar
*name
)
523 : wxCharacterSet(name
)
525 // Do it the hard way
527 for (size_t i
= 0; i
< wxStrlen(name
)+1; i
++)
528 cname
[i
] = (char) name
[i
];
530 // check for charset that represents wchar_t:
531 if (ms_wcCharsetName
== NULL
)
533 ms_wcNeedsSwap
= FALSE
;
535 // try charset with explicit bytesex info (e.g. "UCS-4LE"):
536 ms_wcCharsetName
= WC_NAME_BEST
;
537 m2w
= iconv_open(ms_wcCharsetName
, cname
);
539 if (m2w
== (iconv_t
)-1)
541 // try charset w/o bytesex info (e.g. "UCS4")
542 // and check for bytesex ourselves:
543 ms_wcCharsetName
= WC_NAME
;
544 m2w
= iconv_open(ms_wcCharsetName
, cname
);
546 // last bet, try if it knows WCHAR_T pseudo-charset
547 if (m2w
== (iconv_t
)-1)
549 ms_wcCharsetName
= "WCHAR_T";
550 m2w
= iconv_open(ms_wcCharsetName
, cname
);
553 if (m2w
!= (iconv_t
)-1)
555 char buf
[2], *bufPtr
;
556 wchar_t wbuf
[2], *wbufPtr
;
564 outsz
= SIZEOF_WCHAR_T
* 2;
568 res
= iconv(m2w
, ICONV_CHAR_CAST(&bufPtr
), &insz
,
569 (char**)&wbufPtr
, &outsz
);
571 if (ICONV_FAILED(res
, insz
))
573 ms_wcCharsetName
= NULL
;
574 wxLogLastError(wxT("iconv"));
575 wxLogError(_("Conversion to charset '%s' doesn't work."), name
);
579 ms_wcNeedsSwap
= wbuf
[0] != (wchar_t)buf
[0];
584 ms_wcCharsetName
= NULL
;
586 // VS: we must not output an error here, since wxWindows will safely
587 // fall back to using wxEncodingConverter.
588 wxLogTrace(wxT("strconv"), wxT("Impossible to convert to/from charset '%s' with iconv, falling back to wxEncodingConverter."), name
);
592 wxLogTrace(wxT("strconv"), wxT("wchar_t charset is '%s', needs swap: %i"), ms_wcCharsetName
, ms_wcNeedsSwap
);
594 else // we already have ms_wcCharsetName
596 m2w
= iconv_open(ms_wcCharsetName
, cname
);
599 // NB: don't ever pass NULL to iconv_open(), it may crash!
600 if ( ms_wcCharsetName
)
602 w2m
= iconv_open( cname
, ms_wcCharsetName
);
610 IC_CharSet::~IC_CharSet()
612 if ( m2w
!= (iconv_t
)-1 )
614 if ( w2m
!= (iconv_t
)-1 )
618 size_t IC_CharSet::MB2WC(wchar_t *buf
, const char *psz
, size_t n
)
620 size_t inbuf
= strlen(psz
);
621 size_t outbuf
= n
* SIZEOF_WCHAR_T
;
623 // VS: Use these instead of psz, buf because iconv() modifies its arguments:
624 wchar_t *bufPtr
= buf
;
625 const char *pszPtr
= psz
;
629 // have destination buffer, convert there
631 ICONV_CHAR_CAST(&pszPtr
), &inbuf
,
632 (char**)&bufPtr
, &outbuf
);
633 res
= n
- (outbuf
/ SIZEOF_WCHAR_T
);
637 // convert to native endianness
638 WC_BSWAP(buf
/* _not_ bufPtr */, res
)
641 // NB: iconv was given only strlen(psz) characters on input, and so
642 // it couldn't convert the trailing zero. Let's do it ourselves
643 // if there's some room left for it in the output buffer.
649 // no destination buffer... convert using temp buffer
650 // to calculate destination buffer requirement
655 outbuf
= 8*SIZEOF_WCHAR_T
;
658 ICONV_CHAR_CAST(&pszPtr
), &inbuf
,
659 (char**)&bufPtr
, &outbuf
);
661 res
+= 8-(outbuf
/SIZEOF_WCHAR_T
);
662 } while ((cres
==(size_t)-1) && (errno
==E2BIG
));
665 if (ICONV_FAILED(cres
, inbuf
))
667 //VS: it is ok if iconv fails, hence trace only
668 wxLogTrace(wxT("strconv"), wxT("iconv failed: %s"), wxSysErrorMsg(wxSysErrorCode()));
675 size_t IC_CharSet::WC2MB(char *buf
, const wchar_t *psz
, size_t n
)
677 size_t inbuf
= wxWcslen(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
);
702 // NB: iconv was given only wcslen(psz) characters on input, and so
703 // it couldn't convert the trailing zero. Let's do it ourselves
704 // if there's some room left for it in the output buffer.
710 // no destination buffer... convert using temp buffer
711 // to calculate destination buffer requirement
715 buf
= tbuf
; outbuf
= 16;
717 cres
= iconv( w2m
, ICONV_CHAR_CAST(&psz
), &inbuf
, &buf
, &outbuf
);
720 } while ((cres
==(size_t)-1) && (errno
==E2BIG
));
728 if (ICONV_FAILED(cres
, inbuf
))
730 //VS: it is ok if iconv fails, hence trace only
731 wxLogTrace(wxT("strconv"), wxT("iconv failed: %s"), wxSysErrorMsg(wxSysErrorCode()));
740 // ============================================================================
741 // Win32 conversion classes
742 // ============================================================================
744 #if defined(__WIN32__) && !defined(__WXMICROWIN__) && !defined(__WXUNIVERSAL__)
746 extern long wxCharsetToCodepage(const wxChar
*charset
); // from utils.cpp
748 class CP_CharSet
: public wxCharacterSet
751 CP_CharSet(const wxChar
* name
)
752 : wxCharacterSet(name
)
754 m_CodePage
= wxCharsetToCodepage(name
);
757 size_t MB2WC(wchar_t *buf
, const char *psz
, size_t n
)
759 const size_t len
= ::MultiByteToWideChar
761 m_CodePage
, // code page
764 -1, // its length (NUL-terminated)
765 buf
, // output string
766 buf
? n
: 0 // size of output buffer
769 // note that it returns # of written chars for buf != NULL and *size*
770 // of the needed buffer for buf == NULL
771 return len
? (buf
? len
: len
- 1) : (size_t)-1;
774 size_t WC2MB(char *buf
, const wchar_t *psz
, size_t n
)
776 const size_t len
= ::WideCharToMultiByte
778 m_CodePage
, // code page
781 -1, // it is (wide) NUL-terminated
782 buf
, // output buffer
783 buf
? n
: 0, // and its size
784 NULL
, // default "replacement" char
785 NULL
// [out] was it used?
788 // see the comment above!
789 return len
? (buf
? len
: len
- 1) : (size_t)-1;
793 { return m_CodePage
!= -1; }
798 #endif // defined(__WIN32__) && !defined(__WXMICROWIN__) && !defined(__WXUNIVERSAL__)
800 // ============================================================================
801 // wxEncodingConverter based conversion classes
802 // ============================================================================
806 class EC_CharSet
: public wxCharacterSet
809 // temporarily just use wxEncodingConverter stuff,
810 // so that it works while a better implementation is built
811 EC_CharSet(const wxChar
* name
) : wxCharacterSet(name
),
812 enc(wxFONTENCODING_SYSTEM
)
815 enc
= wxFontMapper::Get()->CharsetToEncoding(name
, FALSE
);
817 m_ok
= m2w
.Init(enc
, wxFONTENCODING_UNICODE
) &&
818 w2m
.Init(wxFONTENCODING_UNICODE
, enc
);
821 size_t MB2WC(wchar_t *buf
, const char *psz
, size_t WXUNUSED(n
))
823 size_t inbuf
= strlen(psz
);
825 m2w
.Convert(psz
,buf
);
829 size_t WC2MB(char *buf
, const wchar_t *psz
, size_t WXUNUSED(n
))
831 const size_t inbuf
= wxWcslen(psz
);
833 w2m
.Convert(psz
,buf
);
838 bool usable() const { return m_ok
; }
842 wxEncodingConverter m2w
, w2m
;
844 // were we initialized successfully?
848 #endif // wxUSE_FONTMAP
850 // ----------------------------------------------------------------------------
851 // the function creating the wxCharacterSet for the specified charset on the
852 // current system, trying all possibilities
853 // ----------------------------------------------------------------------------
855 static wxCharacterSet
*wxGetCharacterSet(const wxChar
*name
)
857 // check for the special case of ASCII charset
859 if ( wxFontMapper::Get()->CharsetToEncoding(name
) == wxFONTENCODING_DEFAULT
)
860 #else // wxUSE_FONTMAP
862 #endif // wxUSE_FONTMAP/!wxUSE_FONTMAP
864 // don't convert at all
868 // the test above must have taken care of this case
869 wxCHECK_MSG( name
, NULL
, _T("NULL name must be wxFONTENCODING_DEFAULT") );
871 wxCharacterSet
*cset
;
873 if ( wxStricmp(name
, wxT("UTF8")) == 0 || wxStricmp(name
, wxT("UTF-8")) == 0)
875 cset
= new ID_CharSet(name
, &wxConvUTF8
);
880 cset
= new IC_CharSet(name
);
883 #endif // HAVE_ICONV/!HAVE_ICONV
886 // it can only be NULL in this case
889 #endif // !HAVE_ICONV
891 if ( cset
->usable() )
898 #if defined(__WIN32__) && !defined(__WXMICROWIN__) && !defined(__WXUNIVERSAL__)
899 cset
= new CP_CharSet(name
);
900 if ( cset
->usable() )
905 #endif // defined(__WIN32__) && !defined(__WXMICROWIN__) && !defined(__WXUNIVERSAL__)
908 cset
= new EC_CharSet(name
);
909 if ( cset
->usable() )
914 #endif // wxUSE_FONTMAP
916 wxLogError(_("Cannot convert from encoding '%s'!"), name
);
921 // ============================================================================
922 // wxCSConv implementation
923 // ============================================================================
925 wxCSConv::wxCSConv(const wxChar
*charset
)
927 m_name
= (wxChar
*)NULL
;
928 m_cset
= (wxCharacterSet
*) NULL
;
934 wxCSConv::~wxCSConv()
939 wxCSConv::wxCSConv(const wxCSConv
& conv
)
943 SetName(conv
.m_name
);
946 wxCSConv
& wxCSConv::operator=(const wxCSConv
& conv
)
949 SetName(conv
.m_name
);
953 void wxCSConv::Clear()
963 void wxCSConv::SetName(const wxChar
*charset
)
967 m_name
= wxStrdup(charset
);
972 void wxCSConv::LoadNow()
976 // it would probably be better to make GetSystemEncodingName() always
977 // available (i.e. even when wxUSE_INTL == 0)?
981 wxString name
= wxLocale::GetSystemEncodingName();
989 // wxGetCharacterSet() complains about NULL name
990 m_cset
= m_name
? wxGetCharacterSet(m_name
) : NULL
;
995 size_t wxCSConv::MB2WC(wchar_t *buf
, const char *psz
, size_t n
) const
997 ((wxCSConv
*)this)->LoadNow(); // discard constness
1000 return m_cset
->MB2WC(buf
, psz
, n
);
1003 size_t len
= strlen(psz
);
1007 for (size_t c
= 0; c
<= len
; c
++)
1008 buf
[c
] = (unsigned char)(psz
[c
]);
1014 size_t wxCSConv::WC2MB(char *buf
, const wchar_t *psz
, size_t n
) const
1016 ((wxCSConv
*)this)->LoadNow(); // discard constness
1019 return m_cset
->WC2MB(buf
, psz
, n
);
1022 const size_t len
= wxWcslen(psz
);
1025 for (size_t c
= 0; c
<= len
; c
++)
1026 buf
[c
] = (psz
[c
] > 0xff) ? '?' : psz
[c
];
1032 #endif // wxUSE_WCHAR_T