summaryrefslogtreecommitdiffstats
path: root/doc/html/qtextcodec.html
blob: f8f03c38762df269a46122fcc511fc8f2501c211 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/src/codecs/qtextcodec.cpp:201 -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>QTextCodec Class</title>
<style type="text/css"><!--
fn { margin-left: 1cm; text-indent: -1cm; }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }
body { background: #ffffff; color: black; }
--></style>
</head>
<body>

<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr bgcolor="#E5E5E5">
<td valign=center>
 <a href="index.html">
<font color="#004faf">Home</font></a>
 | <a href="classes.html">
<font color="#004faf">All&nbsp;Classes</font></a>
 | <a href="mainclasses.html">
<font color="#004faf">Main&nbsp;Classes</font></a>
 | <a href="annotated.html">
<font color="#004faf">Annotated</font></a>
 | <a href="groups.html">
<font color="#004faf">Grouped&nbsp;Classes</font></a>
 | <a href="functions.html">
<font color="#004faf">Functions</font></a>
</td>
<td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>QTextCodec Class Reference</h1>

<p>The QTextCodec class provides conversion between text encodings.
<a href="#details">More...</a>
<p>Almost all the functions in this class are <a href="threads.html#reentrant">reentrant</a> when Qt is built with thread support. The exceptions are <a href="#~QTextCodec"><b>~QTextCodec</b></a>(), <a href="#setCodecForTr"><b>setCodecForTr</b></a>(), <a href="#setCodecForCStrings"><b>setCodecForCStrings</b></a>(), and <a href="#QTextCodec"><b>QTextCodec</b></a>().
</p><p><tt>#include &lt;<a href="qtextcodec-h.html">qtextcodec.h</a>&gt;</tt>
<p>Inherited by <a href="qbig5codec.html">QBig5Codec</a>, <a href="qbig5hkscscodec.html">QBig5hkscsCodec</a>, <a href="qeucjpcodec.html">QEucJpCodec</a>, <a href="qeuckrcodec.html">QEucKrCodec</a>, <a href="qgb18030codec.html">QGb18030Codec</a>, <a href="qjiscodec.html">QJisCodec</a>, <a href="qhebrewcodec.html">QHebrewCodec</a>, <a href="qsjiscodec.html">QSjisCodec</a>, and <a href="qtsciicodec.html">QTsciiCodec</a>.
<p><a href="qtextcodec-members.html">List of all member functions.</a>
<h2>Public Members</h2>
<ul>
<li class=fn>virtual <a href="#~QTextCodec"><b>~QTextCodec</b></a> ()</li>
<li class=fn>virtual const char * <a href="#name"><b>name</b></a> () const = 0</li>
<li class=fn>virtual const char * <a href="#mimeName"><b>mimeName</b></a> () const</li>
<li class=fn>virtual int <a href="#mibEnum"><b>mibEnum</b></a> () const = 0</li>
<li class=fn>virtual QTextDecoder * <a href="#makeDecoder"><b>makeDecoder</b></a> () const</li>
<li class=fn>virtual QTextEncoder * <a href="#makeEncoder"><b>makeEncoder</b></a> () const</li>
<li class=fn>virtual QString <a href="#toUnicode"><b>toUnicode</b></a> ( const&nbsp;char&nbsp;*&nbsp;chars, int&nbsp;len ) const</li>
<li class=fn>virtual QCString <a href="#fromUnicode"><b>fromUnicode</b></a> ( const&nbsp;QString&nbsp;&amp;&nbsp;uc, int&nbsp;&amp;&nbsp;lenInOut ) const</li>
<li class=fn>QCString <a href="#fromUnicode-2"><b>fromUnicode</b></a> ( const&nbsp;QString&nbsp;&amp;&nbsp;uc ) const</li>
<li class=fn>QString <a href="#toUnicode-2"><b>toUnicode</b></a> ( const&nbsp;QByteArray&nbsp;&amp;&nbsp;a, int&nbsp;len ) const</li>
<li class=fn>QString <a href="#toUnicode-3"><b>toUnicode</b></a> ( const&nbsp;QByteArray&nbsp;&amp;&nbsp;a ) const</li>
<li class=fn>QString <a href="#toUnicode-4"><b>toUnicode</b></a> ( const&nbsp;QCString&nbsp;&amp;&nbsp;a, int&nbsp;len ) const</li>
<li class=fn>QString <a href="#toUnicode-5"><b>toUnicode</b></a> ( const&nbsp;QCString&nbsp;&amp;&nbsp;a ) const</li>
<li class=fn>QString <a href="#toUnicode-6"><b>toUnicode</b></a> ( const&nbsp;char&nbsp;*&nbsp;chars ) const</li>
<li class=fn>virtual bool <a href="#canEncode"><b>canEncode</b></a> ( QChar&nbsp;ch ) const</li>
<li class=fn>virtual bool <a href="#canEncode-2"><b>canEncode</b></a> ( const&nbsp;QString&nbsp;&amp;&nbsp;s ) const</li>
<li class=fn>virtual int <a href="#heuristicContentMatch"><b>heuristicContentMatch</b></a> ( const&nbsp;char&nbsp;*&nbsp;chars, int&nbsp;len ) const = 0</li>
<li class=fn>virtual int <a href="#heuristicNameMatch"><b>heuristicNameMatch</b></a> ( const&nbsp;char&nbsp;*&nbsp;hint ) const</li>
</ul>
<h2>Static Public Members</h2>
<ul>
<li class=fn>QTextCodec * <a href="#loadCharmap"><b>loadCharmap</b></a> ( QIODevice&nbsp;*&nbsp;iod )</li>
<li class=fn>QTextCodec * <a href="#loadCharmapFile"><b>loadCharmapFile</b></a> ( QString&nbsp;filename )</li>
<li class=fn>QTextCodec * <a href="#codecForMib"><b>codecForMib</b></a> ( int&nbsp;mib )</li>
<li class=fn>QTextCodec * <a href="#codecForName"><b>codecForName</b></a> ( const&nbsp;char&nbsp;*&nbsp;name, int&nbsp;accuracy = 0 )</li>
<li class=fn>QTextCodec * <a href="#codecForContent"><b>codecForContent</b></a> ( const&nbsp;char&nbsp;*&nbsp;chars, int&nbsp;len )</li>
<li class=fn>QTextCodec * <a href="#codecForIndex"><b>codecForIndex</b></a> ( int&nbsp;i )</li>
<li class=fn>QTextCodec * <a href="#codecForLocale"><b>codecForLocale</b></a> ()</li>
<li class=fn>void <a href="#setCodecForLocale"><b>setCodecForLocale</b></a> ( QTextCodec&nbsp;*&nbsp;c )</li>
<li class=fn>QTextCodec * <a href="#codecForTr"><b>codecForTr</b></a> ()</li>
<li class=fn>void <a href="#setCodecForTr"><b>setCodecForTr</b></a> ( QTextCodec&nbsp;*&nbsp;c )</li>
<li class=fn>QTextCodec * <a href="#codecForCStrings"><b>codecForCStrings</b></a> ()</li>
<li class=fn>void <a href="#setCodecForCStrings"><b>setCodecForCStrings</b></a> ( QTextCodec&nbsp;*&nbsp;c )</li>
<li class=fn>void <a href="#deleteAllCodecs"><b>deleteAllCodecs</b></a> ()</li>
<li class=fn>const char * <a href="#locale"><b>locale</b></a> ()</li>
</ul>
<h2>Protected Members</h2>
<ul>
<li class=fn><a href="#QTextCodec"><b>QTextCodec</b></a> ()</li>
</ul>
<h2>Static Protected Members</h2>
<ul>
<li class=fn>int <a href="#simpleHeuristicNameMatch"><b>simpleHeuristicNameMatch</b></a> ( const&nbsp;char&nbsp;*&nbsp;name, const&nbsp;char&nbsp;*&nbsp;hint )</li>
</ul>
<hr><a name="details"></a><h2>Detailed Description</h2>


The QTextCodec class provides conversion between text encodings.


<p> Qt uses Unicode to store, draw and manipulate strings. In many
situations you may wish to deal with data that uses a different
encoding. For example, most Japanese documents are still stored in
Shift-JIS or ISO2022, while Russian users often have their
documents in KOI8-R or CP1251.
<p> Qt provides a set of QTextCodec classes to help with converting
non-Unicode formats to and from Unicode. You can also create your
own codec classes (<a href="#subclassing">see later</a>).
<p> The supported encodings are:
<ul>
<li> Latin1
<li> Big5 -- Chinese
<li> Big5-HKSCS -- Chinese
<li> eucJP -- Japanese
<li> eucKR -- Korean
<li> GB2312 -- Chinese
<li> GBK -- Chinese
<li> GB18030 -- Chinese
<li> JIS7 -- Japanese
<li> Shift-JIS -- Japanese
<li> TSCII -- Tamil
<li> utf8 -- Unicode, 8-bit
<li> utf16 -- Unicode
<li> KOI8-R -- Russian
<li> KOI8-U -- Ukrainian
<li> ISO8859-1 -- Western
<li> ISO8859-2 -- Central European
<li> ISO8859-3 -- Central European
<li> ISO8859-4 -- Baltic
<li> ISO8859-5 -- Cyrillic
<li> ISO8859-6 -- Arabic
<li> ISO8859-7 -- Greek
<li> ISO8859-8 -- Hebrew, visually ordered
<li> ISO8859-8-i -- Hebrew, logically ordered
<li> ISO8859-9 -- Turkish
<li> ISO8859-10
<li> ISO8859-13
<li> ISO8859-14
<li> ISO8859-15 -- Western
<li> IBM 850
<li> IBM 866
<li> CP874
<li> CP1250 -- Central European
<li> CP1251 -- Cyrillic
<li> CP1252 -- Western
<li> CP1253 -- Greek
<li> CP1254 -- Turkish
<li> CP1255 -- Hebrew
<li> CP1256 -- Arabic
<li> CP1257 -- Baltic
<li> CP1258
<li> Apple Roman
<li> TIS-620 -- Thai
</ul>
<p> QTextCodecs can be used as follows to convert some locally encoded
string to Unicode. Suppose you have some string encoded in Russian
KOI8-R encoding, and want to convert it to Unicode. The simple way
to do this is:
<p> <pre>
    <a href="qcstring.html">QCString</a> locallyEncoded = "..."; // text to convert
    QTextCodec *codec = QTextCodec::<a href="#codecForName">codecForName</a>("KOI8-R"); // get the codec for KOI8-R
    <a href="qstring.html">QString</a> unicodeString = codec-&gt;<a href="#toUnicode">toUnicode</a>( locallyEncoded );
    </pre>
 
<p> After this, <tt>unicodeString</tt> holds the text converted to Unicode.
Converting a string from Unicode to the local encoding is just as
easy:
<p> <pre>
    <a href="qstring.html">QString</a> unicodeString = "..."; // any Unicode text
    QTextCodec *codec = QTextCodec::<a href="#codecForName">codecForName</a>("KOI8-R"); // get the codec for KOI8-R
    <a href="qcstring.html">QCString</a> locallyEncoded = codec-&gt;<a href="#fromUnicode">fromUnicode</a>( unicodeString );
    </pre>
 
<p> Some care must be taken when trying to convert the data in chunks,
for example, when receiving it over a network. In such cases it is
possible that a multi-byte character will be split over two
chunks. At best this might result in the loss of a character and
at worst cause the entire conversion to fail.
<p> The approach to use in these situations is to create a <a href="qtextdecoder.html">QTextDecoder</a>
object for the codec and use this QTextDecoder for the whole
decoding process, as shown below:
<p> <pre>
    QTextCodec *codec = QTextCodec::<a href="#codecForName">codecForName</a>( "Shift-JIS" );
    <a href="qtextdecoder.html">QTextDecoder</a> *decoder = codec-&gt;<a href="#makeDecoder">makeDecoder</a>();

    <a href="qstring.html">QString</a> unicodeString;
    while( receiving_data ) {
        <a href="qbytearray.html">QByteArray</a> chunk = new_data;
        unicodeString += decoder-&gt;<a href="qtextdecoder.html#toUnicode">toUnicode</a>( chunk.<a href="qmemarray.html#data">data</a>(), chunk.length() );
    }
    </pre>
 
<p> The QTextDecoder object maintains state between chunks and therefore
works correctly even if a multi-byte character is split between
chunks.
<p> <a name="subclassing"></a>
<h3> Creating your own Codec class
</h3>
<a name="1"></a><p> Support for new text encodings can be added to Qt by creating
QTextCodec subclasses.
<p> Built-in codecs can be overridden by custom codecs since more
recently created QTextCodec objects take precedence over earlier
ones.
<p> You may find it more convenient to make your codec class available
as a plugin; see the <a href="plugins-howto.html">plugin
    documentation</a> for more details.
<p> The abstract virtual functions describe the encoder to the
system and the coder is used as required in the different
text file formats supported by <a href="qtextstream.html">QTextStream</a>, and under X11, for the
locale-specific character input and output.
<p> To add support for another 8-bit encoding to Qt, make a subclass
of QTextCodec and implement at least the following methods:
<p> <pre>
    const char* name() const
    </pre>
 
Return the official name for the encoding.
<p> <pre>
    int mibEnum() const
    </pre>
 
Return the MIB enum for the encoding if it is listed in the
<a href="http://www.iana.org/assignments/character-sets">IANA character-sets encoding file</a>.
<p> If the encoding is multi-byte then it will have "state"; that is,
the interpretation of some bytes will be dependent on some preceding
bytes. For such encodings, you must implement:
<p> <pre>
    <a href="qtextdecoder.html">QTextDecoder</a>* makeDecoder() const
    </pre>
 
Return a <a href="qtextdecoder.html">QTextDecoder</a> that remembers incomplete multi-byte sequence
prefixes or other required state.
<p> If the encoding does <em>not</em> require state, you should implement:
<p> <pre>
    <a href="qstring.html">QString</a> toUnicode(const char* chars, int len) const
    </pre>
 
Converts <em>len</em> characters from <em>chars</em> to Unicode.
<p> The base QTextCodec class has default implementations of the above
two functions, <em>but they are mutually recursive</em>, so you must
re-implement at least one of them, or both for improved efficiency.
<p> For conversion from Unicode to 8-bit encodings, it is rarely necessary
to maintain state. However, two functions similar to the two above
are used for encoding:
<p> <pre>
    <a href="qtextencoder.html">QTextEncoder</a>* makeEncoder() const
    </pre>
 
Return a <a href="qtextencoder.html">QTextEncoder</a>.
<p> <pre>
    <a href="qcstring.html">QCString</a> fromUnicode(const <a href="qstring.html">QString</a>&amp; uc, int&amp; lenInOut ) const
    </pre>
 
Converts <em>lenInOut</em> characters (of type <a href="qchar.html">QChar</a>) from the start of
the string <em>uc</em>, returning a <a href="qcstring.html">QCString</a> result, and also returning
the <a href="qcstring.html#length">length</a> of the result in
<em>lenInOut</em>.
<p> Again, these are mutually recursive so only one needs to be implemented,
or both if greater efficiency is possible.
<p> Finally, you must implement:
<p> <pre>
    int heuristicContentMatch(const char* chars, int len) const
    </pre>
 
Gives a value indicating how likely it is that <em>len</em> characters
from <em>chars</em> are in the encoding.
<p> A good model for this function is the
QWindowsLocalCodec::heuristicContentMatch function found in the Qt
sources.
<p> A QTextCodec subclass might have improved performance if you also
re-implement:
<p> <pre>
    bool canEncode( <a href="qchar.html">QChar</a> ) const
    </pre>
 
Test if a Unicode character can be encoded.
<p> <pre>
    bool canEncode( const <a href="qstring.html">QString</a>&amp; ) const
    </pre>
 
Test if a string of Unicode characters can be encoded.
<p> <pre>
    int heuristicNameMatch(const char* hint) const
    </pre>
 
Test if a possibly non-standard name is referring to the codec.
<p> Codecs can also be created as <a href="plugins-howto.html">plugins</a>.
<p>See also <a href="i18n.html">Internationalization with Qt</a>.

<hr><h2>Member Function Documentation</h2>
<h3 class=fn><a name="QTextCodec"></a>QTextCodec::QTextCodec ()<tt> [protected]</tt>
</h3><p><b>Warning:</b> This function is <i>not</i> <a href="threads.html#reentrant">reentrant</a>.</p>


<p> Constructs a QTextCodec, and gives it the highest precedence. The
QTextCodec should always be constructed on the heap (i.e. with <tt>new</tt>). Qt takes ownership and will delete it when the application
terminates.

<h3 class=fn><a name="~QTextCodec"></a>QTextCodec::~QTextCodec ()<tt> [virtual]</tt>
</h3><p><b>Warning:</b> This function is <i>not</i> <a href="threads.html#reentrant">reentrant</a>.</p>


<p> Destroys the QTextCodec. Note that you should not delete codecs
yourself: once created they become Qt's responsibility.

<h3 class=fn>bool <a name="canEncode"></a>QTextCodec::canEncode ( <a href="qchar.html">QChar</a>&nbsp;ch ) const<tt> [virtual]</tt>
</h3>
Returns TRUE if the Unicode character <em>ch</em> can be fully encoded
with this codec; otherwise returns FALSE. The default
implementation tests if the result of <a href="#toUnicode">toUnicode</a>(fromUnicode(ch))
is the original <em>ch</em>. Subclasses may be able to improve the
efficiency.

<h3 class=fn>bool <a name="canEncode-2"></a>QTextCodec::canEncode ( const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;s ) const<tt> [virtual]</tt>
</h3>
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
<p> <em>s</em> contains the string being tested for encode-ability.

<h3 class=fn><a href="qtextcodec.html">QTextCodec</a>&nbsp;* <a name="codecForCStrings"></a>QTextCodec::codecForCStrings ()<tt> [static]</tt>
</h3>

<p> Returns the codec used by <a href="qstring.html">QString</a> to convert to and from const
char* and QCStrings. If this function returns 0 (the default),
QString assumes Latin-1.
<p> <p>See also <a href="#setCodecForCStrings">setCodecForCStrings</a>().

<h3 class=fn><a href="qtextcodec.html">QTextCodec</a>&nbsp;* <a name="codecForContent"></a>QTextCodec::codecForContent ( const&nbsp;char&nbsp;*&nbsp;chars, int&nbsp;len )<tt> [static]</tt>
</h3>
Searches all installed QTextCodec objects, returning the one which
most recognizes the given content. May return 0.
<p> Note that this is often a poor choice, since character encodings
often use most of the available character sequences, and so only
by linguistic analysis could a true match be made.
<p> <em>chars</em> contains the string to check, and <em>len</em> contains the
number of characters in the string to use.
<p> <p>See also <a href="#heuristicContentMatch">heuristicContentMatch</a>().

<p>Example: <a href="qwerty-example.html#x391">qwerty/qwerty.cpp</a>.
<h3 class=fn><a href="qtextcodec.html">QTextCodec</a>&nbsp;* <a name="codecForIndex"></a>QTextCodec::codecForIndex ( int&nbsp;i )<tt> [static]</tt>
</h3>
Returns the QTextCodec <em>i</em> positions from the most recently
inserted codec, or 0 if there is no such QTextCodec. Thus,
<a href="#codecForIndex">codecForIndex</a>(0) returns the most recently created QTextCodec.

<p>Example: <a href="qwerty-example.html#x392">qwerty/qwerty.cpp</a>.
<h3 class=fn><a href="qtextcodec.html">QTextCodec</a>&nbsp;* <a name="codecForLocale"></a>QTextCodec::codecForLocale ()<tt> [static]</tt>
</h3> Returns a pointer to the codec most suitable for this locale. 
<p>Example: <a href="qwerty-example.html#x393">qwerty/qwerty.cpp</a>.
<h3 class=fn><a href="qtextcodec.html">QTextCodec</a>&nbsp;* <a name="codecForMib"></a>QTextCodec::codecForMib ( int&nbsp;mib )<tt> [static]</tt>
</h3>
Returns the QTextCodec which matches the <a href="#mibEnum">MIBenum</a> <em>mib</em>.

<h3 class=fn><a href="qtextcodec.html">QTextCodec</a>&nbsp;* <a name="codecForName"></a>QTextCodec::codecForName ( const&nbsp;char&nbsp;*&nbsp;name, int&nbsp;accuracy = 0 )<tt> [static]</tt>
</h3>
Searches all installed QTextCodec objects and returns the one
which best matches <em>name</em>; the match is case-insensitive. Returns
0 if no codec's <a href="#heuristicNameMatch">heuristicNameMatch</a>() reports a match better than
<em>accuracy</em>, or if <em>name</em> is a null string.
<p> <p>See also <a href="#heuristicNameMatch">heuristicNameMatch</a>().

<h3 class=fn><a href="qtextcodec.html">QTextCodec</a>&nbsp;* <a name="codecForTr"></a>QTextCodec::codecForTr ()<tt> [static]</tt>
</h3>

<p> Returns the codec used by <a href="qobject.html#tr">QObject::tr</a>() on its argument. If this
function returns 0 (the default), tr() assumes Latin-1.
<p> <p>See also <a href="#setCodecForTr">setCodecForTr</a>().

<h3 class=fn>void <a name="deleteAllCodecs"></a>QTextCodec::deleteAllCodecs ()<tt> [static]</tt>
</h3>
Deletes all the created codecs.
<p> <b>Warning:</b> Do not call this function.
<p> <a href="qapplication.html">QApplication</a> calls this function just before exiting to delete
any QTextCodec objects that may be lying around. Since various
other classes hold pointers to QTextCodec objects, it is not safe
to call this function earlier.
<p> If you are using the utility classes (like <a href="qstring.html">QString</a>) but not using
QApplication, calling this function at the very end of your
application may be helpful for chasing down memory leaks by
eliminating any QTextCodec objects.

<h3 class=fn><a href="qcstring.html">QCString</a> <a name="fromUnicode"></a>QTextCodec::fromUnicode ( const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;uc, int&nbsp;&amp;&nbsp;lenInOut ) const<tt> [virtual]</tt>
</h3>
QTextCodec subclasses must reimplement either this function or
<a href="#makeEncoder">makeEncoder</a>(). It converts the first <em>lenInOut</em> characters of <em>uc</em> from Unicode to the encoding of the subclass. If <em>lenInOut</em> is
negative or too large, the length of <em>uc</em> is used instead.
<p> Converts <em>lenInOut</em> characters (not bytes) from <em>uc</em>, producing
a <a href="qcstring.html">QCString</a>. <em>lenInOut</em> will be set to the <a href="qcstring.html#length">length</a> of the result (in bytes).
<p> The default implementation makes an encoder with makeEncoder() and
converts the input with that. Note that the default makeEncoder()
implementation makes an encoder that simply calls this function,
hence subclasses <em>must</em> reimplement one function or the other to
avoid infinite recursion.

<p>Reimplemented in <a href="qhebrewcodec.html#fromUnicode">QHebrewCodec</a>.
<h3 class=fn><a href="qcstring.html">QCString</a> <a name="fromUnicode-2"></a>QTextCodec::fromUnicode ( const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;uc ) const
</h3>
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
<p> <em>uc</em> is the unicode source string.

<h3 class=fn>int <a name="heuristicContentMatch"></a>QTextCodec::heuristicContentMatch ( const&nbsp;char&nbsp;*&nbsp;chars, int&nbsp;len ) const<tt> [pure virtual]</tt>
</h3>

<p> QTextCodec subclasses must reimplement this function. It examines
the first <em>len</em> bytes of <em>chars</em> and returns a value indicating
how likely it is that the string is a prefix of text encoded in
the encoding of the subclass. A negative return value indicates
that the text is detectably not in the encoding (e.g. it contains
characters undefined in the encoding). A return value of 0
indicates that the text should be decoded with this codec rather
than as ASCII, but there is no particular evidence. The value
should range up to <em>len</em>. Thus, most decoders will return -1, 0,
or -<em>len</em>.
<p> The characters are not null terminated.
<p> <p>See also <a href="#codecForContent">codecForContent</a>().

<h3 class=fn>int <a name="heuristicNameMatch"></a>QTextCodec::heuristicNameMatch ( const&nbsp;char&nbsp;*&nbsp;hint ) const<tt> [virtual]</tt>
</h3>
Returns a value indicating how likely it is that this decoder is
appropriate for decoding some format that has the given name. The
name is compared with the <em>hint</em>.
<p> A good match returns a positive number around the length of the
string. A bad match is negative.
<p> The default implementation calls <a href="#simpleHeuristicNameMatch">simpleHeuristicNameMatch</a>() with
the name of the codec.

<h3 class=fn><a href="qtextcodec.html">QTextCodec</a>&nbsp;* <a name="loadCharmap"></a>QTextCodec::loadCharmap ( <a href="qiodevice.html">QIODevice</a>&nbsp;*&nbsp;iod )<tt> [static]</tt>
</h3>
Reads a POSIX2 charmap definition from <em>iod</em>.
The parser recognizes the following lines:
<p> <font name="sans">
&nbsp;&nbsp;&lt;code_set_name&gt; <i>name</i></br>
&nbsp;&nbsp;&lt;escape_char&gt; <i>character</i></br>
&nbsp;&nbsp;% alias <i>alias</i></br>
&nbsp;&nbsp;CHARMAP</br>
&nbsp;&nbsp;&lt;<i>token</i>&gt; /x<i>hexbyte</i> &lt;U<i>unicode</i>&gt; ...</br>
&nbsp;&nbsp;&lt;<i>token</i>&gt; /d<i>decbyte</i> &lt;U<i>unicode</i>&gt; ...</br>
&nbsp;&nbsp;&lt;<i>token</i>&gt; /<i>octbyte</i> &lt;U<i>unicode</i>&gt; ...</br>
&nbsp;&nbsp;&lt;<i>token</i>&gt; /<i>any</i>/<i>any</i>... &lt;U<i>unicode</i>&gt; ...</br>
&nbsp;&nbsp;END CHARMAP</br>
</font>
<p> The resulting QTextCodec is returned (and also added to the global
list of codecs). The <a href="#name">name</a>() of the result is taken from the
code_set_name.
<p> Note that a codec constructed in this way uses much more memory
and is slower than a hand-written QTextCodec subclass, since
tables in code are kept in memory shared by all Qt applications.
<p> <p>See also <a href="#loadCharmapFile">loadCharmapFile</a>().

<p>Example: <a href="qwerty-example.html#x394">qwerty/qwerty.cpp</a>.
<h3 class=fn><a href="qtextcodec.html">QTextCodec</a>&nbsp;* <a name="loadCharmapFile"></a>QTextCodec::loadCharmapFile ( <a href="qstring.html">QString</a>&nbsp;filename )<tt> [static]</tt>
</h3>
A convenience function for <a href="#loadCharmap">loadCharmap</a>() that loads the charmap
definition from the file <em>filename</em>.

<h3 class=fn>const char * <a name="locale"></a>QTextCodec::locale ()<tt> [static]</tt>
</h3>
Returns a string representing the current language and
sublanguage, e.g. "pt" for Portuguese, or "pt_br" for Portuguese/Brazil.

<p>Example: <a href="i18n-example.html#x1949">i18n/main.cpp</a>.
<h3 class=fn><a href="qtextdecoder.html">QTextDecoder</a>&nbsp;* <a name="makeDecoder"></a>QTextCodec::makeDecoder () const<tt> [virtual]</tt>
</h3>
Creates a <a href="qtextdecoder.html">QTextDecoder</a> which stores enough state to decode chunks
of char* data to create chunks of Unicode data. The default
implementation creates a stateless decoder, which is only
sufficient for the simplest encodings where each byte corresponds
to exactly one Unicode character.
<p> The caller is responsible for deleting the returned object.

<h3 class=fn><a href="qtextencoder.html">QTextEncoder</a>&nbsp;* <a name="makeEncoder"></a>QTextCodec::makeEncoder () const<tt> [virtual]</tt>
</h3>
Creates a <a href="qtextencoder.html">QTextEncoder</a> which stores enough state to encode chunks
of Unicode data as char* data. The default implementation creates
a stateless encoder, which is only sufficient for the simplest
encodings where each Unicode character corresponds to exactly one
character.
<p> The caller is responsible for deleting the returned object.

<h3 class=fn>int <a name="mibEnum"></a>QTextCodec::mibEnum () const<tt> [pure virtual]</tt>
</h3>

<p> Subclasses of QTextCodec must reimplement this function. It
returns the MIBenum (see <a href="http://www.iana.org/assignments/character-sets">the
    IANA character-sets encoding file</a> for more information).
It is important that each QTextCodec subclass returns the correct
unique value for this function.

<p>Reimplemented in <a href="qeucjpcodec.html#mibEnum">QEucJpCodec</a>.
<h3 class=fn>const char * <a name="mimeName"></a>QTextCodec::mimeName () const<tt> [virtual]</tt>
</h3>
Returns the preferred mime name of the encoding as defined in the
<a href="http://www.iana.org/assignments/character-sets">IANA character-sets encoding file</a>.

<p>Reimplemented in <a href="qeucjpcodec.html#mimeName">QEucJpCodec</a>, <a href="qeuckrcodec.html#mimeName">QEucKrCodec</a>, <a href="qjiscodec.html#mimeName">QJisCodec</a>, <a href="qhebrewcodec.html#mimeName">QHebrewCodec</a>, and <a href="qsjiscodec.html#mimeName">QSjisCodec</a>.
<h3 class=fn>const char * <a name="name"></a>QTextCodec::name () const<tt> [pure virtual]</tt>
</h3>

<p> QTextCodec subclasses must reimplement this function. It returns
the name of the encoding supported by the subclass. When choosing
a name for an encoding, consider these points:
<ul>
<li>	On X11, <a href="#heuristicNameMatch">heuristicNameMatch</a>( const char * hint )
is used to test if a the QTextCodec
can convert between Unicode and the encoding of a font
with encoding <em>hint</em>, such as "iso8859-1" for Latin-1 fonts,
"koi8-r" for Russian KOI8 fonts.
The default algorithm of heuristicNameMatch() uses <a href="#name">name</a>().
<li>	Some applications may use this function to present
encodings to the end user.
</ul>

<p>Example: <a href="qwerty-example.html#x395">qwerty/qwerty.cpp</a>.
<h3 class=fn>void <a name="setCodecForCStrings"></a>QTextCodec::setCodecForCStrings ( <a href="qtextcodec.html">QTextCodec</a>&nbsp;*&nbsp;c )<tt> [static]</tt>
</h3><p><b>Warning:</b> This function is <i>not</i> <a href="threads.html#reentrant">reentrant</a>.</p>



<p> Sets the codec used by <a href="qstring.html">QString</a> to convert to and from const char*
and QCStrings. If <em>c</em> is 0 (the default), QString assumes Latin-1.
<p> <b>Warning:</b> Some codecs do not preserve the characters in the ascii
range (0x00 to 0x7f).  For example, the Japanese Shift-JIS
encoding maps the backslash character (0x5a) to the Yen character.
This leads to unexpected results when using the backslash
character to escape characters in strings used in e.g. regular
expressions.  Use <a href="qstring.html#fromLatin1">QString::fromLatin1</a>() to preserve characters in
the ascii range when needed.
<p> <p>See also <a href="#codecForCStrings">codecForCStrings</a>() and <a href="#setCodecForTr">setCodecForTr</a>().

<h3 class=fn>void <a name="setCodecForLocale"></a>QTextCodec::setCodecForLocale ( <a href="qtextcodec.html">QTextCodec</a>&nbsp;*&nbsp;c )<tt> [static]</tt>
</h3>
Set the codec to <em>c</em>; this will be returned by <a href="#codecForLocale">codecForLocale</a>().
This might be needed for some applications that want to use their
own mechanism for setting the locale.
<p> <p>See also <a href="#codecForLocale">codecForLocale</a>().

<h3 class=fn>void <a name="setCodecForTr"></a>QTextCodec::setCodecForTr ( <a href="qtextcodec.html">QTextCodec</a>&nbsp;*&nbsp;c )<tt> [static]</tt>
</h3><p><b>Warning:</b> This function is <i>not</i> <a href="threads.html#reentrant">reentrant</a>.</p>



<p> Sets the codec used by <a href="qobject.html#tr">QObject::tr</a>() on its argument to <em>c</em>. If
<em>c</em> is 0 (the default), tr() assumes Latin-1.
<p> If the literal quoted text in the program is not in the Latin-1
encoding, this function can be used to set the appropriate
encoding. For example, software developed by Korean programmers
might use eucKR for all the text in the program, in which case the
main() function might look like this:
<p> <pre>
    int main(int argc, char** argv)
    {
        <a href="qapplication.html">QApplication</a> app(argc, argv);
        ... install any additional codecs ...
        QTextCodec::<a href="#setCodecForTr">setCodecForTr</a>( QTextCodec::<a href="#codecForName">codecForName</a>("eucKR") );
        ...
    }
    </pre>
 
<p> Note that this is not the way to select the encoding that the <em>user</em> has chosen. For example, to convert an application containing
literal English strings to Korean, all that is needed is for the
English strings to be passed through tr() and for translation
files to be loaded. For details of <a href="i18n.html#internationalization">internationalization</a>, see the
<a href="i18n.html">Qt internationalization documentation</a>.
<p> <p>See also <a href="#codecForTr">codecForTr</a>() and <a href="#setCodecForCStrings">setCodecForCStrings</a>().

<h3 class=fn>int <a name="simpleHeuristicNameMatch"></a>QTextCodec::simpleHeuristicNameMatch ( const&nbsp;char&nbsp;*&nbsp;name, const&nbsp;char&nbsp;*&nbsp;hint )<tt> [static protected]</tt>
</h3>
A simple utility function for <a href="#heuristicNameMatch">heuristicNameMatch</a>(): it does some
very minor character-skipping so that almost-exact matches score
high. <em>name</em> is the text we're matching and <em>hint</em> is used for
the comparison.

<h3 class=fn><a href="qstring.html">QString</a> <a name="toUnicode"></a>QTextCodec::toUnicode ( const&nbsp;char&nbsp;*&nbsp;chars, int&nbsp;len ) const<tt> [virtual]</tt>
</h3>
QTextCodec subclasses must reimplement this function or
<a href="#makeDecoder">makeDecoder</a>(). It converts the first <em>len</em> characters of <em>chars</em>
to Unicode.
<p> The default implementation makes a decoder with makeDecoder() and
converts the input with that. Note that the default makeDecoder()
implementation makes a decoder that simply calls
this function, hence subclasses <em>must</em> reimplement one function or
the other to avoid infinite recursion.

<h3 class=fn><a href="qstring.html">QString</a> <a name="toUnicode-2"></a>QTextCodec::toUnicode ( const&nbsp;<a href="qbytearray.html">QByteArray</a>&nbsp;&amp;&nbsp;a, int&nbsp;len ) const
</h3>
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
<p> <em>a</em> contains the source characters; <em>len</em> contains the number of
characters in <em>a</em> to use.

<h3 class=fn><a href="qstring.html">QString</a> <a name="toUnicode-3"></a>QTextCodec::toUnicode ( const&nbsp;<a href="qbytearray.html">QByteArray</a>&nbsp;&amp;&nbsp;a ) const
</h3>
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
<p> <em>a</em> contains the source characters.

<h3 class=fn><a href="qstring.html">QString</a> <a name="toUnicode-4"></a>QTextCodec::toUnicode ( const&nbsp;<a href="qcstring.html">QCString</a>&nbsp;&amp;&nbsp;a, int&nbsp;len ) const
</h3>
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
<p> <em>a</em> contains the source characters; <em>len</em> contains the number of
characters in <em>a</em> to use.

<h3 class=fn><a href="qstring.html">QString</a> <a name="toUnicode-5"></a>QTextCodec::toUnicode ( const&nbsp;<a href="qcstring.html">QCString</a>&nbsp;&amp;&nbsp;a ) const
</h3>
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
<p> <em>a</em> contains the source characters.

<h3 class=fn><a href="qstring.html">QString</a> <a name="toUnicode-6"></a>QTextCodec::toUnicode ( const&nbsp;char&nbsp;*&nbsp;chars ) const
</h3>
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
<p> <em>chars</em> contains the source characters.

<!-- eof -->
<hr><p>
This file is part of the <a href="index.html">Qt toolkit</a>.
Copyright &copy; 1995-2007
<a href="http://www.trolltech.com/">Trolltech</a>. All Rights Reserved.<p><address><hr><div align=center>
<table width=100% cellspacing=0 border=0><tr>
<td>Copyright &copy; 2007
<a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
<td align=right><div align=right>Qt 3.3.8</div>
</table></div></address></body>
</html>