| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "tools/gn/xml_element_writer.h" | 5 #include "tools/gn/xml_element_writer.h" |
| 6 | 6 |
| 7 XmlAttributes::XmlAttributes() {} | 7 XmlAttributes::XmlAttributes() {} |
| 8 | 8 |
| 9 XmlAttributes::XmlAttributes(const base::StringPiece& attr_key, | 9 XmlAttributes::XmlAttributes(const base::StringPiece& attr_key, |
| 10 const base::StringPiece& attr_value) { | 10 const base::StringPiece& attr_value) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 indent_(indent), | 31 indent_(indent), |
| 32 opening_tag_finished_(false), | 32 opening_tag_finished_(false), |
| 33 one_line_(true) { | 33 one_line_(true) { |
| 34 out << std::string(indent, ' ') << '<' << tag; | 34 out << std::string(indent, ' ') << '<' << tag; |
| 35 for (auto attribute : attributes) | 35 for (auto attribute : attributes) |
| 36 out << ' ' << attribute.first << "=\"" << attribute.second << '"'; | 36 out << ' ' << attribute.first << "=\"" << attribute.second << '"'; |
| 37 } | 37 } |
| 38 | 38 |
| 39 XmlElementWriter::~XmlElementWriter() { | 39 XmlElementWriter::~XmlElementWriter() { |
| 40 if (!opening_tag_finished_) { | 40 if (!opening_tag_finished_) { |
| 41 out_ << "/>" << std::endl; | 41 // The XML spec does not require a space before the closing slash. However, |
| 42 // Eclipse is unable to parse XML settings files if there is no space. |
| 43 out_ << " />" << std::endl; |
| 42 } else { | 44 } else { |
| 43 if (!one_line_) | 45 if (!one_line_) |
| 44 out_ << std::string(indent_, ' '); | 46 out_ << std::string(indent_, ' '); |
| 45 out_ << "</" << tag_ << '>' << std::endl; | 47 out_ << "</" << tag_ << '>' << std::endl; |
| 46 } | 48 } |
| 47 } | 49 } |
| 48 | 50 |
| 49 void XmlElementWriter::Text(const base::StringPiece& content) { | 51 void XmlElementWriter::Text(const base::StringPiece& content) { |
| 50 StartContent(false); | 52 StartContent(false); |
| 51 out_ << content; | 53 out_ << content; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 70 opening_tag_finished_ = true; | 72 opening_tag_finished_ = true; |
| 71 | 73 |
| 72 if (start_new_line && one_line_) { | 74 if (start_new_line && one_line_) { |
| 73 out_ << std::endl; | 75 out_ << std::endl; |
| 74 one_line_ = false; | 76 one_line_ = false; |
| 75 } | 77 } |
| 76 } | 78 } |
| 77 | 79 |
| 78 return out_; | 80 return out_; |
| 79 } | 81 } |
| OLD | NEW |