1 // Copyright 2017 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 XFA_FDE_CSS_CFDE_CSSTEXTBUF_H_ 8 #define XFA_FDE_CSS_CFDE_CSSTEXTBUF_H_ 9 10 #include "core/fxcrt/cfx_retain_ptr.h" 11 #include "core/fxcrt/fx_memory.h" 12 #include "core/fxcrt/fx_system.h" 13 #include "xfa/fgas/crt/fgas_stream.h" 14 15 class CFDE_CSSTextBuf { 16 public: 17 CFDE_CSSTextBuf(); 18 ~CFDE_CSSTextBuf(); 19 20 bool AttachBuffer(const FX_WCHAR* pBuffer, int32_t iBufLen); 21 bool EstimateSize(int32_t iAllocSize); 22 int32_t LoadFromStream(const CFX_RetainPtr<IFGAS_Stream>& pTxtStream, 23 int32_t iStreamOffset, 24 int32_t iMaxChars, 25 bool& bEOS); AppendChar(FX_WCHAR wch)26 bool AppendChar(FX_WCHAR wch) { 27 if (m_iDatLen >= m_iBufLen && !ExpandBuf(m_iBufLen * 2)) 28 return false; 29 m_pBuffer[m_iDatLen++] = wch; 30 return true; 31 } 32 Clear()33 void Clear() { m_iDatPos = m_iDatLen = 0; } 34 void Reset(); 35 TrimEnd()36 int32_t TrimEnd() { 37 while (m_iDatLen > 0 && m_pBuffer[m_iDatLen - 1] <= ' ') 38 --m_iDatLen; 39 AppendChar(0); 40 return --m_iDatLen; 41 } 42 43 void Subtract(int32_t iStart, int32_t iLength); IsEOF()44 bool IsEOF() const { return m_iDatPos >= m_iDatLen; } 45 GetAt(int32_t index)46 FX_WCHAR GetAt(int32_t index) const { return m_pBuffer[index]; } GetChar()47 FX_WCHAR GetChar() const { return m_pBuffer[m_iDatPos]; } GetNextChar()48 FX_WCHAR GetNextChar() const { 49 return (m_iDatPos + 1 >= m_iDatLen) ? 0 : m_pBuffer[m_iDatPos + 1]; 50 } 51 MoveNext()52 void MoveNext() { m_iDatPos++; } 53 GetLength()54 int32_t GetLength() const { return m_iDatLen; } GetBuffer()55 const FX_WCHAR* GetBuffer() const { return m_pBuffer; } 56 57 protected: 58 bool ExpandBuf(int32_t iDesiredSize); 59 bool m_bExtBuf; 60 FX_WCHAR* m_pBuffer; 61 int32_t m_iBufLen; 62 int32_t m_iDatLen; 63 int32_t m_iDatPos; 64 }; 65 66 #endif // XFA_FDE_CSS_CFDE_CSSTEXTBUF_H_ 67