#include <wx/strconv.h>
This class converts between any character set supported by the system and Unicode.
Please notice that this class uses system-provided conversion functions, e.g. MultiByteToWideChar()
and WideCharToMultiByte()
under MSW and iconv(3)
under Unix systems and as such may support different encodings and different encoding names on different platforms (although all relatively common encodings are supported should be supported everywhere).
It has one predefined instance, wxConvLocal, for the default user character set.
Public Member Functions | |
wxCSConv (const wxString &charset) | |
Constructor. | |
wxCSConv (wxFontEncoding encoding) | |
Constructor. | |
bool | IsOk () const |
Returns true if the charset (or the encoding) given at constructor is really available to use. | |
Public Member Functions inherited from wxMBConv | |
wxMBConv () | |
Trivial default constructor. | |
virtual wxMBConv * | Clone () const =0 |
This pure virtual function is overridden in each of the derived classes to return a new copy of the object it is called on. | |
virtual 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. | |
virtual size_t | ToWChar (wchar_t *dst, size_t dstLen, const char *src, size_t srcLen=wxNO_LEN) const |
Convert multibyte string to a wide character one. | |
virtual size_t | FromWChar (char *dst, size_t dstLen, const wchar_t *src, size_t srcLen=wxNO_LEN) const |
Converts wide character string to multibyte. | |
const wxWCharBuffer | cMB2WC (const char *in, size_t inLen, size_t *outLen) const |
Converts from multibyte encoding to Unicode by calling ToWChar() and allocating a temporary wxWCharBuffer to hold the result. | |
const wxWCharBuffer | cMB2WC (const wxCharBuffer &buf) const |
Converts a char buffer to wide char one. | |
const wxCharBuffer | cWC2MB (const wchar_t *in, size_t inLen, size_t *outLen) const |
Converts from Unicode to multibyte encoding by calling FromWChar() and allocating a temporary wxCharBuffer to hold the result. | |
const wxCharBuffer | cWC2MB (const wxWCharBuffer &buf) const |
Converts a wide char buffer to char one. | |
virtual size_t | MB2WC (wchar_t *out, const char *in, size_t outLen) const |
virtual size_t | WC2MB (char *buf, const wchar_t *psz, size_t n) const |
const char * | cMB2WX (const char *psz) const |
Converts from multibyte encoding to the current wxChar type (which depends on whether wxUSE_UNICODE is set to 1). | |
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). | |
const wchar_t * | cWC2WX (const wchar_t *psz) const |
Converts from Unicode to the current wxChar type. | |
const wxCharBuffer | cWC2WX (const wchar_t *psz) const |
Converts from Unicode to the current wxChar type. | |
const char * | cWX2MB (const wxChar *psz) const |
Converts from the current wxChar type to multibyte encoding. | |
const wxCharBuffer | cWX2MB (const wxChar *psz) const |
Converts from the current wxChar type to multibyte encoding. | |
const wchar_t * | cWX2WC (const wxChar *psz) const |
Converts from the current wxChar type to Unicode. | |
const wxWCharBuffer | cWX2WC (const wxChar *psz) const |
Converts from the current wxChar type to Unicode. | |
Additional Inherited Members | |
Static Public Member Functions inherited from wxMBConv | |
static size_t | GetMaxMBNulLen () |
Returns the maximal value which can be returned by GetMBNulLen() for any conversion object. | |
wxCSConv::wxCSConv | ( | const wxString & | charset | ) |
Constructor.
You can specify the name of the character set you want to convert from/to. If the character set name is not recognized, ISO 8859-1 is used as fall back, use IsOk() to test for this.
charset | The name of the encoding, shouldn't be empty. |
wxCSConv::wxCSConv | ( | wxFontEncoding | encoding | ) |
Constructor.
You can specify an encoding constant for the character set you want to convert from/to. Use IsOk() after construction to check whether the encoding is supported by the current system.
encoding | Any valid (i.e. not wxFONTENCODING_MAX) font encoding. |
bool wxCSConv::IsOk | ( | ) | const |
Returns true if the charset (or the encoding) given at constructor is really available to use.
Returns false if ISO 8859-1 will be used instead.
Note this does not mean that a given string will be correctly converted. A malformed string may still make conversion functions return wxCONV_FAILED
.