Coverage Report

Created: 2025-12-31 10:39

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/xmlscript/source/xml_helper/xml_byteseq.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
 * This file incorporates work covered by the following license notice:
10
 *
11
 *   Licensed to the Apache Software Foundation (ASF) under one or more
12
 *   contributor license agreements. See the NOTICE file distributed
13
 *   with this work for additional information regarding copyright
14
 *   ownership. The ASF licenses this file to you under the Apache
15
 *   License, Version 2.0 (the "License"); you may not use this file
16
 *   except in compliance with the License. You may obtain a copy of
17
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18
 */
19
20
#include <string.h>
21
22
#include <cppuhelper/implbase.hxx>
23
#include <xmlscript/xml_helper.hxx>
24
#include <com/sun/star/io/XInputStream.hpp>
25
#include <com/sun/star/io/XOutputStream.hpp>
26
27
using namespace com::sun::star;
28
using namespace com::sun::star::uno;
29
30
31
namespace xmlscript
32
{
33
34
namespace {
35
36
class BSeqInputStream
37
    : public ::cppu::WeakImplHelper< io::XInputStream >
38
{
39
    std::vector<sal_Int8> _seq;
40
    sal_Int32 _nPos;
41
42
public:
43
    explicit BSeqInputStream( std::vector<sal_Int8>&& rSeq )
44
0
        : _seq( std::move(rSeq) )
45
0
        , _nPos( 0 )
46
0
        {}
47
48
    // XInputStream
49
    virtual sal_Int32 SAL_CALL readBytes(
50
        Sequence< sal_Int8 > & rData, sal_Int32 nBytesToRead ) override;
51
    virtual sal_Int32 SAL_CALL readSomeBytes(
52
        Sequence< sal_Int8 > & rData, sal_Int32 nMaxBytesToRead ) override;
53
    virtual void SAL_CALL skipBytes(
54
        sal_Int32 nBytesToSkip ) override;
55
    virtual sal_Int32 SAL_CALL available() override;
56
    virtual void SAL_CALL closeInput() override;
57
};
58
59
}
60
61
sal_Int32 BSeqInputStream::readBytes(
62
    Sequence< sal_Int8 > & rData, sal_Int32 nBytesToRead )
63
0
{
64
0
    nBytesToRead = ((nBytesToRead > static_cast<sal_Int32>(_seq.size()) - _nPos)
65
0
                    ? _seq.size() - _nPos
66
0
                    : nBytesToRead);
67
68
0
    if (rData.getLength() != nBytesToRead)
69
0
        rData.realloc( nBytesToRead );
70
0
    if (nBytesToRead != 0) {
71
0
        memcpy(rData.getArray(), &_seq[_nPos], nBytesToRead);
72
0
    }
73
0
    _nPos += nBytesToRead;
74
0
    return nBytesToRead;
75
0
}
76
77
sal_Int32 BSeqInputStream::readSomeBytes(
78
    Sequence< sal_Int8 > & rData, sal_Int32 nMaxBytesToRead )
79
0
{
80
0
    return readBytes( rData, nMaxBytesToRead );
81
0
}
82
83
void BSeqInputStream::skipBytes(
84
    sal_Int32 /*nBytesToSkip*/ )
85
0
{
86
0
}
87
88
sal_Int32 BSeqInputStream::available()
89
0
{
90
0
    return _seq.size() - _nPos;
91
0
}
92
93
void BSeqInputStream::closeInput()
94
0
{
95
0
}
96
97
namespace {
98
99
class BSeqOutputStream
100
    : public ::cppu::WeakImplHelper< io::XOutputStream >
101
{
102
    std::vector<sal_Int8> * _seq;
103
104
public:
105
    explicit BSeqOutputStream( std::vector<sal_Int8> * seq )
106
0
        : _seq( seq )
107
0
        {}
108
109
    // XOutputStream
110
    virtual void SAL_CALL writeBytes(
111
        Sequence< sal_Int8 > const & rData ) override;
112
    virtual void SAL_CALL flush() override;
113
    virtual void SAL_CALL closeOutput() override;
114
};
115
116
}
117
118
void BSeqOutputStream::writeBytes( Sequence< sal_Int8 > const & rData )
119
0
{
120
0
    sal_Int32 nPos = _seq->size();
121
0
    _seq->resize( nPos + rData.getLength() );
122
0
    if (rData.getLength() != 0) {
123
0
        std::copy(rData.getConstArray(),
124
0
                  rData.getConstArray() + rData.getLength(),
125
0
                  _seq->begin() + nPos);
126
0
    }
127
0
}
128
void BSeqOutputStream::flush()
129
0
{
130
0
}
131
132
void BSeqOutputStream::closeOutput()
133
0
{
134
0
}
135
136
Reference< io::XInputStream > createInputStream( std::vector<sal_Int8>&& rInData )
137
0
{
138
0
    return new BSeqInputStream( std::move(rInData) );
139
0
}
140
141
Reference< io::XInputStream > createInputStream( const sal_Int8* pData, int len )
142
0
{
143
0
    std::vector<sal_Int8> rInData(len);
144
0
    if (len != 0) {
145
0
        memcpy( rInData.data(), pData, len);
146
0
    }
147
0
    return new BSeqInputStream( std::move(rInData) );
148
0
}
149
150
Reference< io::XOutputStream > createOutputStream( std::vector<sal_Int8> * pOutData )
151
0
{
152
0
    return new BSeqOutputStream( pOutData );
153
0
}
154
155
}
156
157
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */