summaryrefslogtreecommitdiffstats
path: root/src/corelib/codecs
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/codecs')
-rw-r--r--src/corelib/codecs/codecs.pri88
-rw-r--r--src/corelib/codecs/qiconvcodec.cpp2
-rw-r--r--src/corelib/codecs/qicucodec.cpp4
-rw-r--r--src/corelib/codecs/qicucodec_p.h6
-rw-r--r--src/corelib/codecs/qlatincodec.cpp4
-rw-r--r--src/corelib/codecs/qlatincodec_p.h6
-rw-r--r--src/corelib/codecs/qsimplecodec.cpp4
-rw-r--r--src/corelib/codecs/qsimplecodec_p.h6
-rw-r--r--src/corelib/codecs/qtextcodec.cpp64
-rw-r--r--src/corelib/codecs/qtextcodec.h7
-rw-r--r--src/corelib/codecs/qtextcodec_p.h9
-rw-r--r--src/corelib/codecs/qutfcodec.cpp11
-rw-r--r--src/corelib/codecs/qutfcodec_p.h10
-rw-r--r--src/corelib/codecs/qwindowscodec_p.h2
14 files changed, 119 insertions, 104 deletions
diff --git a/src/corelib/codecs/codecs.pri b/src/corelib/codecs/codecs.pri
index d86d446c72..f1bbde1d69 100644
--- a/src/corelib/codecs/codecs.pri
+++ b/src/corelib/codecs/codecs.pri
@@ -1,62 +1,68 @@
# Qt core library codecs module
HEADERS += \
- codecs/qlatincodec_p.h \
- codecs/qsimplecodec_p.h \
codecs/qtextcodec_p.h \
- codecs/qtextcodec.h \
codecs/qutfcodec_p.h
SOURCES += \
- codecs/qlatincodec.cpp \
- codecs/qsimplecodec.cpp \
- codecs/qtextcodec.cpp \
codecs/qutfcodec.cpp
-qtConfig(codecs) {
+qtConfig(textcodec) {
HEADERS += \
- codecs/qisciicodec_p.h \
- codecs/qtsciicodec_p.h
+ codecs/qlatincodec_p.h \
+ codecs/qsimplecodec_p.h \
+ codecs/qtextcodec.h
SOURCES += \
- codecs/qisciicodec.cpp \
- codecs/qtsciicodec.cpp
-}
+ codecs/qlatincodec.cpp \
+ codecs/qsimplecodec.cpp \
+ codecs/qtextcodec.cpp
-qtConfig(icu) {
- HEADERS += \
- codecs/qicucodec_p.h
- SOURCES += \
- codecs/qicucodec.cpp
-} else {
- qtConfig(big_codecs) {
+ qtConfig(codecs) {
HEADERS += \
- codecs/qgb18030codec_p.h \
- codecs/qeucjpcodec_p.h \
- codecs/qjiscodec_p.h \
- codecs/qsjiscodec_p.h \
- codecs/qeuckrcodec_p.h \
- codecs/qbig5codec_p.h
+ codecs/qisciicodec_p.h \
+ codecs/qtsciicodec_p.h
SOURCES += \
- codecs/qgb18030codec.cpp \
- codecs/qjpunicode.cpp \
- codecs/qeucjpcodec.cpp \
- codecs/qjiscodec.cpp \
- codecs/qsjiscodec.cpp \
- codecs/qeuckrcodec.cpp \
- codecs/qbig5codec.cpp
+ codecs/qisciicodec.cpp \
+ codecs/qtsciicodec.cpp
}
- qtConfig(iconv) {
- HEADERS += codecs/qiconvcodec_p.h
- SOURCES += codecs/qiconvcodec.cpp
- qtConfig(gnu-libiconv): \
- QMAKE_USE_PRIVATE += iconv
- }
+ qtConfig(icu) {
+ HEADERS += \
+ codecs/qicucodec_p.h
+ SOURCES += \
+ codecs/qicucodec.cpp
+ } else {
+ qtConfig(big_codecs) {
+ HEADERS += \
+ codecs/qgb18030codec_p.h \
+ codecs/qeucjpcodec_p.h \
+ codecs/qjiscodec_p.h \
+ codecs/qsjiscodec_p.h \
+ codecs/qeuckrcodec_p.h \
+ codecs/qbig5codec_p.h
+
+ SOURCES += \
+ codecs/qgb18030codec.cpp \
+ codecs/qjpunicode.cpp \
+ codecs/qeucjpcodec.cpp \
+ codecs/qjiscodec.cpp \
+ codecs/qsjiscodec.cpp \
+ codecs/qeuckrcodec.cpp \
+ codecs/qbig5codec.cpp
+ }
+
+ qtConfig(iconv) {
+ HEADERS += codecs/qiconvcodec_p.h
+ SOURCES += codecs/qiconvcodec.cpp
+ qtConfig(gnu-libiconv): \
+ QMAKE_USE_PRIVATE += iconv
+ }
- win32 {
- SOURCES += codecs/qwindowscodec.cpp
- HEADERS += codecs/qwindowscodec_p.h
+ win32 {
+ SOURCES += codecs/qwindowscodec.cpp
+ HEADERS += codecs/qwindowscodec_p.h
+ }
}
}
diff --git a/src/corelib/codecs/qiconvcodec.cpp b/src/corelib/codecs/qiconvcodec.cpp
index 330eb7c038..9c39727946 100644
--- a/src/corelib/codecs/qiconvcodec.cpp
+++ b/src/corelib/codecs/qiconvcodec.cpp
@@ -39,8 +39,6 @@
#include <QtCore/private/qglobal_p.h>
-QT_REQUIRE_CONFIG(iconv);
-
#include "qiconvcodec_p.h"
#include "qtextcodec_p.h"
#include <qdebug.h>
diff --git a/src/corelib/codecs/qicucodec.cpp b/src/corelib/codecs/qicucodec.cpp
index 06a6d95e82..101c3a3278 100644
--- a/src/corelib/codecs/qicucodec.cpp
+++ b/src/corelib/codecs/qicucodec.cpp
@@ -39,8 +39,6 @@
#include "qicucodec_p.h"
-#ifndef QT_NO_TEXTCODEC
-
#include "qtextcodec_p.h"
#include "qutfcodec_p.h"
#include "qlatincodec_p.h"
@@ -698,5 +696,3 @@ int QIcuCodec::mibEnum() const
}
QT_END_NAMESPACE
-
-#endif // QT_NO_TEXTCODEC
diff --git a/src/corelib/codecs/qicucodec_p.h b/src/corelib/codecs/qicucodec_p.h
index 0c2dbe17d6..1cbe4d4e7a 100644
--- a/src/corelib/codecs/qicucodec_p.h
+++ b/src/corelib/codecs/qicucodec_p.h
@@ -59,9 +59,9 @@ extern "C" {
typedef struct UConverter UConverter;
}
-QT_BEGIN_NAMESPACE
+QT_REQUIRE_CONFIG(textcodec);
-#ifndef QT_NO_TEXTCODEC
+QT_BEGIN_NAMESPACE
class QIcuCodec : public QTextCodec
{
@@ -90,8 +90,6 @@ private:
const char *m_name;
};
-#endif // QT_NO_TEXTCODEC
-
QT_END_NAMESPACE
#endif
diff --git a/src/corelib/codecs/qlatincodec.cpp b/src/corelib/codecs/qlatincodec.cpp
index cfbd481f1e..1b53d26ef4 100644
--- a/src/corelib/codecs/qlatincodec.cpp
+++ b/src/corelib/codecs/qlatincodec.cpp
@@ -40,8 +40,6 @@
#include "qlatincodec_p.h"
#include "qlist.h"
-#ifndef QT_NO_TEXTCODEC
-
QT_BEGIN_NAMESPACE
QLatin1Codec::~QLatin1Codec()
@@ -238,5 +236,3 @@ int QLatin15Codec::mibEnum() const
}
QT_END_NAMESPACE
-
-#endif // QT_NO_TEXTCODEC
diff --git a/src/corelib/codecs/qlatincodec_p.h b/src/corelib/codecs/qlatincodec_p.h
index 3e258e5ae1..26f9e596a9 100644
--- a/src/corelib/codecs/qlatincodec_p.h
+++ b/src/corelib/codecs/qlatincodec_p.h
@@ -54,9 +54,9 @@
#include <QtCore/private/qglobal_p.h>
#include "QtCore/qtextcodec.h"
-QT_BEGIN_NAMESPACE
+QT_REQUIRE_CONFIG(textcodec);
-#ifndef QT_NO_TEXTCODEC
+QT_BEGIN_NAMESPACE
class QLatin1Codec : public QTextCodec
{
@@ -86,8 +86,6 @@ public:
int mibEnum() const override;
};
-#endif // QT_NO_TEXTCODEC
-
QT_END_NAMESPACE
#endif // QLATINCODEC_P_H
diff --git a/src/corelib/codecs/qsimplecodec.cpp b/src/corelib/codecs/qsimplecodec.cpp
index beb0a08f62..9ab545d783 100644
--- a/src/corelib/codecs/qsimplecodec.cpp
+++ b/src/corelib/codecs/qsimplecodec.cpp
@@ -40,8 +40,6 @@
#include "qsimplecodec_p.h"
#include "qlist.h"
-#ifndef QT_NO_TEXTCODEC
-
QT_BEGIN_NAMESPACE
#define LAST_MIB 2004
@@ -724,5 +722,3 @@ int QSimpleTextCodec::mibEnum() const
}
QT_END_NAMESPACE
-
-#endif // QT_NO_TEXTCODEC
diff --git a/src/corelib/codecs/qsimplecodec_p.h b/src/corelib/codecs/qsimplecodec_p.h
index 188c3f3cb4..a4b2a45e6b 100644
--- a/src/corelib/codecs/qsimplecodec_p.h
+++ b/src/corelib/codecs/qsimplecodec_p.h
@@ -54,9 +54,9 @@
#include <QtCore/private/qglobal_p.h>
#include "QtCore/qtextcodec.h"
-QT_BEGIN_NAMESPACE
+QT_REQUIRE_CONFIG(textcodec);
-#ifndef QT_NO_TEXTCODEC
+QT_BEGIN_NAMESPACE
template <typename T> class QAtomicPointer;
@@ -79,8 +79,6 @@ private:
mutable QAtomicPointer<QByteArray> reverseMap;
};
-#endif // QT_NO_TEXTCODEC
-
QT_END_NAMESPACE
#endif // QSIMPLECODEC_P_H
diff --git a/src/corelib/codecs/qtextcodec.cpp b/src/corelib/codecs/qtextcodec.cpp
index fedd39e104..466c575c3e 100644
--- a/src/corelib/codecs/qtextcodec.cpp
+++ b/src/corelib/codecs/qtextcodec.cpp
@@ -39,14 +39,14 @@
****************************************************************************/
#include "qplatformdefs.h"
+
#include "qtextcodec.h"
#include "qtextcodec_p.h"
-#ifndef QT_NO_TEXTCODEC
-
#include "qbytearraymatcher.h"
-#include "qlist.h"
+#include "qendian.h"
#include "qfile.h"
+#include "qlist.h"
#include "qstringlist.h"
#include "qvarlengtharray.h"
#if !defined(QT_BOOTSTRAPPED)
@@ -1164,41 +1164,50 @@ QTextCodec *QTextCodec::codecForHtml(const QByteArray &ba)
Tries to detect the encoding of the provided snippet \a ba by
using the BOM (Byte Order Mark) and returns a QTextCodec instance
- that is capable of decoding the text to unicode. If the codec
- cannot be detected from the content provided, \a defaultCodec is
- returned.
+ that is capable of decoding the text to unicode. This function can
+ detect one of the following codecs:
+
+ \list
+ \li UTF-32 Little Endian
+ \li UTF-32 Big Endian
+ \li UTF-16 Little Endian
+ \li UTF-16 Big Endian
+ \li UTF-8
+ \endlist
+
+ If the codec cannot be detected from the content provided, \a defaultCodec
+ is returned.
\sa codecForHtml()
*/
QTextCodec *QTextCodec::codecForUtfText(const QByteArray &ba, QTextCodec *defaultCodec)
{
const int arraySize = ba.size();
+ const uchar *buf = reinterpret_cast<const uchar *>(ba.constData());
+ const uint bom = 0xfeff;
if (arraySize > 3) {
- if ((uchar)ba[0] == 0x00
- && (uchar)ba[1] == 0x00
- && (uchar)ba[2] == 0xFE
- && (uchar)ba[3] == 0xFF)
+ uint uc = qFromUnaligned<uint>(buf);
+ if (uc == qToBigEndian(bom))
return QTextCodec::codecForMib(1018); // utf-32 be
- else if ((uchar)ba[0] == 0xFF
- && (uchar)ba[1] == 0xFE
- && (uchar)ba[2] == 0x00
- && (uchar)ba[3] == 0x00)
+ else if (uc == qToLittleEndian(bom))
return QTextCodec::codecForMib(1019); // utf-32 le
}
if (arraySize < 2)
return defaultCodec;
- if ((uchar)ba[0] == 0xfe && (uchar)ba[1] == 0xff)
+
+ ushort uc = qFromUnaligned<ushort>(buf);
+ if (uc == qToBigEndian(ushort(bom)))
return QTextCodec::codecForMib(1013); // utf16 be
- else if ((uchar)ba[0] == 0xff && (uchar)ba[1] == 0xfe)
+ else if (uc == qToLittleEndian(ushort(bom)))
return QTextCodec::codecForMib(1014); // utf16 le
if (arraySize < 3)
return defaultCodec;
- if ((uchar)ba[0] == 0xef
- && (uchar)ba[1] == 0xbb
- && (uchar)ba[2] == 0xbf)
+
+ static const char utf8bom[] = "\xef\xbb\xbf";
+ if (memcmp(buf, utf8bom, sizeof(utf8bom) - 1) == 0)
return QTextCodec::codecForMib(106); // utf-8
return defaultCodec;
@@ -1209,8 +1218,19 @@ QTextCodec *QTextCodec::codecForUtfText(const QByteArray &ba, QTextCodec *defaul
Tries to detect the encoding of the provided snippet \a ba by
using the BOM (Byte Order Mark) and returns a QTextCodec instance
- that is capable of decoding the text to unicode. If the codec
- cannot be detected, this overload returns a Latin-1 QTextCodec.
+ that is capable of decoding the text to unicode. This function can
+ detect one of the following codecs:
+
+ \list
+ \li UTF-32 Little Endian
+ \li UTF-32 Big Endian
+ \li UTF-16 Little Endian
+ \li UTF-16 Big Endian
+ \li UTF-8
+ \endlist
+
+ If the codec cannot be detected from the content provided, this overload
+ returns a Latin-1 QTextCodec.
\sa codecForHtml()
*/
@@ -1253,5 +1273,3 @@ bool QTextDecoder::needsMoreData() const
}
QT_END_NAMESPACE
-
-#endif // QT_NO_TEXTCODEC
diff --git a/src/corelib/codecs/qtextcodec.h b/src/corelib/codecs/qtextcodec.h
index 09d21166d8..3010a2714e 100644
--- a/src/corelib/codecs/qtextcodec.h
+++ b/src/corelib/codecs/qtextcodec.h
@@ -43,10 +43,9 @@
#include <QtCore/qstring.h>
#include <QtCore/qlist.h>
-QT_BEGIN_NAMESPACE
-
+QT_REQUIRE_CONFIG(textcodec);
-#ifndef QT_NO_TEXTCODEC
+QT_BEGIN_NAMESPACE
class QTextCodec;
class QIODevice;
@@ -168,8 +167,6 @@ private:
QTextCodec::ConverterState state;
};
-#endif // QT_NO_TEXTCODEC
-
QT_END_NAMESPACE
#endif // QTEXTCODEC_H
diff --git a/src/corelib/codecs/qtextcodec_p.h b/src/corelib/codecs/qtextcodec_p.h
index be0cab93e6..0e449d994c 100644
--- a/src/corelib/codecs/qtextcodec_p.h
+++ b/src/corelib/codecs/qtextcodec_p.h
@@ -52,12 +52,13 @@
//
#include <QtCore/private/qglobal_p.h>
-#include "qtextcodec.h"
#include <string.h>
QT_BEGIN_NAMESPACE
-#ifndef QT_NO_TEXTCODEC
+#if QT_CONFIG(textcodec)
+
+#include "qtextcodec.h"
#if defined(Q_OS_MAC) || defined(Q_OS_ANDROID) || defined(Q_OS_QNX) || defined(Q_OS_WASM)
#define QT_LOCALE_IS_UTF8
@@ -82,7 +83,7 @@ struct QTextCodecUnalignedPointer
bool qTextCodecNameMatch(const char *a, const char *b);
-#else
+#else // without textcodec:
class QTextCodec
{
@@ -109,7 +110,7 @@ public:
};
};
-#endif //QT_NO_TEXTCODEC
+#endif // textcodec
QT_END_NAMESPACE
diff --git a/src/corelib/codecs/qutfcodec.cpp b/src/corelib/codecs/qutfcodec.cpp
index 26c68cdee5..643c8ee475 100644
--- a/src/corelib/codecs/qutfcodec.cpp
+++ b/src/corelib/codecs/qutfcodec.cpp
@@ -70,9 +70,14 @@ static inline bool simdEncodeAscii(uchar *&dst, const ushort *&nextAscii, const
{
// do sixteen characters at a time
for ( ; end - src >= 16; src += 16, dst += 16) {
+# ifdef __AVX2__
+ __m256i data = _mm256_loadu_si256(reinterpret_cast<const __m256i *>(src));
+ __m128i data1 = _mm256_castsi256_si128(data);
+ __m128i data2 = _mm256_extracti128_si256(data, 1);
+# else
__m128i data1 = _mm_loadu_si128((const __m128i*)src);
__m128i data2 = _mm_loadu_si128(1+(const __m128i*)src);
-
+# endif
// check if everything is ASCII
// the highest ASCII value is U+007F
@@ -967,7 +972,7 @@ QString QUtf32::convertToUnicode(const char *chars, int len, QTextCodec::Convert
}
-#ifndef QT_NO_TEXTCODEC
+#if QT_CONFIG(textcodec)
QUtf8Codec::~QUtf8Codec()
{
@@ -1121,6 +1126,6 @@ QList<QByteArray> QUtf32LECodec::aliases() const
return list;
}
-#endif //QT_NO_TEXTCODEC
+#endif // textcodec
QT_END_NAMESPACE
diff --git a/src/corelib/codecs/qutfcodec_p.h b/src/corelib/codecs/qutfcodec_p.h
index 7405996fba..b24283ac5e 100644
--- a/src/corelib/codecs/qutfcodec_p.h
+++ b/src/corelib/codecs/qutfcodec_p.h
@@ -52,7 +52,13 @@
// We mean it.
//
+#include <QtCore/qstring.h>
+#include <QtCore/qlist.h>
+
+#if QT_CONFIG(textcodec)
#include "QtCore/qtextcodec.h"
+#endif
+
#include "private/qtextcodec_p.h"
QT_BEGIN_NAMESPACE
@@ -311,7 +317,7 @@ struct QUtf32
static QByteArray convertFromUnicode(const QChar *, int, QTextCodec::ConverterState *, DataEndianness = DetectEndianness);
};
-#ifndef QT_NO_TEXTCODEC
+#if QT_CONFIG(textcodec)
class QUtf8Codec : public QTextCodec {
public:
@@ -391,7 +397,7 @@ public:
};
-#endif // QT_NO_TEXTCODEC
+#endif // textcodec
QT_END_NAMESPACE
diff --git a/src/corelib/codecs/qwindowscodec_p.h b/src/corelib/codecs/qwindowscodec_p.h
index 1a74d618be..5bcab0ce66 100644
--- a/src/corelib/codecs/qwindowscodec_p.h
+++ b/src/corelib/codecs/qwindowscodec_p.h
@@ -53,6 +53,8 @@
#include <QtCore/private/qglobal_p.h>
#include "qtextcodec.h"
+QT_REQUIRE_CONFIG(textcodec);
+
QT_BEGIN_NAMESPACE
class QWindowsLocalCodec: public QTextCodec