Use wstring in TerminalCharacterDecoder for UCS-4 compatibility

PlainTextDecoder is used in at least clipboard data handling
HTMLDecoder is not used for now
This commit is contained in:
Chih-Hsuan Yen
2018-02-04 02:51:43 +08:00
committed by Alf Gaida
parent c648297792
commit 51dad30fc0
2 changed files with 23 additions and 23 deletions
+21 -21
View File
@@ -82,7 +82,7 @@ void PlainTextDecoder::decodeLine(const Character* const characters, int count,
//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;
std::wstring plainText;
plainText.reserve(count);
int outputCount = count;
@@ -93,7 +93,7 @@ void PlainTextDecoder::decodeLine(const Character* const characters, int count,
{
for (int i = count-1 ; i >= 0 ; i--)
{
if ( characters[i].character != ' ' )
if ( characters[i].character != L' ' )
break;
else
outputCount--;
@@ -102,10 +102,10 @@ void PlainTextDecoder::decodeLine(const Character* const characters, int count,
for (int i=0;i<outputCount;)
{
plainText.append( QChar(characters[i].character) );
plainText.push_back( characters[i].character );
i += qMax(1,konsole_wcwidth(characters[i].character));
}
*_output << plainText;
*_output << QString::fromStdWString(plainText);
}
HTMLDecoder::HTMLDecoder() :
@@ -121,23 +121,23 @@ void HTMLDecoder::begin(QTextStream* output)
{
_output = output;
QString text;
std::wstring text;
//open monospace span
openSpan(text,"font-family:monospace");
*output << text;
*output << QString::fromStdWString(text);
}
void HTMLDecoder::end()
{
Q_ASSERT( _output );
QString text;
std::wstring text;
closeSpan(text);
*_output << text;
*_output << QString::fromStdWString(text);
_output = 0;
@@ -149,13 +149,13 @@ void HTMLDecoder::decodeLine(const Character* const characters, int count, LineP
{
Q_ASSERT( _output );
QString text;
std::wstring text;
int spaceCount = 0;
for (int i=0;i<count;i++)
{
QChar ch(characters[i].character);
wchar_t ch(characters[i].character);
//check if appearance of character is different from previous char
if ( characters[i].rendition != _lastRendition ||
@@ -202,7 +202,7 @@ void HTMLDecoder::decodeLine(const Character* const characters, int count, LineP
}
//handle whitespace
if (ch.isSpace())
if (std::iswspace(ch))
spaceCount++;
else
spaceCount = 0;
@@ -213,15 +213,15 @@ void HTMLDecoder::decodeLine(const Character* const characters, int count, LineP
{
//escape HTML tag characters and just display others as they are
if ( ch == '<' )
text.append("&lt;");
text.append(L"&lt;");
else if (ch == '>')
text.append("&gt;");
text.append(L"&gt;");
else
text.append(ch);
text.push_back(ch);
}
else
{
text.append("&nbsp;"); //HTML truncates multiple spaces, so use a space marker instead
text.append(L"&nbsp;"); //HTML truncates multiple spaces, so use a space marker instead
}
}
@@ -231,18 +231,18 @@ void HTMLDecoder::decodeLine(const Character* const characters, int count, LineP
closeSpan(text);
//start new line
text.append("<br>");
text.append(L"<br>");
*_output << text;
*_output << QString::fromStdWString(text);
}
void HTMLDecoder::openSpan(QString& text , const QString& style)
void HTMLDecoder::openSpan(std::wstring& text , const QString& style)
{
text.append( QString("<span style=\"%1\">").arg(style) );
text.append( QString("<span style=\"%1\">").arg(style).toStdWString() );
}
void HTMLDecoder::closeSpan(QString& text)
void HTMLDecoder::closeSpan(std::wstring& text)
{
text.append("</span>");
text.append(L"</span>");
}
void HTMLDecoder::setColorTable(const ColorEntry* table)