?? qtextcodec.cpp
字號:
the preferred mime name for the codec if defined, otherwise its name.*//*! \fn int QTextCodec::mibEnum() const Subclasses of QTextCodec must reimplement this function. It returns the MIBenum (see \link http://www.iana.org/assignments/character-sets the IANA character-sets encoding file\endlink for more information). It is important that each QTextCodec subclass returns the correct unique value for this function.*//*! Subclasses can return a number of aliases for the codec in question. Standard aliases for codecs can be found in the \link http://www.iana.org/assignments/character-sets IANA character-sets encoding file\endlink.*/QList<QByteArray> QTextCodec::aliases() const{ return QList<QByteArray>();}/*! \fn QString QTextCodec::convertToUnicode(const char *chars, int len, ConverterState *state) const QTextCodec subclasses must reimplement this function. Converts the first \a len characters of \a chars from the encoding of the subclass to Unicode, and returns the result in a QString. \a state can be 0, in which case the conversion is stateless and default conversion rules should be used. If state is not 0, the codec should save the state after the conversion in \a state, and adjust the remainingChars and invalidChars members of the struct.*//*! \fn QByteArray QTextCodec::convertFromUnicode(const QChar *input, int number, ConverterState *state) const QTextCodec subclasses must reimplement this function. Converts the first \a number of characters from the \a input array from Unicode to the encoding of the subclass, and returns the result in a QByteArray. \a state can be 0 in which case the conversion is stateless and default conversion rules should be used. If state is not 0, the codec should save the state after the conversion in \a state, and adjust the remainingChars and invalidChars members of the struct.*//*! Creates a QTextDecoder which stores enough state to decode chunks of \c{char *} data to create chunks of Unicode data. The caller is responsible for deleting the returned object.*/QTextDecoder* QTextCodec::makeDecoder() const{ return new QTextDecoder(this);}/*! Creates a QTextEncoder which stores enough state to encode chunks of Unicode data as \c{char *} data. The caller is responsible for deleting the returned object.*/QTextEncoder* QTextCodec::makeEncoder() const{ return new QTextEncoder(this);}/*! \fn QByteArray QTextCodec::fromUnicode(const QChar *input, int number, ConverterState *state) const Converts the first \a number of characters from the \a input array from Unicode to the encoding of this codec, and returns the result in a QByteArray. The \a state of the convertor used is updated.*//*! Converts \a str from Unicode to the encoding of this codec, and returns the result in a QByteArray.*/QByteArray QTextCodec::fromUnicode(const QString& str) const{ return convertFromUnicode(str.constData(), str.length(), 0);}/*! \fn QString QTextCodec::toUnicode(const char *input, int size, ConverterState *state) const Converts the first \a size characters from the \a input from the encoding of this codec to Unicode, and returns the result in a QString. The \a state of the convertor used is updated.*//*! Converts \a a from the encoding of this codec to Unicode, and returns the result in a QString.*/QString QTextCodec::toUnicode(const QByteArray& a) const{ return convertToUnicode(a.constData(), a.length(), 0);}/*! Returns true if the Unicode character \a ch can be fully encoded with this codec; otherwise returns false.*/bool QTextCodec::canEncode(QChar ch) const{ ConverterState state; state.flags = ConvertInvalidToNull; convertFromUnicode(&ch, 1, &state); return (state.invalidChars == 0);}/*! \overload \a s contains the string being tested for encode-ability.*/bool QTextCodec::canEncode(const QString& s) const{ ConverterState state; state.flags = ConvertInvalidToNull; convertFromUnicode(s.constData(), s.length(), &state); return (state.invalidChars == 0);#ifdef QT3_SUPPORT/*! Returns a string representing the current language and sublanguage, e.g. "pt" for Portuguese, or "pt_br" for Portuguese/Brazil. \sa QLocale*/const char *QTextCodec::locale(){ static char locale[6]; QByteArray l = QLocale::system().name().toLatin1(); int len = qMin(l.length(), 5); memcpy(locale, l.constData(), len); locale[len] = '\0'; return locale;}/*! \overload*/QByteArray QTextCodec::fromUnicode(const QString& uc, int& lenInOut) const{ QByteArray result = convertFromUnicode(uc.constData(), lenInOut, 0); lenInOut = result.length(); return result;}/*! \overload \a a contains the source characters; \a len contains the number of characters in \a a to use.*/QString QTextCodec::toUnicode(const QByteArray& a, int len) const{ len = qMin(a.size(), len); return convertToUnicode(a.constData(), len, 0);}#endif/*! \overload \a chars contains the source characters.*/QString QTextCodec::toUnicode(const char *chars) const{ int len = qstrlen(chars); return convertToUnicode(chars, len, 0);}/*! \class QTextEncoder \brief The QTextEncoder class provides a state-based encoder. \reentrant \ingroup i18n A text encoder converts text from Unicode into an encoded text format using a specific codec. The encoder converts Unicode into another format, remembering any state that is required between calls. \sa QTextCodec::makeEncoder(), QTextDecoder*//*! \fn QTextEncoder::QTextEncoder(const QTextCodec *codec) Constructs a text encoder for the given \a codec.*//*! Destroys the encoder.*/QTextEncoder::~QTextEncoder(){}/*! Converts the Unicode string \a str into an encoded QByteArray.*/QByteArray QTextEncoder::fromUnicode(const QString& str){ QByteArray result = c->fromUnicode(str.constData(), str.length(), &state); return result;}/*! \overload Converts \a len characters (not bytes) from \a uc, and returns the result in a QByteArray.*/QByteArray QTextEncoder::fromUnicode(const QChar *uc, int len){ QByteArray result = c->fromUnicode(uc, len, &state); return result;}#ifdef QT3_SUPPORT/*! \overload Converts \a lenInOut characters (not bytes) from \a uc, and returns the result in a QByteArray. The number of characters read is returned in the \a lenInOut parameter.*/QByteArray QTextEncoder::fromUnicode(const QString& uc, int& lenInOut){ QByteArray result = c->fromUnicode(uc.constData(), lenInOut, &state); lenInOut = result.length(); return result;}#endif/*! \class QTextDecoder \brief The QTextDecoder class provides a state-based decoder. \reentrant \ingroup i18n A text decoder converts text from an encoded text format into Unicode using a specific codec. The decoder converts text in this format into Unicode, remembering any state that is required between calls. \sa QTextCodec::makeDecoder(), QTextEncoder*//*! \fn QTextDecoder::QTextDecoder(const QTextCodec *codec) Constructs a text decoder for the given \a codec.*//*! Destroys the decoder.*/QTextDecoder::~QTextDecoder(){}/*! \fn QString QTextDecoder::toUnicode(const char *chars, int len) Converts the first \a len bytes in \a chars to Unicode, returning the result. If not all characters are used (e.g. if only part of a multi-byte encoding is at the end of the characters), the decoder remembers enough state to continue with the next call to this function.*/QString QTextDecoder::toUnicode(const char *chars, int len){ return c->toUnicode(chars, len, &state);}/*! \overload Converts the bytes in the byte array specified by \a ba to Unicode and returns the result.*/QString QTextDecoder::toUnicode(const QByteArray &ba){ return c->toUnicode(ba.constData(), ba.length(), &state);}/*! \fn QTextCodec* QTextCodec::codecForTr() Returns the codec used by QObject::tr() on its argument. If this function returns 0 (the default), tr() assumes Latin-1. \sa setCodecForTr()*//*! \fn void QTextCodec::setCodecForTr(QTextCodec *c) \nonreentrant Sets the codec used by QObject::tr() on its argument to \a c. If \a c is 0 (the default), tr() assumes Latin-1. 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: \code int main(int argc, char *argv[]) { QApplication app(argc, argv); QTextCodec::setCodecForTr(QTextCodec::codecForName("eucKR")); ... } \endcode Note that this is not the way to select the encoding that the \e user 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 internationalization, see \l{Internationalization with Qt}. \sa codecForTr(), setCodecForCStrings()*//*! \fn QTextCodec* QTextCodec::codecForCStrings() Returns the codec used by QString to convert to and from \c{const char *} and QByteArrays. If this function returns 0 (the default), QString assumes Latin-1. \sa setCodecForCStrings()*//*! \fn void QTextCodec::setCodecForCStrings(QTextCodec *codec) \nonreentrant Sets the codec used by QString to convert to and from \c{const char *} and QByteArrays. If the \a codec is 0 (the default), QString assumes Latin-1. \warning 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. To avoid undesirable side-effects, we recommend avoiding such codecs with setCodecsForCString(). \sa codecForCStrings(), setCodecForTr()*//*! \internal*/{ // determine charset int mib = 4; // Latin-1 int pos; QTextCodec *c = 0; if (ba.size() > 1 && (((uchar)ba[0] == 0xfe && (uchar)ba[1] == 0xff) || ((uchar)ba[0] == 0xff && (uchar)ba[1] == 0xfe))) { mib = 1015; // utf16 } else if (ba.size() > 2 && (uchar)ba[0] == 0xef && (uchar)ba[1] == 0xbb && (uchar)ba[2] == 0xbf) { mib = 106; // utf-8 } else { QByteArray header = ba.left(512).toLower(); if ((pos = header.indexOf("http-equiv=")) != -1) { pos = header.indexOf("charset=", pos) + int(strlen("charset=")); if (pos != -1) { int pos2 = header.indexOf('\"', pos+1); QByteArray cs = header.mid(pos, pos2-pos); // qDebug("found charset: %s", cs.data()); c = QTextCodec::codecForName(cs); } } } if (!c) c = QTextCodec::codecForMib(mib); return c;}/*! \fn QTextCodec *QTextCodec::codecForContent(const char *str, int size) This functionality is no longer provided by Qt. This compatibility function always returns a null pointer.*//*! \fn QTextCodec *QTextCodec::codecForName(const char *hint, int accuracy) Use the codecForName(const QByteArray &) overload instead.*//*! \fn QTextCodec *QTextCodec::codecForIndex(int i) Use availableCodecs() or availableMibs() instead and iterate through the resulting list.*//*! \fn QByteArray QTextCodec::mimeName() const Use name() instead.*/#endif // QT_NO_TEXTCODEC
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -