diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-17 15:00:52 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-17 15:00:52 +0000 |
commit | 0f157e7d6c4be48f213ea022cb2d6d1316c423c8 (patch) | |
tree | ff4ad271b50a39e23d5a50a54f4bff37342cdc1c /ui/qt/utils | |
parent | Adding debian version 4.2.4-1. (diff) | |
download | wireshark-0f157e7d6c4be48f213ea022cb2d6d1316c423c8.tar.xz wireshark-0f157e7d6c4be48f213ea022cb2d6d1316c423c8.zip |
Merging upstream version 4.2.5.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'ui/qt/utils')
-rw-r--r-- | ui/qt/utils/data_printer.cpp | 48 |
1 files changed, 41 insertions, 7 deletions
diff --git a/ui/qt/utils/data_printer.cpp b/ui/qt/utils/data_printer.cpp index a96e1ed4..3c3e910a 100644 --- a/ui/qt/utils/data_printer.cpp +++ b/ui/qt/utils/data_printer.cpp @@ -38,13 +38,45 @@ void DataPrinter::toClipboard(DataPrinter::DumpType type, IDataPrintable * print // Beginning quote clipboard_text += QString("\""); for (int i = 0; i < printData.length(); i++) { - /* ASCII printable */ - int ch = printData[i]; - if (ch >= 32 && ch <= 126) { - clipboard_text += QChar(ch); - } - else { - clipboard_text += QString("\\x%1").arg((uint8_t) printData[i], 2, 16, QChar('0')); + // backslash and double quote are printable but + // must be escaped in a C string. + char ch = printData[i]; + switch (ch) { + case '\"': + clipboard_text += QString("\\\""); + break; + case '\\': + clipboard_text += QString("\\\\"); + break; + case '\a': + clipboard_text += QString("\\a"); + break; + case '\b': + clipboard_text += QString("\\b"); + break; + case '\f': + clipboard_text += QString("\\f"); + break; + case '\n': + clipboard_text += QString("\\n"); + break; + case '\r': + clipboard_text += QString("\\r"); + break; + case '\t': + clipboard_text += QString("\\t"); + break; + case '\v': + clipboard_text += QString("\\v"); + break; + default: + // ASCII printable + if (ch >= 32 && ch <= 126) { + clipboard_text += QChar(ch); + } + else { + clipboard_text += QString("\\%1").arg((uint8_t) printData[i], 3, 8, QChar('0')); + } } } // End quote @@ -57,6 +89,8 @@ void DataPrinter::toClipboard(DataPrinter::DumpType type, IDataPrintable * print case DP_PrintableText: for (int i = 0; i < printData.length(); i++) { QChar ch(printData[i]); + // This interprets ch as Latin-1. We might want to use ASCII + // printable only. if (ch.isSpace() || ch.isPrint()) { clipboard_text += ch; } |