mirror of https://github.com/kiwix/libkiwix.git
Introduce readCategoriesFromFeed()
Added a function to load categories stored in an OPDS stream
This commit is contained in:
parent
a28c2973e9
commit
94d6bef402
|
@ -28,6 +28,7 @@
|
||||||
namespace kiwix {
|
namespace kiwix {
|
||||||
typedef std::pair<std::string, std::string> LangNameCodePair;
|
typedef std::pair<std::string, std::string> LangNameCodePair;
|
||||||
typedef std::vector<LangNameCodePair> FeedLanguages;
|
typedef std::vector<LangNameCodePair> FeedLanguages;
|
||||||
|
typedef std::vector<std::string> FeedCategories;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the current directory.
|
* Return the current directory.
|
||||||
|
@ -235,5 +236,13 @@ std::string beautifyFileSize(uint64_t number);
|
||||||
* @return vector containing pairs of language code and their corresponding full language name.
|
* @return vector containing pairs of language code and their corresponding full language name.
|
||||||
*/
|
*/
|
||||||
FeedLanguages readLanguagesFromFeed(const std::string& content);
|
FeedLanguages readLanguagesFromFeed(const std::string& content);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load categories stored in an OPDS stream .
|
||||||
|
*
|
||||||
|
* @param content the OPDS stream.
|
||||||
|
* @return vector containing category strings.
|
||||||
|
*/
|
||||||
|
FeedCategories readCategoriesFromFeed(const std::string& content);
|
||||||
}
|
}
|
||||||
#endif // KIWIX_TOOLS_H
|
#endif // KIWIX_TOOLS_H
|
||||||
|
|
|
@ -22,6 +22,20 @@ FeedLanguages parseLanguages(const pugi::xml_document& doc)
|
||||||
return langs;
|
return langs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FeedCategories parseCategories(const pugi::xml_document& doc)
|
||||||
|
{
|
||||||
|
pugi::xml_node feedNode = doc.child("feed");
|
||||||
|
FeedCategories categories;
|
||||||
|
|
||||||
|
for (pugi::xml_node entryNode = feedNode.child("entry"); entryNode;
|
||||||
|
entryNode = entryNode.next_sibling("entry")) {
|
||||||
|
auto title = VALUE("title");
|
||||||
|
categories.push_back(title);
|
||||||
|
}
|
||||||
|
|
||||||
|
return categories;
|
||||||
|
}
|
||||||
|
|
||||||
} // unnamed namespace
|
} // unnamed namespace
|
||||||
|
|
||||||
FeedLanguages readLanguagesFromFeed(const std::string& content)
|
FeedLanguages readLanguagesFromFeed(const std::string& content)
|
||||||
|
@ -38,4 +52,19 @@ FeedLanguages readLanguagesFromFeed(const std::string& content)
|
||||||
return FeedLanguages();
|
return FeedLanguages();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FeedCategories readCategoriesFromFeed(const std::string& content)
|
||||||
|
{
|
||||||
|
pugi::xml_document doc;
|
||||||
|
pugi::xml_parse_result result
|
||||||
|
= doc.load_buffer((void*)content.data(), content.size());
|
||||||
|
|
||||||
|
FeedCategories categories;
|
||||||
|
if (result) {
|
||||||
|
categories = parseCategories(doc);
|
||||||
|
return categories;
|
||||||
|
}
|
||||||
|
|
||||||
|
return categories;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace kiwix
|
} // namespace kiwix
|
||||||
|
|
Loading…
Reference in New Issue