From 4c987f7feb504fe4011b52ffeb231e3b25823de1 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Mon, 13 Aug 2012 01:45:42 +0100 Subject: Basic subtitle test works. --- src/xml.cc | 69 ++++++++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 51 insertions(+), 18 deletions(-) (limited to 'src/xml.cc') diff --git a/src/xml.cc b/src/xml.cc index 79baa01c..21912bdf 100644 --- a/src/xml.cc +++ b/src/xml.cc @@ -2,6 +2,7 @@ #include #include #include +#include #include #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 (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 b; + boost::split (b, t, is_any_of (":")); + assert (b.size() == 4); + + return Time (lexical_cast (b[0]), lexical_cast (b[1]), lexical_cast (b[2]), lexical_cast (b[3])); +} + +string +XMLNode::string_attribute (string name) +{ + xmlpp::Element const * e = dynamic_cast (_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 (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 (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)) { -- cgit v1.2.3