From e436b40d56d24ead6a77d66f2e34d0e9e3e918fb Mon Sep 17 00:00:00 2001 From: Alex Spataru Date: Tue, 7 Jan 2025 22:00:22 -0500 Subject: [PATCH] Fix MSVC build error --- app/CMakeLists.txt | 2 +- app/rcc/messages/Acknowledgements.txt | 28 --------- app/src/IO/Console.cpp | 67 ++++++++++++++++---- app/src/IO/HexDump.h | 89 --------------------------- 4 files changed, 56 insertions(+), 130 deletions(-) delete mode 100644 app/src/IO/HexDump.h diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index 91c616e3..111cf63c 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -149,7 +149,7 @@ set(HEADERS src/IO/CircularBuffer.h src/IO/FileTransmission.h src/IO/FrameReader.h - src/IO/HexDump.h + src/JSON/FrameParser.h src/JSON/ProjectModel.h src/JSON/Frame.h diff --git a/app/rcc/messages/Acknowledgements.txt b/app/rcc/messages/Acknowledgements.txt index 233699d1..140b7903 100644 --- a/app/rcc/messages/Acknowledgements.txt +++ b/app/rcc/messages/Acknowledgements.txt @@ -100,34 +100,6 @@ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -## hexdump - -Copyright (c) 2014, Zac Bergquist -All rights reserved. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. -2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. -3. Neither the name of the copyright holder nor the names of its contributors - may be used to endorse or promote products derived from this software without - specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - ## QSimpleUpdater Copyright (c) 2014-2025 Alex Spataru . diff --git a/app/src/IO/Console.cpp b/app/src/IO/Console.cpp index c615f697..c9a33759 100644 --- a/app/src/IO/Console.cpp +++ b/app/src/IO/Console.cpp @@ -24,7 +24,6 @@ #include "IO/Manager.h" #include "IO/Console.h" -#include "IO/HexDump.h" #include "Misc/Translator.h" /** @@ -557,19 +556,25 @@ QString IO::Console::dataToString(const QByteArray &data) QString IO::Console::plainTextStr(const QByteArray &data) { // Filter out non-printable characters, but keep line breaks - QByteArray filteredData; + QString filteredData; filteredData.reserve(data.size()); for (int i = 0; i < data.size(); ++i) { - unsigned char c = static_cast(data[i]); - if (std::isprint(c) || std::isspace(c) || c == '\r' || c == '\n') - filteredData.append(c); + bool printable = false; + printable |= (data[i] == '\r'); + printable |= (data[i] == '\n'); + printable |= std::isprint(static_cast(data[i])); + printable |= std::iscntrl(static_cast(data[i])); + printable |= std::isspace(static_cast(data[i])); + + if (printable) + filteredData += data[i]; else - filteredData.append('.'); + filteredData += '.'; } - // Convert the filtered data to QString using UTF-8 as default - return QString::fromUtf8(filteredData); + // Return the filtered data + return filteredData; } /** @@ -577,10 +582,48 @@ QString IO::Console::plainTextStr(const QByteArray &data) */ QString IO::Console::hexadecimalStr(const QByteArray &data) { - std::ostringstream oss; + // Initialize parameters + QString out; + constexpr auto rowSize = 16; - Hexdump dump(data.data(), data.size()); - oss << dump << "\n"; + // Print hexadecimal row by row + for (int i = 0; i < data.length(); i += rowSize) + { + // Add offset to output + out += QStringLiteral("0x%1: ").arg(i, 6, 16, QLatin1Char('0')); - return QString::fromStdString(oss.str()); + // Print hexadecimal bytes + for (int j = 0; j < rowSize; ++j) + { + if (i + j < data.length()) + { + out += QStringLiteral("%1 ").arg( + static_cast(data[i + j]), 2, 16, QLatin1Char('0')); + } + + else + out += QStringLiteral(" "); + } + + // Add ASCII representation + out += QStringLiteral(" | "); + for (int j = 0; j < rowSize; ++j) + { + if (i + j < data.length()) + { + char c = data[i + j]; + if (std::isprint(static_cast(c))) + out += c; + else + out += '.'; + } + } + + // Add line break + out += "\n"; + } + + // Add additional line break & return data + out += "\n"; + return out; } diff --git a/app/src/IO/HexDump.h b/app/src/IO/HexDump.h deleted file mode 100644 index 54162406..00000000 --- a/app/src/IO/HexDump.h +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (c) 2014, Zac Bergquist - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#pragma once - -#include -#include -#include - -template -struct CustomHexdump -{ - CustomHexdump(const void *data, unsigned length) - : mData(static_cast(data)) - , mLength(length) - { - } - const unsigned char *mData; - const unsigned mLength; -}; - -template -std::ostream &operator<<(std::ostream &out, - const CustomHexdump &dump) -{ - out.fill('0'); - for (int i = 0; i < dump.mLength; i += RowSize) - { - out << "0x" << std::setw(6) << std::hex << i << ": "; - for (int j = 0; j < RowSize; ++j) - { - if (i + j < dump.mLength) - { - out << std::hex << std::setw(2) << static_cast(dump.mData[i + j]) - << " "; - } - - else - out << " "; - } - - out << " "; - if (ShowAscii) - { - for (int j = 0; j < RowSize; ++j) - { - if (i + j < dump.mLength) - { - if (std::isprint(dump.mData[i + j])) - out << static_cast(dump.mData[i + j]); - else - out << "."; - } - } - } - - out << std::endl; - } - - return out; -} - -typedef CustomHexdump<16, true> Hexdump;