Provides conversion between text encodings. More...
#include <qtextcodec.h>
Inherited by QEucJpCodec, QEucKrCodec, QGbkCodec, QJisCodec, QSjisCodec and QTsciiCodec.
By making objects of subclasses of QTextCodec, support for new text encodings can be added to Qt.
The abstract virtual functions describe the encoder to the system and the coder is used as required in the different text file formats supported QTextStream and, under X11 for the locale-specific character input and output (under Windows NT codecs are not needed for GUI I/O since the system works with Unicode already, and Windows 95/98 has built-in convertors for the 8-bit local encoding).
More recently created QTextCodec objects take precedence over earlier ones.
To add support for another 8-bit encoding to Qt, make a subclass or QTextCodec and implement at least the following methods:
const
char* name() const
int
mibEnum() const
QTextDecoder*
makeDecoder() const
QString
toUnicode(const char* chars, int len) const
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:
QTextEncoder*
makeEncoder() const
QCString
fromUnicode(const QString& uc, int& lenInOut ) const;
Finally, you must implement:
int
heuristicContentMatch(const char* chars, int len) const
A QTextCodec subclass might have improved performance if you also re-implement:
bool
canEncode( QChar ) const
bool
canEncode( const QString& ) const
int
heuristicNameMatch(const char* hint) const
[protected]
Constructs a QTextCodec, making it of highest precedence. The QTextCodec should always be constructed on the heap (with new), and once constructed it becomes the responsibility of Qt to delete it (which is done at QApplication destruction).
[virtual]
Destructs the QTextCodec. Note that you should not delete codecs yourself - once created they become the responsibility of Qt to delete.
[virtual]
Returns TRUE if the unicode character ch can be fully encoded with this codec. The default implementation tests if the result of toUnicode(fromUnicode(ch)) is the original ch. Subclasses may be able to improve the efficiency.
[virtual]
Returns TRUE if the unicode string s can be fully encoded with this codec. The default implementation tests if the result of toUnicode(fromUnicode(s)) is the original s. Subclasses may be able to improve the efficiency.
[static]
Searches all installed QTextCodec objects, returning the one which most recognizes the given content. May return 0.
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.
See also heuristicContentMatch().
[static]
Returns the QTextCodec i places from the more recently inserted, or NULL if there is no such QTextCodec. Thus, codecForIndex(0) returns the most recently created QTextCodec.
[static]
Returns a pointer to the codec most suitable for this locale.
[static]
Returns the QTextCodec which matches the MIBenum mib.
[static]
Searches all installed QTextCodec objects, returning the one which best matches given name. Returns NULL if no codec has a match closeness above accuracy.
See also heuristicNameMatch().
[static]
Deletes all the created codecs.
Warning: Do not call this function.
QApplication calls this 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.
If you are using the utility classes (like QString) but not using QApplication, calling this function at the very end of your application can be helpful to chasing down memory leaks, as QTextCodec objects will not show up.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
[static]
Reads a POSIX2 charmap definition from iod. The parser recognizes the following lines:
<code_set_name> name <escape_char> character % alias alias CHARMAP <token> /xhexbyte <Uunicode> ... <token> /ddecbyte <Uunicode> ... <token> /octbyte <Uunicode> ... <token> /any/any... <Uunicode> ... END CHARMAP
The resulting QTextCodec is returned (and also added to the global list of codecs). The name() of the result is taken from the code_set_name.
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 in memory shared by all applications simultaneously using Qt.
See also loadCharmapFile().
[static]
A convenience function for loadCharmap().
[static]
Returns a string representing the current language.
[virtual]
Creates a QTextEncoder which stores enough state to encode chunks of Unicode data as char* data. The default implementation creates a stateless encoder, which is sufficient for only the simplest encodings where each Unicode character corresponds to exactly one char.
The caller is responsible for deleting the returned object.
[static protected]
A simple utility function for heuristicNameMatch() - it does some very minor character-skipping so that almost-exact matches score high.
[virtual]
Subclasses of QTextCodec must reimplement this function or makeDecoder(). It converts the first len characters of chars to Unicode.
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 must reimplement one function or the other to avoid infinite recursion.
Reimplemented in QEucJpCodec, QEucKrCodec, QJisCodec, QSjisCodec, QGbkCodec and QTsciiCodec.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Search the documentation, FAQ, qt-interest archive and more (uses
www.trolltech.com):
This file is part of the Qt toolkit, copyright © 1995-2000 Trolltech, all rights reserved.
Copyright © 2000 Trolltech | Trademarks | Qt version 2.2.1
|