diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2018-04-23 18:14:16 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-04-23 18:14:16 +0000 |
commit | 9a3a7709103a872037dcea1f3cf0b7785a3da191 (patch) | |
tree | 262538d8f7f8e5b9703a7c37e7ec2f1b477aebe3 /core/fxcrt/xml/cfx_xmlelement.cpp | |
parent | b557bdcbd1584a7e37f8883b0fc491e0641cfc9c (diff) | |
download | pdfium-9a3a7709103a872037dcea1f3cf0b7785a3da191.tar.xz |
Change CFX_XML Save to take a write stream
This CL changes CFX_XML to use an IFX_SeekableWriteStream instead of the more
generic IFX_SeekableStream.
Change-Id: I6e4def380c43eca755d91ad5cb6146c2dfdaee10
Reviewed-on: https://pdfium-review.googlesource.com/30877
Commit-Queue: dsinclair <dsinclair@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'core/fxcrt/xml/cfx_xmlelement.cpp')
-rw-r--r-- | core/fxcrt/xml/cfx_xmlelement.cpp | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/core/fxcrt/xml/cfx_xmlelement.cpp b/core/fxcrt/xml/cfx_xmlelement.cpp index 5e79da63cf..8c8922e0c6 100644 --- a/core/fxcrt/xml/cfx_xmlelement.cpp +++ b/core/fxcrt/xml/cfx_xmlelement.cpp @@ -33,10 +33,9 @@ std::unique_ptr<CFX_XMLNode> CFX_XMLElement::Clone() { // TODO(dsinclair): This clone is wrong. It doesn't clone child nodes just // copies text nodes? WideString wsText; - for (CFX_XMLNode* pChild = GetFirstChild(); pChild; - pChild = pChild->GetNextSibling()) { + for (const auto& pChild : *this) { if (pChild->GetType() == FX_XMLNODE_Text) - wsText += static_cast<CFX_XMLText*>(pChild)->GetText(); + wsText += static_cast<CFX_XMLText*>(pChild.get())->GetText(); } pClone->SetTextData(wsText); return std::move(pClone); @@ -79,11 +78,10 @@ WideString CFX_XMLElement::GetNamespaceURI() const { WideString CFX_XMLElement::GetTextData() const { CFX_WideTextBuf buffer; - for (CFX_XMLNode* pChild = GetFirstChild(); pChild; - pChild = pChild->GetNextSibling()) { + for (const auto& pChild : *this) { if (pChild->GetType() == FX_XMLNODE_Text || pChild->GetType() == FX_XMLNODE_CharData) { - buffer << static_cast<CFX_XMLText*>(pChild)->GetText(); + buffer << static_cast<CFX_XMLText*>(pChild.get())->GetText(); } } return buffer.MakeString(); @@ -96,7 +94,8 @@ void CFX_XMLElement::SetTextData(const WideString& wsText) { AppendChild(pdfium::MakeUnique<CFX_XMLText>(wsText)); } -void CFX_XMLElement::Save(const RetainPtr<IFX_SeekableStream>& pXMLStream) { +void CFX_XMLElement::Save( + const RetainPtr<IFX_SeekableWriteStream>& pXMLStream) { ByteString bsNameEncoded = name_.UTF8Encode(); pXMLStream->WriteString("<"); @@ -109,17 +108,16 @@ void CFX_XMLElement::Save(const RetainPtr<IFX_SeekableStream>& pXMLStream) { AttributeToString(it.first, it.second).UTF8Encode().AsStringView()); } - if (!GetFirstChild()) { + if (HasChildren()) { pXMLStream->WriteString(" />\n"); return; } pXMLStream->WriteString(">\n"); - for (CFX_XMLNode* pChild = GetFirstChild(); pChild; - pChild = pChild->GetNextSibling()) { + for (const auto& pChild : *this) pChild->Save(pXMLStream); - } + pXMLStream->WriteString("</"); pXMLStream->WriteString(bsNameEncoded.AsStringView()); pXMLStream->WriteString(">\n"); @@ -132,11 +130,11 @@ CFX_XMLElement* CFX_XMLElement::GetFirstChildNamed( CFX_XMLElement* CFX_XMLElement::GetNthChildNamed(const WideStringView& name, size_t idx) const { - for (auto* child = GetFirstChild(); child; child = child->GetNextSibling()) { + for (const auto& child : *this) { if (child->GetType() != FX_XMLNODE_Element) continue; - CFX_XMLElement* elem = static_cast<CFX_XMLElement*>(child); + CFX_XMLElement* elem = static_cast<CFX_XMLElement*>(child.get()); if (elem->name_ != name) continue; if (idx == 0) |