qtextcodec.html
来自「QT 下载资料仅供参考」· HTML 代码 · 共 536 行 · 第 1/2 页
HTML
536 行
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><!-- /home/reggie/tmp/qt-3.0-reggie-5401/qt-x11-commercial-3.0.5/src/codecs/qtextcodec.cpp:179 --><html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>QTextCodec Class</title><style type="text/css"><!--h3.fn,span.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><tt>#include <<a href="qtextcodec-h.html">qtextcodec.h</a>></tt><p>Inherited by <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><div class=fn>virtual <a href="#~QTextCodec"><b>~QTextCodec</b></a> ()</div></li><li><div class=fn>virtual const char * <a href="#name"><b>name</b></a> () const = 0</div></li><li><div class=fn>virtual const char * <a href="#mimeName"><b>mimeName</b></a> () const</div></li><li><div class=fn>virtual int <a href="#mibEnum"><b>mibEnum</b></a> () const = 0</div></li><li><div class=fn>virtual QTextDecoder * <a href="#makeDecoder"><b>makeDecoder</b></a> () const</div></li><li><div class=fn>virtual QTextEncoder * <a href="#makeEncoder"><b>makeEncoder</b></a> () const</div></li><li><div class=fn>virtual QString <a href="#toUnicode"><b>toUnicode</b></a> ( const char * chars, int len ) const</div></li><li><div class=fn>virtual QCString <a href="#fromUnicode"><b>fromUnicode</b></a> ( const QString & uc, int & lenInOut ) const</div></li><li><div class=fn>QCString <a href="#fromUnicode-2"><b>fromUnicode</b></a> ( const QString & uc ) const</div></li><li><div class=fn>QString <a href="#toUnicode-2"><b>toUnicode</b></a> ( const QByteArray & a, int len ) const</div></li><li><div class=fn>QString <a href="#toUnicode-3"><b>toUnicode</b></a> ( const QByteArray & a ) const</div></li><li><div class=fn>QString <a href="#toUnicode-4"><b>toUnicode</b></a> ( const QCString & a, int len ) const</div></li><li><div class=fn>QString <a href="#toUnicode-5"><b>toUnicode</b></a> ( const QCString & a ) const</div></li><li><div class=fn>QString <a href="#toUnicode-6"><b>toUnicode</b></a> ( const char * chars ) const</div></li><li><div class=fn>virtual bool <a href="#canEncode"><b>canEncode</b></a> ( QChar ch ) const</div></li><li><div class=fn>virtual bool <a href="#canEncode-2"><b>canEncode</b></a> ( const QString & s ) const</div></li><li><div class=fn>virtual int <a href="#heuristicContentMatch"><b>heuristicContentMatch</b></a> ( const char * chars, int len ) const = 0</div></li><li><div class=fn>virtual int <a href="#heuristicNameMatch"><b>heuristicNameMatch</b></a> ( const char * hint ) const</div></li></ul><h2>Static Public Members</h2><ul><li><div class=fn>QTextCodec * <a href="#loadCharmap"><b>loadCharmap</b></a> ( QIODevice * iod )</div></li><li><div class=fn>QTextCodec * <a href="#loadCharmapFile"><b>loadCharmapFile</b></a> ( QString filename )</div></li><li><div class=fn>QTextCodec * <a href="#codecForMib"><b>codecForMib</b></a> ( int mib )</div></li><li><div class=fn>QTextCodec * <a href="#codecForName"><b>codecForName</b></a> ( const char * name, int accuracy = 0 )</div></li><li><div class=fn>QTextCodec * <a href="#codecForContent"><b>codecForContent</b></a> ( const char * chars, int len )</div></li><li><div class=fn>QTextCodec * <a href="#codecForIndex"><b>codecForIndex</b></a> ( int i )</div></li><li><div class=fn>QTextCodec * <a href="#codecForLocale"><b>codecForLocale</b></a> ()</div></li><li><div class=fn>void <a href="#setCodecForLocale"><b>setCodecForLocale</b></a> ( QTextCodec * c )</div></li><li><div class=fn>void <a href="#deleteAllCodecs"><b>deleteAllCodecs</b></a> ()</div></li><li><div class=fn>const char * <a href="#locale"><b>locale</b></a> ()</div></li></ul><h2>Protected Members</h2><ul><li><div class=fn><a href="#QTextCodec"><b>QTextCodec</b></a> ()</div></li></ul><h2>Static Protected Members</h2><ul><li><div class=fn>int <a href="#simpleHeuristicNameMatch"><b>simpleHeuristicNameMatch</b></a> ( const char * name, const char * hint )</div></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 manysituations you may wish to deal with data that uses a differentencoding. For example, most japanese documents are still stored inShift-JIS or ISO2022, while Russian users often have their documentsin KOI8-R or CP1251.<p> Qt provides a set of QTextCodec classes to help with convertingnon-Unicode formats to and from Unicode. You can also create yourown codec classes (<a href="#subclassing">see later</a>).<p> The supported encodings are:<ul><li> Big5 -- Chinese<li> eucJP -- Japanese<li> eucKR -- Korean<li> GBK -- 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> CP850<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 encodedstring to Unicode. Suppose you have some string encoded in RussianKOI8-R encoding, and want to convert it to Unicode. The simple wayto 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 aseasy:<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 ispossible that a multi-byte character will be split over two chunks.At best this might result in the loss of a character and at worstcause 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 wholedecoding process, as shown below:<p> <pre> QTextCodec *c = QTextCodec::<a href="#codecForName">codecForName</a>( "Shift-JIS" ); <a href="qtextdecoder.html">QTextDecoder</a> *decoder = c-><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 thereforeworks correctly even if a multi-byte character is split betweenchunks.<p> <a name="subclassing"></a><h3> Creating your own Codec class</h3><a name="1"></a><p> By making objects of subclasses of QTextCodec, support fornew text encodings can be added to Qt.<p> More recently created QTextCodec objects take precedenceover earlier ones.<p> You may find it more convenient to make your codec class availableas a plugin; see the <a href="plugins-howto.html">plugin documentation</a> for more details.<p> The abstract virtual functions describe the encoder to thesystem and the coder is used as required in the differenttext file formats supported by <a href="qtextstream.html">QTextStream</a>, and under X11, for thelocale-specific character input and output.<p> To add support for another 8-bit encoding to Qt, make a subclassof 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 precedingbytes. 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 sequenceprefixes 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 abovetwo functions, <em>but they are mutually recursive</em>, so you mustre-implement at least one of them, or both for improved efficiency.<p> For conversion from Unicode to 8-bit encodings, it is rarely necessaryto maintain state. However, two functions similar to the two aboveare used for encoding:<p> <pre> <a href="qtextencoder.html">QTextEncoder</a>* makeEncoder() const </pre> Return a QTextDecoder.<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 ofthe string <em>uc</em>, returning a <a href="qcstring.html">QCString</a> result, and also returningthe <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> charactersfrom <em>chars</em> are in the encoding.<p> A good model for this function is theQWindowsLocalCodec::heuristicContentMatch function found in the Qtsources.<p> A QTextCodec subclass might have improved performance if you alsore-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>.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?