Small code cleanup (#83)

## Summary

* Fix cppcheck low violations
* Remove teardown method on parsers, use destructor
* Code cleanup
This commit is contained in:
Dave Allie
2025-12-21 15:43:53 +11:00
committed by GitHub
parent 9b4dfbd180
commit 0d32d21d75
19 changed files with 70 additions and 86 deletions

View File

@@ -21,9 +21,10 @@ class Section {
int currentPage = 0;
explicit Section(const std::shared_ptr<Epub>& epub, const int spineIndex, GfxRenderer& renderer)
: epub(epub), spineIndex(spineIndex), renderer(renderer) {
cachePath = epub->getCachePath() + "/" + std::to_string(spineIndex);
}
: epub(epub),
spineIndex(spineIndex),
renderer(renderer),
cachePath(epub->getCachePath() + "/" + std::to_string(spineIndex)) {}
~Section() = default;
bool loadCacheMetadata(int fontId, float lineCompression, int marginTop, int marginRight, int marginBottom,
int marginLeft, bool extraParagraphSpacing);

View File

@@ -14,12 +14,11 @@ bool ContainerParser::setup() {
return true;
}
bool ContainerParser::teardown() {
ContainerParser::~ContainerParser() {
if (parser) {
XML_ParserFree(parser);
parser = nullptr;
}
return true;
}
size_t ContainerParser::write(const uint8_t data) { return write(&data, 1); }

View File

@@ -23,9 +23,9 @@ class ContainerParser final : public Print {
std::string fullPath;
explicit ContainerParser(const size_t xmlSize) : remainingSize(xmlSize) {}
~ContainerParser() override;
bool setup();
bool teardown();
size_t write(uint8_t) override;
size_t write(const uint8_t* buffer, size_t size) override;

View File

@@ -4,7 +4,7 @@
#include <ZipFile.h>
namespace {
constexpr const char MEDIA_TYPE_NCX[] = "application/x-dtbncx+xml";
constexpr char MEDIA_TYPE_NCX[] = "application/x-dtbncx+xml";
}
bool ContentOpfParser::setup() {
@@ -20,12 +20,11 @@ bool ContentOpfParser::setup() {
return true;
}
bool ContentOpfParser::teardown() {
ContentOpfParser::~ContentOpfParser() {
if (parser) {
XML_ParserFree(parser);
parser = nullptr;
}
return true;
}
size_t ContentOpfParser::write(const uint8_t data) { return write(&data, 1); }

View File

@@ -34,9 +34,9 @@ class ContentOpfParser final : public Print {
explicit ContentOpfParser(const std::string& baseContentPath, const size_t xmlSize)
: baseContentPath(baseContentPath), remainingSize(xmlSize) {}
~ContentOpfParser() override;
bool setup();
bool teardown();
size_t write(uint8_t) override;
size_t write(const uint8_t* buffer, size_t size) override;

View File

@@ -1,5 +1,6 @@
#include "TocNcxParser.h"
#include <Esp.h>
#include <HardwareSerial.h>
bool TocNcxParser::setup() {
@@ -15,12 +16,11 @@ bool TocNcxParser::setup() {
return true;
}
bool TocNcxParser::teardown() {
TocNcxParser::~TocNcxParser() {
if (parser) {
XML_ParserFree(parser);
parser = nullptr;
}
return true;
}
size_t TocNcxParser::write(const uint8_t data) { return write(&data, 1); }

View File

@@ -28,9 +28,9 @@ class TocNcxParser final : public Print {
explicit TocNcxParser(const std::string& baseContentPath, const size_t xmlSize)
: baseContentPath(baseContentPath), remainingSize(xmlSize) {}
~TocNcxParser() override;
bool setup();
bool teardown();
size_t write(uint8_t) override;
size_t write(const uint8_t* buffer, size_t size) override;