]>
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"
48 #include "wx/module.h"
49 #include "wx/strconv.h"
51 // ----------------------------------------------------------------------------
53 // ----------------------------------------------------------------------------
56 WXDLLIMPEXP_DATA_BASE(wxMBConv
) wxConvLibc
;
57 WXDLLIMPEXP_DATA_BASE(wxCSConv
) wxConvLocal((const wxChar
*)NULL
);
58 WXDLLIMPEXP_DATA_BASE(wxCSConv
) wxConvISO8859_1(_T("iso-8859-1"));
60 // stand-ins in absence of wchar_t
61 WXDLLIMPEXP_DATA_BASE(wxMBConv
) wxConvLibc
,
66 #endif // wxUSE_WCHAR_T
68 WXDLLIMPEXP_DATA_BASE(wxMBConv
*) wxConvCurrent
= &wxConvLibc
;
70 class wxStrConvModule
: public wxModule
73 wxStrConvModule() : wxModule() { }
74 virtual bool OnInit() { return TRUE
; }
79 wxConvISO8859_1
.Clear();
83 DECLARE_DYNAMIC_CLASS(wxStrConvModule
)
86 IMPLEMENT_DYNAMIC_CLASS(wxStrConvModule
, wxModule
)
89 // ----------------------------------------------------------------------------
91 // ----------------------------------------------------------------------------
103 #include "wx/encconv.h"
104 #include "wx/fontmap.h"
106 // ----------------------------------------------------------------------------
108 // ----------------------------------------------------------------------------
110 #define BSWAP_UCS4(str, len) { unsigned _c; for (_c=0; _c<len; _c++) str[_c]=wxUINT32_SWAP_ALWAYS(str[_c]); }
111 #define BSWAP_UTF16(str, len) { unsigned _c; for (_c=0; _c<len; _c++) str[_c]=wxUINT16_SWAP_ALWAYS(str[_c]); }
113 // under Unix SIZEOF_WCHAR_T is defined by configure, but under other platforms
114 // it might be not defined - assume the most common value
115 #ifndef SIZEOF_WCHAR_T
116 #define SIZEOF_WCHAR_T 2
117 #endif // !defined(SIZEOF_WCHAR_T)
119 #if SIZEOF_WCHAR_T == 4
120 #define WC_NAME "UCS4"
121 #define WC_BSWAP BSWAP_UCS4
122 #ifdef WORDS_BIGENDIAN
123 #define WC_NAME_BEST "UCS-4BE"
125 #define WC_NAME_BEST "UCS-4LE"
127 #elif SIZEOF_WCHAR_T == 2
128 #define WC_NAME "UTF16"
129 #define WC_BSWAP BSWAP_UTF16
131 #ifdef WORDS_BIGENDIAN
132 #define WC_NAME_BEST "UTF-16BE"
134 #define WC_NAME_BEST "UTF-16LE"
136 #else // sizeof(wchar_t) != 2 nor 4
137 // I don't know what to do about this
138 #error "Weird sizeof(wchar_t): please report your platform details to wx-users mailing list"
141 // ============================================================================
143 // ============================================================================
145 // ----------------------------------------------------------------------------
146 // UTF-16 en/decoding
147 // ----------------------------------------------------------------------------
151 static size_t encode_utf16(wxUint32 input
, wchar_t *output
)
155 if (output
) *output
++ = (wchar_t) input
;
158 else if (input
>=0x110000)
166 *output
++ = (wchar_t) ((input
>> 10)+0xd7c0);
167 *output
++ = (wchar_t) ((input
&0x3ff)+0xdc00);
173 static size_t decode_utf16(const wchar_t* input
, wxUint32
& output
)
175 if ((*input
<0xd800) || (*input
>0xdfff))
180 else if ((input
[1]<0xdc00) || (input
[1]>=0xdfff))
187 output
= ((input
[0] - 0xd7c0) << 10) + (input
[1] - 0xdc00);
194 // ----------------------------------------------------------------------------
196 // ----------------------------------------------------------------------------
198 #define IGNORE_LIBC 0
200 wxMBConv::~wxMBConv()
202 // nothing to do here
205 size_t wxMBConv::MB2WC(wchar_t *buf
, const char *psz
, size_t n
) const
210 for (size_t i
= 0; i
< strlen( psz
)+1; i
++)
211 buf
[i
] = (wchar_t) psz
[i
];
212 return strlen( psz
);
216 return strlen( psz
);
219 return wxMB2WC(buf
, psz
, n
);
223 size_t wxMBConv::WC2MB(char *buf
, const wchar_t *psz
, size_t n
) const
228 for (size_t i
= 0; i
< wxStrlen( psz
)+1; i
++)
229 buf
[i
] = (char) psz
[i
];
230 return wxStrlen( psz
);
234 return wxStrlen( psz
);
237 return wxWC2MB(buf
, psz
, n
);
241 const wxWCharBuffer
wxMBConv::cMB2WC(const char *psz
) const
245 // calculate the length of the buffer needed first
246 size_t nLen
= MB2WC(NULL
, psz
, 0);
247 if ( nLen
!= (size_t)-1 )
249 // now do the actual conversion
250 wxWCharBuffer
buf(nLen
);
251 MB2WC(buf
.data(), psz
, nLen
+ 1); // with the trailing NUL
257 wxWCharBuffer
buf((wchar_t *)NULL
);
262 const wxCharBuffer
wxMBConv::cWC2MB(const wchar_t *pwz
) const
266 size_t nLen
= WC2MB(NULL
, pwz
, 0);
267 if ( nLen
!= (size_t)-1 )
269 wxCharBuffer
buf(nLen
);
270 WC2MB(buf
.data(), pwz
, nLen
+ 1);
276 wxCharBuffer
buf((char *)NULL
);
281 // ----------------------------------------------------------------------------
283 // ----------------------------------------------------------------------------
285 WXDLLIMPEXP_DATA_BASE(wxMBConvUTF7
) wxConvUTF7
;
288 static char utf7_setD
[]="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
289 "abcdefghijklmnopqrstuvwxyz"
290 "0123456789'(),-./:?";
291 static char utf7_setO
[]="!\"#$%&*;<=>@[]^_`{|}";
292 static char utf7_setB
[]="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
293 "abcdefghijklmnopqrstuvwxyz"
297 // TODO: write actual implementations of UTF-7 here
298 size_t wxMBConvUTF7::MB2WC(wchar_t * WXUNUSED(buf
),
299 const char * WXUNUSED(psz
),
300 size_t WXUNUSED(n
)) const
305 size_t wxMBConvUTF7::WC2MB(char * WXUNUSED(buf
),
306 const wchar_t * WXUNUSED(psz
),
307 size_t WXUNUSED(n
)) const
312 // ----------------------------------------------------------------------------
314 // ----------------------------------------------------------------------------
316 WXDLLIMPEXP_DATA_BASE(wxMBConvUTF8
) wxConvUTF8
;
318 static wxUint32 utf8_max
[]=
319 { 0x7f, 0x7ff, 0xffff, 0x1fffff, 0x3ffffff, 0x7fffffff, 0xffffffff };
321 size_t wxMBConvUTF8::MB2WC(wchar_t *buf
, const char *psz
, size_t n
) const
325 while (*psz
&& ((!buf
) || (len
< n
)))
327 unsigned char cc
= *psz
++, fc
= cc
;
329 for (cnt
= 0; fc
& 0x80; cnt
++)
343 // invalid UTF-8 sequence
348 unsigned ocnt
= cnt
- 1;
349 wxUint32 res
= cc
& (0x3f >> cnt
);
353 if ((cc
& 0xC0) != 0x80)
355 // invalid UTF-8 sequence
358 res
= (res
<< 6) | (cc
& 0x3f);
360 if (res
<= utf8_max
[ocnt
])
362 // illegal UTF-8 encoding
366 size_t pa
= encode_utf16(res
, buf
);
367 if (pa
== (size_t)-1)
376 #endif // WC_UTF16/!WC_UTF16
380 if (buf
&& (len
< n
))
385 size_t wxMBConvUTF8::WC2MB(char *buf
, const wchar_t *psz
, size_t n
) const
389 while (*psz
&& ((!buf
) || (len
< n
)))
393 size_t pa
= decode_utf16(psz
, cc
);
394 psz
+= (pa
== (size_t)-1) ? 1 : pa
;
396 cc
=(*psz
++) & 0x7fffffff;
399 for (cnt
= 0; cc
> utf8_max
[cnt
]; cnt
++) {}
413 *buf
++ = (char) ((-128 >> cnt
) | ((cc
>> (cnt
* 6)) & (0x3f >> cnt
)));
415 *buf
++ = (char) (0x80 | ((cc
>> (cnt
* 6)) & 0x3f));
420 if (buf
&& (len
<n
)) *buf
= 0;
425 // ============================================================================
426 // wxCharacterSet and derived classes
427 // ============================================================================
429 // ----------------------------------------------------------------------------
430 // wxCharacterSet is the ABC for the classes below
431 // ----------------------------------------------------------------------------
436 wxCharacterSet(const wxChar
*name
) : cname(name
) {}
437 virtual ~wxCharacterSet() {}
438 virtual size_t MB2WC(wchar_t *buf
, const char *psz
, size_t n
) = 0;
439 virtual size_t WC2MB(char *buf
, const wchar_t *psz
, size_t n
) = 0;
440 virtual bool usable() const = 0;
445 // ----------------------------------------------------------------------------
446 // ID_CharSet: implementation of wxCharacterSet using an existing wxMBConv
447 // ----------------------------------------------------------------------------
449 class ID_CharSet
: public wxCharacterSet
452 ID_CharSet(const wxChar
*name
, wxMBConv
*cnv
)
453 : wxCharacterSet(name
), work(cnv
) {}
455 size_t MB2WC(wchar_t *buf
, const char *psz
, size_t n
)
456 { return work
? work
->MB2WC(buf
,psz
,n
) : (size_t)-1; }
458 size_t WC2MB(char *buf
, const wchar_t *psz
, size_t n
)
459 { return work
? work
->WC2MB(buf
,psz
,n
) : (size_t)-1; }
462 { return work
!=NULL
; }
468 // ============================================================================
469 // The classes doing conversion using the iconv_xxx() functions
470 // ============================================================================
474 // VS: glibc 2.1.3 is broken in that iconv() conversion to/from UCS4 fails with E2BIG
475 // if output buffer is _exactly_ as big as needed. Such case is (unless there's
476 // yet another bug in glibc) the only case when iconv() returns with (size_t)-1
477 // (which means error) and says there are 0 bytes left in the input buffer --
478 // when _real_ error occurs, bytes-left-in-input buffer is non-zero. Hence,
479 // this alternative test for iconv() failure.
480 // [This bug does not appear in glibc 2.2.]
481 #if defined(__GLIBC__) && __GLIBC__ == 2 && __GLIBC_MINOR__ <= 1
482 #define ICONV_FAILED(cres, bufLeft) ((cres == (size_t)-1) && \
483 (errno != E2BIG || bufLeft != 0))
485 #define ICONV_FAILED(cres, bufLeft) (cres == (size_t)-1)
488 #define ICONV_CHAR_CAST(x) ((ICONV_CONST char **)(x))
490 // ----------------------------------------------------------------------------
491 // IC_CharSet: encapsulates an iconv character set
492 // ----------------------------------------------------------------------------
494 class IC_CharSet
: public wxCharacterSet
497 IC_CharSet(const wxChar
*name
);
498 virtual ~IC_CharSet();
500 virtual size_t MB2WC(wchar_t *buf
, const char *psz
, size_t n
);
501 virtual size_t WC2MB(char *buf
, const wchar_t *psz
, size_t n
);
504 { return (m2w
!= (iconv_t
)-1) && (w2m
!= (iconv_t
)-1); }
507 // the iconv handlers used to translate from multibyte to wide char and in
508 // the other direction
513 // the name (for iconv_open()) of a wide char charset - if none is
514 // available on this machine, it will remain NULL
515 static const char *ms_wcCharsetName
;
517 // true if the wide char encoding we use (i.e. ms_wcCharsetName) has
518 // different endian-ness than the native one
519 static bool ms_wcNeedsSwap
;
522 const char *IC_CharSet::ms_wcCharsetName
= NULL
;
523 bool IC_CharSet::ms_wcNeedsSwap
= FALSE
;
525 IC_CharSet::IC_CharSet(const wxChar
*name
)
526 : wxCharacterSet(name
)
528 // Do it the hard way
530 for (size_t i
= 0; i
< wxStrlen(name
)+1; i
++)
531 cname
[i
] = (char) name
[i
];
533 // check for charset that represents wchar_t:
534 if (ms_wcCharsetName
== NULL
)
536 ms_wcNeedsSwap
= FALSE
;
538 // try charset with explicit bytesex info (e.g. "UCS-4LE"):
539 ms_wcCharsetName
= WC_NAME_BEST
;
540 m2w
= iconv_open(ms_wcCharsetName
, cname
);
542 if (m2w
== (iconv_t
)-1)
544 // try charset w/o bytesex info (e.g. "UCS4")
545 // and check for bytesex ourselves:
546 ms_wcCharsetName
= WC_NAME
;
547 m2w
= iconv_open(ms_wcCharsetName
, cname
);
549 // last bet, try if it knows WCHAR_T pseudo-charset
550 if (m2w
== (iconv_t
)-1)
552 ms_wcCharsetName
= "WCHAR_T";
553 m2w
= iconv_open(ms_wcCharsetName
, cname
);
556 if (m2w
!= (iconv_t
)-1)
558 char buf
[2], *bufPtr
;
559 wchar_t wbuf
[2], *wbufPtr
;
567 outsz
= SIZEOF_WCHAR_T
* 2;
571 res
= iconv(m2w
, ICONV_CHAR_CAST(&bufPtr
), &insz
,
572 (char**)&wbufPtr
, &outsz
);
574 if (ICONV_FAILED(res
, insz
))
576 ms_wcCharsetName
= NULL
;
577 wxLogLastError(wxT("iconv"));
578 wxLogError(_("Conversion to charset '%s' doesn't work."), name
);
582 ms_wcNeedsSwap
= wbuf
[0] != (wchar_t)buf
[0];
587 ms_wcCharsetName
= NULL
;
589 // VS: we must not output an error here, since wxWindows will safely
590 // fall back to using wxEncodingConverter.
591 wxLogTrace(wxT("strconv"), wxT("Impossible to convert to/from charset '%s' with iconv, falling back to wxEncodingConverter."), name
);
595 wxLogTrace(wxT("strconv"), wxT("wchar_t charset is '%s', needs swap: %i"), ms_wcCharsetName
, ms_wcNeedsSwap
);
597 else // we already have ms_wcCharsetName
599 m2w
= iconv_open(ms_wcCharsetName
, cname
);
602 // NB: don't ever pass NULL to iconv_open(), it may crash!
603 if ( ms_wcCharsetName
)
605 w2m
= iconv_open( cname
, ms_wcCharsetName
);
613 IC_CharSet::~IC_CharSet()
615 if ( m2w
!= (iconv_t
)-1 )
617 if ( w2m
!= (iconv_t
)-1 )
621 size_t IC_CharSet::MB2WC(wchar_t *buf
, const char *psz
, size_t n
)
623 size_t inbuf
= strlen(psz
);
624 size_t outbuf
= n
* SIZEOF_WCHAR_T
;
626 // VS: Use these instead of psz, buf because iconv() modifies its arguments:
627 wchar_t *bufPtr
= buf
;
628 const char *pszPtr
= psz
;
632 // have destination buffer, convert there
634 ICONV_CHAR_CAST(&pszPtr
), &inbuf
,
635 (char**)&bufPtr
, &outbuf
);
636 res
= n
- (outbuf
/ SIZEOF_WCHAR_T
);
640 // convert to native endianness
641 WC_BSWAP(buf
/* _not_ bufPtr */, res
)
644 // NB: iconv was given only strlen(psz) characters on input, and so
645 // it couldn't convert the trailing zero. Let's do it ourselves
646 // if there's some room left for it in the output buffer.
652 // no destination buffer... convert using temp buffer
653 // to calculate destination buffer requirement
658 outbuf
= 8*SIZEOF_WCHAR_T
;
661 ICONV_CHAR_CAST(&pszPtr
), &inbuf
,
662 (char**)&bufPtr
, &outbuf
);
664 res
+= 8-(outbuf
/SIZEOF_WCHAR_T
);
665 } while ((cres
==(size_t)-1) && (errno
==E2BIG
));
668 if (ICONV_FAILED(cres
, inbuf
))
670 //VS: it is ok if iconv fails, hence trace only
671 wxLogTrace(wxT("strconv"), wxT("iconv failed: %s"), wxSysErrorMsg(wxSysErrorCode()));
678 size_t IC_CharSet::WC2MB(char *buf
, const wchar_t *psz
, size_t n
)
680 size_t inbuf
= wxWcslen(psz
) * SIZEOF_WCHAR_T
;
688 // need to copy to temp buffer to switch endianness
689 // this absolutely doesn't rock!
690 // (no, doing WC_BSWAP twice on the original buffer won't help, as it
691 // could be in read-only memory, or be accessed in some other thread)
692 tmpbuf
=(wchar_t*)malloc((inbuf
+1)*SIZEOF_WCHAR_T
);
693 memcpy(tmpbuf
,psz
,(inbuf
+1)*SIZEOF_WCHAR_T
);
694 WC_BSWAP(tmpbuf
, inbuf
)
700 // have destination buffer, convert there
701 cres
= iconv( w2m
, ICONV_CHAR_CAST(&psz
), &inbuf
, &buf
, &outbuf
);
705 // NB: iconv was given only wcslen(psz) characters on input, and so
706 // it couldn't convert the trailing zero. Let's do it ourselves
707 // if there's some room left for it in the output buffer.
713 // no destination buffer... convert using temp buffer
714 // to calculate destination buffer requirement
718 buf
= tbuf
; outbuf
= 16;
720 cres
= iconv( w2m
, ICONV_CHAR_CAST(&psz
), &inbuf
, &buf
, &outbuf
);
723 } while ((cres
==(size_t)-1) && (errno
==E2BIG
));
731 if (ICONV_FAILED(cres
, inbuf
))
733 //VS: it is ok if iconv fails, hence trace only
734 wxLogTrace(wxT("strconv"), wxT("iconv failed: %s"), wxSysErrorMsg(wxSysErrorCode()));
743 // ============================================================================
744 // Win32 conversion classes
745 // ============================================================================
747 #if defined(__WIN32__) && !defined(__WXMICROWIN__) && !defined(__WXUNIVERSAL__)
749 extern long wxCharsetToCodepage(const wxChar
*charset
); // from utils.cpp
751 class CP_CharSet
: public wxCharacterSet
754 CP_CharSet(const wxChar
* name
)
755 : wxCharacterSet(name
)
757 m_CodePage
= wxCharsetToCodepage(name
);
760 size_t MB2WC(wchar_t *buf
, const char *psz
, size_t n
)
762 const size_t len
= ::MultiByteToWideChar
764 m_CodePage
, // code page
767 -1, // its length (NUL-terminated)
768 buf
, // output string
769 buf
? n
: 0 // size of output buffer
772 // note that it returns # of written chars for buf != NULL and *size*
773 // of the needed buffer for buf == NULL
774 return len
? (buf
? len
: len
- 1) : (size_t)-1;
777 size_t WC2MB(char *buf
, const wchar_t *psz
, size_t n
)
779 const size_t len
= ::WideCharToMultiByte
781 m_CodePage
, // code page
784 -1, // it is (wide) NUL-terminated
785 buf
, // output buffer
786 buf
? n
: 0, // and its size
787 NULL
, // default "replacement" char
788 NULL
// [out] was it used?
791 // see the comment above!
792 return len
? (buf
? len
: len
- 1) : (size_t)-1;
796 { return m_CodePage
!= -1; }
801 #endif // defined(__WIN32__) && !defined(__WXMICROWIN__) && !defined(__WXUNIVERSAL__)
803 // ============================================================================
804 // wxEncodingConverter based conversion classes
805 // ============================================================================
809 class EC_CharSet
: public wxCharacterSet
812 // temporarily just use wxEncodingConverter stuff,
813 // so that it works while a better implementation is built
814 EC_CharSet(const wxChar
* name
) : wxCharacterSet(name
),
815 enc(wxFONTENCODING_SYSTEM
)
818 enc
= wxFontMapper::Get()->CharsetToEncoding(name
, FALSE
);
820 m_ok
= m2w
.Init(enc
, wxFONTENCODING_UNICODE
) &&
821 w2m
.Init(wxFONTENCODING_UNICODE
, enc
);
824 size_t MB2WC(wchar_t *buf
, const char *psz
, size_t WXUNUSED(n
))
826 size_t inbuf
= strlen(psz
);
828 m2w
.Convert(psz
,buf
);
832 size_t WC2MB(char *buf
, const wchar_t *psz
, size_t WXUNUSED(n
))
834 const size_t inbuf
= wxWcslen(psz
);
836 w2m
.Convert(psz
,buf
);
841 bool usable() const { return m_ok
; }
845 wxEncodingConverter m2w
, w2m
;
847 // were we initialized successfully?
850 DECLARE_NO_COPY_CLASS(EC_CharSet
)
853 #endif // wxUSE_FONTMAP
855 // ----------------------------------------------------------------------------
856 // the function creating the wxCharacterSet for the specified charset on the
857 // current system, trying all possibilities
858 // ----------------------------------------------------------------------------
860 static wxCharacterSet
*wxGetCharacterSet(const wxChar
*name
)
862 // check for the special case of ASCII charset
864 if ( wxFontMapper::Get()->CharsetToEncoding(name
) == wxFONTENCODING_DEFAULT
)
865 #else // wxUSE_FONTMAP
867 #endif // wxUSE_FONTMAP/!wxUSE_FONTMAP
869 // don't convert at all
873 // the test above must have taken care of this case
874 wxCHECK_MSG( name
, NULL
, _T("NULL name must be wxFONTENCODING_DEFAULT") );
876 wxCharacterSet
*cset
;
878 if ( wxStricmp(name
, wxT("UTF8")) == 0 || wxStricmp(name
, wxT("UTF-8")) == 0)
880 cset
= new ID_CharSet(name
, &wxConvUTF8
);
885 cset
= new IC_CharSet(name
);
888 #endif // HAVE_ICONV/!HAVE_ICONV
891 // it can only be NULL in this case
894 #endif // !HAVE_ICONV
896 if ( cset
->usable() )
903 #if defined(__WIN32__) && !defined(__WXMICROWIN__) && !defined(__WXUNIVERSAL__)
904 cset
= new CP_CharSet(name
);
905 if ( cset
->usable() )
910 #endif // defined(__WIN32__) && !defined(__WXMICROWIN__) && !defined(__WXUNIVERSAL__)
913 cset
= new EC_CharSet(name
);
914 if ( cset
->usable() )
919 #endif // wxUSE_FONTMAP
921 wxLogError(_("Cannot convert from encoding '%s'!"), name
);
926 // ============================================================================
927 // wxCSConv implementation
928 // ============================================================================
930 wxCSConv::wxCSConv(const wxChar
*charset
)
932 m_name
= (wxChar
*)NULL
;
933 m_cset
= (wxCharacterSet
*) NULL
;
939 wxCSConv::~wxCSConv()
944 wxCSConv::wxCSConv(const wxCSConv
& conv
)
948 SetName(conv
.m_name
);
951 wxCSConv
& wxCSConv::operator=(const wxCSConv
& conv
)
954 SetName(conv
.m_name
);
958 void wxCSConv::Clear()
968 void wxCSConv::SetName(const wxChar
*charset
)
972 m_name
= wxStrdup(charset
);
977 void wxCSConv::LoadNow()
981 // it would probably be better to make GetSystemEncodingName() always
982 // available (i.e. even when wxUSE_INTL == 0)?
986 wxString name
= wxLocale::GetSystemEncodingName();
994 // wxGetCharacterSet() complains about NULL name
995 m_cset
= m_name
? wxGetCharacterSet(m_name
) : NULL
;
1000 size_t wxCSConv::MB2WC(wchar_t *buf
, const char *psz
, size_t n
) const
1002 ((wxCSConv
*)this)->LoadNow(); // discard constness
1005 return m_cset
->MB2WC(buf
, psz
, n
);
1008 size_t len
= strlen(psz
);
1012 for (size_t c
= 0; c
<= len
; c
++)
1013 buf
[c
] = (unsigned char)(psz
[c
]);
1019 size_t wxCSConv::WC2MB(char *buf
, const wchar_t *psz
, size_t n
) const
1021 ((wxCSConv
*)this)->LoadNow(); // discard constness
1024 return m_cset
->WC2MB(buf
, psz
, n
);
1027 const size_t len
= wxWcslen(psz
);
1030 for (size_t c
= 0; c
<= len
; c
++)
1031 buf
[c
] = (psz
[c
] > 0xff) ? '?' : psz
[c
];
1037 #endif // wxUSE_WCHAR_T