wxEncodingConverter: Converting UTF8 to UNICODE with transliteration
Volker Bartheld
dr_versaeg at freenet.de
Thu Jan 11 04:32:10 PST 2007
Hi!
I want to convert a string containing UTF-8 characters to UNICODE (for
storage in a wxString) and replace possibly invalid characters with '?'
or any other placeholder (if that's possible).
wxUSE_UNICODE is defined due to the _UNICODE preprocessor flag set.
// ...
// #define wxUSE_WCHAR_T 1
// #define wxUSE_UNICODE 1
char* pBuf="Hello World\xE4"; // add the the "ä"
wxEncodingConverter EncConv;
EncConv.Init(wxFONTENCODING_UTF8, wxFONTENCODING_UNICODE, wxCONVERT_SUBSTITUTE);
wchar_t* pwBuf=new wchar_t[strlen(pBuf)+1];
EncConv.Convert(pBuf, pwBuf);
sBuf=wxString(pwBuf);
// expecting L"Hello World?" in pwBuf
delete[] pwBuf;
Currently, this code snippet returns false from
wxEnodingConverter::Init(), even if I set wxUSE_WCHAR_T to 1 in my
project's preprocessor options.
Should I recompile the wxMSW libraries or is there something else wrong
with my code?
Furthermore, UTF-8 strings can can be much longer than the number of
characters they represent. Since strlen() is not aware of that, I'm
wasting memory. Can I somehow detect what size of a buffer is necessary
for pwBuf?
Thanks a lot in advance for your opinions.
Volker
__
Mail replies to/an V B A R T H E L D at G M X dot D E
More information about the wx-users
mailing list