diff options
| author | Carl Hetherington <cth@carlh.net> | 2012-08-13 01:45:42 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2012-08-13 01:45:42 +0100 |
| commit | 4c987f7feb504fe4011b52ffeb231e3b25823de1 (patch) | |
| tree | 893c852593830fa5fe5a769bf61fcef86d57b9bf /src/xml.cc | |
| parent | c14a05a935886345d4d891a92a31b1c35bf10582 (diff) | |
Basic subtitle test works.
Diffstat (limited to 'src/xml.cc')
| -rw-r--r-- | src/xml.cc | 69 |
1 files changed, 51 insertions, 18 deletions
@@ -2,6 +2,7 @@ #include <iostream> #include <boost/lexical_cast.hpp> #include <boost/filesystem.hpp> +#include <boost/algorithm/string.hpp> #include <libxml++/libxml++.h> #include "xml.h" #include "exceptions.h" @@ -59,24 +60,7 @@ XMLNode::xml_nodes (string name) string XMLNode::string_node (string name) { - xmlpp::Node* node = xml_node (name); - - xmlpp::Node::NodeList c = node->get_children (); - - if (c.size() > 1) { - throw XMLError ("unexpected content in XML node"); - } - - if (c.empty ()) { - return ""; - } - - xmlpp::ContentNode const * v = dynamic_cast<xmlpp::ContentNode const *> (c.front()); - if (!v) { - throw XMLError ("missing content in XML node"); - } - - return v->get_content (); + return XMLNode (xml_node (name)).content (); } string @@ -142,7 +126,35 @@ XMLNode::ignore_node (string name) Time XMLNode::time_attribute (string name) { + string const t = string_attribute (name); + + vector<string> b; + boost::split (b, t, is_any_of (":")); + assert (b.size() == 4); + + return Time (lexical_cast<int> (b[0]), lexical_cast<int> (b[1]), lexical_cast<int> (b[2]), lexical_cast<int> (b[3])); +} + +string +XMLNode::string_attribute (string name) +{ + xmlpp::Element const * e = dynamic_cast<const xmlpp::Element *> (_node); + if (!e) { + return ""; + } + + xmlpp::Attribute* a = e->get_attribute (name); + if (!a) { + return ""; + } + return a->get_value (); +} + +float +XMLNode::float_attribute (string name) +{ + return lexical_cast<float> (string_attribute (name)); } void @@ -156,6 +168,27 @@ XMLNode::done () } } +string +XMLNode::content () +{ + xmlpp::Node::NodeList c = _node->get_children (); + + if (c.size() > 1) { + throw XMLError ("unexpected content in XML node"); + } + + if (c.empty ()) { + return ""; + } + + xmlpp::ContentNode const * v = dynamic_cast<xmlpp::ContentNode const *> (c.front()); + if (!v) { + throw XMLError ("missing content in XML node"); + } + + return v->get_content (); +} + XMLFile::XMLFile (string file, string root_name) { if (!filesystem::exists (file)) { |
