c++11utf-8qt5cp1250

Qt5 C++ UTF-8 convertion to Windows-1250 of Romanian ș and ț characters


My application is developed in C++'11 and uses Qt5. In this application, I need to store a UTF-8 text as Windows-1250 coded file. I tried two following ways and both work expect for Romanian 'ș' and 'ț' characters :(

    1.
    auto data = QStringList() << ... <some texts here>;
    QTextStream outStream(&destFile);
    outStream.setCodec(QTextCodec::codecForName("Windows-1250"));
    foreach (auto qstr, data)
    {
        outStream << qstr << EOL_CODE;
    }
    2.
    auto data = QStringList() << ... <some texts here>;
    auto *codec = QTextCodec::codecForName("Windows-1250");
    foreach (auto qstr, data)
    {
        const QByteArray encodedString = codec->fromUnicode(qstr);
        destFile.write(encodedString);
    }

In case of 'ț' character (alias 0xC89B), instead of expected 0xFE value, the character is coded and stored as 0x3F, that it is unexpected.

So I am looking for any help or experience / examples regarding text recoding.

Best regards,


Solution

  • Do not confuse ț with ţ. The former is what is in your post, the latter is what's actually supported by Windows-1250.

    The character ț from your post is T-comma, U+021B, LATIN SMALL LETTER T WITH COMMA BELOW, however:

    This letter was not part of the early Unicode versions, which is why Ţ (T-cedilla, available from version 1.1.0, June 1993) is often used in digital texts in Romanian.

    The character referred to is ţ, U+0163, LATIN SMALL LETTER T WITH CEDILLA (emphasis mine):

    In early versions of Unicode, the Romanian letter Ț (T-comma) was considered a glyph variant of Ţ, and therefore was not present in the Unicode Standard. It is also not present in the Windows-1250 (Central Europe) code page.

    The story of ş and ș, being S-cedilla and S-comma is analogous.

    If you must encode to this archaic Windows 1250 code page, I'd suggest replacing the comma variants by the cedilla variants (both lowercase and uppercase) before encoding. I think Romanians will understand :)