From 726c09029729673cf66386bafb7152b2d3b55466 Mon Sep 17 00:00:00 2001 From: Vitaly Stakhovsky Date: Tue, 22 May 2018 11:01:54 -0400 Subject: cmVisualStudio10TargetGenerator: close XML tag in Elem destructor RAII actually implemented; EndElement() still kept to avoid major reformatting --- Source/cmVisualStudio10TargetGenerator.cxx | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index fa6c8ad..b373dce 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -42,6 +42,7 @@ struct cmVisualStudio10TargetGenerator::Elem std::ostream& S; const int Indent; bool HasElements = false; + bool HasContent = false; std::string Tag; Elem(std::ostream& s) @@ -79,8 +80,7 @@ struct cmVisualStudio10TargetGenerator::Elem } void Element(const char* tag, const std::string& val) { - Elem(*this).WriteString("<") << tag << ">" << cmVS10EscapeXML(val) << "\n"; + Elem(*this, tag).Content(val); } Elem& Attribute(const char* an, const std::string& av) { @@ -88,13 +88,17 @@ struct cmVisualStudio10TargetGenerator::Elem return *this; } // This method for now assumes that this->Tag has been set, e.g. by calling - // StartElement(). Also, it finishes the element so it should be the last - // one called + // StartElement(). void Content(const std::string& val) { - S << ">" << cmVS10EscapeXML(val) << "Tag << ">\n"; + if (!this->HasContent) { + this->S << ">"; + this->HasContent = true; + } + this->S << cmVS10EscapeXML(val); } - void EndElement() + void EndElement() {} + ~Elem() { // Do not emit element which has not been started if (Tag.empty()) { @@ -108,6 +112,8 @@ struct cmVisualStudio10TargetGenerator::Elem } else { // special case: don't print EOL at EOF } + } else if (HasContent) { + this->S << "Tag << ">\n"; } else { this->S << " />\n"; } -- cgit v0.12