/***************************************************************************
- * Copyright (C) 2005-2012 by the Quassel Project *
+ * Copyright (C) 2005-2016 by the Quassel Project *
* devel@quassel-irc.org *
* *
* This program is free software; you can redistribute it and/or modify *
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);
}
timeUnit.append(qMakePair(60, QCoreApplication::translate("Quassel::secondsToString()", "min")));
timeUnit.append(qMakePair(1, QCoreApplication::translate("Quassel::secondsToString()", "sec")));
- QStringList returnString;
- for (int i = 0; i < timeUnit.size(); i++) {
- int n = timeInSeconds / timeUnit[i].first;
- if (n > 0) {
- returnString += QString("%1 %2").arg(QString::number(n), timeUnit[i].second);
+ if (timeInSeconds != 0) {
+ QStringList returnString;
+ for (int i = 0; i < timeUnit.size(); i++) {
+ int n = timeInSeconds / timeUnit[i].first;
+ if (n > 0) {
+ returnString += QString("%1 %2").arg(QString::number(n), timeUnit[i].second);
+ }
+ timeInSeconds = timeInSeconds % timeUnit[i].first;
}
- timeInSeconds = timeInSeconds % timeUnit[i].first;
+ return returnString.join(", ");
+ }
+ else {
+ return QString("%1 %2").arg(QString::number(timeInSeconds), timeUnit.last().second);
}
- return returnString.join(", ");
}