Home | History | Annotate | Download | only in xml
      1 // Copyright 2014 PDFium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
      6 
      7 #ifndef CORE_FXCRT_XML_CXML_PARSER_H_
      8 #define CORE_FXCRT_XML_CXML_PARSER_H_
      9 
     10 #include <algorithm>
     11 #include <memory>
     12 
     13 #include "core/fxcrt/fx_stream.h"
     14 #include "core/fxcrt/xml/cxml_databufacc.h"
     15 
     16 class CFX_UTF8Decoder;
     17 class CXML_Element;
     18 
     19 class CXML_Parser {
     20  public:
     21   CXML_Parser();
     22   ~CXML_Parser();
     23 
     24   bool Init(const uint8_t* pBuffer, size_t size);
     25   bool ReadNextBlock();
     26   bool IsEOF();
     27   bool HaveAvailData();
     28   void SkipWhiteSpaces();
     29   void GetName(ByteString* space, ByteString* name);
     30   WideString GetAttrValue();
     31   uint32_t GetCharRef();
     32   void GetTagName(bool bStartTag,
     33                   bool* bEndTag,
     34                   ByteString* space,
     35                   ByteString* name);
     36   void SkipLiterals(const ByteStringView& str);
     37   std::unique_ptr<CXML_Element> ParseElement(CXML_Element* pParent,
     38                                              bool bStartTag);
     39   void InsertContentSegment(bool bCDATA,
     40                             const WideStringView& content,
     41                             CXML_Element* pElement);
     42   void InsertCDATASegment(CFX_UTF8Decoder& decoder, CXML_Element* pElement);
     43 
     44  private:
     45   std::unique_ptr<CXML_Element> ParseElementInternal(CXML_Element* pParent,
     46                                                      bool bStartTag,
     47                                                      int nDepth);
     48 
     49   std::unique_ptr<CXML_DataBufAcc> m_pDataAcc;
     50   FX_FILESIZE m_nOffset;
     51   const uint8_t* m_pBuffer;
     52   size_t m_dwBufferSize;
     53   FX_FILESIZE m_nBufferOffset;
     54   size_t m_dwIndex;
     55 };
     56 
     57 #endif  // CORE_FXCRT_XML_CXML_PARSER_H_
     58