| 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 #include "base/memory/ptr_util.h" |
| 8 |
| 7 XmlAttributes::XmlAttributes() {} | 9 XmlAttributes::XmlAttributes() {} |
| 8 | 10 |
| 9 XmlAttributes::XmlAttributes(const base::StringPiece& attr_key, | 11 XmlAttributes::XmlAttributes(const base::StringPiece& attr_key, |
| 10 const base::StringPiece& attr_value) { | 12 const base::StringPiece& attr_value) { |
| 11 add(attr_key, attr_value); | 13 add(attr_key, attr_value); |
| 12 } | 14 } |
| 13 | 15 |
| 14 XmlAttributes& XmlAttributes::add(const base::StringPiece& attr_key, | 16 XmlAttributes& XmlAttributes::add(const base::StringPiece& attr_key, |
| 15 const base::StringPiece& attr_value) { | 17 const base::StringPiece& attr_value) { |
| 16 push_back(std::make_pair(attr_key, attr_value)); | 18 push_back(std::make_pair(attr_key, attr_value)); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 46 out_ << std::string(indent_, ' '); | 48 out_ << std::string(indent_, ' '); |
| 47 out_ << "</" << tag_ << '>' << std::endl; | 49 out_ << "</" << tag_ << '>' << std::endl; |
| 48 } | 50 } |
| 49 } | 51 } |
| 50 | 52 |
| 51 void XmlElementWriter::Text(const base::StringPiece& content) { | 53 void XmlElementWriter::Text(const base::StringPiece& content) { |
| 52 StartContent(false); | 54 StartContent(false); |
| 53 out_ << content; | 55 out_ << content; |
| 54 } | 56 } |
| 55 | 57 |
| 56 scoped_ptr<XmlElementWriter> XmlElementWriter::SubElement( | 58 std::unique_ptr<XmlElementWriter> XmlElementWriter::SubElement( |
| 57 const std::string& tag) { | 59 const std::string& tag) { |
| 58 return SubElement(tag, XmlAttributes()); | 60 return SubElement(tag, XmlAttributes()); |
| 59 } | 61 } |
| 60 | 62 |
| 61 scoped_ptr<XmlElementWriter> XmlElementWriter::SubElement( | 63 std::unique_ptr<XmlElementWriter> XmlElementWriter::SubElement( |
| 62 const std::string& tag, | 64 const std::string& tag, |
| 63 const XmlAttributes& attributes) { | 65 const XmlAttributes& attributes) { |
| 64 StartContent(true); | 66 StartContent(true); |
| 65 return make_scoped_ptr( | 67 return base::WrapUnique( |
| 66 new XmlElementWriter(out_, tag, attributes, indent_ + 2)); | 68 new XmlElementWriter(out_, tag, attributes, indent_ + 2)); |
| 67 } | 69 } |
| 68 | 70 |
| 69 std::ostream& XmlElementWriter::StartContent(bool start_new_line) { | 71 std::ostream& XmlElementWriter::StartContent(bool start_new_line) { |
| 70 if (!opening_tag_finished_) { | 72 if (!opening_tag_finished_) { |
| 71 out_ << '>'; | 73 out_ << '>'; |
| 72 opening_tag_finished_ = true; | 74 opening_tag_finished_ = true; |
| 73 | 75 |
| 74 if (start_new_line && one_line_) { | 76 if (start_new_line && one_line_) { |
| 75 out_ << std::endl; | 77 out_ << std::endl; |
| 76 one_line_ = false; | 78 one_line_ = false; |
| 77 } | 79 } |
| 78 } | 80 } |
| 79 | 81 |
| 80 return out_; | 82 return out_; |
| 81 } | 83 } |
| OLD | NEW |