commit d49b84bf518635bba53630e3077a429dff3517f6 Author: Daniel Swanson Date: Fri Jun 11 11:38:29 2021 -0500 another helper (not symmetric - should probably fix that) diff --git a/lttoolbox/xml_parse_util.cc b/lttoolbox/xml_parse_util.cc index eb5da81..055e962 100644 --- a/lttoolbox/xml_parse_util.cc +++ b/lttoolbox/xml_parse_util.cc @@ -46,6 +46,24 @@ XMLParseUtil::attrib(xmlTextReaderPtr reader, UString const& name, const UString } } +std::string +XMLParseUtil::attrib_str(xmlTextReaderPtr reader, const UString& name) +{ + std::string temp; + temp.reserve(name.size()); + utf8::utf16to8(name.begin(), name.end(), std::back_inserter(temp)); + const xmlChar *attrname = reinterpret_cast(temp.c_str()); + xmlChar *myattr = xmlTextReaderGetAttribute(reader, attrname); + if(myattr == NULL) { + xmlFree(myattr); + return ""; + } else { + std::string result = reinterpret_cast(myattr); + xmlFree(myattr); + return result; + } +} + UString XMLParseUtil::readName(xmlTextReaderPtr reader) { diff --git a/lttoolbox/xml_parse_util.h b/lttoolbox/xml_parse_util.h index a9b5c3c..9409cdd 100644 --- a/lttoolbox/xml_parse_util.h +++ b/lttoolbox/xml_parse_util.h @@ -22,6 +22,7 @@ #include #include #include +#include using namespace std; @@ -35,6 +36,8 @@ public: /* If attrib does not exist (or other error), returns fallback: */ static UString attrib(xmlTextReaderPtr reader, UString const &name, const UString& fallback); + static string attrib_str(xmlTextReaderPtr reader, const UString& name); + static UString readName(xmlTextReaderPtr reader); static UString readValue(xmlTextReaderPtr reader); static void readValueInto32(xmlTextReaderPtr reader, vector& vec);