summaryrefslogtreecommitdiff
path: root/xfa/fde/css/cfde_csstextbuf.cpp
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2017-06-26 15:28:15 -0700
committerChromium commit bot <commit-bot@chromium.org>2017-06-30 18:51:27 +0000
commitf3024c3b1fbbfe442f93da3459ea79e817d5b8fe (patch)
tree86652e7b9fc74c60bb966883d02ea14ca0d2995b /xfa/fde/css/cfde_csstextbuf.cpp
parentd24236a926deeb8b9589c330c27dbd300b7f8c9d (diff)
downloadpdfium-f3024c3b1fbbfe442f93da3459ea79e817d5b8fe.tar.xz
Split CFDE_CSSTextBuf in two.
For the external buffer use case, use a CFDE_CSSExtTextBuf instead. With the split, both text buffer implementations are simpler now. As a result, it becomes obvious where it never fails. Adjust callers accordingly. Change-Id: I7b53d36593172487b8c939e6a55af2437ea4ee5a Reviewed-on: https://pdfium-review.googlesource.com/6932 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.cpp66
1 files changed, 13 insertions, 53 deletions
diff --git a/xfa/fde/css/cfde_csstextbuf.cpp b/xfa/fde/css/cfde_csstextbuf.cpp
index 8ccdca9fed..0d8ba2d6ce 100644
--- a/xfa/fde/css/cfde_csstextbuf.cpp
+++ b/xfa/fde/css/cfde_csstextbuf.cpp
@@ -6,69 +6,39 @@
#include "xfa/fde/css/cfde_csstextbuf.h"
-#include "third_party/base/stl_util.h"
+#include "core/fxcrt/fx_memory.h"
CFDE_CSSTextBuf::CFDE_CSSTextBuf()
- : m_bExtBuf(false),
- m_pExtBuffer(nullptr),
- m_pBuffer(nullptr),
- m_iBufLen(0),
- m_iDatLen(0),
- m_iDatPos(0) {}
+ : m_pBuffer(nullptr), m_iBufLen(0), m_iDatLen(0) {}
CFDE_CSSTextBuf::~CFDE_CSSTextBuf() {
- Reset();
+ FX_Free(m_pBuffer);
+ m_pBuffer = nullptr;
+ m_iDatLen = m_iBufLen;
}
-void CFDE_CSSTextBuf::AttachBuffer(const wchar_t* pBuffer, int32_t iBufLen) {
- Reset();
- m_pExtBuffer = pBuffer;
- m_iDatLen = m_iBufLen = iBufLen;
- m_bExtBuf = true;
+void CFDE_CSSTextBuf::InitWithSize(int32_t iAllocSize) {
+ ExpandBuf(iAllocSize);
}
-bool CFDE_CSSTextBuf::EstimateSize(int32_t iAllocSize) {
- ASSERT(iAllocSize > 0);
- Clear();
- m_bExtBuf = false;
- return ExpandBuf(iAllocSize);
-}
-
-bool CFDE_CSSTextBuf::AppendChar(wchar_t wch) {
- if (m_iDatLen >= m_iBufLen && !ExpandBuf(m_iBufLen * 2))
- return false;
+void CFDE_CSSTextBuf::AppendChar(wchar_t wch) {
+ if (m_iDatLen >= m_iBufLen)
+ ExpandBuf(m_iBufLen * 2);
- ASSERT(!m_bExtBuf);
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() {
- ASSERT(!m_bExtBuf);
while (m_iDatLen > 0 && m_pBuffer[m_iDatLen - 1] <= ' ')
--m_iDatLen;
AppendChar(0);
return --m_iDatLen;
}
-const wchar_t* CFDE_CSSTextBuf::GetBuffer() const {
- return m_bExtBuf ? m_pExtBuffer : m_pBuffer;
-}
-
-bool CFDE_CSSTextBuf::ExpandBuf(int32_t iDesiredSize) {
- if (m_bExtBuf)
- return false;
-
+void CFDE_CSSTextBuf::ExpandBuf(int32_t iDesiredSize) {
+ ASSERT(iDesiredSize > 0);
if (m_pBuffer && m_iBufLen == iDesiredSize)
- return true;
+ return;
if (m_pBuffer)
m_pBuffer = FX_Realloc(wchar_t, m_pBuffer, iDesiredSize);
@@ -76,14 +46,4 @@ bool CFDE_CSSTextBuf::ExpandBuf(int32_t iDesiredSize) {
m_pBuffer = FX_Alloc(wchar_t, iDesiredSize);
m_iBufLen = iDesiredSize;
- return true;
-}
-
-void CFDE_CSSTextBuf::Subtract(int32_t iStart, int32_t iLength) {
- ASSERT(iStart >= 0 && iLength >= 0);
- ASSERT(!m_bExtBuf);
-
- iLength = pdfium::clamp(iLength, 0, m_iDatLen - iStart);
- memmove(m_pBuffer, m_pBuffer + iStart, iLength * sizeof(wchar_t));
- m_iDatLen = iLength;
}