Parse the author name from content.opf file (#165)

## Summary

* Parse the author name from content.opf file
  * Listed in the dc:creator tag within the metadata section
This commit is contained in:
Dave Allie
2025-12-30 21:15:44 +10:00
committed by GitHub
parent 3dd52f30fa
commit be1b5bad21
4 changed files with 28 additions and 2 deletions

View File

@@ -102,6 +102,11 @@ void XMLCALL ContentOpfParser::startElement(void* userData, const XML_Char* name
return;
}
if (self->state == IN_METADATA && strcmp(name, "dc:creator") == 0) {
self->state = IN_BOOK_AUTHOR;
return;
}
if (self->state == IN_PACKAGE && (strcmp(name, "manifest") == 0 || strcmp(name, "opf:manifest") == 0)) {
self->state = IN_MANIFEST;
if (!SdMan.openFileForWrite("COF", self->cachePath + itemCacheFile, self->tempItemStore)) {
@@ -209,6 +214,11 @@ void XMLCALL ContentOpfParser::characterData(void* userData, const XML_Char* s,
self->title.append(s, len);
return;
}
if (self->state == IN_BOOK_AUTHOR) {
self->author.append(s, len);
return;
}
}
void XMLCALL ContentOpfParser::endElement(void* userData, const XML_Char* name) {
@@ -232,6 +242,11 @@ void XMLCALL ContentOpfParser::endElement(void* userData, const XML_Char* name)
return;
}
if (self->state == IN_BOOK_AUTHOR && strcmp(name, "dc:creator") == 0) {
self->state = IN_METADATA;
return;
}
if (self->state == IN_METADATA && (strcmp(name, "metadata") == 0 || strcmp(name, "opf:metadata") == 0)) {
self->state = IN_PACKAGE;
return;

View File

@@ -12,6 +12,7 @@ class ContentOpfParser final : public Print {
IN_PACKAGE,
IN_METADATA,
IN_BOOK_TITLE,
IN_BOOK_AUTHOR,
IN_MANIFEST,
IN_SPINE,
};
@@ -31,6 +32,7 @@ class ContentOpfParser final : public Print {
public:
std::string title;
std::string author;
std::string tocNcxPath;
std::string coverItemHref;