Coverage Report

Created: 2026-02-14 09:37

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sot/source/sdstor/storinfo.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
21
#include <sot/storinfo.hxx>
22
#include <sot/exchange.hxx>
23
#include <tools/stream.hxx>
24
#include <comphelper/errcode.hxx>
25
#include <memory>
26
27
/************** class SvStorageInfo **************************************
28
*************************************************************************/
29
SotClipboardFormatId ReadClipboardFormat( SvStream & rStm )
30
0
{
31
0
    SotClipboardFormatId nFormat = SotClipboardFormatId::NONE;
32
0
    sal_Int32 nLen = 0;
33
0
    rStm.ReadInt32( nLen );
34
0
    if( rStm.eof() )
35
0
        rStm.SetError( SVSTREAM_GENERALERROR );
36
0
    if( nLen > 0 )
37
0
    {
38
        // get a string name
39
0
        std::unique_ptr<char[]> p(new( ::std::nothrow ) char[ nLen ]);
40
0
        if (p && rStm.ReadBytes(p.get(), nLen) == static_cast<std::size_t>(nLen))
41
0
        {
42
0
            nFormat = SotExchange::RegisterFormatName(OUString(p.get(), nLen-1, RTL_TEXTENCODING_ASCII_US));
43
0
        }
44
0
        else
45
0
            rStm.SetError( SVSTREAM_GENERALERROR );
46
0
    }
47
0
    else if( nLen == -1 )
48
0
    {
49
        // Windows clipboard format
50
        // SV and Win match (up to and including SotClipboardFormatId::GDIMETAFILE)
51
0
        sal_uInt32 nTmp;
52
0
        rStm.ReadUInt32( nTmp );
53
0
        nFormat = static_cast<SotClipboardFormatId>(nTmp);
54
0
    }
55
0
    else if( nLen == -2 )
56
0
    {
57
0
        sal_uInt32 nTmp;
58
0
        rStm.ReadUInt32( nTmp );
59
0
        nFormat = static_cast<SotClipboardFormatId>(nTmp);
60
        // Mac clipboard format
61
        // ??? not implemented
62
0
        rStm.SetError( SVSTREAM_GENERALERROR );
63
0
    }
64
0
    else if( nLen != 0 )
65
0
    {
66
        // unknown identifier
67
0
        rStm.SetError( SVSTREAM_GENERALERROR );
68
0
    }
69
0
    return nFormat;
70
0
}
71
72
void WriteClipboardFormat( SvStream & rStm, SotClipboardFormatId nFormat )
73
154
{
74
    // determine the clipboard format string
75
154
    OUString aCbFmt;
76
154
    if( nFormat > SotClipboardFormatId::GDIMETAFILE )
77
0
        aCbFmt = SotExchange::GetFormatName( nFormat );
78
154
    if( !aCbFmt.isEmpty() )
79
0
    {
80
0
        OString aAsciiCbFmt(OUStringToOString(aCbFmt,
81
0
                                              RTL_TEXTENCODING_ASCII_US));
82
0
        rStm.WriteInt32( aAsciiCbFmt.getLength() + 1 );
83
0
        rStm.WriteOString( aAsciiCbFmt );
84
0
        rStm.WriteUChar( 0 );
85
0
    }
86
154
    else if( nFormat != SotClipboardFormatId::NONE )
87
0
    {
88
0
        rStm.WriteInt32( -1 )         // for Windows
89
0
            .WriteInt32( static_cast<sal_Int32>(nFormat) );
90
0
    }
91
154
    else
92
154
    {
93
154
        rStm.WriteInt32( 0 );         // no clipboard format
94
154
    }
95
154
}
96
97
98
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */