[PATCH v2] Use UTF-8 for text strings.

Thiago Macieira thiago at macieira.org
Mon Dec 16 17:25:11 UTC 2013


On segunda-feira, 16 de dezembro de 2013 16:16:44, Dirk Hohndel wrote:
> $ git grep toLocal8Bit
> main.cpp:                       parse_argument(a.toLocal8Bit().data());
> qt-ui/divelistview.cpp: QByteArray bt = fileName.toLocal8Bit();
> qt-ui/mainwindow.cpp:           fileNamePtr = fileNames.at(i).toLocal8Bit();
> qt-ui/mainwindow.cpp:           fileNamePtr =
> fileNames.at(i).toLocal8Bit(); qt-ui/subsurfacewebservices.cpp:       
> tempfile = strdup(tempfileQ.toLocal8Bit().data());
> qt-ui/subsurfacewebservices.cpp:                QByteArray url =
> tr("Webservice").toLocal8Bit(); qt-ui/subsurfacewebservices.cpp:       
> struct zip *zip = zip_open(zipFile.fileName().toLocal8Bit().data(), 0,
> &errorcode); qt-ui/subsurfacewebservices.cpp:               
> parse_file(zipFile.fileName().toLocal8Bit().data(), &error); qthelper.cpp: 
>          // qDebug("%s -> %8.5f / %8.5f", gps_text.toLocal8Bit().data(),
> *latitude, *longitude);
> 
> which of these should also be converted???

None of them. Those are file names, except for tr("Webservice").toLocal8Bit() 
and the qDebug(). File names and output to the terminal are always locale-
encoded; the webservice one should probably not be translated at all, it's 
just something we pass to libxml2.

There's a better-named routine for it, called QFile::encodeName(), which I 
used:

$ git grep encodeName | cat
qt-ui/subsurfacewebservices.cpp:        struct zip *zip = 
zip_open(QFile::encodeName(tempfile), ZIP_CREATE, &error_code);

In fact, we should probably use it... The implementation is:

static QByteArray locale_encode(const QString &f)
{
#if defined(Q_OS_DARWIN)
    // Mac always expects UTF-8... and decomposed...
    return f.normalized(QString::NormalizationForm_D).toUtf8();
#elif defined(Q_OS_SYMBIAN)
    return f.toUtf8();
#else
    return f.toLocal8Bit();
#endif
}

Linus, do you want to rant about the use of NFD? :-)

Oh, we should also avoid 8-bit filenames as much as possible, Windows locales 
are not Unicode-complete. Testcase: create C:\Temp\éΓЯ€\ and move one of the 
data files there. Then try to open it.

That would mean rewriting much of file.c to use QFile. At the very least the 
read_file function, with filenames passed as an opaque type through C code.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel Open Source Technology Center
      PGP/GPG: 0x6EF45358; fingerprint:
      E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.hohndel.org/pipermail/subsurface/attachments/20131216/a767071d/attachment.sig>


More information about the subsurface mailing list