mirror of https://github.com/kiwix/libkiwix.git
* merge unescapeurl() with the kiwix:urlDecode()
* create getContentByDecodedUrl() and getContentByEncodedUrl()
This commit is contained in:
parent
5e974f67c6
commit
8397c81e6f
|
@ -49,25 +49,6 @@ std::string hexUUID (std::string in) {
|
||||||
return op;
|
return op;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static char charFromHex(std::string a) {
|
|
||||||
std::istringstream Blat (a);
|
|
||||||
int Z;
|
|
||||||
Blat >> std::hex >> Z;
|
|
||||||
return char (Z);
|
|
||||||
}
|
|
||||||
|
|
||||||
void unescapeUrl(string &url) {
|
|
||||||
std::string::size_type pos = 0;
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace kiwix {
|
namespace kiwix {
|
||||||
|
|
||||||
/* Constructor */
|
/* Constructor */
|
||||||
|
@ -385,24 +366,30 @@ namespace kiwix {
|
||||||
|
|
||||||
/* unescape title */
|
/* unescape title */
|
||||||
title = url.substr(titleOffset, offset - titleOffset);
|
title = url.substr(titleOffset, offset - titleOffset);
|
||||||
unescapeUrl(title);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get a content from a zim file */
|
/* Get a content from a zim file */
|
||||||
bool Reader::getContentByUrl(const string &urlStr, string &content, unsigned int &contentLength, string &contentType) {
|
bool Reader::getContentByUrl(const string &url, string &content, unsigned int &contentLength, string &contentType) {
|
||||||
|
return this->getContentByEncodedUrl(url, content, contentLength, contentType);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Reader::getContentByEncodedUrl(const string &url, string &content, unsigned int &contentLength, string &contentType) {
|
||||||
|
return this->getContentByDecodedUrl(kiwix::urlDecode(url), content, contentLength, contentType);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Reader::getContentByDecodedUrl(const string &url, string &content, unsigned int &contentLength, string &contentType) {
|
||||||
bool retVal = false;
|
bool retVal = false;
|
||||||
content="";
|
content="";
|
||||||
contentType="";
|
contentType="";
|
||||||
contentLength = 0;
|
contentLength = 0;
|
||||||
|
|
||||||
if (this->zimFileHandler != NULL) {
|
if (this->zimFileHandler != NULL) {
|
||||||
|
|
||||||
/* Parse the url */
|
/* Parse the url */
|
||||||
char ns = 0;
|
char ns = 0;
|
||||||
string titleStr;
|
string titleStr;
|
||||||
this->parseUrl(urlStr, &ns, titleStr);
|
this->parseUrl(url, &ns, titleStr);
|
||||||
|
|
||||||
/* Main page */
|
/* Main page */
|
||||||
if (titleStr.empty() && ns == 0) {
|
if (titleStr.empty() && ns == 0) {
|
||||||
|
|
Loading…
Reference in New Issue