Skip to content

Instantly share code, notes, and snippets.

@MartinDelille
Created May 1, 2014 16:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MartinDelille/a9d9d8228135191ba4dd to your computer and use it in GitHub Desktop.
Save MartinDelille/a9d9d8228135191ba4dd to your computer and use it in GitHub Desktop.
Encoding test around œ
/**
* Copyright (C) 2012-2014 Phonations
* License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher
*/
#include <QFileInfo>
#include <QDebug>
#include <QTextCodec>
#include <QDir>
#include <QDomDocument>
#include <QTextCodec>
//#include <QCoreApplication>
#include <QDebug>
int main(int argc, char *argv[])
{
for(int i = 30; i < 255; i++)
qDebug() << i << (char)i;
QString s = "œ";
qDebug() << s;
qDebug() << s.at(0).unicode();
qDebug() << (unsigned char)s.toUtf8().at(0);
qDebug() << (unsigned char)s.toStdString().c_str()[0] << s.toStdString().c_str();
qDebug() << (unsigned char)s.toLatin1().at(0) << s.toLatin1();
qDebug() << s.toUcs4().at(0);
QTextCodec *codec = QTextCodec::codecForName("latin9");
QByteArray array = codec->fromUnicode(s);
qDebug() << (unsigned char)array.at(0);
foreach(QByteArray encoding, QTextCodec::availableCodecs()) {
QTextCodec *codec = QTextCodec::codecForName(encoding);
QByteArray array = codec->fromUnicode(s);
if(array.length())
qDebug() << encoding << (unsigned char)array.at(0);
else
qDebug() << encoding << "problem";
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment