/***************************************************************************
- * Copyright (C) 2005-2012 by the Quassel Project *
+ * Copyright (C) 2005-2015 by the Quassel Project *
* devel@quassel-irc.org *
* *
* This program is free software; you can redistribute it and/or modify *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
#include "util.h"
class QMetaMethod;
+// MIBenum values from http://www.iana.org/assignments/character-sets/character-sets.xml#table-character-sets-1
+static QList<int> utf8DetectionBlacklist = QList<int>()
+ << 39 /* ISO-2022-JP */;
+
QString nickFromMask(QString mask)
{
return mask.section('!', 0, 0);
QString decodeString(const QByteArray &input, QTextCodec *codec)
{
+ if (codec && utf8DetectionBlacklist.contains(codec->mibEnum()))
+ return codec->toUnicode(input);
+
// First, we check if it's utf8. It is very improbable to encounter a string that looks like
// valid utf8, but in fact is not. This means that if the input string passes as valid utf8, it
// is safe to assume that it is.
//qDebug() << "Detected utf8:" << s;
return s;
}
- //QTextCodec *codec = QTextCodec::codecForName(encoding.toAscii());
- if (!codec) return QString::fromAscii(input);
+ //QTextCodec *codec = QTextCodec::codecForName(encoding.toLatin1());
+ if (!codec) return QString::fromLatin1(input);
return codec->toUnicode(input);
}