catching up with master

This commit is contained in:
renaud gaudin 2013-12-09 12:02:58 +00:00
commit fd9c9ac17e
7 changed files with 225 additions and 140 deletions

View File

@ -67,6 +67,7 @@ namespace kiwix {
string publisher;
string date;
string url;
string origId;
string articleCount;
string mediaCount;
bool readOnly;

View File

@ -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,41 +155,46 @@ namespace kiwix {
bookNode.append_attribute("indexType") = "xapian";
}
if (!itr->title.empty())
bookNode.append_attribute("title") = itr->title.c_str();
if (itr->origId.empty()) {
if (!itr->title.empty())
bookNode.append_attribute("title") = itr->title.c_str();
if (itr->description != "")
bookNode.append_attribute("description") = itr->description.c_str();
if (!itr->description.empty())
bookNode.append_attribute("description") = itr->description.c_str();
if (itr->language != "")
bookNode.append_attribute("language") = itr->language.c_str();
if (!itr->language.empty())
bookNode.append_attribute("language") = itr->language.c_str();
if (itr->date != "")
if (!itr->creator.empty())
bookNode.append_attribute("creator") = itr->creator.c_str();
if (!itr->publisher.empty())
bookNode.append_attribute("publisher") = itr->publisher.c_str();
if (!itr->favicon.empty())
bookNode.append_attribute("favicon") = itr->favicon.c_str();
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->creator != "")
bookNode.append_attribute("creator") = itr->creator.c_str();
if (itr->publisher != "")
bookNode.append_attribute("publisher") = itr->publisher.c_str();
if (itr->url != "")
if (!itr->url.empty())
bookNode.append_attribute("url") = itr->url.c_str();
if (itr->articleCount != "")
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 != "")
if (!itr->mediaCount.empty())
bookNode.append_attribute("mediaCount") = itr->mediaCount.c_str();
if (itr->size != "")
if (!itr->size.empty())
bookNode.append_attribute("size") = itr->size.c_str();
if (itr->favicon != "")
bookNode.append_attribute("favicon") = itr->favicon.c_str();
if (itr->faviconMimeType != "")
bookNode.append_attribute("faviconMimeType") = itr->faviconMimeType.c_str();
}
}
@ -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();
@ -307,10 +313,12 @@ namespace kiwix {
std::map<string, bool> booksLanguagesMap;
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()) {
booksLanguagesMap[itr->language] = true;
booksLanguages.push_back(itr->language);
if (itr->origId.empty()) {
booksLanguagesMap[itr->language] = true;
booksLanguages.push_back(itr->language);
}
}
}
@ -323,10 +331,12 @@ namespace kiwix {
std::map<string, bool> booksCreatorsMap;
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()) {
booksCreatorsMap[itr->creator] = true;
booksCreators.push_back(itr->creator);
if (itr->origId.empty()) {
booksCreatorsMap[itr->creator] = true;
booksCreators.push_back(itr->creator);
}
}
}
@ -353,8 +363,10 @@ 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()) {
booksPublishersMap[itr->publisher] = true;
booksPublishers.push_back(itr->publisher);
if (itr->origId.empty()) {
booksPublishersMap[itr->publisher] = true;
booksPublishers.push_back(itr->publisher);
}
}
}

View File

@ -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;
}

View File

@ -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);

View File

@ -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;
}

View File

@ -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