@ -69,12 +69,6 @@ void PlainTextDecoder::decodeLine(const Character *const characters, int count,
// TODO should we ignore or respect the LINE_WRAPPED line property?
// note: we build up a QString and send it to the text stream rather writing into the text
// stream a character at a time because it is more efficient.
//(since QTextStream always deals with QStrings internally anyway)
QString plainText ;
plainText . reserve ( count ) ;
// If we should remove leading whitespace find the first non-space character
int start = 0 ;
if ( ! _includeLeadingWhitespace ) {
@ -109,14 +103,19 @@ void PlainTextDecoder::decodeLine(const Character *const characters, int count,
}
}
// note: we build up a QVector<uint> and send it to the text stream transformed into a QString
// rather than writing into the text stream a character at a time because it is more efficient.
//(since QTextStream always deals with QStrings internally anyway)
QVector < uint > characterBuffer ;
characterBuffer . reserve ( count ) ;
for ( int i = start ; i < outputCount ; ) {
if ( ( characters [ i ] . rendition & RE_EXTENDED_CHAR ) ! = 0 ) {
ushort extendedCharLength = 0 ;
const uint * chars = ExtendedCharTable : : instance . lookupExtendedChar ( characters [ i ] . character , extendedCharLength ) ;
if ( chars ! = nullptr ) {
const QString s = QString : : fromUcs4 ( chars , extendedCharLength ) ;
plainText . append ( s ) ;
i + = qMax ( 1 , Character : : stringWidth ( s ) ) ;
characterBuffer . insert ( characterBuffer . end ( ) , extendedCharLength , * chars ) ;
i + = qMax ( 1 , Character : : stringWidth ( chars , extendedCharLength ) ) ;
} else {
+ + i ;
}
@ -129,12 +128,12 @@ void PlainTextDecoder::decodeLine(const Character *const characters, int count,
// lost in some situation. One typical example is copying the result
// of `dialog --infobox "qwe" 10 10` .
if ( characters [ i ] . isRealCharacter | | i < = realCharacterGuard ) {
plainText . append ( QString : : fromUcs4 ( & characters [ i ] . character , 1 ) ) ;
characterBuffer . append ( characters [ i ] . character ) ;
i + = qMax ( 1 , characters [ i ] . width ( ) ) ;
} else {
+ + i ; // should we 'break' directly here?
}
}
}
* _output < < plainText ;
* _output < < QString : : fromUcs4 ( characterBuffer . data ( ) , characterBuffer . size ( ) ) ;
}