From bc069b7a855998ab28f487d2f09152851dddb16a Mon Sep 17 00:00:00 2001 From: dan sinclair Date: Tue, 17 Apr 2018 18:12:38 +0000 Subject: Use an IFX_SeekableStream for XML saving This CL converts the CFX_XML Save methods to take an IFX_SeekableStream instead of a CFX_SeekableStreamProxy. Change-Id: I6b3f6acc9f51e73b3c863b965b4dcdcbd25ba949 Reviewed-on: https://pdfium-review.googlesource.com/30850 Commit-Queue: dsinclair Reviewed-by: Tom Sepez --- core/fxcrt/xml/cfx_xmlchardata.cpp | 10 ++++------ core/fxcrt/xml/cfx_xmlchardata.h | 2 +- core/fxcrt/xml/cfx_xmlelement.cpp | 21 +++++++++++---------- core/fxcrt/xml/cfx_xmlelement.h | 2 +- core/fxcrt/xml/cfx_xmlinstruction.cpp | 27 ++++++++------------------- core/fxcrt/xml/cfx_xmlinstruction.h | 2 +- core/fxcrt/xml/cfx_xmlnode.cpp | 2 +- core/fxcrt/xml/cfx_xmlnode.h | 4 ++-- core/fxcrt/xml/cfx_xmltext.cpp | 5 +++-- core/fxcrt/xml/cfx_xmltext.h | 2 +- 10 files changed, 33 insertions(+), 44 deletions(-) (limited to 'core/fxcrt/xml') diff --git a/core/fxcrt/xml/cfx_xmlchardata.cpp b/core/fxcrt/xml/cfx_xmlchardata.cpp index 7712b30dfe..b613b15d00 100644 --- a/core/fxcrt/xml/cfx_xmlchardata.cpp +++ b/core/fxcrt/xml/cfx_xmlchardata.cpp @@ -21,10 +21,8 @@ std::unique_ptr CFX_XMLCharData::Clone() { return pdfium::MakeUnique(GetText()); } -void CFX_XMLCharData::Save( - const RetainPtr& pXMLStream) { - WideString ws = L""; - pXMLStream->WriteString(ws.AsStringView()); +void CFX_XMLCharData::Save(const RetainPtr& pXMLStream) { + pXMLStream->WriteString("WriteString(GetText().UTF8Encode().AsStringView()); + pXMLStream->WriteString("]]>"); } diff --git a/core/fxcrt/xml/cfx_xmlchardata.h b/core/fxcrt/xml/cfx_xmlchardata.h index c702d9636f..5b00597955 100644 --- a/core/fxcrt/xml/cfx_xmlchardata.h +++ b/core/fxcrt/xml/cfx_xmlchardata.h @@ -20,7 +20,7 @@ class CFX_XMLCharData : public CFX_XMLText { // CFX_XMLNode FX_XMLNODETYPE GetType() const override; std::unique_ptr Clone() override; - void Save(const RetainPtr& pXMLStream) override; + void Save(const RetainPtr& pXMLStream) override; }; #endif // CORE_FXCRT_XML_CFX_XMLCHARDATA_H_ diff --git a/core/fxcrt/xml/cfx_xmlelement.cpp b/core/fxcrt/xml/cfx_xmlelement.cpp index 42588c6393..c54d8488a3 100644 --- a/core/fxcrt/xml/cfx_xmlelement.cpp +++ b/core/fxcrt/xml/cfx_xmlelement.cpp @@ -93,30 +93,31 @@ void CFX_XMLElement::SetTextData(const WideString& wsText) { AppendChild(new CFX_XMLText(wsText)); } -void CFX_XMLElement::Save( - const RetainPtr& pXMLStream) { - pXMLStream->WriteString(L"<"); - pXMLStream->WriteString(name_.AsStringView()); +void CFX_XMLElement::Save(const RetainPtr& pXMLStream) { + ByteStringView name_encoded = name_.UTF8Encode().AsStringView(); + + pXMLStream->WriteString("<"); + pXMLStream->WriteString(name_encoded); for (auto it : attrs_) { pXMLStream->WriteString( - AttributeToString(it.first, it.second).AsStringView()); + AttributeToString(it.first, it.second).UTF8Encode().AsStringView()); } if (!GetFirstChild()) { - pXMLStream->WriteString(L" />"); + pXMLStream->WriteString(" />\n"); return; } - pXMLStream->WriteString(L">"); + pXMLStream->WriteString(">\n"); for (CFX_XMLNode* pChild = GetFirstChild(); pChild; pChild = pChild->GetNextSibling()) { pChild->Save(pXMLStream); } - pXMLStream->WriteString(L"WriteString(name_.AsStringView()); - pXMLStream->WriteString(L"\n>"); + pXMLStream->WriteString("WriteString(name_encoded); + pXMLStream->WriteString(">\n"); } CFX_XMLElement* CFX_XMLElement::GetFirstChildNamed( diff --git a/core/fxcrt/xml/cfx_xmlelement.h b/core/fxcrt/xml/cfx_xmlelement.h index f8533a1445..c1d9fea3f0 100644 --- a/core/fxcrt/xml/cfx_xmlelement.h +++ b/core/fxcrt/xml/cfx_xmlelement.h @@ -22,7 +22,7 @@ class CFX_XMLElement : public CFX_XMLNode { // CFX_XMLNode FX_XMLNODETYPE GetType() const override; std::unique_ptr Clone() override; - void Save(const RetainPtr& pXMLStream) override; + void Save(const RetainPtr& pXMLStream) override; WideString GetName() const { return name_; } diff --git a/core/fxcrt/xml/cfx_xmlinstruction.cpp b/core/fxcrt/xml/cfx_xmlinstruction.cpp index f3185fbf5b..7b844e6808 100644 --- a/core/fxcrt/xml/cfx_xmlinstruction.cpp +++ b/core/fxcrt/xml/cfx_xmlinstruction.cpp @@ -40,31 +40,20 @@ bool CFX_XMLInstruction::IsAcrobat() const { return name_ == L"acrobat"; } -void CFX_XMLInstruction::Save( - const RetainPtr& pXMLStream) { +void CFX_XMLInstruction::Save(const RetainPtr& pXMLStream) { if (name_.CompareNoCase(L"xml") == 0) { - WideString ws = L"GetCodePage(); - if (wCodePage == FX_CODEPAGE_UTF16LE) - ws += L"UTF-16"; - else if (wCodePage == FX_CODEPAGE_UTF16BE) - ws += L"UTF-16be"; - else - ws += L"UTF-8"; - - ws += L"\"?>"; - pXMLStream->WriteString(ws.AsStringView()); + pXMLStream->WriteString("\n"); return; } - pXMLStream->WriteString( - WideString::Format(L"WriteString("WriteString(name_.UTF8Encode().AsStringView()); for (const WideString& target : m_TargetData) { - pXMLStream->WriteString(L"\""); - pXMLStream->WriteString(target.AsStringView()); - pXMLStream->WriteString(L"\""); + pXMLStream->WriteString("\""); + pXMLStream->WriteString(target.UTF8Encode().AsStringView()); + pXMLStream->WriteString("\""); } - pXMLStream->WriteString(WideStringView(L"?>")); + pXMLStream->WriteString("?>"); } diff --git a/core/fxcrt/xml/cfx_xmlinstruction.h b/core/fxcrt/xml/cfx_xmlinstruction.h index 7cee1d4fc0..045610bd8a 100644 --- a/core/fxcrt/xml/cfx_xmlinstruction.h +++ b/core/fxcrt/xml/cfx_xmlinstruction.h @@ -21,7 +21,7 @@ class CFX_XMLInstruction : public CFX_XMLNode { // CFX_XMLNode FX_XMLNODETYPE GetType() const override; std::unique_ptr Clone() override; - void Save(const RetainPtr& pXMLStream) override; + void Save(const RetainPtr& pXMLStream) override; bool IsOriginalXFAVersion() const; bool IsAcrobat() const; diff --git a/core/fxcrt/xml/cfx_xmlnode.cpp b/core/fxcrt/xml/cfx_xmlnode.cpp index 540b20e721..6303615d01 100644 --- a/core/fxcrt/xml/cfx_xmlnode.cpp +++ b/core/fxcrt/xml/cfx_xmlnode.cpp @@ -108,7 +108,7 @@ std::unique_ptr CFX_XMLNode::Clone() { return nullptr; } -void CFX_XMLNode::Save(const RetainPtr& pXMLStream) {} +void CFX_XMLNode::Save(const RetainPtr& pXMLStream) {} WideString CFX_XMLNode::EncodeEntities(const WideString& value) { WideString ret = value; diff --git a/core/fxcrt/xml/cfx_xmlnode.h b/core/fxcrt/xml/cfx_xmlnode.h index 7278d2b4ca..86b5e998e6 100644 --- a/core/fxcrt/xml/cfx_xmlnode.h +++ b/core/fxcrt/xml/cfx_xmlnode.h @@ -9,7 +9,7 @@ #include -#include "core/fxcrt/cfx_seekablestreamproxy.h" +#include "core/fxcrt/fx_stream.h" #include "core/fxcrt/retain_ptr.h" enum FX_XMLNODETYPE { @@ -32,7 +32,7 @@ class CFX_XMLNode { virtual FX_XMLNODETYPE GetType() const; virtual std::unique_ptr Clone(); - virtual void Save(const RetainPtr& pXMLStream); + virtual void Save(const RetainPtr& pXMLStream); CFX_XMLNode* GetRoot(); CFX_XMLNode* GetParent() const { return parent_; } diff --git a/core/fxcrt/xml/cfx_xmltext.cpp b/core/fxcrt/xml/cfx_xmltext.cpp index 05e2935440..74d0a501eb 100644 --- a/core/fxcrt/xml/cfx_xmltext.cpp +++ b/core/fxcrt/xml/cfx_xmltext.cpp @@ -21,6 +21,7 @@ std::unique_ptr CFX_XMLText::Clone() { return pdfium::MakeUnique(m_wsText); } -void CFX_XMLText::Save(const RetainPtr& pXMLStream) { - pXMLStream->WriteString(EncodeEntities(GetText()).AsStringView()); +void CFX_XMLText::Save(const RetainPtr& pXMLStream) { + pXMLStream->WriteString( + EncodeEntities(GetText()).UTF8Encode().AsStringView()); } diff --git a/core/fxcrt/xml/cfx_xmltext.h b/core/fxcrt/xml/cfx_xmltext.h index b26eef14ac..bbf14be257 100644 --- a/core/fxcrt/xml/cfx_xmltext.h +++ b/core/fxcrt/xml/cfx_xmltext.h @@ -20,7 +20,7 @@ class CFX_XMLText : public CFX_XMLNode { // CFX_XMLNode FX_XMLNODETYPE GetType() const override; std::unique_ptr Clone() override; - void Save(const RetainPtr& pXMLStream) override; + void Save(const RetainPtr& pXMLStream) override; WideString GetText() const { return m_wsText; } void SetText(const WideString& wsText) { m_wsText = wsText; } -- cgit v1.2.3