summaryrefslogtreecommitdiffstats
path: root/fbreader/src/formats/docbook/DocBookDescriptionReader.cpp
diff options
context:
space:
mode:
authorMichele Calgaro <[email protected]>2024-05-11 21:28:48 +0900
committerMichele Calgaro <[email protected]>2024-05-11 21:28:48 +0900
commit2462d03f322261bd616721c2b2065c4004b36c9c (patch)
tree239947a0737bb8386703a1497f12c09aebd3080a /fbreader/src/formats/docbook/DocBookDescriptionReader.cpp
downloadtde-ebook-reader-2462d03f322261bd616721c2b2065c4004b36c9c.tar.gz
tde-ebook-reader-2462d03f322261bd616721c2b2065c4004b36c9c.zip
Initial import (as is) from Debian Snapshot's 'fbreader' source code (https://snapshot.debian.org/package/fbreader/0.99.4%2Bdfsg-6).
The Debian code is provided under GPL2 license. Signed-off-by: Michele Calgaro <[email protected]>
Diffstat (limited to 'fbreader/src/formats/docbook/DocBookDescriptionReader.cpp')
-rw-r--r--fbreader/src/formats/docbook/DocBookDescriptionReader.cpp137
1 files changed, 137 insertions, 0 deletions
diff --git a/fbreader/src/formats/docbook/DocBookDescriptionReader.cpp b/fbreader/src/formats/docbook/DocBookDescriptionReader.cpp
new file mode 100644
index 0000000..bcd4ae4
--- /dev/null
+++ b/fbreader/src/formats/docbook/DocBookDescriptionReader.cpp
@@ -0,0 +1,137 @@
+/*
+ * Copyright (C) 2004-2012 Geometer Plus <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#include <ZLInputStream.h>
+#include <ZLUnicodeUtil.h>
+
+#include "DocBookDescriptionReader.h"
+
+#include "../../library/Book.h"
+#include "../../library/Author.h"
+
+DocBookDescriptionReader::DocBookDescriptionReader(Book &book) : myBook(book) {
+ myReadTitle = false;
+ myReadAuthor = false;
+ for (int i = 0; i < 3; ++i) {
+ myReadAuthorName[i] = false;
+ }
+ myBook.setLanguage("en");
+ myDepth = 0;
+}
+
+void DocBookDescriptionReader::characterDataHandler(const char *text, std::size_t len) {
+ if (myReadTitle) {
+ myBook.setTitle(myBook.title() + std::string(text, len));
+ } else {
+ for (int i = 0; i < 3; ++i) {
+ if (myReadAuthorName[i]) {
+ myAuthorNames[i].append(text, len);
+ break;
+ }
+ }
+ }
+}
+
+void DocBookDescriptionReader::startElementHandler(int tag, const char **) {
+ ++myDepth;
+ switch (tag) {
+ case _SECT1:
+ myReturnCode = true;
+ myDoBreak = true;
+ break;
+ case _TITLE:
+ if (myDepth == 2) {
+ myReadTitle = true;
+ }
+ break;
+ case _AUTHOR:
+ if (myDepth == 3) {
+ myReadAuthor = true;
+ }
+ break;
+ case _FIRSTNAME:
+ if (myReadAuthor) {
+ myReadAuthorName[0] = true;
+ }
+ break;
+ case _OTHERNAME:
+ if (myReadAuthor) {
+ myReadAuthorName[1] = true;
+ }
+ break;
+ case _SURNAME:
+ if (myReadAuthor) {
+ myReadAuthorName[2] = true;
+ }
+ break;
+ default:
+ break;
+ }
+}
+
+void DocBookDescriptionReader::endElementHandler(int tag) {
+ --myDepth;
+ switch (tag) {
+ case _TITLE:
+ myReadTitle = false;
+ break;
+ case _AUTHOR: {
+ ZLUnicodeUtil::utf8Trim(myAuthorNames[0]);
+ ZLUnicodeUtil::utf8Trim(myAuthorNames[1]);
+ ZLUnicodeUtil::utf8Trim(myAuthorNames[2]);
+ std::string fullName = myAuthorNames[0];
+ if (!fullName.empty() && !myAuthorNames[1].empty()) {
+ fullName += ' ';
+ }
+ fullName += myAuthorNames[1];
+ if (!fullName.empty() && !myAuthorNames[2].empty()) {
+ fullName += ' ';
+ }
+ fullName += myAuthorNames[2];
+ shared_ptr<Author> author = Author::create(fullName, myAuthorNames[2]);
+ if (!author.isNull()) {
+ myBook.authors().add( author );
+ }
+ }
+ myAuthorNames[0].erase();
+ myAuthorNames[1].erase();
+ myAuthorNames[2].erase();
+ myReadAuthor = false;
+ break;
+ case _FIRSTNAME:
+ myReadAuthorName[0] = false;
+ break;
+ case _OTHERNAME:
+ myReadAuthorName[1] = false;
+ break;
+ case _SURNAME:
+ myReadAuthorName[2] = false;
+ break;
+ default:
+ break;
+ }
+}
+
+bool DocBookDescriptionReader::readMetaInfo(shared_ptr<ZLInputStream> stream) {
+ bool code = readDocument(stream);
+ if (myBook.authors().empty()) {
+ myBook.authors().push_back( new Author() );
+ }
+ return code;
+}