OSDN Git Service

assume QTextCodec::codecForLocale() does not return null
authorIvailo Monev <xakepa10@gmail.com>
Mon, 25 Jan 2021 20:14:36 +0000 (22:14 +0200)
committerIvailo Monev <xakepa10@gmail.com>
Mon, 25 Jan 2021 20:20:48 +0000 (22:20 +0200)
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
src/core/tools/qstring.cpp
src/gui/text/qfont_x11.cpp

index 5634053..46b9348 100644 (file)
@@ -3343,10 +3343,10 @@ QByteArray QString::toAscii() const
 static QByteArray toLocal8Bit_helper(const QChar *data, int length)
 {
 #ifndef QT_NO_TEXTCODEC
-    if (QTextCodec::codecForLocale())
-        return QTextCodec::codecForLocale()->fromUnicode(data, length);
-#endif // QT_NO_TEXTCODEC
+    return QTextCodec::codecForLocale()->fromUnicode(data, length);
+#else
     return toLatin1_helper(data, length);
+#endif // QT_NO_TEXTCODEC
 }
 
 /*!
@@ -3367,10 +3367,10 @@ static QByteArray toLocal8Bit_helper(const QChar *data, int length)
 QByteArray QString::toLocal8Bit() const
 {
 #ifndef QT_NO_TEXTCODEC
-    if (QTextCodec::codecForLocale())
-        return QTextCodec::codecForLocale()->fromUnicode(*this);
-#endif // QT_NO_TEXTCODEC
+    return QTextCodec::codecForLocale()->fromUnicode(*this);
+#else
     return toLatin1();
+#endif // QT_NO_TEXTCODEC
 }
 
 /*!
@@ -3507,11 +3507,10 @@ QString QString::fromLocal8Bit(const char *str, int size)
 #if !defined(QT_NO_TEXTCODEC)
     if (size < 0)
         size = qstrlen(str);
-    QTextCodec *codec = QTextCodec::codecForLocale();
-    if (codec)
-        return codec->toUnicode(str, size);
-#endif // !QT_NO_TEXTCODEC
+    return QTextCodec::codecForLocale()->toUnicode(str, size);
+#else
     return fromLatin1(str, size);
+#endif // !QT_NO_TEXTCODEC
 }
 
 /*!
@@ -8372,10 +8371,10 @@ QByteArray QStringRef::toAscii() const
 QByteArray QStringRef::toLocal8Bit() const
 {
 #ifndef QT_NO_TEXTCODEC
-    if (QTextCodec::codecForLocale())
-        return QTextCodec::codecForLocale()->fromUnicode(unicode(), length());
-#endif // QT_NO_TEXTCODEC
+    return QTextCodec::codecForLocale()->fromUnicode(unicode(), length());
+#else
     return toLatin1();
+#endif // QT_NO_TEXTCODEC
 }
 
 /*!
index 195a5fe..22d09a3 100644 (file)
@@ -78,10 +78,8 @@ int QFontPrivate::defaultEncodingID = -1;
 void QFont::initialize()
 {
     extern int qt_encoding_id_for_mib(int mib); // from qfontdatabase_x11.cpp
-    QTextCodec *codec = QTextCodec::codecForLocale();
     // determine the default encoding id using the locale, otherwise
-    // fallback to latin1 (mib == 4)
-    int mib = codec ? codec->mibEnum() : 4;
+    int mib = QTextCodec::codecForLocale()->mibEnum();
 
     // for asian locales, use the mib for the font codec instead of the locale codec
     switch (mib) {