Coverage Report

Created: 2025-12-31 10:39

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/writerperfect/source/writer/exp/XMLBase64ImportContext.cxx
Line
Count
Source
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/*
3
 * This file is part of the LibreOffice project.
4
 *
5
 * This Source Code Form is subject to the terms of the Mozilla Public
6
 * License, v. 2.0. If a copy of the MPL was not distributed with this
7
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8
 */
9
10
#include "XMLBase64ImportContext.hxx"
11
12
#include <comphelper/base64.hxx>
13
14
using namespace com::sun::star;
15
16
namespace writerperfect::exp
17
{
18
XMLBase64ImportContext::XMLBase64ImportContext(XMLImport& rImport)
19
0
    : XMLImportContext(rImport)
20
0
{
21
0
}
22
23
void XMLBase64ImportContext::startElement(
24
    const OUString& /*rName*/,
25
    const css::uno::Reference<css::xml::sax::XAttributeList>& /*xAttribs*/)
26
0
{
27
0
}
28
29
void XMLBase64ImportContext::endElement(const OUString& /*rName*/)
30
0
{
31
0
    m_aBinaryData.append(static_cast<const unsigned char*>(m_aStream.GetData()),
32
0
                         m_aStream.GetSize());
33
0
}
34
35
void XMLBase64ImportContext::characters(const OUString& rChars)
36
0
{
37
0
    OUString aTrimmedChars(rChars.trim());
38
39
0
    if (aTrimmedChars.isEmpty())
40
0
        return;
41
42
0
    OUString aChars;
43
0
    if (!m_aBase64CharsLeft.isEmpty())
44
0
    {
45
0
        aChars = m_aBase64CharsLeft + aTrimmedChars;
46
0
        m_aBase64CharsLeft.clear();
47
0
    }
48
0
    else
49
0
        aChars = aTrimmedChars;
50
51
0
    uno::Sequence<sal_Int8> aBuffer((aChars.getLength() / 4) * 3);
52
0
    const sal_Int32 nCharsDecoded = comphelper::Base64::decodeSomeChars(aBuffer, aChars);
53
0
    m_aStream.WriteBytes(aBuffer.getArray(), aBuffer.getLength());
54
0
    if (nCharsDecoded != aChars.getLength())
55
0
        m_aBase64CharsLeft = aChars.copy(nCharsDecoded);
56
0
}
57
58
const librevenge::RVNGBinaryData& XMLBase64ImportContext::getBinaryData() const
59
0
{
60
0
    return m_aBinaryData;
61
0
}
62
63
} // namespace writerperfect::exp
64
65
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */