From 5ae87922cb96810a05b2262c66b55b7e8f00e46d Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Tue, 18 Apr 2017 11:54:04 -0400 Subject: Update IFGAS_Stream::WriteString to take a string. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This Cl updates the WriteString method to accept a CFX_WideString. Change-Id: I9f480abf32f4132f8ca33799e673a9e8540285f6 Reviewed-on: https://pdfium-review.googlesource.com/4151 Reviewed-by: Nicolás Peña Reviewed-by: Tom Sepez Commit-Queue: dsinclair --- xfa/fde/xml/cfde_xmldoc.cpp | 22 +++---- xfa/fde/xml/cfde_xmlnode.cpp | 22 +++---- xfa/fgas/crt/ifgas_stream.cpp | 113 +++++++--------------------------- xfa/fgas/crt/ifgas_stream.h | 4 +- xfa/fxfa/parser/cxfa_dataexporter.cpp | 52 ++++++++-------- xfa/fxfa/parser/cxfa_node.cpp | 11 ++-- 6 files changed, 79 insertions(+), 145 deletions(-) diff --git a/xfa/fde/xml/cfde_xmldoc.cpp b/xfa/fde/xml/cfde_xmldoc.cpp index 7032700578..209ce9c68f 100644 --- a/xfa/fde/xml/cfde_xmldoc.cpp +++ b/xfa/fde/xml/cfde_xmldoc.cpp @@ -65,10 +65,10 @@ void CFDE_XMLDoc::SaveXMLNode(const CFX_RetainPtr& pXMLStream, ws += L"UTF-8"; } ws += L"\"?>"; - pXMLStream->WriteString(ws.c_str(), ws.GetLength()); + pXMLStream->WriteString(ws.AsStringC()); } else { ws.Format(L"GetName().c_str()); - pXMLStream->WriteString(ws.c_str(), ws.GetLength()); + pXMLStream->WriteString(ws.AsStringC()); for (auto it : pInstruction->GetAttributes()) { CFX_WideString wsValue = it.second; @@ -83,17 +83,17 @@ void CFDE_XMLDoc::SaveXMLNode(const CFX_RetainPtr& pXMLStream, ws += L"=\""; ws += wsValue; ws += L"\""; - pXMLStream->WriteString(ws.c_str(), ws.GetLength()); + pXMLStream->WriteString(ws.AsStringC()); } for (auto target : pInstruction->GetTargetData()) { ws = L" \""; ws += target; ws += L"\""; - pXMLStream->WriteString(ws.c_str(), ws.GetLength()); + pXMLStream->WriteString(ws.AsStringC()); } ws = L"?>"; - pXMLStream->WriteString(ws.c_str(), ws.GetLength()); + pXMLStream->WriteString(ws.AsStringC()); } break; } @@ -101,7 +101,7 @@ void CFDE_XMLDoc::SaveXMLNode(const CFX_RetainPtr& pXMLStream, CFX_WideString ws; ws = L"<"; ws += static_cast(pNode)->GetName(); - pXMLStream->WriteString(ws.c_str(), ws.GetLength()); + pXMLStream->WriteString(ws.AsStringC()); for (auto it : static_cast(pNode)->GetAttributes()) { CFX_WideString wsValue = it.second; @@ -116,11 +116,11 @@ void CFDE_XMLDoc::SaveXMLNode(const CFX_RetainPtr& pXMLStream, ws += L"=\""; ws += wsValue; ws += L"\""; - pXMLStream->WriteString(ws.c_str(), ws.GetLength()); + pXMLStream->WriteString(ws.AsStringC()); } if (pNode->m_pChild) { ws = L"\n>"; - pXMLStream->WriteString(ws.c_str(), ws.GetLength()); + pXMLStream->WriteString(ws.AsStringC()); CFDE_XMLNode* pChild = pNode->m_pChild; while (pChild) { SaveXMLNode(pXMLStream, static_cast(pChild)); @@ -132,7 +132,7 @@ void CFDE_XMLDoc::SaveXMLNode(const CFX_RetainPtr& pXMLStream, } else { ws = L"\n/>"; } - pXMLStream->WriteString(ws.c_str(), ws.GetLength()); + pXMLStream->WriteString(ws.AsStringC()); break; } case FDE_XMLNODE_Text: { @@ -142,14 +142,14 @@ void CFDE_XMLDoc::SaveXMLNode(const CFX_RetainPtr& pXMLStream, ws.Replace(L">", L">"); ws.Replace(L"\'", L"'"); ws.Replace(L"\"", L"""); - pXMLStream->WriteString(ws.c_str(), ws.GetLength()); + pXMLStream->WriteString(ws.AsStringC()); break; } case FDE_XMLNODE_CharData: { CFX_WideString ws = L"(pNode)->GetText(); ws += L"]]>"; - pXMLStream->WriteString(ws.c_str(), ws.GetLength()); + pXMLStream->WriteString(ws.AsStringC()); break; } case FDE_XMLNODE_Unknown: diff --git a/xfa/fde/xml/cfde_xmlnode.cpp b/xfa/fde/xml/cfde_xmlnode.cpp index 82db939a23..e4d7880cac 100644 --- a/xfa/fde/xml/cfde_xmlnode.cpp +++ b/xfa/fde/xml/cfde_xmlnode.cpp @@ -346,10 +346,10 @@ void CFDE_XMLNode::SaveXMLNode(const CFX_RetainPtr& pXMLStream) { ws += L"UTF-8"; } ws += L"\"?>"; - pXMLStream->WriteString(ws.c_str(), ws.GetLength()); + pXMLStream->WriteString(ws.AsStringC()); } else { ws.Format(L"GetName().c_str()); - pXMLStream->WriteString(ws.c_str(), ws.GetLength()); + pXMLStream->WriteString(ws.AsStringC()); for (auto it : pInstruction->GetAttributes()) { CFX_WideString wsValue = it.second; @@ -364,17 +364,17 @@ void CFDE_XMLNode::SaveXMLNode(const CFX_RetainPtr& pXMLStream) { ws += L"=\""; ws += wsValue; ws += L"\""; - pXMLStream->WriteString(ws.c_str(), ws.GetLength()); + pXMLStream->WriteString(ws.AsStringC()); } for (auto target : pInstruction->GetTargetData()) { ws = L" \""; ws += target; ws += L"\""; - pXMLStream->WriteString(ws.c_str(), ws.GetLength()); + pXMLStream->WriteString(ws.AsStringC()); } ws = L"?>"; - pXMLStream->WriteString(ws.c_str(), ws.GetLength()); + pXMLStream->WriteString(ws.AsStringC()); } break; } @@ -382,7 +382,7 @@ void CFDE_XMLNode::SaveXMLNode(const CFX_RetainPtr& pXMLStream) { CFX_WideString ws; ws = L"<"; ws += static_cast(pNode)->GetName(); - pXMLStream->WriteString(ws.c_str(), ws.GetLength()); + pXMLStream->WriteString(ws.AsStringC()); for (auto it : static_cast(pNode)->GetAttributes()) { CFX_WideString wsValue = it.second; @@ -397,11 +397,11 @@ void CFDE_XMLNode::SaveXMLNode(const CFX_RetainPtr& pXMLStream) { ws += L"=\""; ws += wsValue; ws += L"\""; - pXMLStream->WriteString(ws.c_str(), ws.GetLength()); + pXMLStream->WriteString(ws.AsStringC()); } if (pNode->m_pChild) { ws = L"\n>"; - pXMLStream->WriteString(ws.c_str(), ws.GetLength()); + pXMLStream->WriteString(ws.AsStringC()); CFDE_XMLNode* pChild = pNode->m_pChild; while (pChild) { pChild->SaveXMLNode(pXMLStream); @@ -413,7 +413,7 @@ void CFDE_XMLNode::SaveXMLNode(const CFX_RetainPtr& pXMLStream) { } else { ws = L"\n/>"; } - pXMLStream->WriteString(ws.c_str(), ws.GetLength()); + pXMLStream->WriteString(ws.AsStringC()); break; } case FDE_XMLNODE_Text: { @@ -423,14 +423,14 @@ void CFDE_XMLNode::SaveXMLNode(const CFX_RetainPtr& pXMLStream) { ws.Replace(L">", L">"); ws.Replace(L"\'", L"'"); ws.Replace(L"\"", L"""); - pXMLStream->WriteString(ws.c_str(), ws.GetLength()); + pXMLStream->WriteString(ws.AsStringC()); break; } case FDE_XMLNODE_CharData: { CFX_WideString ws = L"(pNode)->GetText(); ws += L"]]>"; - pXMLStream->WriteString(ws.c_str(), ws.GetLength()); + pXMLStream->WriteString(ws.AsStringC()); break; } case FDE_XMLNODE_Unknown: diff --git a/xfa/fgas/crt/ifgas_stream.cpp b/xfa/fgas/crt/ifgas_stream.cpp index b4d03cf810..41913b28b6 100644 --- a/xfa/fgas/crt/ifgas_stream.cpp +++ b/xfa/fgas/crt/ifgas_stream.cpp @@ -29,14 +29,12 @@ class IFGAS_StreamImp { virtual FX_FILESIZE GetLength() const = 0; virtual FX_FILESIZE GetPosition() = 0; + virtual void Seek(FX_STREAMSEEK eSeek, FX_FILESIZE iOffset) = 0; virtual bool IsEOF() const = 0; + virtual FX_STRSIZE ReadData(uint8_t* pBuffer, FX_STRSIZE iBufferSize) = 0; - virtual FX_STRSIZE ReadString(wchar_t* pStr, - FX_STRSIZE iMaxLength, - bool* bEOS) = 0; - virtual void WriteData(const uint8_t* pBuffer, FX_STRSIZE iBufferSize) = 0; - virtual void WriteString(const wchar_t* pStr, FX_STRSIZE iLength) = 0; + virtual void WriteData(const CFX_WideStringC& str) = 0; protected: IFGAS_StreamImp(); @@ -54,11 +52,7 @@ class CFGAS_FileReadStreamImp : public IFGAS_StreamImp { void Seek(FX_STREAMSEEK eSeek, FX_FILESIZE iOffset) override; bool IsEOF() const override; FX_STRSIZE ReadData(uint8_t* pBuffer, FX_STRSIZE iBufferSize) override; - FX_STRSIZE ReadString(wchar_t* pStr, - FX_STRSIZE iMaxLength, - bool* bEOS) override; - void WriteData(const uint8_t* pBuffer, FX_STRSIZE iBufferSize) override {} - void WriteString(const wchar_t* pStr, FX_STRSIZE iLength) override {} + void WriteData(const CFX_WideStringC& str) override {} private: CFX_RetainPtr m_pFileRead; @@ -79,13 +73,7 @@ class CFGAS_FileWriteStreamImp : public IFGAS_StreamImp { FX_STRSIZE ReadData(uint8_t* pBuffer, FX_STRSIZE iBufferSize) override { return 0; } - FX_STRSIZE ReadString(wchar_t* pStr, - FX_STRSIZE iMaxLength, - bool* bEOS) override { - return 0; - } - void WriteData(const uint8_t* pBuffer, FX_STRSIZE iBufferSize) override; - void WriteString(const wchar_t* pStr, FX_STRSIZE iLength) override; + void WriteData(const CFX_WideStringC& str) override; private: CFX_RetainPtr m_pFileWrite; @@ -103,12 +91,10 @@ class CFGAS_TextStream : public IFGAS_Stream { FX_STRSIZE GetBOMLength() const override; void Seek(FX_STREAMSEEK eSeek, FX_FILESIZE iOffset) override; bool IsEOF() const override; - FX_STRSIZE ReadData(uint8_t* pBuffer, FX_STRSIZE iBufferSize) override; FX_STRSIZE ReadString(wchar_t* pStr, FX_STRSIZE iMaxLength, bool* bEOS) override; - void WriteData(const uint8_t* pBuffer, FX_STRSIZE iBufferSize) override; - void WriteString(const wchar_t* pStr, FX_STRSIZE iLength) override; + void WriteString(const CFX_WideStringC& str) override; uint16_t GetCodePage() const override; void SetCodePage(uint16_t wCodePage) override; @@ -135,14 +121,10 @@ class CFGAS_WideStringReadStream : public IFGAS_Stream { FX_STRSIZE GetBOMLength() const override { return 0; } void Seek(FX_STREAMSEEK eSeek, FX_FILESIZE iOffset) override; bool IsEOF() const override; - FX_STRSIZE ReadData(uint8_t* pBuffer, FX_STRSIZE iBufferSize) override { - return 0; - } FX_STRSIZE ReadString(wchar_t* pStr, FX_STRSIZE iMaxLength, bool* bEOS) override; - void WriteData(const uint8_t* pBuffer, FX_STRSIZE iBufferSize) override {} - void WriteString(const wchar_t* pStr, FX_STRSIZE iLength) override {} + void WriteString(const CFX_WideStringC& str) override {} uint16_t GetCodePage() const override; void SetCodePage(uint16_t wCodePage) override {} @@ -295,6 +277,9 @@ FX_STRSIZE CFGAS_FileReadStreamImp::ReadData(uint8_t* pBuffer, iBufferSize = std::min(iBufferSize, static_cast(m_pFileRead->GetSize() - m_iPosition)); + if (iBufferSize <= 0) + return 0; + if (m_pFileRead->ReadBlock(pBuffer, m_iPosition, iBufferSize)) { pdfium::base::CheckedNumeric new_pos = m_iPosition; new_pos += iBufferSize; @@ -307,23 +292,6 @@ FX_STRSIZE CFGAS_FileReadStreamImp::ReadData(uint8_t* pBuffer, return 0; } -FX_STRSIZE CFGAS_FileReadStreamImp::ReadString(wchar_t* pStr, - FX_STRSIZE iMaxLength, - bool* bEOS) { - ASSERT(pStr && iMaxLength > 0); - - iMaxLength = ReadData(reinterpret_cast(pStr), iMaxLength * 2) / 2; - if (iMaxLength <= 0) - return 0; - - FX_STRSIZE i = 0; - while (i < iMaxLength && pStr[i] != L'\0') - ++i; - - *bEOS = m_iPosition >= m_pFileRead->GetSize() || pStr[i] == L'\0'; - return i; -} - CFGAS_FileWriteStreamImp::CFGAS_FileWriteStreamImp( const CFX_RetainPtr& pFileWrite) : m_pFileWrite(pFileWrite), m_iPosition(m_pFileWrite->GetSize()) { @@ -352,11 +320,14 @@ bool CFGAS_FileWriteStreamImp::IsEOF() const { return m_iPosition >= GetLength(); } -void CFGAS_FileWriteStreamImp::WriteData(const uint8_t* pBuffer, - FX_STRSIZE iBufferSize) { - if (m_pFileWrite->WriteBlock(pBuffer, m_iPosition, iBufferSize)) { +void CFGAS_FileWriteStreamImp::WriteData(const CFX_WideStringC& str) { + if (str.GetLength() == 0) + return; + + if (m_pFileWrite->WriteBlock(str.c_str(), m_iPosition, + str.GetLength() * sizeof(wchar_t))) { pdfium::base::CheckedNumeric new_pos = m_iPosition; - new_pos += iBufferSize; + new_pos += str.GetLength() * sizeof(wchar_t); // TODO(dsinclair): Not sure what to do if we over flow .... if (!new_pos.IsValid()) return; @@ -365,11 +336,6 @@ void CFGAS_FileWriteStreamImp::WriteData(const uint8_t* pBuffer, } } -void CFGAS_FileWriteStreamImp::WriteString(const wchar_t* pStr, - FX_STRSIZE iLength) { - WriteData(reinterpret_cast(pStr), iLength * sizeof(wchar_t)); -} - CFGAS_TextStream::CFGAS_TextStream(std::unique_ptr imp, bool isWriteStream) : m_wCodePage(FX_CODEPAGE_DefANSI), @@ -442,32 +408,6 @@ bool CFGAS_TextStream::IsEOF() const { return m_pStreamImp->IsEOF(); } -FX_STRSIZE CFGAS_TextStream::ReadData(uint8_t* pBuffer, - FX_STRSIZE iBufferSize) { - ASSERT(pBuffer && iBufferSize > 0); - - if (m_IsWriteStream) - return -1; - - FX_STRSIZE iLen = - std::min(static_cast(m_pStreamImp->GetLength() - - m_pStreamImp->GetPosition()), - iBufferSize); - if (iLen <= 0) - return 0; - - return m_pStreamImp->ReadData(pBuffer, iLen); -} - -void CFGAS_TextStream::WriteData(const uint8_t* pBuffer, - FX_STRSIZE iBufferSize) { - ASSERT(pBuffer && iBufferSize > 0); - - if (!m_IsWriteStream) - return; - m_pStreamImp->WriteData(pBuffer, iBufferSize); -} - FX_STRSIZE CFGAS_TextStream::GetBOMLength() const { if (m_wBOMLength < 1) return 0; @@ -481,7 +421,6 @@ uint16_t CFGAS_TextStream::GetCodePage() const { void CFGAS_TextStream::SetCodePage(uint16_t wCodePage) { if (m_wBOMLength > 0) return; - m_wCodePage = wCodePage; } @@ -496,7 +435,8 @@ FX_STRSIZE CFGAS_TextStream::ReadString(wchar_t* pStr, if (m_wCodePage == FX_CODEPAGE_UTF16LE || m_wCodePage == FX_CODEPAGE_UTF16BE) { FX_FILESIZE iBytes = iMaxLength * 2; - FX_STRSIZE iLen = m_pStreamImp->ReadData((uint8_t*)pStr, iBytes); + FX_STRSIZE iLen = + m_pStreamImp->ReadData(reinterpret_cast(pStr), iBytes); iMaxLength = iLen / 2; if (sizeof(wchar_t) > 2) UTF16ToWChar(pStr, iMaxLength); @@ -534,22 +474,15 @@ FX_STRSIZE CFGAS_TextStream::ReadString(wchar_t* pStr, return iMaxLength; } -void CFGAS_TextStream::WriteString(const wchar_t* pStr, FX_STRSIZE iLength) { - ASSERT(pStr && iLength > 0); +void CFGAS_TextStream::WriteString(const CFX_WideStringC& str) { if (!m_IsWriteStream) return; - + if (str.GetLength() == 0) + return; if (m_wCodePage != FX_CODEPAGE_UTF8) return; - FX_STRSIZE len = iLength; - CFX_UTF8Encoder encoder; - while (len-- > 0) - encoder.Input(*pStr++); - - CFX_ByteStringC bsResult = encoder.GetResult(); - m_pStreamImp->WriteData(reinterpret_cast(bsResult.c_str()), - bsResult.GetLength()); + m_pStreamImp->WriteData(str); } CFGAS_WideStringReadStream::CFGAS_WideStringReadStream( diff --git a/xfa/fgas/crt/ifgas_stream.h b/xfa/fgas/crt/ifgas_stream.h index 658afe73bf..be42fe5ca3 100644 --- a/xfa/fgas/crt/ifgas_stream.h +++ b/xfa/fgas/crt/ifgas_stream.h @@ -34,15 +34,13 @@ class IFGAS_Stream : public CFX_Retainable { virtual FX_STRSIZE ReadString(wchar_t* pStr, FX_STRSIZE iMaxLength, bool* bEOS) = 0; - virtual void WriteData(const uint8_t* pBuffer, FX_STRSIZE iBufferSize) = 0; - virtual void WriteString(const wchar_t* pStr, FX_STRSIZE iLength) = 0; + virtual void WriteString(const CFX_WideStringC& str) = 0; virtual uint16_t GetCodePage() const = 0; virtual void SetCodePage(uint16_t wCodePage) = 0; protected: virtual bool IsEOF() const = 0; - virtual FX_STRSIZE ReadData(uint8_t* pBuffer, FX_STRSIZE iBufferSize) = 0; }; #endif // XFA_FGAS_CRT_IFGAS_STREAM_H_ diff --git a/xfa/fxfa/parser/cxfa_dataexporter.cpp b/xfa/fxfa/parser/cxfa_dataexporter.cpp index 3963b162cb..3976fd6912 100644 --- a/xfa/fxfa/parser/cxfa_dataexporter.cpp +++ b/xfa/fxfa/parser/cxfa_dataexporter.cpp @@ -352,15 +352,17 @@ void RegenerateFormFile_Container(CXFA_Node* pNode, RegenerateFormFile_Changed(pNode, buf, bSaveXML); FX_STRSIZE nLen = buf.GetLength(); if (nLen > 0) - pStream->WriteString((const wchar_t*)buf.GetBuffer(), nLen); + pStream->WriteString(buf.AsStringC()); return; } - CFX_WideStringC wsElement = pNode->GetClassName(); - pStream->WriteString(L"<", 1); - pStream->WriteString(wsElement.c_str(), wsElement.GetLength()); + CFX_WideStringC wsElement(pNode->GetClassName()); + pStream->WriteString(L"<"); + pStream->WriteString(wsElement); + CFX_WideString wsOutput; SaveAttribute(pNode, XFA_ATTRIBUTE_Name, L"name", true, wsOutput); + CFX_WideString wsAttrs; int32_t iAttrs = 0; const uint8_t* pAttrs = @@ -377,20 +379,20 @@ void RegenerateFormFile_Container(CXFA_Node* pNode, } if (!wsOutput.IsEmpty()) - pStream->WriteString(wsOutput.c_str(), wsOutput.GetLength()); + pStream->WriteString(wsOutput.AsStringC()); CXFA_Node* pChildNode = pNode->GetNodeItem(XFA_NODEITEM_FirstChild); if (pChildNode) { - pStream->WriteString(L"\n>", 2); + pStream->WriteString(L"\n>"); while (pChildNode) { RegenerateFormFile_Container(pChildNode, pStream, bSaveXML); pChildNode = pChildNode->GetNodeItem(XFA_NODEITEM_NextSibling); } - pStream->WriteString(L"WriteString(wsElement.c_str(), wsElement.GetLength()); - pStream->WriteString(L"\n>", 2); + pStream->WriteString(L"WriteString(wsElement); + pStream->WriteString(L"\n>"); } else { - pStream->WriteString(L"\n/>", 3); + pStream->WriteString(L"\n/>"); } } @@ -402,19 +404,18 @@ void XFA_DataExporter_RegenerateFormFile( const char* pChecksum, bool bSaveXML) { if (pNode->IsModelNode()) { - static const wchar_t s_pwsTagName[] = L""; - pStream->WriteString(s_pwsTagName, FXSYS_wcslen(s_pwsTagName)); + pStream->WriteString(L"WriteString(s_pwChecksum, FXSYS_wcslen(s_pwChecksum)); - pStream->WriteString(wsChecksum.c_str(), wsChecksum.GetLength()); - pStream->WriteString(L"\"", 1); + pStream->WriteString(L" checksum=\""); + pStream->WriteString(wsChecksum.AsStringC()); + pStream->WriteString(L"\""); } - pStream->WriteString(L" xmlns=\"", FXSYS_wcslen(L" xmlns=\"")); + pStream->WriteString(L" xmlns=\""); + const wchar_t* pURI = XFA_GetPacketByIndex(XFA_PACKET_Form)->pURI; - pStream->WriteString(pURI, FXSYS_wcslen(pURI)); + pStream->WriteString(CFX_WideStringC(pURI, FXSYS_wcslen(pURI))); + CFX_WideString wsVersionNumber; RecognizeXFAVersionNumber( ToNode(pNode->GetDocument()->GetXFAObject(XFA_HASHCODE_Template)), @@ -423,13 +424,14 @@ void XFA_DataExporter_RegenerateFormFile( wsVersionNumber = L"2.8"; wsVersionNumber += L"/\"\n>"; - pStream->WriteString(wsVersionNumber.c_str(), wsVersionNumber.GetLength()); + pStream->WriteString(wsVersionNumber.AsStringC()); + CXFA_Node* pChildNode = pNode->GetNodeItem(XFA_NODEITEM_FirstChild); while (pChildNode) { RegenerateFormFile_Container(pChildNode, pStream); pChildNode = pChildNode->GetNodeItem(XFA_NODEITEM_NextSibling); } - pStream->WriteString(s_pwsClose, FXSYS_wcslen(s_pwsClose)); + pStream->WriteString(L""); } else { RegenerateFormFile_Container(pNode, pStream, bSaveXML); } @@ -501,15 +503,13 @@ bool CXFA_DataExporter::Export(const CFX_RetainPtr& pStream, if (pNode->IsModelNode()) { switch (pNode->GetPacketID()) { case XFA_XDPPACKET_XDP: { - static const wchar_t s_pwsPreamble[] = - L""; - pStream->WriteString(s_pwsPreamble, FXSYS_wcslen(s_pwsPreamble)); + pStream->WriteString( + L""); for (CXFA_Node* pChild = pNode->GetNodeItem(XFA_NODEITEM_FirstChild); pChild; pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling)) { Export(pStream, pChild, dwFlag, pChecksum); } - static const wchar_t s_pwsPostamble[] = L""; - pStream->WriteString(s_pwsPostamble, FXSYS_wcslen(s_pwsPostamble)); + pStream->WriteString(L""); break; } case XFA_XDPPACKET_Datasets: { diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp index 5f582458de..d29df39e8e 100644 --- a/xfa/fxfa/parser/cxfa_node.cpp +++ b/xfa/fxfa/parser/cxfa_node.cpp @@ -1397,14 +1397,15 @@ void CXFA_Node::Script_NodeClass_SaveXML(CFXJSE_Arguments* pArguments) { } bPrettyMode = true; } - CFX_ByteStringC bsXMLHeader = "\n"; + CFX_WideString bsXMLHeader = L"\n"; if (GetPacketID() == XFA_XDPPACKET_Form || GetPacketID() == XFA_XDPPACKET_Datasets) { CFDE_XMLNode* pElement = nullptr; if (GetPacketID() == XFA_XDPPACKET_Datasets) { pElement = GetXMLMappingNode(); if (!pElement || pElement->GetType() != FDE_XMLNODE_Element) { - pArguments->GetReturnValue()->SetString(bsXMLHeader); + pArguments->GetReturnValue()->SetString( + bsXMLHeader.UTF8Encode().AsStringC()); return; } XFA_DataExporter_DealWithDataGroupNode(this); @@ -1415,11 +1416,13 @@ void CXFA_Node::Script_NodeClass_SaveXML(CFXJSE_Arguments* pArguments) { IFGAS_Stream::CreateWriteStream(pMemoryStream); if (!pStream) { - pArguments->GetReturnValue()->SetString(bsXMLHeader); + pArguments->GetReturnValue()->SetString( + bsXMLHeader.UTF8Encode().AsStringC()); return; } pStream->SetCodePage(FX_CODEPAGE_UTF8); - pStream->WriteData(bsXMLHeader.raw_str(), bsXMLHeader.GetLength()); + pStream->WriteString(bsXMLHeader.AsStringC()); + if (GetPacketID() == XFA_XDPPACKET_Form) XFA_DataExporter_RegenerateFormFile(this, pStream, nullptr, true); else -- cgit v1.2.3