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 date;
|
||||
string url;
|
||||
string origId;
|
||||
string articleCount;
|
||||
string mediaCount;
|
||||
bool readOnly;
|
||||
|
|
|
@ -56,6 +56,7 @@ namespace kiwix {
|
|||
book.creator = bookNode.attribute("creator").value();
|
||||
book.publisher = bookNode.attribute("publisher").value();
|
||||
book.url = bookNode.attribute("url").value();
|
||||
book.origId = bookNode.attribute("origId").value();
|
||||
book.articleCount = bookNode.attribute("articleCount").value();
|
||||
book.mediaCount = bookNode.attribute("mediaCount").value();
|
||||
book.size = bookNode.attribute("size").value();
|
||||
|
@ -154,42 +155,47 @@ namespace kiwix {
|
|||
bookNode.append_attribute("indexType") = "xapian";
|
||||
}
|
||||
|
||||
if (itr->origId.empty()) {
|
||||
if (!itr->title.empty())
|
||||
bookNode.append_attribute("title") = itr->title.c_str();
|
||||
|
||||
if (itr->description != "")
|
||||
if (!itr->description.empty())
|
||||
bookNode.append_attribute("description") = itr->description.c_str();
|
||||
|
||||
if (itr->language != "")
|
||||
if (!itr->language.empty())
|
||||
bookNode.append_attribute("language") = itr->language.c_str();
|
||||
|
||||
if (itr->date != "")
|
||||
bookNode.append_attribute("date") = itr->date.c_str();
|
||||
|
||||
if (itr->creator != "")
|
||||
if (!itr->creator.empty())
|
||||
bookNode.append_attribute("creator") = itr->creator.c_str();
|
||||
|
||||
if (itr->publisher != "")
|
||||
if (!itr->publisher.empty())
|
||||
bookNode.append_attribute("publisher") = itr->publisher.c_str();
|
||||
|
||||
if (itr->url != "")
|
||||
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 != "")
|
||||
if (!itr->favicon.empty())
|
||||
bookNode.append_attribute("favicon") = itr->favicon.c_str();
|
||||
|
||||
if (itr->faviconMimeType != "")
|
||||
if (!itr->faviconMimeType.empty())
|
||||
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 */
|
||||
|
@ -256,7 +262,7 @@ namespace kiwix {
|
|||
book->creator = reader->getCreator();
|
||||
book->publisher = reader->getPublisher();
|
||||
book->title = reader->getTitle();
|
||||
|
||||
book->origId = reader->getOrigId();
|
||||
std::ostringstream articleCountStream;
|
||||
articleCountStream << reader->getArticleCount();
|
||||
book->articleCount = articleCountStream.str();
|
||||
|
@ -309,10 +315,12 @@ namespace kiwix {
|
|||
std::sort(library.books.begin(), library.books.end(), kiwix::Book::sortByLanguage);
|
||||
for (itr = library.books.begin(); itr != library.books.end(); ++itr) {
|
||||
if (booksLanguagesMap.find(itr->language) == booksLanguagesMap.end()) {
|
||||
if (itr->origId.empty()) {
|
||||
booksLanguagesMap[itr->language] = true;
|
||||
booksLanguages.push_back(itr->language);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return booksLanguages;
|
||||
}
|
||||
|
@ -325,10 +333,12 @@ namespace kiwix {
|
|||
std::sort(library.books.begin(), library.books.end(), kiwix::Book::sortByCreator);
|
||||
for (itr = library.books.begin(); itr != library.books.end(); ++itr) {
|
||||
if (booksCreatorsMap.find(itr->creator) == booksCreatorsMap.end()) {
|
||||
if (itr->origId.empty()) {
|
||||
booksCreatorsMap[itr->creator] = true;
|
||||
booksCreators.push_back(itr->creator);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return booksCreators;
|
||||
}
|
||||
|
@ -353,10 +363,12 @@ namespace kiwix {
|
|||
std::sort(library.books.begin(), library.books.end(), kiwix::Book::sortByPublisher);
|
||||
for ( itr = library.books.begin(); itr != library.books.end(); ++itr ) {
|
||||
if (booksPublishersMap.find(itr->publisher) == booksPublishersMap.end()) {
|
||||
if (itr->origId.empty()) {
|
||||
booksPublishersMap[itr->publisher] = true;
|
||||
booksPublishers.push_back(itr->publisher);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return booksPublishers;
|
||||
}
|
||||
|
|
|
@ -19,6 +19,38 @@
|
|||
|
||||
#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) {
|
||||
std::istringstream Blat (a);
|
||||
int Z;
|
||||
|
@ -28,9 +60,10 @@ static char charFromHex(std::string a) {
|
|||
|
||||
void unescapeUrl(string &url) {
|
||||
std::string::size_type pos = 0;
|
||||
while ((pos = url.find('%', pos + 1)) != std::string::npos &&
|
||||
pos + 3 <= url.length()) {
|
||||
while ((pos = url.find('%', pos)) != std::string::npos &&
|
||||
pos + 2 < url.length()) {
|
||||
url.replace(pos, 3, 1, charFromHex(url.substr(pos + 1, 2)));
|
||||
++pos;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -289,6 +322,33 @@ namespace kiwix {
|
|||
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 */
|
||||
string Reader::getFirstPageUrl() {
|
||||
string url;
|
||||
|
@ -393,9 +453,13 @@ namespace kiwix {
|
|||
std::vector<std::string>::iterator suggestionItr;
|
||||
int result;
|
||||
|
||||
/* Reset the suggestions */
|
||||
/* Reset the suggestions otherwise check if the suggestions number is less than the suggestionsCount */
|
||||
if (reset) {
|
||||
this->suggestions.clear();
|
||||
} else {
|
||||
if (this->suggestions.size() > suggestionsCount) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (prefix.size()) {
|
||||
|
@ -407,7 +471,7 @@ namespace kiwix {
|
|||
|
||||
if (this->suggestions.size() == 0) {
|
||||
this->suggestions.push_back(articleItr->getTitle());
|
||||
} else {
|
||||
} else if (this->suggestions.size() < suggestionsCount) {
|
||||
for (suggestionItr = this->suggestions.begin() ;
|
||||
suggestionItr != this->suggestions.end();
|
||||
++suggestionItr) {
|
||||
|
@ -452,6 +516,10 @@ namespace kiwix {
|
|||
myPrefix = kiwix::lcFirst(myPrefix);
|
||||
this->searchSuggestions(myPrefix, suggestionsCount, false);
|
||||
|
||||
/* Try with title words */
|
||||
myPrefix = kiwix::toTitle(myPrefix);
|
||||
this->searchSuggestions(myPrefix, suggestionsCount, false);
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
|
|
|
@ -58,6 +58,7 @@ namespace kiwix {
|
|||
string getDate();
|
||||
string getCreator();
|
||||
string getPublisher();
|
||||
string getOrigId();
|
||||
bool getFavicon(string &content, string &mimeType);
|
||||
bool getPageUrlFromTitle(const string &title, string &url);
|
||||
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())
|
||||
return "";
|
||||
|
||||
std::string ucFirstWord;
|
||||
std::string result;
|
||||
|
||||
#ifdef __ANDROID__
|
||||
ucFirstWord = word;
|
||||
ucFirstWord[0] = toupper(ucFirstWord[0]);
|
||||
#else
|
||||
UnicodeString firstLetter = UnicodeString(word.substr(0, 1).c_str());
|
||||
UnicodeString ucFirstLetter = firstLetter.toUpper();
|
||||
ucFirstLetter.toUTF8String(ucFirstWord);
|
||||
ucFirstWord += word.substr(1);
|
||||
#endif
|
||||
UnicodeString unicodeWord(word.c_str());
|
||||
UnicodeString unicodeFirstLetter = unicodeWord.tempSubString(0, 1).toUpper();
|
||||
unicodeWord.replace(0, 1, unicodeFirstLetter);
|
||||
unicodeWord.toUTF8String(result);
|
||||
|
||||
return ucFirstWord;
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string kiwix::lcFirst (const std::string &word) {
|
||||
if (word.empty())
|
||||
return "";
|
||||
|
||||
std::string ucFirstWord;
|
||||
std::string result;
|
||||
|
||||
#ifdef __ANDROID__
|
||||
ucFirstWord = word;
|
||||
ucFirstWord[0] = tolower(ucFirstWord[0]);
|
||||
#else
|
||||
UnicodeString firstLetter = UnicodeString(word.substr(0, 1).c_str());
|
||||
UnicodeString ucFirstLetter = firstLetter.toLower();
|
||||
ucFirstLetter.toUTF8String(ucFirstWord);
|
||||
ucFirstWord += word.substr(1);
|
||||
#endif
|
||||
UnicodeString unicodeWord(word.c_str());
|
||||
UnicodeString unicodeFirstLetter = unicodeWord.tempSubString(0, 1).toLower();
|
||||
unicodeWord.replace(0, 1, unicodeFirstLetter);
|
||||
unicodeWord.toUTF8String(result);
|
||||
|
||||
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
|
||||
#define KIWIX_STRINGTOOLS_H
|
||||
|
||||
#ifndef __ANDROID__
|
||||
#include <unicode/translit.h>
|
||||
#include <unicode/normlzr.h>
|
||||
#include <unicode/unistr.h>
|
||||
|
@ -29,7 +28,6 @@
|
|||
#include <unicode/uniset.h>
|
||||
#include <unicode/ustring.h>
|
||||
#include <unicode/ucnv.h>
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
@ -58,6 +56,7 @@ namespace kiwix {
|
|||
|
||||
std::string ucFirst(const std::string &word);
|
||||
std::string lcFirst(const std::string &word);
|
||||
std::string toTitle(const std::string &word);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue