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 /xfa/fde/css/cfde_csstextbuf.cpp | |
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>
Diffstat (limited to 'xfa/fde/css/cfde_csstextbuf.cpp')
-rw-r--r-- | xfa/fde/css/cfde_csstextbuf.cpp | 48 |
1 files changed, 30 insertions, 18 deletions
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; } |