Add item attribute accessor functions

This commit is contained in:
Clortox 2021-07-25 19:50:30 -04:00
parent 56ffed1260
commit b29bc17bee
2 changed files with 58 additions and 10 deletions

View File

@ -434,6 +434,18 @@ std::string item::getGuid() const {
return cdata_to_string(tmp);
}
bool item::getGuidPermaLink() const {
rapidxml::xml_node<>* tmp = _item->first_node("guid");
if(tmp == 0)
return false;
rapidxml::xml_attribute<>* attr = tmp->first_attribute("isPermaLink");
if(attr == 0)
return false;
else if(attr->value() == std::string("true"))
return false;
return false;
}
std::string item::getPubDate() const {
rapidxml::xml_node<>* tmp = _item->first_node("pubDate");
if(tmp == 0)
@ -448,3 +460,35 @@ std::string item::getSource() const {
return cdata_to_string(tmp);
}
std::string item::getEnclosureURL() const {
rapidxml::xml_node<>* tmp = _item->first_node("enclosure");
if(tmp == 0)
return "";
rapidxml::xml_attribute<>* attr = tmp->first_attribute("url");
if(attr == 0)
return "";
else
return attr->value();
}
std::string item::getEnclosureType() const {
rapidxml::xml_node<>* tmp = _item->first_node("enclosure");
if(tmp == 0)
return "";
rapidxml::xml_attribute<>* attr = tmp->first_attribute("type");
if(attr == 0)
return "";
else
return attr->value();
}
int item::getEnclosureLength() const {
rapidxml::xml_node<>* tmp = _item->first_node("enclosure");
if(tmp == 0)
return -1;
rapidxml::xml_attribute<>* attr = tmp->first_attribute("length");
if(attr == 0)
return -1;
else
return atoi(attr->value());
}

View File

@ -94,11 +94,15 @@ namespace rss_utils {
std::string getAuthor() const;
std::string getCategory() const;
std::string getComments() const;
//std::string getEnclosure() const;
std::string getGuid() const;
bool getGuidPermaLink() const;
std::string getPubDate() const;
std::string getSource() const;
std::string getEnclosureURL() const;
std::string getEnclosureType() const;
int getEnclosureLength() const;
private:
std::string cdata_to_string(const rapidxml::xml_node<>*) const;