[Interest] Unicode code points in Vusual Studio. Output differs from MinGW

Henry Skoglund fromqt at tungware.se
Thu Aug 11 23:07:41 CEST 2016


On 2016-08-11 19:53, Mark Gaiser wrote:
> On Thu, Aug 11, 2016 at 6:29 PM, Thiago Macieira
> <thiago.macieira at intel.com <mailto:thiago.macieira at intel.com>> wrote:
>
>     On quinta-feira, 11 de agosto de 2016 11:40:46 PDT Mark Gaiser wrote:
>     > Is there any way that i can use a string with unicode code points within
>     > tr(...) that works on MSVC 2010 (as that is my setup), but it would be
>     > great if it also works under MSVC 2015 and MinGW.
>
>     There's no way to make that work with MSVC 2010. If you want this to
>     work,
>     your options are:
>
..
..
> The only option i seem to have left for 2010 are apparently:
> - Making sure the source files are UTF-8 formatted (most is ascii at the
> moment)
> - Using tr("Coördinaat"); as opposed to tr("Co\u00F6rdinaat");, that
> does work, but is not preferred.

Actually it's possible to use unicode code points in tr(...) you just 
have to know how to play hardball with the compiler :-)

Instead of trying to play nice with tr("Co\u00F6rdinaat"); you use
tr("Co\xC3\xB6rdinaat");

Yes \uC3B6 is the UTF-8 encoding of the Unicode code point U+00F6
(if you type in tr("Coördinaat") and then hexdump the .exe file you'll 
see those bytes.)

Effectively you're saying to the compiler: don't mind us hex bytes 
passing, we're not the unicode characters you're looking for. This works 
as long as none of the 2, 3 or 4 UTF-8 characters are null chaps.

I've used this trick on MSVC2012 and MSVC2013, so it should work in 
MSVC2010 as well. (The reason: usually I code (Swedish) characters with 
tr("Coöordinaat"); but this is brittle, because then Notepad becomes 
your enemy. If you're tired one day and make a quick edit in Notepad on 
your mainwindow.cpp, Notepad "helps" your by inserting the BOM and 
*BOOM* tr("Coördinaat") does not longer compile correctly, but 
tr("Co\xC3\xB6rdinaat") does.)

Rgrds Henry





More information about the Interest mailing list