author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Wed, 21 Apr 2010 11:15:19 +0300 | |
branch | RCL_3 |
changeset 11 | 25a739ee40f4 |
parent 8 | 740e5562c97f |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 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; |
|
8
740e5562c97f
8b5beb2a553102639e9eb38c8f8f0f6775e8545b
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
148 |
static bool validCodecs(); |
0 | 149 |
}; |
150 |
Q_DECLARE_OPERATORS_FOR_FLAGS(QTextCodec::ConversionFlags) |
|
151 |
||
8
740e5562c97f
8b5beb2a553102639e9eb38c8f8f0f6775e8545b
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
152 |
inline QTextCodec* QTextCodec::codecForTr() { return validCodecs() ? cftr : 0; } |
0 | 153 |
inline void QTextCodec::setCodecForTr(QTextCodec *c) { cftr = c; } |
8
740e5562c97f
8b5beb2a553102639e9eb38c8f8f0f6775e8545b
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
154 |
inline QTextCodec* QTextCodec::codecForCStrings() { return validCodecs() ? QString::codecForCStrings : 0; } |
0 | 155 |
inline void QTextCodec::setCodecForCStrings(QTextCodec *c) { QString::codecForCStrings = c; } |
156 |
||
157 |
class Q_CORE_EXPORT QTextEncoder { |
|
158 |
Q_DISABLE_COPY(QTextEncoder) |
|
159 |
public: |
|
160 |
explicit QTextEncoder(const QTextCodec *codec) : c(codec), state() {} |
|
161 |
~QTextEncoder(); |
|
162 |
QByteArray fromUnicode(const QString& str); |
|
163 |
QByteArray fromUnicode(const QChar *uc, int len); |
|
164 |
#ifdef QT3_SUPPORT |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
165 |
QT3_SUPPORT QByteArray fromUnicode(const QString& uc, int& lenInOut); |
0 | 166 |
#endif |
167 |
bool hasFailure() const; |
|
168 |
private: |
|
169 |
const QTextCodec *c; |
|
170 |
QTextCodec::ConverterState state; |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
171 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
172 |
friend class QXmlStreamWriter; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
173 |
friend class QXmlStreamWriterPrivate; |
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
174 |
#if defined(Q_OS_MAC32) || defined(Q_OS_AIX) |
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
175 |
friend class QCoreXmlStreamWriter; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
176 |
friend class QCoreXmlStreamWriterPrivate; |
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
177 |
#endif |
0 | 178 |
}; |
179 |
||
180 |
class Q_CORE_EXPORT QTextDecoder { |
|
181 |
Q_DISABLE_COPY(QTextDecoder) |
|
182 |
public: |
|
183 |
explicit QTextDecoder(const QTextCodec *codec) : c(codec), state() {} |
|
184 |
~QTextDecoder(); |
|
185 |
QString toUnicode(const char* chars, int len); |
|
186 |
QString toUnicode(const QByteArray &ba); |
|
187 |
void toUnicode(QString *target, const char *chars, int len); |
|
188 |
bool hasFailure() const; |
|
189 |
private: |
|
190 |
const QTextCodec *c; |
|
191 |
QTextCodec::ConverterState state; |
|
192 |
}; |
|
193 |
||
194 |
#endif // QT_NO_TEXTCODEC |
|
195 |
||
196 |
QT_END_NAMESPACE |
|
197 |
||
198 |
QT_END_HEADER |
|
199 |
||
200 |
#endif // QTEXTCODEC_H |