From 51dad30fc008456fe11a010b56f76440c0a0d444 Mon Sep 17 00:00:00 2001 From: Chih-Hsuan Yen Date: Sun, 4 Feb 2018 02:51:43 +0800 Subject: [PATCH] Use wstring in TerminalCharacterDecoder for UCS-4 compatibility PlainTextDecoder is used in at least clipboard data handling HTMLDecoder is not used for now --- lib/TerminalCharacterDecoder.cpp | 42 ++++++++++++++++---------------- lib/TerminalCharacterDecoder.h | 4 +-- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/lib/TerminalCharacterDecoder.cpp b/lib/TerminalCharacterDecoder.cpp index b267b37..4cf458b 100644 --- a/lib/TerminalCharacterDecoder.cpp +++ b/lib/TerminalCharacterDecoder.cpp @@ -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') - text.append(">"); + text.append(L">"); else - text.append(ch); + text.push_back(ch); } else { - text.append(" "); //HTML truncates multiple spaces, so use a space marker instead + text.append(L" "); //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("
"); + text.append(L"
"); - *_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("").arg(style) ); + text.append( QString("").arg(style).toStdWString() ); } -void HTMLDecoder::closeSpan(QString& text) +void HTMLDecoder::closeSpan(std::wstring& text) { - text.append(""); + text.append(L""); } void HTMLDecoder::setColorTable(const ColorEntry* table) diff --git a/lib/TerminalCharacterDecoder.h b/lib/TerminalCharacterDecoder.h index 75d40c3..a73e9a1 100644 --- a/lib/TerminalCharacterDecoder.h +++ b/lib/TerminalCharacterDecoder.h @@ -133,8 +133,8 @@ public: virtual void end(); private: - void openSpan(QString& text , const QString& style); - void closeSpan(QString& text); + void openSpan(std::wstring& text , const QString& style); + void closeSpan(std::wstring& text); QTextStream* _output; const ColorEntry* _colorTable;