Hello All,
we need to migrate a multi-language multi-platform (GTK, Win32) application from wxWidgets 2.8 to wxWidgets 3.0.
The main issue we are facing at the moment is the new wxString class, that provides constructor with const char * data.
We are using standard (I believe) unicode-enabled builds on Linux and Win32. All our sources and translation files are encoded in UTF-8.
Before: all wxString objects had to be initialized with the wxT() macro, that ensured the strings were treated correctly.
It was a bit boring, but it worked.
Now: the wxT() macro is still there and works perfectly. But it is also possible to create wxString objects from const char *. Such objects are never interpreted as UTF-8 under Windows (but Latin-1 instead, at least on the systems I tested). This is unfortunate for us, because any forgotten wxT() lead to (possible!) encoding mismatches, that are hard to find and predict.
Proposal: permit developers to disable all methods of wxString, including constructors, that deal with bare const char * data. This solution is adopted by the Qt 4 library, by means of the QT_NO_CAST_FROM_ASCII and related macros.
What do you think about this proposal? Are there any alternative ways we can have the compiler help us avoid encoding errors?
Thank you in advance and best regards.
Disable wxString constructor and methods dealing with standard C string
Re: Disable wxString constructor and methods dealing with standard C string
I think you should discuss this on the wx-dev mailing list where you can reach the core developers. This is a user forum.
https://groups.google.com/forum/#!forum/wx-dev
And i don't think there is any setting that enforces the behavior you want. It would be nice if the default conversion class "wxConvLibc" could be set externally.
https://groups.google.com/forum/#!forum/wx-dev
And i don't think there is any setting that enforces the behavior you want. It would be nice if the default conversion class "wxConvLibc" could be set externally.
Use the source, Luke!
Re: Disable wxString constructor and methods dealing with standard C string
Dealing with multi-language gets tricky if you don't care from the very beginning.
The first intention is just to write in "my language" and later I will add translations. When the default language is other than English, this means that default strings are not ASCII. Perhaps a "use my language"-flag in the compiler helps.
That was more or less how wx2.8 worked. But then translations were not so easy, and passing strings around needed a lot of conversions from/to different encodings.
wx2.9 did a radical change. Internally stores the OS default encoding (but you can change this, forcing to UTF8) which makes things much more easy... with the bad thing being now the wxString constructors. Using char* onky works for ASCII. See more at http://docs.wxwidgets.org/trunk/overview_string.html and http://docs.wxwidgets.org/trunk/classwx_string.html and http://docs.wxwidgets.org/trunk/overview_unicode.html
For your problem you can warp all your char* at ctrs with FromUTF8 (as seen in the links above).
What I do is write all "default" strings in ASCII, enclosed by _() macro and use translations, even for my own language.
The first intention is just to write in "my language" and later I will add translations. When the default language is other than English, this means that default strings are not ASCII. Perhaps a "use my language"-flag in the compiler helps.
That was more or less how wx2.8 worked. But then translations were not so easy, and passing strings around needed a lot of conversions from/to different encodings.
wx2.9 did a radical change. Internally stores the OS default encoding (but you can change this, forcing to UTF8) which makes things much more easy... with the bad thing being now the wxString constructors. Using char* onky works for ASCII. See more at http://docs.wxwidgets.org/trunk/overview_string.html and http://docs.wxwidgets.org/trunk/classwx_string.html and http://docs.wxwidgets.org/trunk/overview_unicode.html
For your problem you can warp all your char* at ctrs with FromUTF8 (as seen in the links above).
What I do is write all "default" strings in ASCII, enclosed by _() macro and use translations, even for my own language.
Re: Disable wxString constructor and methods dealing with standard C string
Thank you Manolo and doublemax,
I will ask wx-dev. My goal is to make expression such as
detected again as compiler errors.
Best regards.
I will ask wx-dev. My goal is to make expression such as
Code: Select all
wxString s("Hello");
Best regards.
Re: Disable wxString constructor and methods dealing with standard C string
I am replying to myself just for the records. The idea was already proposed and rejected.
References:
References:
- Bug #17616: http://trac.wxwidgets.org/ticket/17610 "UTF-8 bridge support on Windows for wxString"
Bug #11830: http://trac.wxwidgets.org/ticket/11830 "Allow disabling implicit conversions of wxString to char*"
Re: Disable wxString constructor and methods dealing with standard C string
I don't know if this was already proposed, but i think an easy solution would be to replace the default parameter "wxConvLibc" with something like "wxConvDefault". And that one should be configurable by a user-call. So it would be possible to set it to wxConvUTF8.
Use the source, Luke!