0
|
1 |
/****************************************************************************
|
|
2 |
**
|
|
3 |
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
4 |
** All rights reserved.
|
|
5 |
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
6 |
**
|
|
7 |
** This file is part of the QtCore module of the Qt Toolkit.
|
|
8 |
**
|
|
9 |
** $QT_BEGIN_LICENSE:LGPL$
|
|
10 |
** No Commercial Usage
|
|
11 |
** This file contains pre-release code and may not be distributed.
|
|
12 |
** You may use this file in accordance with the terms and conditions
|
|
13 |
** contained in the Technology Preview License Agreement accompanying
|
|
14 |
** this package.
|
|
15 |
**
|
|
16 |
** GNU Lesser General Public License Usage
|
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
18 |
** General Public License version 2.1 as published by the Free Software
|
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
20 |
** packaging of this file. Please review the following information to
|
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
23 |
**
|
|
24 |
** In addition, as a special exception, Nokia gives you certain additional
|
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception
|
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
27 |
**
|
|
28 |
** If you have questions regarding the use of this file, please contact
|
|
29 |
** Nokia at qt-info@nokia.com.
|
|
30 |
**
|
|
31 |
**
|
|
32 |
**
|
|
33 |
**
|
|
34 |
**
|
|
35 |
**
|
|
36 |
**
|
|
37 |
**
|
|
38 |
** $QT_END_LICENSE$
|
|
39 |
**
|
|
40 |
****************************************************************************/
|
|
41 |
|
|
42 |
#ifndef QTEXTCODEC_H
|
|
43 |
#define QTEXTCODEC_H
|
|
44 |
|
|
45 |
#include <QtCore/qstring.h>
|
|
46 |
#include <QtCore/qlist.h>
|
|
47 |
|
|
48 |
QT_BEGIN_HEADER
|
|
49 |
|
|
50 |
QT_BEGIN_NAMESPACE
|
|
51 |
|
|
52 |
QT_MODULE(Core)
|
|
53 |
|
|
54 |
#ifndef QT_NO_TEXTCODEC
|
|
55 |
|
|
56 |
class QTextCodec;
|
|
57 |
class QIODevice;
|
|
58 |
|
|
59 |
class QTextDecoder;
|
|
60 |
class QTextEncoder;
|
|
61 |
|
|
62 |
class Q_CORE_EXPORT QTextCodec
|
|
63 |
{
|
|
64 |
Q_DISABLE_COPY(QTextCodec)
|
|
65 |
public:
|
|
66 |
static QTextCodec* codecForName(const QByteArray &name);
|
|
67 |
static QTextCodec* codecForName(const char *name) { return codecForName(QByteArray(name)); }
|
|
68 |
static QTextCodec* codecForMib(int mib);
|
|
69 |
|
|
70 |
static QList<QByteArray> availableCodecs();
|
|
71 |
static QList<int> availableMibs();
|
|
72 |
|
|
73 |
static QTextCodec* codecForLocale();
|
|
74 |
static void setCodecForLocale(QTextCodec *c);
|
|
75 |
|
|
76 |
static QTextCodec* codecForTr();
|
|
77 |
static void setCodecForTr(QTextCodec *c);
|
|
78 |
|
|
79 |
static QTextCodec* codecForCStrings();
|
|
80 |
static void setCodecForCStrings(QTextCodec *c);
|
|
81 |
|
|
82 |
static QTextCodec *codecForHtml(const QByteArray &ba);
|
|
83 |
static QTextCodec *codecForHtml(const QByteArray &ba, QTextCodec *defaultCodec);
|
|
84 |
|
|
85 |
static QTextCodec *codecForUtfText(const QByteArray &ba);
|
|
86 |
static QTextCodec *codecForUtfText(const QByteArray &ba, QTextCodec *defaultCodec);
|
|
87 |
|
|
88 |
QTextDecoder* makeDecoder() const;
|
|
89 |
QTextEncoder* makeEncoder() const;
|
|
90 |
|
|
91 |
bool canEncode(QChar) const;
|
|
92 |
bool canEncode(const QString&) const;
|
|
93 |
|
|
94 |
QString toUnicode(const QByteArray&) const;
|
|
95 |
QString toUnicode(const char* chars) const;
|
|
96 |
QByteArray fromUnicode(const QString& uc) const;
|
|
97 |
enum ConversionFlag {
|
|
98 |
DefaultConversion,
|
|
99 |
ConvertInvalidToNull = 0x80000000,
|
|
100 |
IgnoreHeader = 0x1,
|
|
101 |
FreeFunction = 0x2
|
|
102 |
};
|
|
103 |
Q_DECLARE_FLAGS(ConversionFlags, ConversionFlag)
|
|
104 |
|
|
105 |
struct Q_CORE_EXPORT ConverterState {
|
|
106 |
ConverterState(ConversionFlags f = DefaultConversion)
|
|
107 |
: flags(f), remainingChars(0), invalidChars(0), d(0) { state_data[0] = state_data[1] = state_data[2] = 0; }
|
|
108 |
~ConverterState();
|
|
109 |
ConversionFlags flags;
|
|
110 |
int remainingChars;
|
|
111 |
int invalidChars;
|
|
112 |
uint state_data[3];
|
|
113 |
void *d;
|
|
114 |
private:
|
|
115 |
Q_DISABLE_COPY(ConverterState)
|
|
116 |
};
|
|
117 |
|
|
118 |
QString toUnicode(const char *in, int length, ConverterState *state = 0) const
|
|
119 |
{ return convertToUnicode(in, length, state); }
|
|
120 |
QByteArray fromUnicode(const QChar *in, int length, ConverterState *state = 0) const
|
|
121 |
{ return convertFromUnicode(in, length, state); }
|
|
122 |
|
|
123 |
virtual QByteArray name() const = 0;
|
|
124 |
virtual QList<QByteArray> aliases() const;
|
|
125 |
virtual int mibEnum() const = 0;
|
|
126 |
|
|
127 |
protected:
|
|
128 |
virtual QString convertToUnicode(const char *in, int length, ConverterState *state) const = 0;
|
|
129 |
virtual QByteArray convertFromUnicode(const QChar *in, int length, ConverterState *state) const = 0;
|
|
130 |
|
|
131 |
QTextCodec();
|
|
132 |
virtual ~QTextCodec();
|
|
133 |
|
|
134 |
public:
|
|
135 |
#ifdef QT3_SUPPORT
|
|
136 |
static QT3_SUPPORT QTextCodec* codecForContent(const char*, int) { return 0; }
|
|
137 |
static QT3_SUPPORT const char* locale();
|
|
138 |
static QT3_SUPPORT QTextCodec* codecForName(const char* hint, int) { return codecForName(QByteArray(hint)); }
|
|
139 |
QT3_SUPPORT QByteArray fromUnicode(const QString& uc, int& lenInOut) const;
|
|
140 |
QT3_SUPPORT QString toUnicode(const QByteArray&, int len) const;
|
|
141 |
QT3_SUPPORT QByteArray mimeName() const { return name(); }
|
|
142 |
static QT3_SUPPORT QTextCodec *codecForIndex(int i) { return codecForName(availableCodecs().value(i)); }
|
|
143 |
#endif
|
|
144 |
|
|
145 |
private:
|
|
146 |
friend class QTextCodecCleanup;
|
|
147 |
static QTextCodec *cftr;
|
|
148 |
};
|
|
149 |
Q_DECLARE_OPERATORS_FOR_FLAGS(QTextCodec::ConversionFlags)
|
|
150 |
|
|
151 |
inline QTextCodec* QTextCodec::codecForTr() { return cftr; }
|
|
152 |
inline void QTextCodec::setCodecForTr(QTextCodec *c) { cftr = c; }
|
|
153 |
inline QTextCodec* QTextCodec::codecForCStrings() { return QString::codecForCStrings; }
|
|
154 |
inline void QTextCodec::setCodecForCStrings(QTextCodec *c) { QString::codecForCStrings = c; }
|
|
155 |
|
|
156 |
class Q_CORE_EXPORT QTextEncoder {
|
|
157 |
Q_DISABLE_COPY(QTextEncoder)
|
|
158 |
public:
|
|
159 |
explicit QTextEncoder(const QTextCodec *codec) : c(codec), state() {}
|
|
160 |
~QTextEncoder();
|
|
161 |
QByteArray fromUnicode(const QString& str);
|
|
162 |
QByteArray fromUnicode(const QChar *uc, int len);
|
|
163 |
#ifdef QT3_SUPPORT
|
|
164 |
QByteArray fromUnicode(const QString& uc, int& lenInOut);
|
|
165 |
#endif
|
|
166 |
bool hasFailure() const;
|
|
167 |
private:
|
|
168 |
const QTextCodec *c;
|
|
169 |
QTextCodec::ConverterState state;
|
|
170 |
};
|
|
171 |
|
|
172 |
class Q_CORE_EXPORT QTextDecoder {
|
|
173 |
Q_DISABLE_COPY(QTextDecoder)
|
|
174 |
public:
|
|
175 |
explicit QTextDecoder(const QTextCodec *codec) : c(codec), state() {}
|
|
176 |
~QTextDecoder();
|
|
177 |
QString toUnicode(const char* chars, int len);
|
|
178 |
QString toUnicode(const QByteArray &ba);
|
|
179 |
void toUnicode(QString *target, const char *chars, int len);
|
|
180 |
bool hasFailure() const;
|
|
181 |
private:
|
|
182 |
const QTextCodec *c;
|
|
183 |
QTextCodec::ConverterState state;
|
|
184 |
};
|
|
185 |
|
|
186 |
#endif // QT_NO_TEXTCODEC
|
|
187 |
|
|
188 |
QT_END_NAMESPACE
|
|
189 |
|
|
190 |
QT_END_HEADER
|
|
191 |
|
|
192 |
#endif // QTEXTCODEC_H
|