Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat exactly does U+ stand for and why can't I create a table of Unicode intermediate strings in my C++ application?
    primarykey
    data
    text
    <p>I'm trying to convert an application from Java + Swing to C++ + Qt. At one point I had to deal with some Unicode intermediates. In Java, this was fairly easy:</p> <pre><code>private static String[] hiraganaTable = { "\u3042", "\u3044", "\u3046", "\u3048", "\u304a", "\u304b", "\u304d", "\u304f", "\u3051", "\u3053", ... } </code></pre> <p>...whereas in C++ I'm having problems:</p> <pre><code>QString hiraganaTable[] = { "\x30\x42", "\x30\x44", "\x30\x46", "\x30\x48", "\x30\x4a", "\x30\x4b", "\x30\x4d", "\x30\x4f", "\x30\x51", "\x30\x53", ... }; </code></pre> <p>I couldn't use \u in VS2008 because I got a heap of warnings of the form:</p> <blockquote> <p>character represented by universal-character-name '\u3042' cannot be represented in the current code page (1250)</p> </blockquote> <p>And don't call me stupid, I tried to use File->Advanced Save Options to no avail, the codepage didn't seem to change at all. Seems like this is a known problem: <a href="https://stackoverflow.com/questions/688760/how-to-create-a-utf-8-string-literal-in-visual-c-2008">How to create a UTF-8 string literal in Visual C++ 2008</a></p> <p>The table I'm using is fairly short, so with the help of Vim and some introductory-level regexp-magic, I was able to convert it to <strong>\x30\x42</strong> notation. Unfortunately, the QStrings would not initialize properly from such an input. I tried everything. fromAscii(), fromUtf8(), fromLocal8Bit(), QString(QByteArray), the works. Then, trying to write U+3042 without BOM to a file and then viewing it in hex mode, I found out it actually turns out to be <strong>"E3 81 82"</strong>. Suddenly, an entry like this seemed to work with <strong>QString::fromAscii()</strong>. Now I'm left wondering how much does exactly the "U+" stand for in "U+3042" (since 0xE38182 - 0x3042 = E35140, maybe I'd better add this Magic Constant to all my would-be Unicode chars?). How should I proceed from here to get an array of proper UTF-8 strings?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload