2025-12-13 19:36:01 +11:00
|
|
|
#pragma once
|
|
|
|
|
#include <Print.h>
|
2025-12-24 22:36:13 +11:00
|
|
|
#include <expat.h>
|
2025-12-13 19:36:01 +11:00
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
2025-12-24 22:36:13 +11:00
|
|
|
class BookMetadataCache;
|
2025-12-13 19:36:01 +11:00
|
|
|
|
|
|
|
|
class TocNcxParser final : public Print {
|
|
|
|
|
enum ParserState { START, IN_NCX, IN_NAV_MAP, IN_NAV_POINT, IN_NAV_LABEL, IN_NAV_LABEL_TEXT, IN_CONTENT };
|
|
|
|
|
|
|
|
|
|
const std::string& baseContentPath;
|
|
|
|
|
size_t remainingSize;
|
|
|
|
|
XML_Parser parser = nullptr;
|
|
|
|
|
ParserState state = START;
|
2025-12-24 22:36:13 +11:00
|
|
|
BookMetadataCache* cache;
|
2025-12-13 19:36:01 +11:00
|
|
|
|
|
|
|
|
std::string currentLabel;
|
|
|
|
|
std::string currentSrc;
|
2025-12-21 17:08:34 +11:00
|
|
|
uint8_t currentDepth = 0;
|
2025-12-13 19:36:01 +11:00
|
|
|
|
|
|
|
|
static void startElement(void* userData, const XML_Char* name, const XML_Char** atts);
|
|
|
|
|
static void characterData(void* userData, const XML_Char* s, int len);
|
|
|
|
|
static void endElement(void* userData, const XML_Char* name);
|
|
|
|
|
|
|
|
|
|
public:
|
2025-12-24 22:36:13 +11:00
|
|
|
explicit TocNcxParser(const std::string& baseContentPath, const size_t xmlSize, BookMetadataCache* cache)
|
|
|
|
|
: baseContentPath(baseContentPath), remainingSize(xmlSize), cache(cache) {}
|
2025-12-21 15:43:53 +11:00
|
|
|
~TocNcxParser() override;
|
2025-12-13 19:36:01 +11:00
|
|
|
|
|
|
|
|
bool setup();
|
|
|
|
|
|
|
|
|
|
size_t write(uint8_t) override;
|
|
|
|
|
size_t write(const uint8_t* buffer, size_t size) override;
|
|
|
|
|
};
|