merge the formfield patch from ooo-build
[ooovba.git] / oox / source / vml / vmlinputstream.cxx
blob56964ad4ab1965a0b1c6e8a2e049340406be74a1
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: vmldrawing.cxx,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include "oox/vml/vmlinputstream.hxx"
32 #include <algorithm>
33 #include <string.h>
35 using ::com::sun::star::uno::Exception;
36 using ::com::sun::star::uno::Reference;
37 using ::com::sun::star::io::XInputStream;
39 namespace oox {
40 namespace vml {
42 // ============================================================================
44 StreamDataContainer::StreamDataContainer( const Reference< XInputStream >& rxInStrm )
46 if( rxInStrm.is() ) try
48 // read all bytes we can read
49 rxInStrm->readBytes( maDataSeq, SAL_MAX_INT32 );
51 catch( Exception& )
55 // parse the data and eat all parser instructions that make expat sad
56 if( maDataSeq.hasElements() )
58 sal_Char* pcBeg = reinterpret_cast< sal_Char* >( maDataSeq.getArray() );
59 sal_Char* pcEnd = pcBeg + maDataSeq.getLength();
60 sal_Char* pcCurr = pcBeg;
61 while( pcCurr < pcEnd )
63 pcCurr = ::std::find( pcCurr, pcEnd, '<' );
64 sal_Char* pcClose = ::std::find( pcCurr, pcEnd, '>' );
65 if( (pcCurr < pcEnd) && (pcClose < pcEnd) && (pcClose - pcCurr >= 5) && (pcCurr[ 1 ] == '!') && (pcCurr[ 2 ] == '[') && (pcClose[ -1 ] == ']') )
67 ++pcClose;
68 memmove( pcCurr, pcClose, pcEnd - pcClose );
69 pcEnd -= (pcClose - pcCurr);
71 else
72 pcCurr = pcClose;
74 maDataSeq.realloc( static_cast< sal_Int32 >( pcEnd - pcBeg ) );
78 // ============================================================================
80 InputStream::InputStream( const Reference< XInputStream >& rxInStrm ) :
81 StreamDataContainer( rxInStrm ),
82 ::comphelper::SequenceInputStream( maDataSeq )
86 InputStream::~InputStream()
90 // ============================================================================
92 } // namespace vml
93 } // namespave oox