1// Copyright (C) 2016 The Qt Company Ltd.
2// Copyright (C) 2018 Intel Corporation.
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4
5#include "qutfcodec_p.h"
6#include "qlist.h"
7#include "qendian.h"
8#include "qchar.h"
9
10#include "private/qsimd_p.h"
11#include "private/qstringiterator_p.h"
12
13QT_BEGIN_NAMESPACE
14
15#if QT_CONFIG(textcodec)
16
17QUtf8Codec::~QUtf8Codec()
18{
19}
20
21QByteArray QUtf8Codec::convertFromUnicode(const QChar *uc, int len, ConverterState *state) const
22{
23 ConverterState s(QStringConverter::Flag::Stateless);
24 if (!state)
25 state = &s;
26 return QUtf8::convertFromUnicode(in: QStringView(uc, len), state);
27}
28
29void QUtf8Codec::convertToUnicode(QString *target, const char *chars, int len, ConverterState *state) const
30{
31 ConverterState s(QStringConverter::Flag::Stateless);
32 if (!state)
33 state = &s;
34 *target += QUtf8::convertToUnicode(in: QByteArrayView(chars, len), state);
35}
36
37QString QUtf8Codec::convertToUnicode(const char *chars, int len, ConverterState *state) const
38{
39 ConverterState s(QStringConverter::Flag::Stateless);
40 if (!state)
41 state = &s;
42 return QUtf8::convertToUnicode(in: QByteArrayView(chars, len), state);
43}
44
45QByteArray QUtf8Codec::name() const
46{
47 return "UTF-8";
48}
49
50int QUtf8Codec::mibEnum() const
51{
52 return 106;
53}
54
55QUtf16Codec::~QUtf16Codec()
56{
57}
58
59QByteArray QUtf16Codec::convertFromUnicode(const QChar *uc, int len, ConverterState *state) const
60{
61 ConverterState s(QStringConverter::Flag::Stateless);
62 if (!state)
63 state = &s;
64 return QUtf16::convertFromUnicode(QStringView(uc, len), state, e);
65}
66
67QString QUtf16Codec::convertToUnicode(const char *chars, int len, ConverterState *state) const
68{
69 ConverterState s(QStringConverter::Flag::Stateless);
70 if (!state)
71 state = &s;
72 return QUtf16::convertToUnicode(QByteArrayView(chars, len), state, e);
73}
74
75int QUtf16Codec::mibEnum() const
76{
77 return 1015;
78}
79
80QByteArray QUtf16Codec::name() const
81{
82 return "UTF-16";
83}
84
85QList<QByteArray> QUtf16Codec::aliases() const
86{
87 return QList<QByteArray>();
88}
89
90int QUtf16BECodec::mibEnum() const
91{
92 return 1013;
93}
94
95QByteArray QUtf16BECodec::name() const
96{
97 return "UTF-16BE";
98}
99
100QList<QByteArray> QUtf16BECodec::aliases() const
101{
102 QList<QByteArray> list;
103 return list;
104}
105
106int QUtf16LECodec::mibEnum() const
107{
108 return 1014;
109}
110
111QByteArray QUtf16LECodec::name() const
112{
113 return "UTF-16LE";
114}
115
116QList<QByteArray> QUtf16LECodec::aliases() const
117{
118 QList<QByteArray> list;
119 return list;
120}
121
122QUtf32Codec::~QUtf32Codec()
123{
124}
125
126QByteArray QUtf32Codec::convertFromUnicode(const QChar *uc, int len, ConverterState *state) const
127{
128 ConverterState s(QStringConverter::Flag::Stateless);
129 if (!state)
130 state = &s;
131 return QUtf32::convertFromUnicode(QStringView(uc, len), state, e);
132}
133
134QString QUtf32Codec::convertToUnicode(const char *chars, int len, ConverterState *state) const
135{
136 ConverterState s(QStringConverter::Flag::Stateless);
137 if (!state)
138 state = &s;
139 return QUtf32::convertToUnicode(QByteArrayView(chars, len), state, e);
140}
141
142int QUtf32Codec::mibEnum() const
143{
144 return 1017;
145}
146
147QByteArray QUtf32Codec::name() const
148{
149 return "UTF-32";
150}
151
152QList<QByteArray> QUtf32Codec::aliases() const
153{
154 QList<QByteArray> list;
155 return list;
156}
157
158int QUtf32BECodec::mibEnum() const
159{
160 return 1018;
161}
162
163QByteArray QUtf32BECodec::name() const
164{
165 return "UTF-32BE";
166}
167
168QList<QByteArray> QUtf32BECodec::aliases() const
169{
170 QList<QByteArray> list;
171 return list;
172}
173
174int QUtf32LECodec::mibEnum() const
175{
176 return 1019;
177}
178
179QByteArray QUtf32LECodec::name() const
180{
181 return "UTF-32LE";
182}
183
184QList<QByteArray> QUtf32LECodec::aliases() const
185{
186 QList<QByteArray> list;
187 return list;
188}
189
190#endif // textcodec
191
192QT_END_NAMESPACE
193

source code of qt5compat/src/core5/codecs/qutfcodec.cpp