1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

#include "rtfstringbuffer.hxx"
#include "rtfattributeoutput.hxx"
#include "rtfexport.hxx"

RtfStringBufferValue::RtfStringBufferValue() = default;

RtfStringBufferValue::RtfStringBufferValue(const SwFlyFrameFormat* pFlyFrameFormat,
                                           const SwGrfNode* pGrfNode)
    : m_pFlyFrameFormat(pFlyFrameFormat)
    , m_pGrfNode(pGrfNode)
{
}

void RtfStringBufferValue::makeStringAndClear(RtfAttributeOutput* pAttributeOutput)
{
    if (!isGraphic())
        pAttributeOutput->m_rExport.Strm().WriteOString(m_aBuffer.makeStringAndClear());
    else
        pAttributeOutput->FlyFrameGraphic(m_pFlyFrameFormat, m_pGrfNode);
}

OString RtfStringBufferValue::makeStringAndClear() { return m_aBuffer.makeStringAndClear(); }

bool RtfStringBufferValue::isGraphic() const
{
    return m_pFlyFrameFormat != nullptr && m_pGrfNode != nullptr;
}

RtfStringBuffer::RtfStringBuffer() = default;

sal_Int32 RtfStringBuffer::getLength() const
{
    sal_Int32 nRet = 0;
    for (const auto& rValue : m_aValues)
        if (!rValue.isGraphic())
            nRet += rValue.getBuffer().getLength();<--- Consider using std::accumulate algorithm instead of a raw loop.
    return nRet;
}

void RtfStringBuffer::makeStringAndClear(RtfAttributeOutput* pAttributeOutput)
{
    for (auto& rValue : m_aValues)
        rValue.makeStringAndClear(pAttributeOutput);
}

OString RtfStringBuffer::makeStringAndClear()
{
    OStringBuffer aBuf;
    for (auto& rValue : m_aValues)
        if (!rValue.isGraphic())
            aBuf.append(rValue.makeStringAndClear());
    return aBuf.makeStringAndClear();
}

OStringBuffer& RtfStringBuffer::getLastBuffer()
{
    if (m_aValues.empty() || m_aValues.back().isGraphic())
        m_aValues.emplace_back(RtfStringBufferValue());
    return m_aValues.back().getBuffer();
}

OStringBuffer* RtfStringBuffer::operator->() { return &getLastBuffer(); }

void RtfStringBuffer::clear() { m_aValues.clear(); }

void RtfStringBuffer::append(const SwFlyFrameFormat* pFlyFrameFormat, const SwGrfNode* pGrfNode)
{
    m_aValues.emplace_back(RtfStringBufferValue(pFlyFrameFormat, pGrfNode));
}

void RtfStringBuffer::appendAndClear(RtfStringBuffer& rBuf)
{
    for (const auto& rValue : rBuf.m_aValues)
        m_aValues.push_back(rValue);<--- Consider using std::copy algorithm instead of a raw loop.
    rBuf.clear();
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */