wxWidgets and UTF8 - some characters missing

188 views Asked by At

So I have this file encoded in UTF8. I load it and print like this:

char buffer[2048] = {0};

FILE *pFile = fopen("D:/localization.csv","rb");
int iret = fread(buffer,1,2048,pFile);
fclose(pFile);

wxString strMessageText = wxString::FromUTF8(buffer);
wxMessageBox(strMessageText);

The problem is that when the text contains some "invalid" characters, it doesn't get created (length of strMessageText is 0). I noticed, for instance, that Danish or German characters are fine but when I put Polish or Russian chars in the text file the wxString::FromUTF8 function fails to create proper text. Any idea?

2

There are 2 answers

0
VZ. On

If the file contains correctly encoded UTF-8 text, wxString::FromUTF8() will decode it. If it doesn't, you can still use wxMBConvUTF8 with e.g. MAP_INVALID_UTF8_TO_OCTAL to preserve even incorrectly encoded bytes in the input, but this isn't a good idea, in general.

0
maxest On

I found solution here https://forums.wxwidgets.org/viewtopic.php?f=1&t=41068 It turned out that my wxWidgets lib was out of date. I had version 2.8.12 and updated to 3.0.2 and it's fine.