diff options
author | Lei Zhang <thestig@chromium.org> | 2017-06-26 13:33:47 -0700 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-06-26 20:49:42 +0000 |
commit | f76e9d33b6246358d34cb476dbf197788fe49425 (patch) | |
tree | 5207216d0850b602816b0bb0f196ecb29117ff0f | |
parent | bdb330ee4d4d9d6fafc6bc84d4fa28c045eda936 (diff) | |
download | pdfium-f76e9d33b6246358d34cb476dbf197788fe49425.tar.xz |
Clean up CFDE_CSSTextBuf.
Change-Id: I8230c2d5e5450ea36ff6d2a4fefc1619a13e9c44
Reviewed-on: https://pdfium-review.googlesource.com/6930
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
-rw-r--r-- | xfa/fde/css/cfde_csssyntaxparser.cpp | 3 | ||||
-rw-r--r-- | xfa/fde/css/cfde_csstextbuf.cpp | 48 | ||||
-rw-r--r-- | xfa/fde/css/cfde_csstextbuf.h | 16 |
3 files changed, 35 insertions, 32 deletions
diff --git a/xfa/fde/css/cfde_csssyntaxparser.cpp b/xfa/fde/css/cfde_csssyntaxparser.cpp index e943f29f4d..b896eb79b8 100644 --- a/xfa/fde/css/cfde_csssyntaxparser.cpp +++ b/xfa/fde/css/cfde_csssyntaxparser.cpp @@ -41,7 +41,8 @@ bool CFDE_CSSSyntaxParser::Init(const wchar_t* pBuffer, Reset(bOnlyDeclaration); if (!m_TextData.EstimateSize(iTextDatSize)) return false; - return m_TextPlane.AttachBuffer(pBuffer, iBufferSize); + m_TextPlane.AttachBuffer(pBuffer, iBufferSize); + return true; } void CFDE_CSSSyntaxParser::Reset(bool bOnlyDeclaration) { diff --git a/xfa/fde/css/cfde_csstextbuf.cpp b/xfa/fde/css/cfde_csstextbuf.cpp index 2d8f93f2b3..c408a95b03 100644 --- a/xfa/fde/css/cfde_csstextbuf.cpp +++ b/xfa/fde/css/cfde_csstextbuf.cpp @@ -19,19 +19,11 @@ CFDE_CSSTextBuf::~CFDE_CSSTextBuf() { Reset(); } -void CFDE_CSSTextBuf::Reset() { - if (!m_bExtBuf) { - FX_Free(m_pBuffer); - m_pBuffer = nullptr; - } - m_iDatPos = m_iDatLen = m_iBufLen; -} - -bool CFDE_CSSTextBuf::AttachBuffer(const wchar_t* pBuffer, int32_t iBufLen) { +void CFDE_CSSTextBuf::AttachBuffer(const wchar_t* pBuffer, int32_t iBufLen) { Reset(); m_pBuffer = const_cast<wchar_t*>(pBuffer); m_iDatLen = m_iBufLen = iBufLen; - return m_bExtBuf = true; + m_bExtBuf = true; } bool CFDE_CSSTextBuf::EstimateSize(int32_t iAllocSize) { @@ -41,20 +33,40 @@ bool CFDE_CSSTextBuf::EstimateSize(int32_t iAllocSize) { return ExpandBuf(iAllocSize); } +bool CFDE_CSSTextBuf::AppendChar(wchar_t wch) { + if (m_iDatLen >= m_iBufLen && !ExpandBuf(m_iBufLen * 2)) + return false; + m_pBuffer[m_iDatLen++] = wch; + return true; +} + +void CFDE_CSSTextBuf::Reset() { + if (!m_bExtBuf) { + FX_Free(m_pBuffer); + m_pBuffer = nullptr; + } + m_iDatPos = m_iDatLen = m_iBufLen; +} + +int32_t CFDE_CSSTextBuf::TrimEnd() { + while (m_iDatLen > 0 && m_pBuffer[m_iDatLen - 1] <= ' ') + --m_iDatLen; + AppendChar(0); + return --m_iDatLen; +} + bool CFDE_CSSTextBuf::ExpandBuf(int32_t iDesiredSize) { if (m_bExtBuf) return false; - if (!m_pBuffer) - m_pBuffer = FX_Alloc(wchar_t, iDesiredSize); - else if (m_iBufLen != iDesiredSize) + + if (m_pBuffer && m_iBufLen == iDesiredSize) + return true; + + if (m_pBuffer) m_pBuffer = FX_Realloc(wchar_t, m_pBuffer, iDesiredSize); else - return true; + m_pBuffer = FX_Alloc(wchar_t, iDesiredSize); - if (!m_pBuffer) { - m_iBufLen = 0; - return false; - } m_iBufLen = iDesiredSize; return true; } diff --git a/xfa/fde/css/cfde_csstextbuf.h b/xfa/fde/css/cfde_csstextbuf.h index 71c76f3361..eaeb085971 100644 --- a/xfa/fde/css/cfde_csstextbuf.h +++ b/xfa/fde/css/cfde_csstextbuf.h @@ -17,24 +17,14 @@ class CFDE_CSSTextBuf { CFDE_CSSTextBuf(); ~CFDE_CSSTextBuf(); - bool AttachBuffer(const wchar_t* pBuffer, int32_t iBufLen); + void AttachBuffer(const wchar_t* pBuffer, int32_t iBufLen); bool EstimateSize(int32_t iAllocSize); - bool AppendChar(wchar_t wch) { - if (m_iDatLen >= m_iBufLen && !ExpandBuf(m_iBufLen * 2)) - return false; - m_pBuffer[m_iDatLen++] = wch; - return true; - } + bool AppendChar(wchar_t wch); void Clear() { m_iDatPos = m_iDatLen = 0; } void Reset(); - int32_t TrimEnd() { - while (m_iDatLen > 0 && m_pBuffer[m_iDatLen - 1] <= ' ') - --m_iDatLen; - AppendChar(0); - return --m_iDatLen; - } + int32_t TrimEnd(); void Subtract(int32_t iStart, int32_t iLength); bool IsEOF() const { return m_iDatPos >= m_iDatLen; } |