1*f9b72d11SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*f9b72d11SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*f9b72d11SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*f9b72d11SAndrew Rist * distributed with this work for additional information 6*f9b72d11SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*f9b72d11SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*f9b72d11SAndrew Rist * "License"); you may not use this file except in compliance 9*f9b72d11SAndrew Rist * with the License. You may obtain a copy of the License at 10*f9b72d11SAndrew Rist * 11*f9b72d11SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*f9b72d11SAndrew Rist * 13*f9b72d11SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*f9b72d11SAndrew Rist * software distributed under the License is distributed on an 15*f9b72d11SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*f9b72d11SAndrew Rist * KIND, either express or implied. See the License for the 17*f9b72d11SAndrew Rist * specific language governing permissions and limitations 18*f9b72d11SAndrew Rist * under the License. 19*f9b72d11SAndrew Rist * 20*f9b72d11SAndrew Rist *************************************************************/ 21*f9b72d11SAndrew Rist 22*f9b72d11SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #include "fastserializer.hxx" 25cdf0e10cSrcweir #include <rtl/ustrbuf.hxx> 26cdf0e10cSrcweir #include <rtl/byteseq.hxx> 27cdf0e10cSrcweir 28cdf0e10cSrcweir #include <com/sun/star/xml/Attribute.hpp> 29cdf0e10cSrcweir #include <com/sun/star/xml/FastAttribute.hpp> 30cdf0e10cSrcweir #include <com/sun/star/xml/sax/XFastAttributeList.hpp> 31cdf0e10cSrcweir 32cdf0e10cSrcweir #include <string.h> 33cdf0e10cSrcweir 34cdf0e10cSrcweir using ::rtl::OString; 35cdf0e10cSrcweir using ::rtl::OUString; 36cdf0e10cSrcweir using ::rtl::OUStringBuffer; 37cdf0e10cSrcweir using ::rtl::OUStringToOString; 38cdf0e10cSrcweir using ::com::sun::star::uno::Reference; 39cdf0e10cSrcweir using ::com::sun::star::uno::RuntimeException; 40cdf0e10cSrcweir using ::com::sun::star::uno::Sequence; 41cdf0e10cSrcweir using ::com::sun::star::uno::toUnoSequence; 42cdf0e10cSrcweir using ::com::sun::star::xml::FastAttribute; 43cdf0e10cSrcweir using ::com::sun::star::xml::Attribute; 44cdf0e10cSrcweir using ::com::sun::star::xml::sax::SAXException; 45cdf0e10cSrcweir using ::com::sun::star::xml::sax::XFastAttributeList; 46cdf0e10cSrcweir using ::com::sun::star::xml::sax::XFastTokenHandler; 47cdf0e10cSrcweir using ::com::sun::star::xml::sax::XFastSerializer; 48cdf0e10cSrcweir using ::com::sun::star::io::XOutputStream; 49cdf0e10cSrcweir using ::com::sun::star::io::NotConnectedException; 50cdf0e10cSrcweir using ::com::sun::star::io::IOException; 51cdf0e10cSrcweir using ::com::sun::star::io::BufferSizeExceededException; 52cdf0e10cSrcweir 53cdf0e10cSrcweir static rtl::ByteSequence aClosingBracket((const sal_Int8 *)">", 1); 54cdf0e10cSrcweir static rtl::ByteSequence aSlashAndClosingBracket((const sal_Int8 *)"/>", 2); 55cdf0e10cSrcweir static rtl::ByteSequence aColon((const sal_Int8 *)":", 1); 56cdf0e10cSrcweir static rtl::ByteSequence aOpeningBracket((const sal_Int8 *)"<", 1); 57cdf0e10cSrcweir static rtl::ByteSequence aOpeningBracketAndSlash((const sal_Int8 *)"</", 2); 58cdf0e10cSrcweir static rtl::ByteSequence aQuote((const sal_Int8 *)"\"", 1); 59cdf0e10cSrcweir static rtl::ByteSequence aEqualSignAndQuote((const sal_Int8 *)"=\"", 2); 60cdf0e10cSrcweir static rtl::ByteSequence aSpace((const sal_Int8 *)" ", 1); 61cdf0e10cSrcweir static rtl::ByteSequence aXmlHeader((const sal_Int8*) "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n", 56); 62cdf0e10cSrcweir 63cdf0e10cSrcweir #define HAS_NAMESPACE(x) ((x & 0xffff0000) != 0) 64cdf0e10cSrcweir #define NAMESPACE(x) (x >> 16) 65cdf0e10cSrcweir #define TOKEN(x) (x & 0xffff) 66cdf0e10cSrcweir 67cdf0e10cSrcweir namespace sax_fastparser { 68cdf0e10cSrcweir FastSaxSerializer::FastSaxSerializer( ) : mxOutputStream(), mxFastTokenHandler(), maMarkStack() {} 69cdf0e10cSrcweir FastSaxSerializer::~FastSaxSerializer() {} 70cdf0e10cSrcweir 71cdf0e10cSrcweir void SAL_CALL FastSaxSerializer::startDocument( ) throw (SAXException, RuntimeException) 72cdf0e10cSrcweir { 73cdf0e10cSrcweir if (!mxOutputStream.is()) 74cdf0e10cSrcweir return; 75cdf0e10cSrcweir writeBytes(toUnoSequence(aXmlHeader)); 76cdf0e10cSrcweir } 77cdf0e10cSrcweir 78cdf0e10cSrcweir OUString FastSaxSerializer::escapeXml( const OUString& s ) 79cdf0e10cSrcweir { 80cdf0e10cSrcweir ::rtl::OUStringBuffer sBuf( s.getLength() ); 81cdf0e10cSrcweir const sal_Unicode* pStr = s; 82cdf0e10cSrcweir sal_Int32 nLen = s.getLength(); 83cdf0e10cSrcweir for( sal_Int32 i = 0; i < nLen; ++i) 84cdf0e10cSrcweir { 85cdf0e10cSrcweir sal_Unicode c = pStr[ i ]; 86cdf0e10cSrcweir switch( c ) 87cdf0e10cSrcweir { 88cdf0e10cSrcweir case '<': sBuf.appendAscii( "<" ); break; 89cdf0e10cSrcweir case '>': sBuf.appendAscii( ">" ); break; 90cdf0e10cSrcweir case '&': sBuf.appendAscii( "&" ); break; 91cdf0e10cSrcweir case '\'': sBuf.appendAscii( "'" ); break; 92cdf0e10cSrcweir case '"': sBuf.appendAscii( """ ); break; 93cdf0e10cSrcweir default: sBuf.append( c ); break; 94cdf0e10cSrcweir } 95cdf0e10cSrcweir } 96cdf0e10cSrcweir return sBuf.makeStringAndClear(); 97cdf0e10cSrcweir } 98cdf0e10cSrcweir 99cdf0e10cSrcweir void FastSaxSerializer::write( const OUString& s ) 100cdf0e10cSrcweir { 101cdf0e10cSrcweir OString sOutput( OUStringToOString( s, RTL_TEXTENCODING_UTF8 ) ); 102cdf0e10cSrcweir writeBytes( Sequence< sal_Int8 >( 103cdf0e10cSrcweir reinterpret_cast< const sal_Int8*>( sOutput.getStr() ), 104cdf0e10cSrcweir sOutput.getLength() ) ); 105cdf0e10cSrcweir } 106cdf0e10cSrcweir 107cdf0e10cSrcweir void SAL_CALL FastSaxSerializer::endDocument( ) throw (SAXException, RuntimeException) 108cdf0e10cSrcweir { 109cdf0e10cSrcweir if (!mxOutputStream.is()) 110cdf0e10cSrcweir return; 111cdf0e10cSrcweir } 112cdf0e10cSrcweir 113cdf0e10cSrcweir void SAL_CALL FastSaxSerializer::writeId( ::sal_Int32 nElement ) 114cdf0e10cSrcweir { 115cdf0e10cSrcweir if( HAS_NAMESPACE( nElement ) ) { 116cdf0e10cSrcweir writeBytes(mxFastTokenHandler->getUTF8Identifier(NAMESPACE(nElement))); 117cdf0e10cSrcweir writeBytes(toUnoSequence(aColon)); 118cdf0e10cSrcweir writeBytes(mxFastTokenHandler->getUTF8Identifier(TOKEN(nElement))); 119cdf0e10cSrcweir } else 120cdf0e10cSrcweir writeBytes(mxFastTokenHandler->getUTF8Identifier(nElement)); 121cdf0e10cSrcweir } 122cdf0e10cSrcweir 123cdf0e10cSrcweir void SAL_CALL FastSaxSerializer::startFastElement( ::sal_Int32 Element, const Reference< XFastAttributeList >& Attribs ) 124cdf0e10cSrcweir throw (SAXException, RuntimeException) 125cdf0e10cSrcweir { 126cdf0e10cSrcweir if (!mxOutputStream.is()) 127cdf0e10cSrcweir return; 128cdf0e10cSrcweir 129cdf0e10cSrcweir writeBytes(toUnoSequence(aOpeningBracket)); 130cdf0e10cSrcweir 131cdf0e10cSrcweir writeId(Element); 132cdf0e10cSrcweir writeFastAttributeList(Attribs); 133cdf0e10cSrcweir 134cdf0e10cSrcweir writeBytes(toUnoSequence(aClosingBracket)); 135cdf0e10cSrcweir } 136cdf0e10cSrcweir 137cdf0e10cSrcweir void SAL_CALL FastSaxSerializer::startUnknownElement( const OUString& Namespace, const OUString& Name, const Reference< XFastAttributeList >& Attribs ) 138cdf0e10cSrcweir throw (SAXException, RuntimeException) 139cdf0e10cSrcweir { 140cdf0e10cSrcweir if (!mxOutputStream.is()) 141cdf0e10cSrcweir return; 142cdf0e10cSrcweir 143cdf0e10cSrcweir writeBytes(toUnoSequence(aOpeningBracket)); 144cdf0e10cSrcweir 145cdf0e10cSrcweir if (Namespace.getLength()) 146cdf0e10cSrcweir { 147cdf0e10cSrcweir write(Namespace); 148cdf0e10cSrcweir writeBytes(toUnoSequence(aColon)); 149cdf0e10cSrcweir } 150cdf0e10cSrcweir 151cdf0e10cSrcweir write(Name); 152cdf0e10cSrcweir 153cdf0e10cSrcweir writeFastAttributeList(Attribs); 154cdf0e10cSrcweir 155cdf0e10cSrcweir writeBytes(toUnoSequence(aClosingBracket)); 156cdf0e10cSrcweir } 157cdf0e10cSrcweir 158cdf0e10cSrcweir void SAL_CALL FastSaxSerializer::endFastElement( ::sal_Int32 Element ) 159cdf0e10cSrcweir throw (SAXException, RuntimeException) 160cdf0e10cSrcweir { 161cdf0e10cSrcweir if (!mxOutputStream.is()) 162cdf0e10cSrcweir return; 163cdf0e10cSrcweir 164cdf0e10cSrcweir writeBytes(toUnoSequence(aOpeningBracketAndSlash)); 165cdf0e10cSrcweir 166cdf0e10cSrcweir writeId(Element); 167cdf0e10cSrcweir 168cdf0e10cSrcweir writeBytes(toUnoSequence(aClosingBracket)); 169cdf0e10cSrcweir } 170cdf0e10cSrcweir 171cdf0e10cSrcweir void SAL_CALL FastSaxSerializer::endUnknownElement( const OUString& Namespace, const OUString& Name ) 172cdf0e10cSrcweir throw (SAXException, RuntimeException) 173cdf0e10cSrcweir { 174cdf0e10cSrcweir if (!mxOutputStream.is()) 175cdf0e10cSrcweir return; 176cdf0e10cSrcweir 177cdf0e10cSrcweir writeBytes(toUnoSequence(aOpeningBracketAndSlash)); 178cdf0e10cSrcweir 179cdf0e10cSrcweir if (Namespace.getLength()) 180cdf0e10cSrcweir { 181cdf0e10cSrcweir write(Namespace); 182cdf0e10cSrcweir writeBytes(toUnoSequence(aColon)); 183cdf0e10cSrcweir } 184cdf0e10cSrcweir 185cdf0e10cSrcweir write(Name); 186cdf0e10cSrcweir 187cdf0e10cSrcweir writeBytes(toUnoSequence(aClosingBracket)); 188cdf0e10cSrcweir } 189cdf0e10cSrcweir 190cdf0e10cSrcweir void SAL_CALL FastSaxSerializer::singleFastElement( ::sal_Int32 Element, const Reference< XFastAttributeList >& Attribs ) 191cdf0e10cSrcweir throw (SAXException, RuntimeException) 192cdf0e10cSrcweir { 193cdf0e10cSrcweir if (!mxOutputStream.is()) 194cdf0e10cSrcweir return; 195cdf0e10cSrcweir 196cdf0e10cSrcweir writeBytes(toUnoSequence(aOpeningBracket)); 197cdf0e10cSrcweir 198cdf0e10cSrcweir writeId(Element); 199cdf0e10cSrcweir writeFastAttributeList(Attribs); 200cdf0e10cSrcweir 201cdf0e10cSrcweir writeBytes(toUnoSequence(aSlashAndClosingBracket)); 202cdf0e10cSrcweir } 203cdf0e10cSrcweir 204cdf0e10cSrcweir void SAL_CALL FastSaxSerializer::singleUnknownElement( const OUString& Namespace, const OUString& Name, const Reference< XFastAttributeList >& Attribs ) 205cdf0e10cSrcweir throw (SAXException, RuntimeException) 206cdf0e10cSrcweir { 207cdf0e10cSrcweir if (!mxOutputStream.is()) 208cdf0e10cSrcweir return; 209cdf0e10cSrcweir 210cdf0e10cSrcweir writeBytes(toUnoSequence(aOpeningBracket)); 211cdf0e10cSrcweir 212cdf0e10cSrcweir if (Namespace.getLength()) 213cdf0e10cSrcweir { 214cdf0e10cSrcweir write(Namespace); 215cdf0e10cSrcweir writeBytes(toUnoSequence(aColon)); 216cdf0e10cSrcweir } 217cdf0e10cSrcweir 218cdf0e10cSrcweir write(Name); 219cdf0e10cSrcweir 220cdf0e10cSrcweir writeFastAttributeList(Attribs); 221cdf0e10cSrcweir 222cdf0e10cSrcweir writeBytes(toUnoSequence(aSlashAndClosingBracket)); 223cdf0e10cSrcweir } 224cdf0e10cSrcweir 225cdf0e10cSrcweir void SAL_CALL FastSaxSerializer::characters( const OUString& aChars ) 226cdf0e10cSrcweir throw (SAXException, RuntimeException) 227cdf0e10cSrcweir { 228cdf0e10cSrcweir if (!mxOutputStream.is()) 229cdf0e10cSrcweir return; 230cdf0e10cSrcweir 231cdf0e10cSrcweir write( aChars ); 232cdf0e10cSrcweir } 233cdf0e10cSrcweir 234cdf0e10cSrcweir void SAL_CALL FastSaxSerializer::setOutputStream( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream >& xOutputStream ) 235cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException) 236cdf0e10cSrcweir { 237cdf0e10cSrcweir mxOutputStream = xOutputStream; 238cdf0e10cSrcweir } 239cdf0e10cSrcweir 240cdf0e10cSrcweir void SAL_CALL FastSaxSerializer::setFastTokenHandler( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastTokenHandler >& xFastTokenHandler ) 241cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException) 242cdf0e10cSrcweir { 243cdf0e10cSrcweir mxFastTokenHandler = xFastTokenHandler; 244cdf0e10cSrcweir } 245cdf0e10cSrcweir void FastSaxSerializer::writeFastAttributeList( const Reference< XFastAttributeList >& Attribs ) 246cdf0e10cSrcweir { 247cdf0e10cSrcweir Sequence< Attribute > aAttrSeq = Attribs->getUnknownAttributes(); 248cdf0e10cSrcweir const Attribute *pAttr = aAttrSeq.getConstArray(); 249cdf0e10cSrcweir sal_Int32 nAttrLength = aAttrSeq.getLength(); 250cdf0e10cSrcweir for (sal_Int32 i = 0; i < nAttrLength; i++) 251cdf0e10cSrcweir { 252cdf0e10cSrcweir writeBytes(toUnoSequence(aSpace)); 253cdf0e10cSrcweir 254cdf0e10cSrcweir write(pAttr[i].Name); 255cdf0e10cSrcweir writeBytes(toUnoSequence(aEqualSignAndQuote)); 256cdf0e10cSrcweir write(escapeXml(pAttr[i].Value)); 257cdf0e10cSrcweir writeBytes(toUnoSequence(aQuote)); 258cdf0e10cSrcweir } 259cdf0e10cSrcweir 260cdf0e10cSrcweir Sequence< FastAttribute > aFastAttrSeq = Attribs->getFastAttributes(); 261cdf0e10cSrcweir const FastAttribute *pFastAttr = aFastAttrSeq.getConstArray(); 262cdf0e10cSrcweir sal_Int32 nFastAttrLength = aFastAttrSeq.getLength(); 263cdf0e10cSrcweir for (sal_Int32 j = 0; j < nFastAttrLength; j++) 264cdf0e10cSrcweir { 265cdf0e10cSrcweir writeBytes(toUnoSequence(aSpace)); 266cdf0e10cSrcweir 267cdf0e10cSrcweir sal_Int32 nToken = pFastAttr[j].Token; 268cdf0e10cSrcweir writeId(nToken); 269cdf0e10cSrcweir 270cdf0e10cSrcweir writeBytes(toUnoSequence(aEqualSignAndQuote)); 271cdf0e10cSrcweir 272cdf0e10cSrcweir write(escapeXml(Attribs->getValue(pFastAttr[j].Token))); 273cdf0e10cSrcweir 274cdf0e10cSrcweir writeBytes(toUnoSequence(aQuote)); 275cdf0e10cSrcweir } 276cdf0e10cSrcweir } 277cdf0e10cSrcweir 278cdf0e10cSrcweir // XServiceInfo 279cdf0e10cSrcweir OUString FastSaxSerializer::getImplementationName() throw (RuntimeException) 280cdf0e10cSrcweir { 281cdf0e10cSrcweir return OUString::createFromAscii( SERIALIZER_IMPLEMENTATION_NAME ); 282cdf0e10cSrcweir } 283cdf0e10cSrcweir 284cdf0e10cSrcweir // XServiceInfo 285cdf0e10cSrcweir sal_Bool FastSaxSerializer::supportsService(const OUString& ServiceName) throw (RuntimeException) 286cdf0e10cSrcweir { 287cdf0e10cSrcweir Sequence< OUString > aSNL = getSupportedServiceNames(); 288cdf0e10cSrcweir const OUString * pArray = aSNL.getConstArray(); 289cdf0e10cSrcweir 290cdf0e10cSrcweir for( sal_Int32 i = 0; i < aSNL.getLength(); i++ ) 291cdf0e10cSrcweir if( pArray[i] == ServiceName ) 292cdf0e10cSrcweir return sal_True; 293cdf0e10cSrcweir 294cdf0e10cSrcweir return sal_False; 295cdf0e10cSrcweir } 296cdf0e10cSrcweir 297cdf0e10cSrcweir // XServiceInfo 298cdf0e10cSrcweir Sequence< OUString > FastSaxSerializer::getSupportedServiceNames(void) throw (RuntimeException) 299cdf0e10cSrcweir { 300cdf0e10cSrcweir Sequence<OUString> seq(1); 301cdf0e10cSrcweir seq.getArray()[0] = OUString::createFromAscii( SERIALIZER_SERVICE_NAME ); 302cdf0e10cSrcweir return seq; 303cdf0e10cSrcweir } 304cdf0e10cSrcweir 305cdf0e10cSrcweir OUString FastSaxSerializer::getImplementationName_Static() 306cdf0e10cSrcweir { 307cdf0e10cSrcweir return OUString::createFromAscii( SERIALIZER_IMPLEMENTATION_NAME ); 308cdf0e10cSrcweir } 309cdf0e10cSrcweir 310cdf0e10cSrcweir Sequence< OUString > FastSaxSerializer::getSupportedServiceNames_Static(void) 311cdf0e10cSrcweir { 312cdf0e10cSrcweir Sequence<OUString> aRet(1); 313cdf0e10cSrcweir aRet.getArray()[0] = OUString( RTL_CONSTASCII_USTRINGPARAM(SERIALIZER_SERVICE_NAME) ); 314cdf0e10cSrcweir return aRet; 315cdf0e10cSrcweir } 316cdf0e10cSrcweir 317cdf0e10cSrcweir void FastSaxSerializer::mark() 318cdf0e10cSrcweir { 319cdf0e10cSrcweir maMarkStack.push( ForMerge() ); 320cdf0e10cSrcweir } 321cdf0e10cSrcweir 322cdf0e10cSrcweir void FastSaxSerializer::mergeTopMarks( sax_fastparser::MergeMarksEnum eMergeType ) 323cdf0e10cSrcweir { 324cdf0e10cSrcweir if ( maMarkStack.empty() ) 325cdf0e10cSrcweir return; 326cdf0e10cSrcweir 327cdf0e10cSrcweir if ( maMarkStack.size() == 1 ) 328cdf0e10cSrcweir { 329cdf0e10cSrcweir mxOutputStream->writeBytes( maMarkStack.top().getData() ); 330cdf0e10cSrcweir maMarkStack.pop(); 331cdf0e10cSrcweir return; 332cdf0e10cSrcweir } 333cdf0e10cSrcweir 334cdf0e10cSrcweir const Int8Sequence aMerge( maMarkStack.top().getData() ); 335cdf0e10cSrcweir maMarkStack.pop(); 336cdf0e10cSrcweir 337cdf0e10cSrcweir switch ( eMergeType ) 338cdf0e10cSrcweir { 339cdf0e10cSrcweir case MERGE_MARKS_APPEND: maMarkStack.top().append( aMerge ); break; 340cdf0e10cSrcweir case MERGE_MARKS_PREPEND: maMarkStack.top().prepend( aMerge ); break; 341cdf0e10cSrcweir case MERGE_MARKS_POSTPONE: maMarkStack.top().postpone( aMerge ); break; 342cdf0e10cSrcweir } 343cdf0e10cSrcweir } 344cdf0e10cSrcweir 345cdf0e10cSrcweir void FastSaxSerializer::writeBytes( const Sequence< ::sal_Int8 >& aData ) throw ( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException ) 346cdf0e10cSrcweir { 347cdf0e10cSrcweir if ( maMarkStack.empty() ) 348cdf0e10cSrcweir mxOutputStream->writeBytes( aData ); 349cdf0e10cSrcweir else 350cdf0e10cSrcweir maMarkStack.top().append( aData ); 351cdf0e10cSrcweir } 352cdf0e10cSrcweir 353cdf0e10cSrcweir FastSaxSerializer::Int8Sequence& FastSaxSerializer::ForMerge::getData() 354cdf0e10cSrcweir { 355cdf0e10cSrcweir merge( maData, maPostponed, true ); 356cdf0e10cSrcweir maPostponed.realloc( 0 ); 357cdf0e10cSrcweir 358cdf0e10cSrcweir return maData; 359cdf0e10cSrcweir } 360cdf0e10cSrcweir 361cdf0e10cSrcweir void FastSaxSerializer::ForMerge::prepend( const Int8Sequence &rWhat ) 362cdf0e10cSrcweir { 363cdf0e10cSrcweir merge( maData, rWhat, false ); 364cdf0e10cSrcweir } 365cdf0e10cSrcweir 366cdf0e10cSrcweir void FastSaxSerializer::ForMerge::append( const Int8Sequence &rWhat ) 367cdf0e10cSrcweir { 368cdf0e10cSrcweir merge( maData, rWhat, true ); 369cdf0e10cSrcweir } 370cdf0e10cSrcweir 371cdf0e10cSrcweir void FastSaxSerializer::ForMerge::postpone( const Int8Sequence &rWhat ) 372cdf0e10cSrcweir { 373cdf0e10cSrcweir merge( maPostponed, rWhat, true ); 374cdf0e10cSrcweir } 375cdf0e10cSrcweir 376cdf0e10cSrcweir void FastSaxSerializer::ForMerge::merge( Int8Sequence &rTop, const Int8Sequence &rMerge, bool bAppend ) 377cdf0e10cSrcweir { 378cdf0e10cSrcweir sal_Int32 nMergeLen = rMerge.getLength(); 379cdf0e10cSrcweir if ( nMergeLen > 0 ) 380cdf0e10cSrcweir { 381cdf0e10cSrcweir sal_Int32 nTopLen = rTop.getLength(); 382cdf0e10cSrcweir 383cdf0e10cSrcweir rTop.realloc( nTopLen + nMergeLen ); 384cdf0e10cSrcweir if ( bAppend ) 385cdf0e10cSrcweir { 386cdf0e10cSrcweir // append the rMerge to the rTop 387cdf0e10cSrcweir memcpy( rTop.getArray() + nTopLen, rMerge.getConstArray(), nMergeLen ); 388cdf0e10cSrcweir } 389cdf0e10cSrcweir else 390cdf0e10cSrcweir { 391cdf0e10cSrcweir // prepend the rMerge to the rTop 392cdf0e10cSrcweir memmove( rTop.getArray() + nMergeLen, rTop.getConstArray(), nTopLen ); 393cdf0e10cSrcweir memcpy( rTop.getArray(), rMerge.getConstArray(), nMergeLen ); 394cdf0e10cSrcweir } 395cdf0e10cSrcweir } 396cdf0e10cSrcweir } 397cdf0e10cSrcweir 398cdf0e10cSrcweir } // namespace sax_fastparser 399cdf0e10cSrcweir 400