Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
35 lines (27 sloc) 754 Bytes
#include "encoder.h"
encoder::encoder(QObject *parent) : QObject(parent)
{
QByteArray a;
QString result;
bool ok;
a.append(0xDF);
a.append(0xBF);
result = fromUtf8(a.constData(), 2, &ok);
qDebug("%i, %i", ok, a.size());
a.clear();
result.clear();
a.append(0xEF);
result = fromUtf8(a.constData(), a.size(), &ok);
qDebug("%i, %i", ok, a.size());
}
QString encoder::fromUtf8(const char *str, int size, bool *ok)
{
QTextCodec * codec = QTextCodec::codecForName("utf-8");
QTextCodec::ConverterState state;
QString result = codec->toUnicode(str, size, &state);
if(state.invalidChars == 0 && state.remainingChars == 0)
*ok = true;
else
*ok = false;
return result;
}