1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-04 10:19:33 +02:00

language/encoding detection (in progress)

This commit is contained in:
Nikolay Pultsin 2012-03-18 03:12:25 +00:00
parent bc97e8420a
commit 092c1f00d2
4 changed files with 14 additions and 20 deletions

View file

@ -31,24 +31,20 @@ void FormatPlugin::detectEncodingAndLanguage(Book &book, ZLInputStream &stream)
std::string language = book.language();
std::string encoding = book.encoding();
if (!encoding.empty() && !language.empty()) {
if (!encoding.empty()) {
return;
}
PluginCollection &collection = PluginCollection::Instance();
if (language.empty()) {
language = collection.defaultLanguage();
}
if (encoding.empty()) {
encoding = collection.defaultEncoding();
encoding = "utf-8";
}
if (collection.isLanguageAutoDetectEnabled() && stream.open()) {
static const int BUFSIZE = 65536;
char *buffer = new char[BUFSIZE];
const size_t size = stream.read(buffer, BUFSIZE);
stream.close();
shared_ptr<ZLLanguageDetector::LanguageInfo> info =
ZLLanguageDetector().findInfo(buffer, size);
shared_ptr<ZLLanguageDetector::LanguageInfo> info = ZLLanguageDetector().findInfo(buffer, size);
delete[] buffer;
if (!info.isNull()) {
if (!info->Language.empty()) {
@ -71,9 +67,6 @@ void FormatPlugin::detectLanguage(Book &book, ZLInputStream &stream) {
}
PluginCollection &collection = PluginCollection::Instance();
if (language.empty()) {
language = collection.defaultLanguage();
}
if (collection.isLanguageAutoDetectEnabled() && stream.open()) {
static const int BUFSIZE = 65536;
char *buffer = new char[BUFSIZE];