Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed conversion to std::wstring #554

Merged
merged 1 commit into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/Emulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Emulation::Emulation() :
_keyTranslator(nullptr),
_usesMouse(false),
_bracketedPasteMode(false),
_fromUtf8(QStringEncoder::Utf16)
_toUtf16(QStringConverter::Utf8)
{
// create screens with a default size
_screen[0] = new Screen(40,80);
Expand Down Expand Up @@ -224,9 +224,9 @@ void Emulation::receiveData(const char* text, int length)
* U+10FFFF
* https://unicodebook.readthedocs.io/unicode_encodings.html#surrogates
*/
QString str = QString::fromUtf8(text, length);
auto encoded = _fromUtf8(str);
std::wstring unicodeText = encoded.data.toStdWString();
QByteArray ba(text, length);
QString str = _toUtf16(ba);

This comment was marked as resolved.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you wanted to be a lil more specific here...

They're exactly the same thing.

and if you wanted to be even more explicit,...

Not to this extent ;)

This comment was marked as resolved.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only suggested it because I saw you do this:

Yes, I guessed that :) I did so only to prevent confusion for code readers (we have a decoder now, not an encoder).

std::wstring unicodeText = str.toStdWString();

//send characters to terminal emulator
for (size_t i=0;i<unicodeText.length();i++)
Expand Down
4 changes: 2 additions & 2 deletions lib/Emulation.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
//#include <QPointer>
#include <QTextStream>
#include <QTimer>
#include <QStringEncoder>
#include <QStringDecoder>

#include "qtermwidget_export.h"
#include "KeyboardTranslator.h"
Expand Down Expand Up @@ -494,7 +494,7 @@ private slots:
bool _bracketedPasteMode;
QTimer _bulkTimer1{this};
QTimer _bulkTimer2{this};
QStringEncoder _fromUtf8;
QStringDecoder _toUtf16;
};

}
Expand Down
Loading