summaryrefslogtreecommitdiff
path: root/xfa/fde/css/cfde_csstextbuf.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'xfa/fde/css/cfde_csstextbuf.cpp')
-rw-r--r--xfa/fde/css/cfde_csstextbuf.cpp48
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;
}