chore: remove unused deskflow::string methods toHex, fromHex, uppercase, fromHexChar

This commit is contained in:
sithlord48
2025-05-12 20:30:24 -04:00
committed by Chris Rizzitello
parent 0309d35aef
commit de583145d0
5 changed files with 2 additions and 173 deletions

View File

@ -10,8 +10,8 @@
#include <algorithm>
#include <cstdarg>
#include <iomanip>
#include <sstream>
#include <vector>
namespace deskflow {
namespace string {
@ -138,92 +138,6 @@ std::string sprintf(const char *fmt, ...)
return result;
}
std::string toHex(const std::string &subject, int width, const char fill)
{
std::stringstream ss;
ss << std::hex;
for (unsigned int i = 0; i < subject.length(); i++) {
ss << std::setw(width) << std::setfill(fill) << (int)(unsigned char)subject[i];
}
return ss.str();
}
std::string toHex(const std::vector<uint8_t> &input, int width, const char fill)
{
std::stringstream ss;
ss << std::hex;
for (unsigned int i = 0; i < input.size(); i++) {
ss << std::setw(width) << std::setfill(fill) << static_cast<int>(input[i]);
}
return ss.str();
}
// clang-format off
int fromHexChar(char c)
{
switch (c) {
case '0': return 0;
case '1': return 1;
case '2': return 2;
case '3': return 3;
case '4': return 4;
case '5': return 5;
case '6': return 6;
case '7': return 7;
case '8': return 8;
case '9': return 9;
case 'a':
case 'A': return 10;
case 'b':
case 'B': return 11;
case 'c':
case 'C': return 12;
case 'd':
case 'D': return 13;
case 'e':
case 'E': return 14;
case 'f':
case 'F': return 15;
default: return -1;
}
return -1;
}
// clang-format on
std::vector<uint8_t> fromHex(const std::string &hexString)
{
std::vector<uint8_t> result;
result.reserve(hexString.size() / 2);
size_t i = 0;
while (i < hexString.size()) {
if (hexString[i] == ':') {
i++;
continue;
}
if (i + 2 > hexString.size()) {
return {}; // uneven character count follows, it's unclear how to interpret it
}
auto high = fromHexChar(hexString[i]);
auto low = fromHexChar(hexString[i + 1]);
if (high < 0 || low < 0) {
return {};
}
result.push_back(high * 16 + low);
i += 2;
}
return result;
}
void uppercase(std::string &subject)
{
std::transform(subject.begin(), subject.end(), subject.begin(), ::toupper);
}
std::string sizeTypeToString(size_t n)
{
std::stringstream ss;

View File

@ -11,7 +11,6 @@
#include "common/Common.h"
#include <string>
#include <vector>
namespace deskflow {
@ -45,42 +44,6 @@ Equivalent to sprintf() except the result is returned as a String.
*/
std::string sprintf(const char *fmt, ...);
//! Convert into hexdecimal
/*!
Convert each character in \c subject into hexdecimal form with \c width
Return a new hexString
*/
std::string toHex(const std::string &subject, int width, const char fill = '0');
/**
* @brief toHex Convert each value in input into a hex string
* @param input vector of uint8_t
* @param width
* @param fill fill character 0 is default
* @return a hex string
*/
std::string toHex(const std::vector<uint8_t> &input, int width, const char fill = '0');
/**
* @brief fromHexChar Convert a single char to its hexidecmal value
* @param c input char 0-F
* @return The value of c in Hex or -1 for invalid hex chars
*/
int fromHexChar(char c);
/**
* @brief fromHex Turn the string into a std::vector<uint8_t>
* @param hexString a Hexidecimal string
* @return std::vector<uint8_t> version of the hex chars
*/
std::vector<uint8_t> fromHex(const std::string &hexString);
//! Convert to all uppercase
/*!
Convert each character in \c subject to uppercase
*/
void uppercase(std::string &subject);
//! Convert a size type to a string
/*!
Convert an size type to a string

View File

@ -33,7 +33,7 @@ FingerprintPreview::FingerprintPreview(QWidget *parent, const QList<Fingerprint>
sha256Art = deskflow::generateFingerprintArt(fingerprint.data);
break;
default:
qWarning() << "FingerprintPreview: Unknown fingerprint type: " << fingerprint.type;
qWarning() << "unknown fingerprint type:" << fingerprint.type;
break;
}
}

View File

@ -33,51 +33,6 @@ void StringTests::formatedString()
QCOMPARE("answer=42", result);
}
void StringTests::toHex()
{
QCOMPARE(deskflow::string::toHex("foobar", 2), "666f6f626172");
std::vector<std::uint8_t> subject{'f', 'o', 'o', 'b', 'a', 'r'};
QCOMPARE(deskflow::string::toHex(subject, 2), "666f6f626172");
}
void StringTests::fromHex()
{
QCOMPARE(deskflow::string::fromHexChar('z'), -1);
QCOMPARE(deskflow::string::fromHexChar('0'), 0);
QCOMPARE(deskflow::string::fromHexChar('1'), 1);
QCOMPARE(deskflow::string::fromHexChar('2'), 2);
QCOMPARE(deskflow::string::fromHexChar('3'), 3);
QCOMPARE(deskflow::string::fromHexChar('4'), 4);
QCOMPARE(deskflow::string::fromHexChar('5'), 5);
QCOMPARE(deskflow::string::fromHexChar('6'), 6);
QCOMPARE(deskflow::string::fromHexChar('7'), 7);
QCOMPARE(deskflow::string::fromHexChar('8'), 8);
QCOMPARE(deskflow::string::fromHexChar('9'), 9);
QCOMPARE(deskflow::string::fromHexChar('a'), 10);
QCOMPARE(deskflow::string::fromHexChar('A'), 10);
QCOMPARE(deskflow::string::fromHexChar('b'), 11);
QCOMPARE(deskflow::string::fromHexChar('B'), 11);
QCOMPARE(deskflow::string::fromHexChar('c'), 12);
QCOMPARE(deskflow::string::fromHexChar('C'), 12);
QCOMPARE(deskflow::string::fromHexChar('d'), 13);
QCOMPARE(deskflow::string::fromHexChar('D'), 13);
QCOMPARE(deskflow::string::fromHexChar('e'), 14);
QCOMPARE(deskflow::string::fromHexChar('E'), 14);
QCOMPARE(deskflow::string::fromHexChar('f'), 15);
QCOMPARE(deskflow::string::fromHexChar('F'), 15);
QCOMPARE(deskflow::string::fromHex("FF")[0], 255);
QCOMPARE(deskflow::string::fromHex(":FF:EE")[0], 255);
QCOMPARE(deskflow::string::fromHex(":FF:EE")[1], 238);
}
void StringTests::toLower()
{
std::string subject = "12foo3BaR";
deskflow::string::uppercase(subject);
QCOMPARE(subject, "12FOO3BAR");
}
void StringTests::stringToInt()
{
std::string number = "123";

View File

@ -12,9 +12,6 @@ class StringTests : public QObject
private slots:
void formatWithArgs();
void formatedString();
void toHex();
void fromHex();
void toLower();
void intToString();
void stringToInt();
};