1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QTEXTCODEC_P_H
5#define QTEXTCODEC_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists for the convenience
12// of the QTextCodec class. This header file may change from
13// version to version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtCore/qhash.h>
19#include <QtCore/qstring.h>
20
21#include <QtCore5Compat/qtcore5compat-config.h>
22#if QT_CONFIG(textcodec)
23#include <QtCore5Compat/qtextcodec.h>
24#endif
25
26#include <private/qtcore5compat-config_p.h>
27
28#include "qcodecmacros_p.h"
29
30QT_BEGIN_NAMESPACE
31
32#if QT_CONFIG(textcodec)
33
34#if defined(Q_OS_MAC) || defined(Q_OS_ANDROID) || defined(Q_OS_QNX) || defined(Q_OS_WASM)
35#define QT_LOCALE_IS_UTF8
36#endif
37
38typedef void (*QTextCodecStateFreeFunction)(QTextCodec::ConverterState*);
39
40typedef QHash<QByteArray, QTextCodec *> QTextCodecCache;
41
42struct QTextCodecData
43{
44 QTextCodecData();
45 ~QTextCodecData();
46
47 QList<QTextCodec*> allCodecs;
48 QAtomicPointer<QTextCodec> codecForLocale;
49 QTextCodecCache codecCache;
50
51 static QTextCodecData *instance();
52};
53
54bool qTextCodecNameMatch(const char *a, const char *b);
55
56#else // without textcodec:
57
58// ELFVERSION:ignore-next
59class QTextCodec
60{
61public:
62 enum ConversionFlag {
63 DefaultConversion,
64 ConvertInvalidToNull = 0x80000000,
65 IgnoreHeader = 0x1,
66 FreeFunction = 0x2
67 };
68 Q_DECLARE_FLAGS(ConversionFlags, ConversionFlag)
69
70 struct ConverterState {
71 ConverterState(ConversionFlags f = DefaultConversion)
72 : flags(f), remainingChars(0), invalidChars(0), d(nullptr) { state_data[0] = state_data[1] = state_data[2] = 0; }
73 ~ConverterState() { }
74 ConversionFlags flags;
75 int remainingChars;
76 int invalidChars;
77 uint state_data[3];
78 void *d;
79 private:
80 Q_DISABLE_COPY(ConverterState)
81 };
82};
83
84#endif // textcodec
85
86QT_END_NAMESPACE
87
88#endif
89

source code of qt5compat/src/core5/codecs/qtextcodec_p.h