mirror of https://github.com/kiwix/libkiwix.git
catching up with master
This commit is contained in:
commit
fd9c9ac17e
|
@ -67,6 +67,7 @@ namespace kiwix {
|
||||||
string publisher;
|
string publisher;
|
||||||
string date;
|
string date;
|
||||||
string url;
|
string url;
|
||||||
|
string origId;
|
||||||
string articleCount;
|
string articleCount;
|
||||||
string mediaCount;
|
string mediaCount;
|
||||||
bool readOnly;
|
bool readOnly;
|
||||||
|
|
|
@ -56,6 +56,7 @@ namespace kiwix {
|
||||||
book.creator = bookNode.attribute("creator").value();
|
book.creator = bookNode.attribute("creator").value();
|
||||||
book.publisher = bookNode.attribute("publisher").value();
|
book.publisher = bookNode.attribute("publisher").value();
|
||||||
book.url = bookNode.attribute("url").value();
|
book.url = bookNode.attribute("url").value();
|
||||||
|
book.origId = bookNode.attribute("origId").value();
|
||||||
book.articleCount = bookNode.attribute("articleCount").value();
|
book.articleCount = bookNode.attribute("articleCount").value();
|
||||||
book.mediaCount = bookNode.attribute("mediaCount").value();
|
book.mediaCount = bookNode.attribute("mediaCount").value();
|
||||||
book.size = bookNode.attribute("size").value();
|
book.size = bookNode.attribute("size").value();
|
||||||
|
@ -154,42 +155,47 @@ namespace kiwix {
|
||||||
bookNode.append_attribute("indexType") = "xapian";
|
bookNode.append_attribute("indexType") = "xapian";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (itr->origId.empty()) {
|
||||||
if (!itr->title.empty())
|
if (!itr->title.empty())
|
||||||
bookNode.append_attribute("title") = itr->title.c_str();
|
bookNode.append_attribute("title") = itr->title.c_str();
|
||||||
|
|
||||||
if (itr->description != "")
|
if (!itr->description.empty())
|
||||||
bookNode.append_attribute("description") = itr->description.c_str();
|
bookNode.append_attribute("description") = itr->description.c_str();
|
||||||
|
|
||||||
if (itr->language != "")
|
if (!itr->language.empty())
|
||||||
bookNode.append_attribute("language") = itr->language.c_str();
|
bookNode.append_attribute("language") = itr->language.c_str();
|
||||||
|
|
||||||
if (itr->date != "")
|
if (!itr->creator.empty())
|
||||||
bookNode.append_attribute("date") = itr->date.c_str();
|
|
||||||
|
|
||||||
if (itr->creator != "")
|
|
||||||
bookNode.append_attribute("creator") = itr->creator.c_str();
|
bookNode.append_attribute("creator") = itr->creator.c_str();
|
||||||
|
|
||||||
if (itr->publisher != "")
|
if (!itr->publisher.empty())
|
||||||
bookNode.append_attribute("publisher") = itr->publisher.c_str();
|
bookNode.append_attribute("publisher") = itr->publisher.c_str();
|
||||||
|
|
||||||
if (itr->url != "")
|
if (!itr->favicon.empty())
|
||||||
bookNode.append_attribute("url") = itr->url.c_str();
|
|
||||||
|
|
||||||
if (itr->articleCount != "")
|
|
||||||
bookNode.append_attribute("articleCount") = itr->articleCount.c_str();
|
|
||||||
|
|
||||||
if (itr->mediaCount != "")
|
|
||||||
bookNode.append_attribute("mediaCount") = itr->mediaCount.c_str();
|
|
||||||
|
|
||||||
if (itr->size != "")
|
|
||||||
bookNode.append_attribute("size") = itr->size.c_str();
|
|
||||||
|
|
||||||
if (itr->favicon != "")
|
|
||||||
bookNode.append_attribute("favicon") = itr->favicon.c_str();
|
bookNode.append_attribute("favicon") = itr->favicon.c_str();
|
||||||
|
|
||||||
if (itr->faviconMimeType != "")
|
if (!itr->faviconMimeType.empty())
|
||||||
bookNode.append_attribute("faviconMimeType") = itr->faviconMimeType.c_str();
|
bookNode.append_attribute("faviconMimeType") = itr->faviconMimeType.c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!itr->date.empty())
|
||||||
|
bookNode.append_attribute("date") = itr->date.c_str();
|
||||||
|
|
||||||
|
if (!itr->url.empty())
|
||||||
|
bookNode.append_attribute("url") = itr->url.c_str();
|
||||||
|
|
||||||
|
if (!itr->origId.empty())
|
||||||
|
bookNode.append_attribute("origId") = itr->origId.c_str();
|
||||||
|
|
||||||
|
if (!itr->articleCount.empty())
|
||||||
|
bookNode.append_attribute("articleCount") = itr->articleCount.c_str();
|
||||||
|
|
||||||
|
if (!itr->mediaCount.empty())
|
||||||
|
bookNode.append_attribute("mediaCount") = itr->mediaCount.c_str();
|
||||||
|
|
||||||
|
if (!itr->size.empty())
|
||||||
|
bookNode.append_attribute("size") = itr->size.c_str();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* saving file */
|
/* saving file */
|
||||||
|
@ -256,7 +262,7 @@ namespace kiwix {
|
||||||
book->creator = reader->getCreator();
|
book->creator = reader->getCreator();
|
||||||
book->publisher = reader->getPublisher();
|
book->publisher = reader->getPublisher();
|
||||||
book->title = reader->getTitle();
|
book->title = reader->getTitle();
|
||||||
|
book->origId = reader->getOrigId();
|
||||||
std::ostringstream articleCountStream;
|
std::ostringstream articleCountStream;
|
||||||
articleCountStream << reader->getArticleCount();
|
articleCountStream << reader->getArticleCount();
|
||||||
book->articleCount = articleCountStream.str();
|
book->articleCount = articleCountStream.str();
|
||||||
|
@ -307,12 +313,14 @@ namespace kiwix {
|
||||||
std::map<string, bool> booksLanguagesMap;
|
std::map<string, bool> booksLanguagesMap;
|
||||||
|
|
||||||
std::sort(library.books.begin(), library.books.end(), kiwix::Book::sortByLanguage);
|
std::sort(library.books.begin(), library.books.end(), kiwix::Book::sortByLanguage);
|
||||||
for ( itr = library.books.begin(); itr != library.books.end(); ++itr ) {
|
for (itr = library.books.begin(); itr != library.books.end(); ++itr) {
|
||||||
if (booksLanguagesMap.find(itr->language) == booksLanguagesMap.end()) {
|
if (booksLanguagesMap.find(itr->language) == booksLanguagesMap.end()) {
|
||||||
|
if (itr->origId.empty()) {
|
||||||
booksLanguagesMap[itr->language] = true;
|
booksLanguagesMap[itr->language] = true;
|
||||||
booksLanguages.push_back(itr->language);
|
booksLanguages.push_back(itr->language);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return booksLanguages;
|
return booksLanguages;
|
||||||
}
|
}
|
||||||
|
@ -323,12 +331,14 @@ namespace kiwix {
|
||||||
std::map<string, bool> booksCreatorsMap;
|
std::map<string, bool> booksCreatorsMap;
|
||||||
|
|
||||||
std::sort(library.books.begin(), library.books.end(), kiwix::Book::sortByCreator);
|
std::sort(library.books.begin(), library.books.end(), kiwix::Book::sortByCreator);
|
||||||
for ( itr = library.books.begin(); itr != library.books.end(); ++itr ) {
|
for (itr = library.books.begin(); itr != library.books.end(); ++itr) {
|
||||||
if (booksCreatorsMap.find(itr->creator) == booksCreatorsMap.end()) {
|
if (booksCreatorsMap.find(itr->creator) == booksCreatorsMap.end()) {
|
||||||
|
if (itr->origId.empty()) {
|
||||||
booksCreatorsMap[itr->creator] = true;
|
booksCreatorsMap[itr->creator] = true;
|
||||||
booksCreators.push_back(itr->creator);
|
booksCreators.push_back(itr->creator);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return booksCreators;
|
return booksCreators;
|
||||||
}
|
}
|
||||||
|
@ -353,10 +363,12 @@ namespace kiwix {
|
||||||
std::sort(library.books.begin(), library.books.end(), kiwix::Book::sortByPublisher);
|
std::sort(library.books.begin(), library.books.end(), kiwix::Book::sortByPublisher);
|
||||||
for ( itr = library.books.begin(); itr != library.books.end(); ++itr ) {
|
for ( itr = library.books.begin(); itr != library.books.end(); ++itr ) {
|
||||||
if (booksPublishersMap.find(itr->publisher) == booksPublishersMap.end()) {
|
if (booksPublishersMap.find(itr->publisher) == booksPublishersMap.end()) {
|
||||||
|
if (itr->origId.empty()) {
|
||||||
booksPublishersMap[itr->publisher] = true;
|
booksPublishersMap[itr->publisher] = true;
|
||||||
booksPublishers.push_back(itr->publisher);
|
booksPublishers.push_back(itr->publisher);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return booksPublishers;
|
return booksPublishers;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,38 @@
|
||||||
|
|
||||||
#include "reader.h"
|
#include "reader.h"
|
||||||
|
|
||||||
|
inline char hi(char v) {
|
||||||
|
char hex[] = "0123456789abcdef";
|
||||||
|
return hex[(v >> 4) & 0xf];
|
||||||
|
}
|
||||||
|
|
||||||
|
inline char lo(char v) {
|
||||||
|
char hex[] = "0123456789abcdef";
|
||||||
|
return hex[v & 0xf];
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string hexUUID (std::string in) {
|
||||||
|
std::ostringstream out;
|
||||||
|
for (unsigned n = 0; n < 4; ++n)
|
||||||
|
out << hi(in[n]) << lo(in[n]);
|
||||||
|
out << '-';
|
||||||
|
for (unsigned n = 4; n < 6; ++n)
|
||||||
|
out << hi(in[n]) << lo(in[n]);
|
||||||
|
out << '-';
|
||||||
|
for (unsigned n = 6; n < 8; ++n)
|
||||||
|
out << hi(in[n]) << lo(in[n]);
|
||||||
|
out << '-';
|
||||||
|
for (unsigned n = 8; n < 10; ++n)
|
||||||
|
out << hi(in[n]) << lo(in[n]);
|
||||||
|
out << '-';
|
||||||
|
for (unsigned n = 10; n < 16; ++n)
|
||||||
|
out << hi(in[n]) << lo(in[n]);
|
||||||
|
std::string op=out.str();
|
||||||
|
return op;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static char charFromHex(std::string a) {
|
static char charFromHex(std::string a) {
|
||||||
std::istringstream Blat (a);
|
std::istringstream Blat (a);
|
||||||
int Z;
|
int Z;
|
||||||
|
@ -28,9 +60,10 @@ static char charFromHex(std::string a) {
|
||||||
|
|
||||||
void unescapeUrl(string &url) {
|
void unescapeUrl(string &url) {
|
||||||
std::string::size_type pos = 0;
|
std::string::size_type pos = 0;
|
||||||
while ((pos = url.find('%', pos + 1)) != std::string::npos &&
|
while ((pos = url.find('%', pos)) != std::string::npos &&
|
||||||
pos + 3 <= url.length()) {
|
pos + 2 < url.length()) {
|
||||||
url.replace(pos, 3, 1, charFromHex(url.substr(pos + 1, 2)));
|
url.replace(pos, 3, 1, charFromHex(url.substr(pos + 1, 2)));
|
||||||
|
++pos;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -289,6 +322,33 @@ namespace kiwix {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string Reader::getOrigId() {
|
||||||
|
string value;
|
||||||
|
this->getMetatag("startfileuid", value);
|
||||||
|
if(value.empty())
|
||||||
|
return "";
|
||||||
|
std::string id=value;
|
||||||
|
std::string origID;
|
||||||
|
std::string temp="";
|
||||||
|
unsigned int k=0;
|
||||||
|
char tempArray[16]="";
|
||||||
|
for(unsigned int i=0; i<id.size(); i++)
|
||||||
|
{
|
||||||
|
if(id[i]=='\n')
|
||||||
|
{
|
||||||
|
tempArray[k]= atoi(temp.c_str());
|
||||||
|
temp="";
|
||||||
|
k++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
temp+=id[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
origID=hexUUID(tempArray);
|
||||||
|
return origID;
|
||||||
|
}
|
||||||
|
|
||||||
/* Return the first page URL */
|
/* Return the first page URL */
|
||||||
string Reader::getFirstPageUrl() {
|
string Reader::getFirstPageUrl() {
|
||||||
string url;
|
string url;
|
||||||
|
@ -393,9 +453,13 @@ namespace kiwix {
|
||||||
std::vector<std::string>::iterator suggestionItr;
|
std::vector<std::string>::iterator suggestionItr;
|
||||||
int result;
|
int result;
|
||||||
|
|
||||||
/* Reset the suggestions */
|
/* Reset the suggestions otherwise check if the suggestions number is less than the suggestionsCount */
|
||||||
if (reset) {
|
if (reset) {
|
||||||
this->suggestions.clear();
|
this->suggestions.clear();
|
||||||
|
} else {
|
||||||
|
if (this->suggestions.size() > suggestionsCount) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (prefix.size()) {
|
if (prefix.size()) {
|
||||||
|
@ -407,7 +471,7 @@ namespace kiwix {
|
||||||
|
|
||||||
if (this->suggestions.size() == 0) {
|
if (this->suggestions.size() == 0) {
|
||||||
this->suggestions.push_back(articleItr->getTitle());
|
this->suggestions.push_back(articleItr->getTitle());
|
||||||
} else {
|
} else if (this->suggestions.size() < suggestionsCount) {
|
||||||
for (suggestionItr = this->suggestions.begin() ;
|
for (suggestionItr = this->suggestions.begin() ;
|
||||||
suggestionItr != this->suggestions.end();
|
suggestionItr != this->suggestions.end();
|
||||||
++suggestionItr) {
|
++suggestionItr) {
|
||||||
|
@ -452,6 +516,10 @@ namespace kiwix {
|
||||||
myPrefix = kiwix::lcFirst(myPrefix);
|
myPrefix = kiwix::lcFirst(myPrefix);
|
||||||
this->searchSuggestions(myPrefix, suggestionsCount, false);
|
this->searchSuggestions(myPrefix, suggestionsCount, false);
|
||||||
|
|
||||||
|
/* Try with title words */
|
||||||
|
myPrefix = kiwix::toTitle(myPrefix);
|
||||||
|
this->searchSuggestions(myPrefix, suggestionsCount, false);
|
||||||
|
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -58,6 +58,7 @@ namespace kiwix {
|
||||||
string getDate();
|
string getDate();
|
||||||
string getCreator();
|
string getCreator();
|
||||||
string getPublisher();
|
string getPublisher();
|
||||||
|
string getOrigId();
|
||||||
bool getFavicon(string &content, string &mimeType);
|
bool getFavicon(string &content, string &mimeType);
|
||||||
bool getPageUrlFromTitle(const string &title, string &url);
|
bool getPageUrlFromTitle(const string &title, string &url);
|
||||||
bool getContentByUrl(const string &url, string &content, unsigned int &contentLength, string &contentType);
|
bool getContentByUrl(const string &url, string &content, unsigned int &contentLength, string &contentType);
|
||||||
|
|
|
@ -174,36 +174,40 @@ std::string kiwix::ucFirst (const std::string &word) {
|
||||||
if (word.empty())
|
if (word.empty())
|
||||||
return "";
|
return "";
|
||||||
|
|
||||||
std::string ucFirstWord;
|
std::string result;
|
||||||
|
|
||||||
#ifdef __ANDROID__
|
UnicodeString unicodeWord(word.c_str());
|
||||||
ucFirstWord = word;
|
UnicodeString unicodeFirstLetter = unicodeWord.tempSubString(0, 1).toUpper();
|
||||||
ucFirstWord[0] = toupper(ucFirstWord[0]);
|
unicodeWord.replace(0, 1, unicodeFirstLetter);
|
||||||
#else
|
unicodeWord.toUTF8String(result);
|
||||||
UnicodeString firstLetter = UnicodeString(word.substr(0, 1).c_str());
|
|
||||||
UnicodeString ucFirstLetter = firstLetter.toUpper();
|
|
||||||
ucFirstLetter.toUTF8String(ucFirstWord);
|
|
||||||
ucFirstWord += word.substr(1);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return ucFirstWord;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string kiwix::lcFirst (const std::string &word) {
|
std::string kiwix::lcFirst (const std::string &word) {
|
||||||
if (word.empty())
|
if (word.empty())
|
||||||
return "";
|
return "";
|
||||||
|
|
||||||
std::string ucFirstWord;
|
std::string result;
|
||||||
|
|
||||||
#ifdef __ANDROID__
|
UnicodeString unicodeWord(word.c_str());
|
||||||
ucFirstWord = word;
|
UnicodeString unicodeFirstLetter = unicodeWord.tempSubString(0, 1).toLower();
|
||||||
ucFirstWord[0] = tolower(ucFirstWord[0]);
|
unicodeWord.replace(0, 1, unicodeFirstLetter);
|
||||||
#else
|
unicodeWord.toUTF8String(result);
|
||||||
UnicodeString firstLetter = UnicodeString(word.substr(0, 1).c_str());
|
|
||||||
UnicodeString ucFirstLetter = firstLetter.toLower();
|
|
||||||
ucFirstLetter.toUTF8String(ucFirstWord);
|
|
||||||
ucFirstWord += word.substr(1);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return ucFirstWord;
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::string kiwix::toTitle (const std::string &word) {
|
||||||
|
if (word.empty())
|
||||||
|
return "";
|
||||||
|
|
||||||
|
std::string result;
|
||||||
|
|
||||||
|
UnicodeString unicodeWord(word.c_str());
|
||||||
|
unicodeWord = unicodeWord.toTitle(0);
|
||||||
|
unicodeWord.toUTF8String(result);
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,6 @@
|
||||||
#ifndef KIWIX_STRINGTOOLS_H
|
#ifndef KIWIX_STRINGTOOLS_H
|
||||||
#define KIWIX_STRINGTOOLS_H
|
#define KIWIX_STRINGTOOLS_H
|
||||||
|
|
||||||
#ifndef __ANDROID__
|
|
||||||
#include <unicode/translit.h>
|
#include <unicode/translit.h>
|
||||||
#include <unicode/normlzr.h>
|
#include <unicode/normlzr.h>
|
||||||
#include <unicode/unistr.h>
|
#include <unicode/unistr.h>
|
||||||
|
@ -29,7 +28,6 @@
|
||||||
#include <unicode/uniset.h>
|
#include <unicode/uniset.h>
|
||||||
#include <unicode/ustring.h>
|
#include <unicode/ustring.h>
|
||||||
#include <unicode/ucnv.h>
|
#include <unicode/ucnv.h>
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
@ -58,6 +56,7 @@ namespace kiwix {
|
||||||
|
|
||||||
std::string ucFirst(const std::string &word);
|
std::string ucFirst(const std::string &word);
|
||||||
std::string lcFirst(const std::string &word);
|
std::string lcFirst(const std::string &word);
|
||||||
|
std::string toTitle(const std::string &word);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue