LibreOffice Module sfx2 (master) 1
mieclip.cxx
Go to the documentation of this file.
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 <sal/config.h>
21
22#include <o3tl/safeint.hxx>
23#include <o3tl/string_view.hxx>
24#include <tools/stream.hxx>
25#include <comphelper/string.hxx>
26
27#include <sfx2/mieclip.hxx>
28
30{
31}
32
34{
35 bool bRet = false;
36 pStrm.reset();
37
38 OStringBuffer sLine;
39 sal_Int32 nStt = -1, nEnd = -1, nFragStart = -1, nFragEnd = -1;
40 sal_Int32 nIndex = 0;
41
43 rStream.ResetError();
44
45 if( rStream.ReadLine( sLine ) &&
46 o3tl::getToken(sLine, 0, ':', nIndex ) == "Version" )
47 {
48 while( rStream.ReadLine( sLine ) )
49 {
50 nIndex = 0;
51 std::string_view sTmp(o3tl::getToken(sLine, 0, ':', nIndex));
52 std::string_view sView(sLine);
53 if (sTmp == "StartHTML")
54 nStt = o3tl::toInt32(sView.substr(nIndex));
55 else if (sTmp == "EndHTML")
56 nEnd = o3tl::toInt32(sView.substr(nIndex));
57 else if (sTmp == "StartFragment")
58 nFragStart = o3tl::toInt32(sView.substr(nIndex));
59 else if (sTmp == "EndFragment")
60 nFragEnd = o3tl::toInt32(sView.substr(nIndex));
61 else if (sTmp == "SourceURL")
62 sBaseURL = OStringToOUString( sView.substr(nIndex), RTL_TEXTENCODING_UTF8 );
63
64 if (nEnd >= 0 && nStt >= 0 &&
65 (!sBaseURL.isEmpty() || rStream.Tell() >= o3tl::make_unsigned(nStt)))
66 {
67 bRet = true;
68 break;
69 }
70 }
71 }
72
73 if( bRet )
74 {
75 rStream.Seek( nStt );
76
77 pStrm.reset( new SvMemoryStream( ( nEnd - nStt < 0x10000l
78 ? nEnd - nStt + 32
79 : 0 )) );
80 pStrm->WriteStream( rStream );
81 pStrm->SetStreamSize( nEnd - nStt + 1 );
83 return pStrm.get();
84 }
85
86 if (nFragStart > 0 && nFragEnd > 0 && nFragEnd > nFragStart)
87 {
88 size_t nSize = nFragEnd - nFragStart + 1;
89 if (nSize < 0x10000L)
90 {
91 rStream.Seek(nFragStart);
92 pStrm.reset( new SvMemoryStream(nSize) );
93 pStrm->WriteStream( rStream );
94 pStrm->SetStreamSize(nSize);
96 return pStrm.get();
97 }
98 }
99
100 return nullptr;
101}
102
103/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SvStream * IsValid(SvStream &)
Definition: mieclip.cxx:33
std::unique_ptr< SvStream > pStrm
Definition: mieclip.hxx:31
virtual void ResetError()
sal_uInt64 Tell() const
bool ReadLine(OStringBuffer &rStr, sal_Int32 nMaxBytesToRead=0xFFFE)
sal_uInt64 Seek(sal_uInt64 nPos)
sal_Int32 nIndex
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
sal_Int32 toInt32(std::u16string_view str, sal_Int16 radix=10)
std::basic_string_view< charT, traits > getToken(std::basic_string_view< charT, traits > sv, charT delimiter, std::size_t &position)
#define STREAM_SEEK_TO_BEGIN