You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
612 lines
33 KiB
612 lines
33 KiB
14 years ago
|
<!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 Classes</font></a>
|
||
|
| <a href="mainclasses.html">
|
||
|
<font color="#004faf">Main Classes</font></a>
|
||
|
| <a href="annotated.html">
|
||
|
<font color="#004faf">Annotated</font></a>
|
||
|
| <a href="groups.html">
|
||
|
<font color="#004faf">Grouped 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 <<a href="qtextcodec-h.html">qtextcodec.h</a>></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 char * chars, int len ) const</li>
|
||
|
<li class=fn>virtual QCString <a href="#fromUnicode"><b>fromUnicode</b></a> ( const QString & uc, int & lenInOut ) const</li>
|
||
|
<li class=fn>QCString <a href="#fromUnicode-2"><b>fromUnicode</b></a> ( const QString & uc ) const</li>
|
||
|
<li class=fn>QString <a href="#toUnicode-2"><b>toUnicode</b></a> ( const QByteArray & a, int len ) const</li>
|
||
|
<li class=fn>QString <a href="#toUnicode-3"><b>toUnicode</b></a> ( const QByteArray & a ) const</li>
|
||
|
<li class=fn>QString <a href="#toUnicode-4"><b>toUnicode</b></a> ( const QCString & a, int len ) const</li>
|
||
|
<li class=fn>QString <a href="#toUnicode-5"><b>toUnicode</b></a> ( const QCString & a ) const</li>
|
||
|
<li class=fn>QString <a href="#toUnicode-6"><b>toUnicode</b></a> ( const char * chars ) const</li>
|
||
|
<li class=fn>virtual bool <a href="#canEncode"><b>canEncode</b></a> ( QChar ch ) const</li>
|
||
|
<li class=fn>virtual bool <a href="#canEncode-2"><b>canEncode</b></a> ( const QString & s ) const</li>
|
||
|
<li class=fn>virtual int <a href="#heuristicContentMatch"><b>heuristicContentMatch</b></a> ( const char * chars, int len ) const = 0</li>
|
||
|
<li class=fn>virtual int <a href="#heuristicNameMatch"><b>heuristicNameMatch</b></a> ( const char * hint ) const</li>
|
||
|
</ul>
|
||
|
<h2>Static Public Members</h2>
|
||
|
<ul>
|
||
|
<li class=fn>QTextCodec * <a href="#loadCharmap"><b>loadCharmap</b></a> ( QIODevice * iod )</li>
|
||
|
<li class=fn>QTextCodec * <a href="#loadCharmapFile"><b>loadCharmapFile</b></a> ( QString filename )</li>
|
||
|
<li class=fn>QTextCodec * <a href="#codecForMib"><b>codecForMib</b></a> ( int mib )</li>
|
||
|
<li class=fn>QTextCodec * <a href="#codecForName"><b>codecForName</b></a> ( const char * name, int accuracy = 0 )</li>
|
||
|
<li class=fn>QTextCodec * <a href="#codecForContent"><b>codecForContent</b></a> ( const char * chars, int len )</li>
|
||
|
<li class=fn>QTextCodec * <a href="#codecForIndex"><b>codecForIndex</b></a> ( int 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 * 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 * 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 * 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 char * name, const char * 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-><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-><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-><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-><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>& uc, int& 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>& ) 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> 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 <a href="qstring.html">QString</a> & 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> * <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> * <a name="codecForContent"></a>QTextCodec::codecForContent ( const char * chars, int 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> * <a name="codecForIndex"></a>QTextCodec::codecForIndex ( int 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> * <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> * <a name="codecForMib"></a>QTextCodec::codecForMib ( int 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> * <a name="codecForName"></a>QTextCodec::codecForName ( const char * name, int 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> * <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 <a href="qstring.html">QString</a> & uc, int & 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 <a href="qstring.html">QString</a> & 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 char * chars, int 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 char * 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> * <a name="loadCharmap"></a>QTextCodec::loadCharmap ( <a href="qiodevice.html">QIODevice</a> * iod )<tt> [static]</tt>
|
||
|
</h3>
|
||
|
Reads a POSIX2 charmap definition from <em>iod</em>.
|
||
|
The parser recognizes the following lines:
|
||
|
<p> <font name="sans">
|
||
|
<code_set_name> <i>name</i></br>
|
||
|
<escape_char> <i>character</i></br>
|
||
|
% alias <i>alias</i></br>
|
||
|
CHARMAP</br>
|
||
|
<<i>token</i>> /x<i>hexbyte</i> <U<i>unicode</i>> ...</br>
|
||
|
<<i>token</i>> /d<i>decbyte</i> <U<i>unicode</i>> ...</br>
|
||
|
<<i>token</i>> /<i>octbyte</i> <U<i>unicode</i>> ...</br>
|
||
|
<<i>token</i>> /<i>any</i>/<i>any</i>... <U<i>unicode</i>> ...</br>
|
||
|
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> * <a name="loadCharmapFile"></a>QTextCodec::loadCharmapFile ( <a href="qstring.html">QString</a> 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> * <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> * <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> * 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> * 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> * 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 char * name, const char * 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 char * chars, int 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 <a href="qbytearray.html">QByteArray</a> & a, int 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 <a href="qbytearray.html">QByteArray</a> & 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 <a href="qcstring.html">QCString</a> & a, int 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 <a href="qcstring.html">QCString</a> & 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 char * 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 © 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 © 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>
|