mirror of
https://github.com/Serial-Studio/Serial-Studio.git
synced 2025-01-23 11:32:53 +08:00
Fix MSVC build error
This commit is contained in:
parent
ca20ed2092
commit
e436b40d56
@ -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
|
||||
|
@ -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 <https://aspatru.com>.
|
||||
|
@ -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<unsigned char>(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<unsigned char>(data[i]));
|
||||
printable |= std::iscntrl(static_cast<unsigned char>(data[i]));
|
||||
printable |= std::isspace(static_cast<unsigned char>(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<unsigned char>(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<unsigned char>(c)))
|
||||
out += c;
|
||||
else
|
||||
out += '.';
|
||||
}
|
||||
}
|
||||
|
||||
// Add line break
|
||||
out += "\n";
|
||||
}
|
||||
|
||||
// Add additional line break & return data
|
||||
out += "\n";
|
||||
return out;
|
||||
}
|
||||
|
@ -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 <cctype>
|
||||
#include <iomanip>
|
||||
#include <ostream>
|
||||
|
||||
template<unsigned RowSize, bool ShowAscii>
|
||||
struct CustomHexdump
|
||||
{
|
||||
CustomHexdump(const void *data, unsigned length)
|
||||
: mData(static_cast<const unsigned char *>(data))
|
||||
, mLength(length)
|
||||
{
|
||||
}
|
||||
const unsigned char *mData;
|
||||
const unsigned mLength;
|
||||
};
|
||||
|
||||
template<unsigned RowSize, bool ShowAscii>
|
||||
std::ostream &operator<<(std::ostream &out,
|
||||
const CustomHexdump<RowSize, ShowAscii> &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<int>(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<char>(dump.mData[i + j]);
|
||||
else
|
||||
out << ".";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
out << std::endl;
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
typedef CustomHexdump<16, true> Hexdump;
|
Loading…
x
Reference in New Issue
Block a user