Kill operator LPCWSTR from CFX_WideString().
[pdfium.git] / core / src / fxcrt / xml_int.h
index 8ad8ef4..964c794 100644 (file)
-// Copyright 2014 PDFium Authors. All rights reserved.\r
-// Use of this source code is governed by a BSD-style license that can be\r
-// found in the LICENSE file.\r
\r
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com\r
-\r
-#ifndef _FXCRT_XML_INT_\r
-#define _FXCRT_XML_INT_\r
-class CXML_DataBufAcc : public IFX_BufferRead, public CFX_Object\r
-{\r
-public:\r
-    CXML_DataBufAcc(FX_LPCBYTE pBuffer, size_t size, IFX_Allocator* pAllocator = NULL)\r
-        : m_pAllocator(pAllocator)\r
-        , m_pBuffer(pBuffer)\r
-        , m_dwSize(size)\r
-        , m_dwCurPos(0)\r
-    {\r
-    }\r
-    virtual ~CXML_DataBufAcc() {}\r
-    virtual void                       Release()\r
-    {\r
-        if (m_pAllocator) {\r
-            FX_DeleteAtAllocator(this, m_pAllocator, CXML_DataBufAcc);\r
-        } else {\r
-            delete this;\r
-        }\r
-    }\r
-    virtual FX_BOOL                    IsEOF()\r
-    {\r
-        return m_dwCurPos >= m_dwSize;\r
-    }\r
-    virtual FX_FILESIZE                GetPosition()\r
-    {\r
-        return (FX_FILESIZE)m_dwCurPos;\r
-    }\r
-    virtual size_t                     ReadBlock(void* buffer, size_t size)\r
-    {\r
-        return 0;\r
-    }\r
-    virtual FX_BOOL                    ReadNextBlock(FX_BOOL bRestart = FALSE)\r
-    {\r
-        if (bRestart) {\r
-            m_dwCurPos = 0;\r
-        }\r
-        if (m_dwCurPos < m_dwSize) {\r
-            m_dwCurPos = m_dwSize;\r
-            return TRUE;\r
-        }\r
-        return FALSE;\r
-    }\r
-    virtual FX_LPCBYTE         GetBlockBuffer()\r
-    {\r
-        return m_pBuffer;\r
-    }\r
-    virtual size_t                     GetBlockSize()\r
-    {\r
-        return m_dwSize;\r
-    }\r
-    virtual FX_FILESIZE                GetBlockOffset()\r
-    {\r
-        return 0;\r
-    }\r
-protected:\r
-    IFX_Allocator*     m_pAllocator;\r
-    FX_LPCBYTE         m_pBuffer;\r
-    size_t                     m_dwSize;\r
-    size_t                     m_dwCurPos;\r
-};\r
-#define FX_XMLDATASTREAM_BufferSize            (32 * 1024)\r
-class CXML_DataStmAcc : public IFX_BufferRead, public CFX_Object\r
-{\r
-public:\r
-    CXML_DataStmAcc(IFX_FileRead *pFileRead, IFX_Allocator* pAllocator = NULL)\r
-        : m_pAllocator(pAllocator)\r
-        , m_pFileRead(pFileRead)\r
-        , m_pBuffer(NULL)\r
-        , m_nStart(0)\r
-        , m_dwSize(0)\r
-    {\r
-        FXSYS_assert(m_pFileRead != NULL);\r
-    }\r
-    virtual ~CXML_DataStmAcc()\r
-    {\r
-        if (m_pBuffer) {\r
-            FX_Allocator_Free(m_pAllocator, m_pBuffer);\r
-        }\r
-    }\r
-    virtual void                       Release()\r
-    {\r
-        if (m_pAllocator) {\r
-            FX_DeleteAtAllocator(this, m_pAllocator, CXML_DataStmAcc);\r
-        } else {\r
-            delete this;\r
-        }\r
-    }\r
-    virtual FX_BOOL                    IsEOF()\r
-    {\r
-        return m_nStart + (FX_FILESIZE)m_dwSize >= m_pFileRead->GetSize();\r
-    }\r
-    virtual FX_FILESIZE                GetPosition()\r
-    {\r
-        return m_nStart + (FX_FILESIZE)m_dwSize;\r
-    }\r
-    virtual size_t                     ReadBlock(void* buffer, size_t size)\r
-    {\r
-        return 0;\r
-    }\r
-    virtual FX_BOOL                    ReadNextBlock(FX_BOOL bRestart = FALSE)\r
-    {\r
-        if (bRestart) {\r
-            m_nStart = 0;\r
-        }\r
-        FX_FILESIZE nLength = m_pFileRead->GetSize();\r
-        m_nStart += (FX_FILESIZE)m_dwSize;\r
-        if (m_nStart >= nLength) {\r
-            return FALSE;\r
-        }\r
-        m_dwSize = (size_t)FX_MIN(FX_XMLDATASTREAM_BufferSize, nLength - m_nStart);\r
-        if (!m_pBuffer) {\r
-            m_pBuffer = FX_Allocator_Alloc(m_pAllocator, FX_BYTE, m_dwSize);\r
-            if (!m_pBuffer) {\r
-                return FALSE;\r
-            }\r
-        }\r
-        return m_pFileRead->ReadBlock(m_pBuffer, m_nStart, m_dwSize);\r
-    }\r
-    virtual FX_LPCBYTE         GetBlockBuffer()\r
-    {\r
-        return (FX_LPCBYTE)m_pBuffer;\r
-    }\r
-    virtual size_t                     GetBlockSize()\r
-    {\r
-        return m_dwSize;\r
-    }\r
-    virtual FX_FILESIZE                GetBlockOffset()\r
-    {\r
-        return m_nStart;\r
-    }\r
-protected:\r
-    IFX_Allocator*     m_pAllocator;\r
-    IFX_FileRead       *m_pFileRead;\r
-    FX_LPBYTE          m_pBuffer;\r
-    FX_FILESIZE                m_nStart;\r
-    size_t                     m_dwSize;\r
-};\r
-class CXML_Parser\r
-{\r
-public:\r
-    CXML_Parser(IFX_Allocator* pAllocator = NULL) : m_pAllocator(pAllocator) {}\r
-    ~CXML_Parser();\r
-    IFX_Allocator*     m_pAllocator;\r
-    IFX_BufferRead*    m_pDataAcc;\r
-    FX_BOOL                    m_bOwnedStream;\r
-    FX_FILESIZE                m_nOffset;\r
-    FX_BOOL                    m_bSaveSpaceChars;\r
-    FX_LPCBYTE         m_pBuffer;\r
-    size_t                     m_dwBufferSize;\r
-    FX_FILESIZE                m_nBufferOffset;\r
-    size_t                     m_dwIndex;\r
-    FX_BOOL                    Init(FX_LPBYTE pBuffer, size_t size);\r
-    FX_BOOL                    Init(IFX_FileRead *pFileRead);\r
-    FX_BOOL                    Init(IFX_BufferRead *pBuffer);\r
-    FX_BOOL                    Init(FX_BOOL bOwndedStream);\r
-    FX_BOOL                    ReadNextBlock();\r
-    FX_BOOL                    IsEOF();\r
-    FX_BOOL                    HaveAvailData();\r
-    void                       SkipWhiteSpaces();\r
-    void                       GetName(CFX_ByteStringL &space, CFX_ByteStringL &name);\r
-    void                       GetAttrValue(CFX_WideStringL &value);\r
-    FX_DWORD           GetCharRef();\r
-    void                       GetTagName(CFX_ByteStringL &space, CFX_ByteStringL &name, FX_BOOL &bEndTag, FX_BOOL bStartTag = FALSE);\r
-    void                       SkipLiterals(FX_BSTR str);\r
-    CXML_Element*      ParseElement(CXML_Element* pParent, FX_BOOL bStartTag = FALSE);\r
-    void                       InsertContentSegment(FX_BOOL bCDATA, FX_WSTR content, CXML_Element* pElement);\r
-    void                       InsertCDATASegment(CFX_UTF8Decoder& decoder, CXML_Element* pElement);\r
-};\r
-void FX_XML_SplitQualifiedName(FX_BSTR bsFullName, CFX_ByteStringC &bsSpace, CFX_ByteStringC &bsName);\r
-#endif\r
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef _FXCRT_XML_INT_
+#define _FXCRT_XML_INT_
+class CXML_DataBufAcc : public IFX_BufferRead
+{
+public:
+    CXML_DataBufAcc(FX_LPCBYTE pBuffer, size_t size)
+        : m_pBuffer(pBuffer)
+        , m_dwSize(size)
+        , m_dwCurPos(0)
+    {
+    }
+    virtual ~CXML_DataBufAcc() {}
+    virtual void                       Release()
+    {
+        delete this;
+    }
+    virtual FX_BOOL                    IsEOF()
+    {
+        return m_dwCurPos >= m_dwSize;
+    }
+    virtual FX_FILESIZE                GetPosition()
+    {
+        return (FX_FILESIZE)m_dwCurPos;
+    }
+    virtual size_t                     ReadBlock(void* buffer, size_t size)
+    {
+        return 0;
+    }
+    virtual FX_BOOL                    ReadNextBlock(FX_BOOL bRestart = FALSE)
+    {
+        if (bRestart) {
+            m_dwCurPos = 0;
+        }
+        if (m_dwCurPos < m_dwSize) {
+            m_dwCurPos = m_dwSize;
+            return TRUE;
+        }
+        return FALSE;
+    }
+    virtual FX_LPCBYTE         GetBlockBuffer()
+    {
+        return m_pBuffer;
+    }
+    virtual size_t                     GetBlockSize()
+    {
+        return m_dwSize;
+    }
+    virtual FX_FILESIZE                GetBlockOffset()
+    {
+        return 0;
+    }
+protected:
+    FX_LPCBYTE         m_pBuffer;
+    size_t                     m_dwSize;
+    size_t                     m_dwCurPos;
+};
+#define FX_XMLDATASTREAM_BufferSize            (32 * 1024)
+class CXML_DataStmAcc : public IFX_BufferRead
+{
+public:
+    CXML_DataStmAcc(IFX_FileRead *pFileRead)
+        : m_pFileRead(pFileRead)
+        , m_pBuffer(NULL)
+        , m_nStart(0)
+        , m_dwSize(0)
+    {
+        FXSYS_assert(m_pFileRead != NULL);
+    }
+    virtual ~CXML_DataStmAcc()
+    {
+        if (m_pBuffer) {
+            FX_Free(m_pBuffer);
+        }
+    }
+    virtual void                       Release()
+    {
+        delete this;
+    }
+    virtual FX_BOOL                    IsEOF()
+    {
+        return m_nStart + (FX_FILESIZE)m_dwSize >= m_pFileRead->GetSize();
+    }
+    virtual FX_FILESIZE                GetPosition()
+    {
+        return m_nStart + (FX_FILESIZE)m_dwSize;
+    }
+    virtual size_t                     ReadBlock(void* buffer, size_t size)
+    {
+        return 0;
+    }
+    virtual FX_BOOL                    ReadNextBlock(FX_BOOL bRestart = FALSE)
+    {
+        if (bRestart) {
+            m_nStart = 0;
+        }
+        FX_FILESIZE nLength = m_pFileRead->GetSize();
+        m_nStart += (FX_FILESIZE)m_dwSize;
+        if (m_nStart >= nLength) {
+            return FALSE;
+        }
+        m_dwSize = (size_t)FX_MIN(FX_XMLDATASTREAM_BufferSize, nLength - m_nStart);
+        if (!m_pBuffer) {
+            m_pBuffer = FX_Alloc(FX_BYTE, m_dwSize);
+            if (!m_pBuffer) {
+                return FALSE;
+            }
+        }
+        return m_pFileRead->ReadBlock(m_pBuffer, m_nStart, m_dwSize);
+    }
+    virtual FX_LPCBYTE         GetBlockBuffer()
+    {
+        return (FX_LPCBYTE)m_pBuffer;
+    }
+    virtual size_t                     GetBlockSize()
+    {
+        return m_dwSize;
+    }
+    virtual FX_FILESIZE                GetBlockOffset()
+    {
+        return m_nStart;
+    }
+protected:
+    IFX_FileRead       *m_pFileRead;
+    FX_LPBYTE          m_pBuffer;
+    FX_FILESIZE                m_nStart;
+    size_t                     m_dwSize;
+};
+class CXML_Parser
+{
+public:
+    ~CXML_Parser();
+    IFX_BufferRead*    m_pDataAcc;
+    FX_BOOL                    m_bOwnedStream;
+    FX_FILESIZE                m_nOffset;
+    FX_BOOL                    m_bSaveSpaceChars;
+    FX_LPCBYTE         m_pBuffer;
+    size_t                     m_dwBufferSize;
+    FX_FILESIZE                m_nBufferOffset;
+    size_t                     m_dwIndex;
+    FX_BOOL                    Init(FX_LPBYTE pBuffer, size_t size);
+    FX_BOOL                    Init(IFX_FileRead *pFileRead);
+    FX_BOOL                    Init(IFX_BufferRead *pBuffer);
+    FX_BOOL                    Init(FX_BOOL bOwndedStream);
+    FX_BOOL                    ReadNextBlock();
+    FX_BOOL                    IsEOF();
+    FX_BOOL                    HaveAvailData();
+    void                       SkipWhiteSpaces();
+    void                       GetName(CFX_ByteString& space, CFX_ByteString& name);
+    void                       GetAttrValue(CFX_WideString &value);
+    FX_DWORD           GetCharRef();
+    void                       GetTagName(CFX_ByteString &space, CFX_ByteString &name, FX_BOOL &bEndTag, FX_BOOL bStartTag = FALSE);
+    void                       SkipLiterals(FX_BSTR str);
+    CXML_Element*      ParseElement(CXML_Element* pParent, FX_BOOL bStartTag = FALSE);
+    void                       InsertContentSegment(FX_BOOL bCDATA, FX_WSTR content, CXML_Element* pElement);
+    void                       InsertCDATASegment(CFX_UTF8Decoder& decoder, CXML_Element* pElement);
+};
+void FX_XML_SplitQualifiedName(FX_BSTR bsFullName, CFX_ByteStringC &bsSpace, CFX_ByteStringC &bsName);
+#endif