summaryrefslogtreecommitdiff
path: root/xfa
diff options
context:
space:
mode:
Diffstat (limited to 'xfa')
-rw-r--r--xfa/fgas/crt/ifgas_stream.cpp71
-rw-r--r--xfa/fgas/crt/ifgas_stream.h2
-rw-r--r--xfa/fxfa/parser/cxfa_node.cpp18
-rw-r--r--xfa/fxfa/parser/cxfa_simple_parser.cpp20
-rw-r--r--xfa/fxfa/parser/cxfa_simple_parser.h4
5 files changed, 15 insertions, 100 deletions
diff --git a/xfa/fgas/crt/ifgas_stream.cpp b/xfa/fgas/crt/ifgas_stream.cpp
index 06ab46551d..7a90626fe8 100644
--- a/xfa/fgas/crt/ifgas_stream.cpp
+++ b/xfa/fgas/crt/ifgas_stream.cpp
@@ -56,36 +56,6 @@ class CFGAS_Stream : public IFGAS_Stream {
CFX_RetainPtr<IFX_SeekableStream> m_pStream;
};
-class CFGAS_WideStringReadStream : public IFGAS_Stream {
- public:
- template <typename T, typename... Args>
- friend CFX_RetainPtr<T> pdfium::MakeRetain(Args&&... args);
-
- // IFGAS_Stream
- FX_FILESIZE GetLength() const override {
- return m_wsBuffer.GetLength() * sizeof(wchar_t);
- }
- FX_FILESIZE GetPosition() override { return m_iPosition * sizeof(wchar_t); }
- FX_STRSIZE GetBOMLength() const override { return 0; }
- void Seek(FX_STREAMSEEK eSeek, FX_FILESIZE iOffset) override;
- bool IsEOF() const override { return m_iPosition >= m_wsBuffer.GetLength(); }
- FX_STRSIZE ReadString(wchar_t* pStr,
- FX_STRSIZE iMaxLength,
- bool* bEOS) override;
- void WriteString(const CFX_WideStringC& str) override {}
- uint16_t GetCodePage() const override {
- return sizeof(wchar_t) == 2 ? FX_CODEPAGE_UTF16LE : FX_CODEPAGE_UTF32LE;
- }
- void SetCodePage(uint16_t wCodePage) override {}
-
- private:
- explicit CFGAS_WideStringReadStream(const CFX_WideString& wsBuffer);
- ~CFGAS_WideStringReadStream() override;
-
- CFX_WideString m_wsBuffer;
- FX_FILESIZE m_iPosition;
-};
-
// Returns {src bytes consumed, dst bytes produced}.
std::pair<FX_STRSIZE, FX_STRSIZE> UTF8Decode(const char* pSrc,
FX_STRSIZE srcLen,
@@ -366,41 +336,6 @@ void CFGAS_Stream::WriteString(const CFX_WideStringC& str) {
WriteData(str);
}
-CFGAS_WideStringReadStream::CFGAS_WideStringReadStream(
- const CFX_WideString& wsBuffer)
- : m_wsBuffer(wsBuffer), m_iPosition(0) {}
-
-CFGAS_WideStringReadStream::~CFGAS_WideStringReadStream() {}
-
-void CFGAS_WideStringReadStream::Seek(FX_STREAMSEEK eSeek,
- FX_FILESIZE iOffset) {
- switch (eSeek) {
- case FX_STREAMSEEK_Begin:
- m_iPosition = iOffset;
- break;
- case FX_STREAMSEEK_Current:
- m_iPosition += iOffset;
- break;
- }
- m_iPosition = pdfium::clamp(m_iPosition, static_cast<FX_FILESIZE>(0),
- static_cast<FX_FILESIZE>(m_wsBuffer.GetLength()));
-}
-
-FX_STRSIZE CFGAS_WideStringReadStream::ReadString(wchar_t* pStr,
- FX_STRSIZE iMaxLength,
- bool* bEOS) {
- iMaxLength =
- std::min(iMaxLength,
- static_cast<FX_STRSIZE>(m_wsBuffer.GetLength() - m_iPosition));
- if (iMaxLength == 0)
- return 0;
-
- FXSYS_wcsncpy(pStr, m_wsBuffer.c_str() + m_iPosition, iMaxLength);
- m_iPosition += iMaxLength;
- *bEOS = IsEOF();
- return iMaxLength;
-}
-
} // namespace
// static
@@ -420,9 +355,3 @@ CFX_RetainPtr<IFGAS_Stream> IFGAS_Stream::CreateWriteStream(
return pdfium::MakeRetain<CFGAS_Stream>(pFileWrite, true);
}
-
-// static
-CFX_RetainPtr<IFGAS_Stream> IFGAS_Stream::CreateWideStringReadStream(
- const CFX_WideString& buffer) {
- return pdfium::MakeRetain<CFGAS_WideStringReadStream>(buffer);
-}
diff --git a/xfa/fgas/crt/ifgas_stream.h b/xfa/fgas/crt/ifgas_stream.h
index 620a023dd8..acc9f1c4eb 100644
--- a/xfa/fgas/crt/ifgas_stream.h
+++ b/xfa/fgas/crt/ifgas_stream.h
@@ -22,8 +22,6 @@ class IFGAS_Stream : public CFX_Retainable {
const CFX_RetainPtr<IFX_SeekableStream>& pFileRead);
static CFX_RetainPtr<IFGAS_Stream> CreateWriteStream(
const CFX_RetainPtr<IFX_SeekableStream>& pFileWrite);
- static CFX_RetainPtr<IFGAS_Stream> CreateWideStringReadStream(
- const CFX_WideString& buffer);
virtual FX_FILESIZE GetLength() const = 0;
virtual FX_FILESIZE GetPosition() = 0;
diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp
index d29df39e8e..90e93fbda5 100644
--- a/xfa/fxfa/parser/cxfa_node.cpp
+++ b/xfa/fxfa/parser/cxfa_node.cpp
@@ -996,8 +996,8 @@ void CXFA_Node::Script_TreeClass_ResolveNode(CFXJSE_Arguments* pArguments) {
const XFA_SCRIPTATTRIBUTEINFO* lpAttributeInfo =
resoveNodeRS.pScriptAttribute;
if (lpAttributeInfo && lpAttributeInfo->eValueType == XFA_SCRIPT_Object) {
- std::unique_ptr<CFXJSE_Value> pValue(
- new CFXJSE_Value(pScriptContext->GetRuntime()));
+ auto pValue =
+ pdfium::MakeUnique<CFXJSE_Value>(pScriptContext->GetRuntime());
(resoveNodeRS.objects.front()->*(lpAttributeInfo->lpfnCallback))(
pValue.get(), false, (XFA_ATTRIBUTE)lpAttributeInfo->eAttribute);
pArguments->GetReturnValue()->Assign(pValue.get());
@@ -1271,25 +1271,21 @@ void CXFA_Node::Script_NodeClass_LoadXML(CFXJSE_Arguments* pArguments) {
ThrowParamCountMismatchException(L"loadXML");
return;
}
- CFX_WideString wsExpression;
+
bool bIgnoreRoot = true;
bool bOverwrite = 0;
- wsExpression =
- CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
+ CFX_ByteString wsExpression = pArguments->GetUTF8String(0);
if (wsExpression.IsEmpty())
return;
if (iLength >= 2)
bIgnoreRoot = !!pArguments->GetInt32(1);
if (iLength >= 3)
bOverwrite = !!pArguments->GetInt32(2);
- std::unique_ptr<CXFA_SimpleParser> pParser(
- new CXFA_SimpleParser(m_pDocument, false));
+ auto pParser = pdfium::MakeUnique<CXFA_SimpleParser>(m_pDocument, false);
if (!pParser)
return;
- CFDE_XMLNode* pXMLNode = nullptr;
- int32_t iParserStatus =
- pParser->ParseXMLData(wsExpression, pXMLNode, nullptr);
- if (iParserStatus != XFA_PARSESTATUS_Done || !pXMLNode)
+ CFDE_XMLNode* pXMLNode = pParser->ParseXMLData(wsExpression, nullptr);
+ if (!pXMLNode)
return;
if (bIgnoreRoot &&
(pXMLNode->GetType() != FDE_XMLNODE_Element ||
diff --git a/xfa/fxfa/parser/cxfa_simple_parser.cpp b/xfa/fxfa/parser/cxfa_simple_parser.cpp
index 806e5445a0..1ebed10b4d 100644
--- a/xfa/fxfa/parser/cxfa_simple_parser.cpp
+++ b/xfa/fxfa/parser/cxfa_simple_parser.cpp
@@ -317,30 +317,24 @@ int32_t CXFA_SimpleParser::DoParse(IFX_Pause* pPause) {
return XFA_PARSESTATUS_Done;
}
-int32_t CXFA_SimpleParser::ParseXMLData(const CFX_WideString& wsXML,
- CFDE_XMLNode*& pXMLNode,
- IFX_Pause* pPause) {
+CFDE_XMLNode* CXFA_SimpleParser::ParseXMLData(const CFX_ByteString& wsXML,
+ IFX_Pause* pPause) {
CloseParser();
- pXMLNode = nullptr;
m_pXMLDoc = pdfium::MakeUnique<CFDE_XMLDoc>();
+
CFX_RetainPtr<IFGAS_Stream> pStream =
- IFGAS_Stream::CreateWideStringReadStream(wsXML);
+ IFGAS_Stream::CreateReadStream(IFX_MemoryStream::Create(
+ const_cast<uint8_t*>(wsXML.raw_str()), wsXML.GetLength()));
auto pParser =
pdfium::MakeUnique<CFDE_XMLParser>(m_pXMLDoc->GetRoot(), pStream);
pParser->m_dwCheckStatus = 0x03;
if (!m_pXMLDoc->LoadXML(std::move(pParser)))
- return XFA_PARSESTATUS_StatusErr;
+ return nullptr;
int32_t iRet = m_pXMLDoc->DoLoad(pPause);
if (iRet < 0 || iRet >= 100)
m_pXMLDoc->CloseXML();
- if (iRet < 0)
- return XFA_PARSESTATUS_SyntaxErr;
- if (iRet < 100)
- return iRet / 2;
-
- pXMLNode = GetDocumentNode(m_pXMLDoc.get());
- return XFA_PARSESTATUS_Done;
+ return iRet < 100 ? nullptr : GetDocumentNode(m_pXMLDoc.get());
}
void CXFA_SimpleParser::ConstructXFANode(CXFA_Node* pXFANode,
diff --git a/xfa/fxfa/parser/cxfa_simple_parser.h b/xfa/fxfa/parser/cxfa_simple_parser.h
index ccb258a7d4..7671e8d740 100644
--- a/xfa/fxfa/parser/cxfa_simple_parser.h
+++ b/xfa/fxfa/parser/cxfa_simple_parser.h
@@ -29,9 +29,7 @@ class CXFA_SimpleParser {
int32_t StartParse(const CFX_RetainPtr<IFX_SeekableStream>& pStream,
XFA_XDPPACKET ePacketID);
int32_t DoParse(IFX_Pause* pPause);
- int32_t ParseXMLData(const CFX_WideString& wsXML,
- CFDE_XMLNode*& pXMLNode,
- IFX_Pause* pPause);
+ CFDE_XMLNode* ParseXMLData(const CFX_ByteString& wsXML, IFX_Pause* pPause);
void ConstructXFANode(CXFA_Node* pXFANode, CFDE_XMLNode* pXMLNode);
CXFA_Node* GetRootNode() const;
CFDE_XMLDoc* GetXMLDoc() const;