LanguageTool: don't crash if REST protocol isn't set
[LibreOffice.git] / sfx2 / source / bastyp / mieclip.cxx
blobae3a2d5e5684b8ef6d435d417f3ada1a61a7e531
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <tools/stream.hxx>
25 #include <sfx2/mieclip.hxx>
27 MSE40HTMLClipFormatObj::~MSE40HTMLClipFormatObj()
31 SvStream* MSE40HTMLClipFormatObj::IsValid( SvStream& rStream )
33 bool bRet = false;
34 pStrm.reset();
36 OString sLine;
37 sal_Int32 nStt = -1, nEnd = -1, nFragStart = -1, nFragEnd = -1;
38 sal_Int32 nIndex = 0;
40 rStream.Seek(STREAM_SEEK_TO_BEGIN);
41 rStream.ResetError();
43 if( rStream.ReadLine( sLine ) &&
44 sLine.getToken( 0, ':', nIndex ) == "Version" )
46 while( rStream.ReadLine( sLine ) )
48 nIndex = 0;
49 OString sTmp(sLine.getToken(0, ':', nIndex));
50 if (sTmp == "StartHTML")
51 nStt = sLine.copy(nIndex).toInt32();
52 else if (sTmp == "EndHTML")
53 nEnd = sLine.copy(nIndex).toInt32();
54 else if (sTmp == "StartFragment")
55 nFragStart = sLine.copy(nIndex).toInt32();
56 else if (sTmp == "EndFragment")
57 nFragEnd = sLine.copy(nIndex).toInt32();
58 else if (sTmp == "SourceURL")
59 sBaseURL = OStringToOUString( sLine.subView(nIndex), RTL_TEXTENCODING_UTF8 );
61 if (nEnd >= 0 && nStt >= 0 &&
62 (!sBaseURL.isEmpty() || rStream.Tell() >= o3tl::make_unsigned(nStt)))
64 bRet = true;
65 break;
70 if( bRet )
72 rStream.Seek( nStt );
74 pStrm.reset( new SvMemoryStream( ( nEnd - nStt < 0x10000l
75 ? nEnd - nStt + 32
76 : 0 )) );
77 pStrm->WriteStream( rStream );
78 pStrm->SetStreamSize( nEnd - nStt + 1 );
79 pStrm->Seek( STREAM_SEEK_TO_BEGIN );
80 return pStrm.get();
83 if (nFragStart > 0 && nFragEnd > 0 && nFragEnd > nFragStart)
85 size_t nSize = nFragEnd - nFragStart + 1;
86 if (nSize < 0x10000L)
88 rStream.Seek(nFragStart);
89 pStrm.reset( new SvMemoryStream(nSize) );
90 pStrm->WriteStream( rStream );
91 pStrm->SetStreamSize(nSize);
92 pStrm->Seek(STREAM_SEEK_TO_BEGIN);
93 return pStrm.get();
97 return nullptr;
100 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */