Question

i am using wxMac 2.8 in non-unicode build. I try to read a file with mutated vowels "ü" to a wxtextctrl. When i do, the data gets interpreted as current encoding, but it is a multibyte string. I narrowed the problem down to this:

text_ctrl->Clear();
text_ctrl->SetValue("üüüäääööößßß");

This is the result:

üüüäääööößßß

Note that the character count has doubled - printing the string in gdb displays "\303\274" and similar per original char. Typing "ü" or similar into the textctrl is no problem. I tried various wxMBConv methods but the result is always the same. Is there a way to solve this?

Best regards,

Was it helpful?

Solution

If you use anything but 7 bit ASCII, you must use Unicode build of wxWidgets. Just do yourself a favour and switch to it. If you have too much existing code that was written for "ANSI" build of wxWidgets 2.8 and earlier and doesn't compile with Unicode build, use wxWidgets 2.9 instead where it will compile -- and work as intended.

OTHER TIPS

It sounds like your text editor (for program source code) is in a different encoding from the running program.

Suppose for example that your text entry control and the rest of your program are (correctly) using UTF-8. Now if your text editor is using some other encoding, then a string that looks fine on screen will actually contain garbage bytes.

Assuming you are in a position to help create a pure-UTF8 world, then you should:

1) Encode UTF-8 directly into the string literals using escapes, e.g. "\303" or "\xc3". That's annoying to do, but it means you just don't have to worry about you text editor (or the editor settings of other developers).

2) Then check that the program is using UTF-8 everywhere.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top