nss: upgrade to release 3.73
[LibreOffice.git] / sw / source / filter / ww8 / rtfstringbuffer.cxx
blob055ace53a4299f5c8073358a5ddad90c1f8183cd
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 */
9 #include "rtfstringbuffer.hxx"
10 #include "rtfattributeoutput.hxx"
11 #include "rtfexport.hxx"
13 RtfStringBufferValue::RtfStringBufferValue() = default;
15 RtfStringBufferValue::RtfStringBufferValue(const SwFlyFrameFormat* pFlyFrameFormat,
16 const SwGrfNode* pGrfNode)
17 : m_pFlyFrameFormat(pFlyFrameFormat)
18 , m_pGrfNode(pGrfNode)
22 void RtfStringBufferValue::makeStringAndClear(RtfAttributeOutput* pAttributeOutput)
24 if (!isGraphic())
25 pAttributeOutput->m_rExport.Strm().WriteOString(m_aBuffer.makeStringAndClear());
26 else
27 pAttributeOutput->FlyFrameGraphic(m_pFlyFrameFormat, m_pGrfNode);
30 OString RtfStringBufferValue::makeStringAndClear() { return m_aBuffer.makeStringAndClear(); }
32 bool RtfStringBufferValue::isGraphic() const
34 return m_pFlyFrameFormat != nullptr && m_pGrfNode != nullptr;
37 RtfStringBuffer::RtfStringBuffer() = default;
39 sal_Int32 RtfStringBuffer::getLength() const
41 sal_Int32 nRet = 0;
42 for (const auto& rValue : m_aValues)
43 if (!rValue.isGraphic())
44 nRet += rValue.getBuffer().getLength();
45 return nRet;
48 void RtfStringBuffer::makeStringAndClear(RtfAttributeOutput* pAttributeOutput)
50 for (auto& rValue : m_aValues)
51 rValue.makeStringAndClear(pAttributeOutput);
54 OString RtfStringBuffer::makeStringAndClear()
56 OStringBuffer aBuf;
57 for (auto& rValue : m_aValues)
58 if (!rValue.isGraphic())
59 aBuf.append(rValue.makeStringAndClear());
60 return aBuf.makeStringAndClear();
63 OStringBuffer& RtfStringBuffer::getLastBuffer()
65 if (m_aValues.empty() || m_aValues.back().isGraphic())
66 m_aValues.emplace_back(RtfStringBufferValue());
67 return m_aValues.back().getBuffer();
70 OStringBuffer* RtfStringBuffer::operator->() { return &getLastBuffer(); }
72 void RtfStringBuffer::clear() { m_aValues.clear(); }
74 void RtfStringBuffer::append(const SwFlyFrameFormat* pFlyFrameFormat, const SwGrfNode* pGrfNode)
76 m_aValues.emplace_back(RtfStringBufferValue(pFlyFrameFormat, pGrfNode));
79 void RtfStringBuffer::appendAndClear(RtfStringBuffer& rBuf)
81 for (const auto& rValue : rBuf.m_aValues)
82 m_aValues.push_back(rValue);
83 rBuf.clear();
86 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */