mirror of https://github.com/kiwix/libkiwix.git
Move mimetypeCounter parsing in its own function.
This commit is contained in:
parent
d546ae38c4
commit
4407dd12bd
|
@ -22,6 +22,8 @@
|
|||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <zim/zim.h>
|
||||
|
||||
namespace pugi {
|
||||
class xml_node;
|
||||
|
@ -41,6 +43,8 @@ namespace kiwix
|
|||
const std::string& tagName);
|
||||
bool convertStrToBool(const std::string& value);
|
||||
|
||||
using MimeCounterType = std::map<const std::string, zim::article_index_type>;
|
||||
MimeCounterType parseMimetypeCounter(const std::string& counterData);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -103,29 +103,16 @@ zim::File* Reader::getZimFileHandler() const
|
|||
{
|
||||
return this->zimFileHandler;
|
||||
}
|
||||
std::map<const std::string, unsigned int> Reader::parseCounterMetadata() const
|
||||
{
|
||||
std::map<const std::string, unsigned int> counters;
|
||||
string mimeType, item, counterString;
|
||||
unsigned int counter;
|
||||
|
||||
MimeCounterType Reader::parseCounterMetadata() const
|
||||
{
|
||||
zim::Article article = this->zimFileHandler->getArticle('M', "Counter");
|
||||
|
||||
if (article.good()) {
|
||||
stringstream ssContent(article.getData());
|
||||
|
||||
while (getline(ssContent, item, ';')) {
|
||||
stringstream ssItem(item);
|
||||
getline(ssItem, mimeType, '=');
|
||||
getline(ssItem, counterString, '=');
|
||||
if (!counterString.empty() && !mimeType.empty()) {
|
||||
sscanf(counterString.c_str(), "%u", &counter);
|
||||
counters.insert(pair<string, int>(mimeType, counter));
|
||||
}
|
||||
}
|
||||
return parseMimetypeCounter(article.getData());
|
||||
}
|
||||
|
||||
return counters;
|
||||
return MimeCounterType();
|
||||
}
|
||||
|
||||
/* Get the count of articles which can be indexed/displayed */
|
||||
|
|
|
@ -280,3 +280,24 @@ bool kiwix::convertStrToBool(const std::string& value)
|
|||
throw std::domain_error(ss.str());
|
||||
}
|
||||
|
||||
|
||||
kiwix::MimeCounterType kiwix::parseMimetypeCounter(const std::string& counterData)
|
||||
{
|
||||
kiwix::MimeCounterType counters;
|
||||
std::string mimeType, item, counterString;
|
||||
unsigned int counter;
|
||||
|
||||
std::stringstream ssContent(counterData);
|
||||
|
||||
while (getline(ssContent, item, ';')) {
|
||||
std::stringstream ssItem(item);
|
||||
getline(ssItem, mimeType, '=');
|
||||
getline(ssItem, counterString, '=');
|
||||
if (!counterString.empty() && !mimeType.empty()) {
|
||||
sscanf(counterString.c_str(), "%u", &counter);
|
||||
counters.insert(std::pair<std::string, int>(mimeType, counter));
|
||||
}
|
||||
}
|
||||
|
||||
return counters;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue