1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-05 10:49:24 +02:00

more c++ files

This commit is contained in:
Nikolay Pultsin 2012-04-02 14:14:59 +01:00
parent ccf39daeff
commit f3a459963c
6 changed files with 238 additions and 2 deletions

View file

@ -114,6 +114,8 @@ LOCAL_SRC_FILES := \
NativeFormats/fbreader/src/formats/txt/TxtBookReader.cpp \
NativeFormats/fbreader/src/formats/txt/TxtPlugin.cpp \
NativeFormats/fbreader/src/formats/txt/TxtReader.cpp \
NativeFormats/fbreader/src/formats/util/EntityFilesCollector.cpp \
NativeFormats/fbreader/src/formats/util/MiscUtil.cpp \
NativeFormats/fbreader/src/formats/xhtml/XHTMLReader.cpp \
NativeFormats/fbreader/src/library/Author.cpp \
NativeFormats/fbreader/src/library/Book.cpp \

View file

@ -1,4 +1,4 @@
#APP_ABI := armeabi
APP_ABI := armeabi
#APP_ABI := armeabi armeabi-v7a x86 mips mips-r2 mips-r2-sf
APP_ABI := all
#APP_ABI := all
APP_STL := stlport_static

View file

@ -0,0 +1,62 @@
/*
* Copyright (C) 2004-2012 Geometer Plus <contact@geometerplus.com>
*
* 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 <ZLStringUtil.h>
#include <ZLibrary.h>
#include <ZLFile.h>
#include <ZLDir.h>
#include "EntityFilesCollector.h"
EntityFilesCollector *EntityFilesCollector::ourInstance = 0;
EntityFilesCollector &EntityFilesCollector::Instance() {
if (ourInstance == 0) {
ourInstance = new EntityFilesCollector();
}
return *ourInstance;
}
const std::vector<std::string> &EntityFilesCollector::externalDTDs(const std::string &format) {
std::map<std::string,std::vector<std::string> >::const_iterator it = myCollections.find(format);
if (it != myCollections.end()) {
return it->second;
}
std::vector<std::string> &collection = myCollections[format];
std::string directoryName =
ZLibrary::ApplicationDirectory() + ZLibrary::FileNameDelimiter +
"formats" + ZLibrary::FileNameDelimiter + format;
shared_ptr<ZLDir> dtdPath = ZLFile(directoryName).directory();
if (!dtdPath.isNull()) {
std::vector<std::string> files;
dtdPath->collectFiles(files, false);
for (std::vector<std::string>::const_iterator it = files.begin(); it != files.end(); ++it) {
if (ZLStringUtil::stringEndsWith(*it, ".ent")) {
collection.push_back(dtdPath->itemPath(*it));
}
}
}
return collection;
}
EntityFilesCollector::EntityFilesCollector() {
}

View file

@ -0,0 +1,42 @@
/*
* Copyright (C) 2004-2012 Geometer Plus <contact@geometerplus.com>
*
* 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.
*/
#ifndef __ENTITYFILESCOLLECTOR_H__
#define __ENTITYFILESCOLLECTOR_H__
#include <map>
#include <vector>
#include <string>
class EntityFilesCollector {
public:
static EntityFilesCollector &Instance();
const std::vector<std::string> &externalDTDs(const std::string &format);
private:
EntityFilesCollector();
private:
static EntityFilesCollector *ourInstance;
std::map<std::string,std::vector<std::string> > myCollections;
};
#endif /* __ENTITYFILESCOLLECTOR_H__ */

View file

@ -0,0 +1,91 @@
/*
* Copyright (C) 2004-2012 Geometer Plus <contact@geometerplus.com>
*
* 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 <cstdlib>
#include <ZLFile.h>
#include <ZLStringUtil.h>
#include "MiscUtil.h"
FBTextKind MiscUtil::referenceType(const std::string &link) {
std::string lowerCasedLink = link;
bool isFileReference =
ZLStringUtil::stringStartsWith(lowerCasedLink, "http://") ||
ZLStringUtil::stringStartsWith(lowerCasedLink, "https://") ||
ZLStringUtil::stringStartsWith(lowerCasedLink, "ftp://");
if (!isFileReference) {
return ZLStringUtil::stringStartsWith(lowerCasedLink, "mailto:") ? EXTERNAL_HYPERLINK : INTERNAL_HYPERLINK;
}
/*static const std::string FeedBooksPrefix0 = "http://feedbooks.com/book/stanza/";
static const std::string FeedBooksPrefix1 = "http://www.feedbooks.com/book/stanza/";
bool isBookHyperlink =
ZLStringUtil::stringStartsWith(lowerCasedLink, FeedBooksPrefix0) ||
ZLStringUtil::stringStartsWith(lowerCasedLink, FeedBooksPrefix1) ||
ZLStringUtil::stringEndsWith(lowerCasedLink, ".epub") ||
ZLStringUtil::stringEndsWith(lowerCasedLink, ".mobi") ||
ZLStringUtil::stringEndsWith(lowerCasedLink, ".chm") ||
ZLStringUtil::stringEndsWith(lowerCasedLink, ".fb2");
return isBookHyperlink ? BOOK_HYPERLINK : EXTERNAL_HYPERLINK;*/
return EXTERNAL_HYPERLINK;
}
std::string MiscUtil::htmlDirectoryPrefix(const std::string &fileName) {
ZLFile file(fileName);
std::string shortName = file.name(false);
std::string path = file.path();
int index = -1;
if ((path.length() > shortName.length()) &&
(path[path.length() - shortName.length() - 1] == ':')) {
index = shortName.rfind('/');
}
return path.substr(0, path.length() - shortName.length() + index + 1);
}
std::string MiscUtil::htmlFileName(const std::string &fileName) {
ZLFile file(fileName);
std::string shortName = file.name(false);
std::string path = file.path();
int index = -1;
if ((path.length() > shortName.length()) &&
(path[path.length() - shortName.length() - 1] == ':')) {
index = shortName.rfind('/');
}
return path.substr(path.length() - shortName.length() + index + 1);
}
std::string MiscUtil::decodeHtmlURL(const std::string &encoded) {
char buffer[3];
buffer[2] = '\0';
std::string decoded;
const int len = encoded.length();
decoded.reserve(len);
for (int i = 0; i < len; i++) {
if ((encoded[i] == '%') && (i < len - 2)) {
buffer[0] = *(encoded.data() + i + 1);
buffer[1] = *(encoded.data() + i + 2);
decoded += (char)strtol(buffer, 0, 16);
i += 2;
} else {
decoded += encoded[i];
}
}
return decoded;
}

View file

@ -0,0 +1,39 @@
/*
* Copyright (C) 2004-2012 Geometer Plus <contact@geometerplus.com>
*
* 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.
*/
#ifndef __MISCUTIL_H__
#define __MISCUTIL_H__
#include <string>
#include "../../bookmodel/FBTextKind.h"
class MiscUtil {
private:
MiscUtil();
public:
static FBTextKind referenceType(const std::string &link);
static std::string htmlDirectoryPrefix(const std::string &fileName);
static std::string htmlFileName(const std::string &fileName);
static std::string decodeHtmlURL(const std::string &encodedURL);
};
#endif /* __MISCUTIL_H__ */