X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=c%2B%2B11%2Fxml-template.cpp;h=bf6c085052356e0729c1f73600fcff36e13de4c7;hb=7d1da52761b9ec9747c4400609658a379a34392c;hp=4f0c9fef6e903aa4a9772de64e176d612dd3c291;hpb=cba8eef965a5c243cd8bf51059f3bdd98793a22c;p=xml-template diff --git a/c++11/xml-template.cpp b/c++11/xml-template.cpp index 4f0c9fe..bf6c085 100644 --- a/c++11/xml-template.cpp +++ b/c++11/xml-template.cpp @@ -1,5 +1,6 @@ #include "xml-template.h" +#include #include #include @@ -144,6 +145,7 @@ Alternate::Alternate(const string &attribute, continue; } string value = alternatives[jx++ % alternatives.size()]; + Replace *r = new Replace { value }; subdirectives_subs[ix]->substitution_map.insert(make_pair( attribute, new Replace { value })); @@ -191,18 +193,21 @@ void Substitute::process(xmlNode *node, bool clean) // Check all substitutions to see if we found anything appropriate. string tag = reinterpret_cast(child->name); for (auto it : substitution_map) { + assert(it.second != nullptr); // Attribute substitution. if (begins_with(it.first, tag + "/")) { + string contents = it.second->get_contents(); const xmlChar *attr_key = reinterpret_cast( it.first.c_str() + tag.size() + 1); const xmlChar *attr_value = reinterpret_cast( - it.second->get_contents().c_str()); + contents.c_str()); xmlSetProp(child, attr_key, attr_value); } else if ((!id.empty() && begins_with(it.first, "#" + id + "/"))) { + string contents = it.second->get_contents(); const xmlChar *attr_key = reinterpret_cast( it.first.c_str() + id.size() + 2); const xmlChar *attr_value = reinterpret_cast( - it.second->get_contents().c_str()); + contents.c_str()); xmlSetProp(child, attr_key, attr_value); }