$szTitle = "wxmbconv"; include "./_header.inc"; ?>
this class is the base class of a hierarchy of classes capable of converting text strings between multibyte (sbcs or dbcs) encodings and unicode.
in the documentation for this and related classes please notice that length of the string refers to the number of characters in the string not counting the terminating nul, if any. while the size of the string is the total number of bytes in the string, including any trailing nul. thus, length of wide character string l"foo" is 3 while its size can be either 8 or 16 depending on whether wchar_t is 2 bytes (as under windows) or 4 (unix).
global variables
there are several predefined instances of this class:
wxconvlibc | uses the standard ansi c mbstowcs() and wcstombs() functions to perform the conversions; thus depends on the current locale. |
wxconvlocal | another conversion corresponding to the current locale but this one uses the best available conversion. |
wxconvui | the conversion used for hte standard ui elements such as menu items and buttons. this is a pointer which is initially set to wxconvlocal as the program uses the current locale by default but can be set to some specific conversion if the program needs to use a specific encoding for its ui. |
wxconviso8859_1 | conversion to and from iso-8859-1 (latin i) encoding. |
wxconvutf8 | conversion to and from utf-8 encoding. |
wxconvfile | the appropriate conversion for the file names, depends on the system. |
constants
wxconv_failed value is defined as (size_t)-1 and is returned by the conversion functions instead of the length of the converted string if the conversion fails.
derived from
no base class
include files
<wx/strconv.h>
see also
wxcsconv, wxencodingconverter, wxmbconv classes overview
members
wxmbconv::wxmbconv
wxmbconv::mb2wc
wxmbconv::wc2mb
wxmbconv::cmb2wc
wxmbconv::cwc2mb
wxmbconv::cmb2wx
wxmbconv::cwx2mb
wxmbconv::cwc2wx
wxmbconv::cwx2wc
wxmbconv::fromwchar
wxmbconv::getmaxmbnullen
wxmbconv::getmbnullen
wxmbconv::towchar
wxmbconv()
trivial default constructor.
virtual size_t mb2wc(wchar_t *out, const char *in, size_t outlen) const
this function is deprecated, please use towchar instead
converts from a string in in multibyte encoding to unicode putting up to outlen characters into the buffer out.
if out is null, only the length of the string which would result from the conversion is calculated and returned. note that this is the length and not size, i.e. the returned value does not include the trailing nul. but when the function is called with a non-null out buffer, the outlen parameter should be one more to allow to properly nul-terminate the string.
parameters
out
in
outlen
return value
the length of the converted string excluding the trailing nul.
virtual size_t wc2mb(char* buf, const wchar_t* psz, size_t n) const
this function is deprecated, please use fromwchar instead
converts from unicode to multibyte encoding. the semantics of this function (including the return value meaning) is the same as for mb2wc.
notice that when the function is called with a non-null buffer, the n parameter should be the size of the buffer and so it should take into account the trailing nul, which might take two or four bytes for some encodings (utf-16 and utf-32) and not one.
const wxwcharbuffer cmb2wc(const char *in) const
const wxwcharbuffer cmb2wc(const char *in, size_t inlen, size_t *outlen) const
converts from multibyte encoding to unicode by calling mb2wc, allocating a temporary wxwcharbuffer to hold the result.
the first overload takes a nul-terminated input string. the second one takes a string of exactly the specified length and the string may include or not the trailing nul character(s). if the string is not nul-terminated, a temporary nul-terminated copy of it suitable for passing to mb2wc is made, so it is more efficient to ensure that the string is does have the appropriate number of nul bytes (which is usually 1 but may be 2 or 4 for utf-16 or utf-32, see getmbnullen), especially for long strings.
if outlen is not-null, it receives the length of the converted string.
const wxcharbuffer cwc2mb(const wchar_t* in) const
const wxcharbuffer cwc2mb(const wchar_t* in, size_t inlen, size_t *outlen) const
converts from unicode to multibyte encoding by calling wc2mb, allocating a temporary wxcharbuffer to hold the result.
the second overload of this function allows to convert a string of the given length inlen, whether it is nul-terminated or not (for wide character strings, unlike for the multibyte ones, a single nul is always enough). but notice that just as with cmb2wc, it is more efficient to pass an already terminated string to this function as otherwise a copy is made internally.
if outlen is not-null, it receives the length of the converted string.
const char* cmb2wx(const char* psz) const
const wxwcharbuffer cmb2wx(const char* psz) const
converts from multibyte encoding to the current wxchar type (which depends on whether wxuse_unicode is set to 1). if wxchar is char, it returns the parameter unaltered. if wxchar is wchar_t, it returns the result in a wxwcharbuffer. the macro wxmb2wxbuf is defined as the correct return type (without const).
const char* cwx2mb(const wxchar* psz) const
const wxcharbuffer cwx2mb(const wxchar* psz) const
converts from the current wxchar type to multibyte encoding. if wxchar is char, it returns the parameter unaltered. if wxchar is wchar_t, it returns the result in a wxcharbuffer. the macro wxwx2mbbuf is defined as the correct return type (without const).
const wchar_t* cwc2wx(const wchar_t* psz) const
const wxcharbuffer cwc2wx(const wchar_t* psz) const
converts from unicode to the current wxchar type. if wxchar is wchar_t, it returns the parameter unaltered. if wxchar is char, it returns the result in a wxcharbuffer. the macro wxwc2wxbuf is defined as the correct return type (without const).
const wchar_t* cwx2wc(const wxchar* psz) const
const wxwcharbuffer cwx2wc(const wxchar* psz) const
converts from the current wxchar type to unicode. if wxchar is wchar_t, it returns the parameter unaltered. if wxchar is char, it returns the result in a wxwcharbuffer. the macro wxwx2wcbuf is defined as the correct return type (without const).
virtual size_t fromwchar(wchar_t *dst, size_t dstlen, const char *src, size_t srclen = wxno_len) const
the most general function for converting a multibyte string to a wide string. the main case is when dst is not null and srclen is not wxno_len (which is defined as (size_t)-1): then the function converts exactly srclen bytes starting at src into wide string which it output to dst. if the length of the resulting wide string is greater than dstlen, an error is returned. note that if srclen bytes don't include nul characters, the resulting wide string is not nul-terminated neither.
if srclen is wxno_len, the function supposes that the string is properly (i.e. as necessary for the encoding handled by this conversion) nul-terminated and converts the entire string, including any trailing nul bytes. in this case the wide string is also nul-terminated.
finally, if dst is null, the function returns the length of the needed buffer.
return value
the number of characters written to dst (or the number of characters which would have been written to it if it were non-null) on success or wxconv_failed on error.
const size_t getmaxmbnullen()
returns the maximal value which can be returned by getmbnullen for any conversion object. currently this value is 4.
this method can be used to allocate the buffer with enough space for the trailing nul characters for any encoding.
size_t getmbnullen() const
this function returns 1 for most of the multibyte encodings in which the string is terminated by a single nul, 2 for utf-16 and 4 for utf-32 for which the string is terminated with 2 and 4 nul characters respectively. the other cases are not currently supported and wxconv_failed (defined as -1) is returned for them.
virtual size_t towchar(char_t *dst, size_t dstlen, const wchar_t *src, size_t srclen = wxno_len) const
this function has the same semantics as fromwchar except that it converts a wide string to multibyte one.
include "./_footer.inc"; ?>