summaryrefslogtreecommitdiffstats
path: root/fbreader/src/formats/fb2/FB2Reader.cpp
blob: c8e279c100723573ba8e6328cf82eb94f84a38ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
 * 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 <cstring>

#include <ZLibrary.h>
#include <ZLStringUtil.h>
#include <ZLXMLNamespace.h>

#include "FB2Reader.h"

#include "../util/EntityFilesCollector.h"

FB2Reader::FB2Reader() : myHrefPredicate(ZLXMLNamespace::XLink, "href") {
}

void FB2Reader::startElementHandler(const char *t, const char **attributes) {
	startElementHandler(tag(t), attributes);
}

void FB2Reader::endElementHandler(const char *t) {
	endElementHandler(tag(t));
}

static const FB2Reader::Tag TAGS[] = {
	{"p", FB2Reader::_P},
	{"subtitle", FB2Reader::_SUBTITLE},
	{"cite", FB2Reader::_CITE},
	{"text-author", FB2Reader::_TEXT_AUTHOR},
	{"date", FB2Reader::_DATE},
	{"section", FB2Reader::_SECTION},
	{"v", FB2Reader::_V},
	{"title", FB2Reader::_TITLE},
	{"poem", FB2Reader::_POEM},
	{"stanza", FB2Reader::_STANZA},
	{"epigraph", FB2Reader::_EPIGRAPH},
	{"annotation", FB2Reader::_ANNOTATION},
	{"sub", FB2Reader::_SUB},
	{"sup", FB2Reader::_SUP},
	{"code", FB2Reader::_CODE},
	{"strikethrough", FB2Reader::_STRIKETHROUGH},
	{"strong", FB2Reader::_STRONG},
	{"emphasis", FB2Reader::_EMPHASIS},
	{"a", FB2Reader::_A},
	{"image", FB2Reader::_IMAGE},
	{"binary", FB2Reader::_BINARY},
	{"description", FB2Reader::_DESCRIPTION},
	{"body", FB2Reader::_BODY},
	{"empty-line", FB2Reader::_EMPTY_LINE},
	{"title-info", FB2Reader::_TITLE_INFO},
	{"book-title", FB2Reader::_BOOK_TITLE},
	{"author", FB2Reader::_AUTHOR},
	{"lang", FB2Reader::_LANG},
	{"first-name", FB2Reader::_FIRST_NAME},
	{"middle-name", FB2Reader::_MIDDLE_NAME},
	{"last-name", FB2Reader::_LAST_NAME},
	{"coverpage", FB2Reader::_COVERPAGE},
	{"sequence", FB2Reader::_SEQUENCE},
	{"genre", FB2Reader::_GENRE},
	{0, FB2Reader::_UNKNOWN}
};

int FB2Reader::tag(const char *name) {
	for (int i = 0; ; ++i) {
		if (TAGS[i].tagName == 0 || std::strcmp(name, TAGS[i].tagName) == 0) {
			return TAGS[i].tagCode;
		}
	}
}

const std::vector<std::string> &FB2Reader::externalDTDs() const {
	return EntityFilesCollector::Instance().externalDTDs("fb2");
}