/*! \reimp */ QString QTsciiCodec::toUnicode(const char* chars, int len) const { QString result; for (int i = 0; i < len; i++) { uchar ch = chars[i]; if ( ch < 0x80 ) { // ASCII result += QChar(ch); } else if ( IsTSCIIChar(ch) ) { // TSCII uint s[3]; uint u = qt_TSCIIToUnicode(ch, s); uint *p = s; while ( u-- ) { uint c = *p++; result += QValidChar(c); } } else { // Invalid result += QChar::replacement; } } return result; }
/*! Converts the first \a len characters in \a chars from this encoding to Unicode, and returns the result in a QString. The \a state contains some conversion flags, and is used by the codec to maintain state information. */ QString QTsciiCodec::convertToUnicode(const char* chars, int len, ConverterState *state) { ushort replacement = QChar::ReplacementCharacter; if (state) { if (state->flags & ConvertInvalidToNull) replacement = QChar::Null; } int invalid = 0; QString result; result.resize((len<<1)+len+1); ushort* cursor = result.data(); for (int i = 0; i < len; i++) { uchar ch = chars[i]; if (ch < 0x80) { // ASCII *cursor++ = ushort(ch); } else if (IsTSCIIChar(ch)) { // TSCII uint s[3]; uint u = qt_TSCIIToUnicode(ch, s); uint *p = s; while (u--) { uint c = *p++; if (c) *cursor++ = ushort(c); else { *cursor++ = replacement; ++invalid; } } } else { // Invalid *cursor++ = replacement; ++invalid; } } result.resize(cursor - result.constData()); if (state) { state->invalidChars += invalid; } return result; }
/*! Converts the first \a len characters in \a chars from this encoding to Unicode, and returns the result in a QString. The \a state contains some conversion flags, and is used by the codec to maintain state information. */ QString QTsciiCodec::convertToUnicode(const char* chars, int len, ConverterState *state) const { QChar replacement = QChar::ReplacementCharacter; if (state) { if (state->flags & ConvertInvalidToNull) replacement = QChar::Null; } int invalid = 0; QString result; for (int i = 0; i < len; i++) { uchar ch = chars[i]; if (ch < 0x80) { // ASCII result += QLatin1Char(ch); } else if (IsTSCIIChar(ch)) { // TSCII uint s[3]; uint u = qt_TSCIIToUnicode(ch, s); uint *p = s; while (u--) { uint c = *p++; if (c) result += QChar(c); else { result += replacement; ++invalid; } } } else { // Invalid result += replacement; ++invalid; } } if (state) { state->invalidChars += invalid; } return result; }
/*! \reimp */ int QTsciiCodec::heuristicContentMatch(const char* chars, int len) const { int score = 0; for (int i=0; i<len; i++) { uchar ch = chars[i]; // No nulls allowed. if ( !ch ) return -1; if ( ch < 32 && ch != '\t' && ch != '\n' && ch != '\r' ) { // Suspicious if ( score ) score--; } else if ( ch < 0x80 ) { // Inconclusive } else if ( IsTSCIIChar(ch) ) { score++; } else { // Invalid return -1; } } return score; }