Esempio n. 1
0
/*! \reimp */
QCString QTsciiCodec::fromUnicode(const QString& uc, int& lenInOut) const
{
    int l = QMIN((int)uc.length(), lenInOut);
    int rlen = l+1;
    QCString rstr(rlen);
    uchar* cursor = (uchar*)rstr.data();
    for (int i = 0; i < l; i++) {
	QChar ch = uc[i];
	uchar j;
	if ( ch.row() == 0x00 && ch.cell() < 0x80 ) {
	    // ASCII
	    j = ch.cell();
	} else if ((j = qt_UnicodeToTSCII(uc[i].unicode(),
					  uc[i + 1].unicode(),
					  uc[i + 2].unicode()))) {
	    // We have to check the combined chars first!
	    i += 2;
	} else if ((j = qt_UnicodeToTSCII(uc[i].unicode(),
					  uc[i + 1].unicode(), 0))) {
	    i++;
	} else if ((j = qt_UnicodeToTSCII(uc[i].unicode(), 0, 0))) {
	} else {
	    // Error
	    j = '?';	// unknown char
	}
	*cursor++ = j;
    }
    lenInOut = cursor - (uchar*)rstr.data();
    *cursor = 0;
    return rstr;
}
Esempio n. 2
0
/*!
    Converts the first \a len characters in \a uc from Unicode to this
    encoding, and returns the result in a byte array. The \a state contains
    some conversion flags, and is used by the codec to maintain state
    information.
*/
QByteArray QTsciiCodec::convertFromUnicode(const ushort *uc, int len, ConverterState *state)
{
    char replacement = '?';
    if (state) {
        if (state->flags & ConvertInvalidToNull)
            replacement = 0;
    }
    int invalid = 0;

    QByteArray rstr;
    rstr.resize(len);
    uchar* cursor = (uchar*)rstr.data();
    for (int i = 0; i < len; i++) {
        QChar ch = uc[i];
        uchar j;
        if (ch.row() == 0x00 && ch.cell() < 0x80) {
            // ASCII
            j = ch.cell();
        } else if ((j = qt_UnicodeToTSCII(uc[i],
                                          uc[i + 1],
                                          uc[i + 2]))) {
            // We have to check the combined chars first!
            i += 2;
        } else if ((j = qt_UnicodeToTSCII(uc[i],
                                          uc[i + 1], 0))) {
            i++;
        } else if ((j = qt_UnicodeToTSCII(uc[i], 0, 0))) {
        } else {
            // Error
            j = replacement;
            ++invalid;
        }
        *cursor++ = j;
    }
    rstr.resize(cursor - (const uchar*)rstr.constData());

    if (state) {
        state->invalidChars += invalid;
    }
    return rstr;
}