gui
[lbook_fbreader.git] / fbreader / src / formats / html / HtmlEntityCollection.cpp
blob815f38df041fec130f35269c865dc2a9f103de94
1 /*
2 * Copyright (C) 2004-2008 Geometer Plus <contact@geometerplus.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 * 02110-1301, USA.
20 #include <stdlib.h>
22 #include <cctype>
24 #include <ZLXMLReader.h>
25 #include <ZLibrary.h>
27 #include "HtmlEntityCollection.h"
29 class CollectionReader : public ZLXMLReader {
31 public:
32 CollectionReader(std::map<std::string,int> &collection);
33 void startElementHandler(const char *tag, const char **attributes);
35 private:
36 std::map<std::string,int> &myCollection;
39 std::map<std::string,int> HtmlEntityCollection::ourCollection;
41 int HtmlEntityCollection::symbolNumber(const std::string &name) {
42 if (ourCollection.empty()) {
43 CollectionReader(ourCollection).readDocument(
44 ZLibrary::ApplicationDirectory() + ZLibrary::FileNameDelimiter + "formats" + ZLibrary::FileNameDelimiter + "html" + ZLibrary::FileNameDelimiter + "html.ent"
47 std::map<std::string,int>::const_iterator it = ourCollection.find(name);
48 return (it == ourCollection.end()) ? 0 : it->second;
51 CollectionReader::CollectionReader(std::map<std::string,int> &collection) : myCollection(collection) {
54 void CollectionReader::startElementHandler(const char *tag, const char **attributes) {
55 static const std::string ENTITY = "entity";
57 if (ENTITY == tag) {
58 for (int i = 0; i < 4; ++i) {
59 if (attributes[i] == 0) {
60 return;
63 static const std::string _name = "name";
64 static const std::string _number = "number";
65 if ((_name == attributes[0]) && (_number == attributes[2])) {
66 myCollection[attributes[1]] = atoi(attributes[3]);