1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sal/config.h>
22 #include <o3tl/safeint.hxx>
23 #include <o3tl/string_view.hxx>
24 #include <tools/stream.hxx>
25 #include <comphelper/string.hxx>
27 #include <sfx2/mieclip.hxx>
29 MSE40HTMLClipFormatObj::~MSE40HTMLClipFormatObj()
33 SvStream
* MSE40HTMLClipFormatObj::IsValid( SvStream
& rStream
)
39 sal_Int32 nStt
= -1, nEnd
= -1, nFragStart
= -1, nFragEnd
= -1;
42 rStream
.Seek(STREAM_SEEK_TO_BEGIN
);
45 if( rStream
.ReadLine( sLine
) &&
46 o3tl::getToken(sLine
, 0, ':', nIndex
) == "Version" )
48 while( rStream
.ReadLine( sLine
) )
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
);
64 if (nEnd
>= 0 && nStt
>= 0 &&
65 (!sBaseURL
.isEmpty() || rStream
.Tell() >= o3tl::make_unsigned(nStt
)))
77 pStrm
.reset( new SvMemoryStream( ( nEnd
- nStt
< 0x10000l
80 pStrm
->WriteStream( rStream
);
81 pStrm
->SetStreamSize( nEnd
- nStt
+ 1 );
82 pStrm
->Seek( STREAM_SEEK_TO_BEGIN
);
86 if (nFragStart
> 0 && nFragEnd
> 0 && nFragEnd
> nFragStart
)
88 size_t nSize
= nFragEnd
- nFragStart
+ 1;
91 rStream
.Seek(nFragStart
);
92 pStrm
.reset( new SvMemoryStream(nSize
) );
93 pStrm
->WriteStream( rStream
);
94 pStrm
->SetStreamSize(nSize
);
95 pStrm
->Seek(STREAM_SEEK_TO_BEGIN
);
103 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */