LCOV - code coverage report
Current view: top level - sax/source/tools - fastserializer.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 159 217 73.3 %
Date: 2012-08-25 Functions: 28 36 77.8 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 137 320 42.8 %

           Branch data     Line data    Source code
       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 "fastserializer.hxx"
      21                 :            : #include <rtl/ustrbuf.hxx>
      22                 :            : 
      23                 :            : #include <comphelper/sequenceasvector.hxx>
      24                 :            : 
      25                 :            : #include <com/sun/star/xml/Attribute.hpp>
      26                 :            : #include <com/sun/star/xml/FastAttribute.hpp>
      27                 :            : #include <com/sun/star/xml/sax/XFastAttributeList.hpp>
      28                 :            : 
      29                 :            : #include <string.h>
      30                 :            : 
      31                 :            : #if DEBUG
      32                 :            : #include <iostream>
      33                 :            : #endif
      34                 :            : 
      35                 :            : using ::comphelper::SequenceAsVector;
      36                 :            : using ::rtl::OString;
      37                 :            : using ::rtl::OUString;
      38                 :            : using ::rtl::OUStringBuffer;
      39                 :            : using ::rtl::OUStringToOString;
      40                 :            : using ::com::sun::star::uno::Reference;
      41                 :            : using ::com::sun::star::uno::RuntimeException;
      42                 :            : using ::com::sun::star::uno::Sequence;
      43                 :            : using ::com::sun::star::uno::toUnoSequence;
      44                 :            : using ::com::sun::star::xml::FastAttribute;
      45                 :            : using ::com::sun::star::xml::Attribute;
      46                 :            : using ::com::sun::star::xml::sax::SAXException;
      47                 :            : using ::com::sun::star::xml::sax::XFastAttributeList;
      48                 :            : using ::com::sun::star::xml::sax::XFastTokenHandler;
      49                 :            : using ::com::sun::star::xml::sax::XFastSerializer;
      50                 :            : using ::com::sun::star::io::XOutputStream;
      51                 :            : using ::com::sun::star::io::NotConnectedException;
      52                 :            : using ::com::sun::star::io::IOException;
      53                 :            : using ::com::sun::star::io::BufferSizeExceededException;
      54                 :            : 
      55                 :            : #define HAS_NAMESPACE(x) ((x & 0xffff0000) != 0)
      56                 :            : #define NAMESPACE(x) (x >> 16)
      57                 :            : #define TOKEN(x) (x & 0xffff)
      58                 :            : 
      59                 :            : namespace sax_fastparser {
      60                 :        345 :     FastSaxSerializer::FastSaxSerializer( )
      61                 :            :         : mxOutputStream()
      62                 :            :         , mxFastTokenHandler()
      63                 :            :         , maMarkStack()
      64                 :            :         , maClosingBracket((const sal_Int8 *)">", 1)
      65                 :            :         , maSlashAndClosingBracket((const sal_Int8 *)"/>", 2)
      66                 :            :         , maColon((const sal_Int8 *)":", 1)
      67                 :            :         , maOpeningBracket((const sal_Int8 *)"<", 1)
      68                 :            :         , maOpeningBracketAndSlash((const sal_Int8 *)"</", 2)
      69                 :            :         , maQuote((const sal_Int8 *)"\"", 1)
      70                 :            :         , maEqualSignAndQuote((const sal_Int8 *)"=\"", 2)
      71 [ +  - ][ +  - ]:        345 :         , maSpace((const sal_Int8 *)" ", 1)
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
      72                 :            :     {
      73                 :        345 :     }
      74         [ -  + ]:        690 :     FastSaxSerializer::~FastSaxSerializer() {}
      75                 :            : 
      76                 :        345 :     void SAL_CALL FastSaxSerializer::startDocument(  ) throw (SAXException, RuntimeException)
      77                 :            :     {
      78         [ +  - ]:        345 :         if (!mxOutputStream.is())
      79                 :        345 :             return;
      80         [ +  - ]:        345 :         rtl::ByteSequence aXmlHeader((const sal_Int8*) "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n", 56);
      81 [ +  - ][ +  - ]:        345 :         writeBytes(toUnoSequence(aXmlHeader));
                 [ +  - ]
      82                 :            :     }
      83                 :            : 
      84                 :       9993 :     OUString FastSaxSerializer::escapeXml( const OUString& s )
      85                 :            :     {
      86                 :       9993 :         ::rtl::OUStringBuffer sBuf( s.getLength() );
      87                 :       9993 :         const sal_Unicode* pStr = s.getStr();
      88                 :       9993 :         sal_Int32 nLen = s.getLength();
      89         [ +  + ]:     119538 :         for( sal_Int32 i = 0; i < nLen; ++i)
      90                 :            :         {
      91                 :     109545 :             sal_Unicode c = pStr[ i ];
      92   [ +  -  -  +  :     109545 :             switch( c )
             +  -  -  + ]
      93                 :            :             {
      94         [ +  - ]:         12 :                 case '<':   sBuf.appendAscii( "&lt;" );     break;
      95         [ #  # ]:          0 :                 case '>':   sBuf.appendAscii( "&gt;" );     break;
      96         [ #  # ]:          0 :                 case '&':   sBuf.appendAscii( "&amp;" );    break;
      97         [ +  - ]:          3 :                 case '\'':  sBuf.appendAscii( "&apos;" );   break;
      98         [ +  - ]:         12 :                 case '"':   sBuf.appendAscii( "&quot;" );   break;
      99         [ #  # ]:          0 :                 case '\n':  sBuf.appendAscii( "&#10;" );    break;
     100         [ #  # ]:          0 :                 case '\r':  sBuf.appendAscii( "&#13;" );    break;
     101         [ +  - ]:     109518 :                 default:    sBuf.append( c );               break;
     102                 :            :             }
     103                 :            :         }
     104         [ +  - ]:       9993 :         return sBuf.makeStringAndClear();
     105                 :            :     }
     106                 :            : 
     107                 :      10224 :     void FastSaxSerializer::write( const OUString& s )
     108                 :            :     {
     109         [ +  - ]:      10224 :         OString sOutput( OUStringToOString( s, RTL_TEXTENCODING_UTF8 ) );
     110                 :            :         writeBytes( Sequence< sal_Int8 >(
     111                 :      10224 :                     reinterpret_cast< const sal_Int8*>( sOutput.getStr() ),
     112 [ +  - ][ +  - ]:      20448 :                     sOutput.getLength() ) );
                 [ +  - ]
     113                 :      10224 :     }
     114                 :            : 
     115                 :        345 :     void SAL_CALL FastSaxSerializer::endDocument(  ) throw (SAXException, RuntimeException)
     116                 :            :     {
     117         [ -  + ]:        345 :         if (!mxOutputStream.is())
     118                 :        345 :             return;
     119                 :            :     }
     120                 :            : 
     121                 :      24192 :     void SAL_CALL FastSaxSerializer::writeId( ::sal_Int32 nElement )
     122                 :            :     {
     123         [ +  + ]:      24192 :         if( HAS_NAMESPACE( nElement ) ) {
     124         [ +  - ]:      23847 :             writeBytes(mxFastTokenHandler->getUTF8Identifier(NAMESPACE(nElement)));
     125         [ +  - ]:      23847 :             writeBytes(toUnoSequence(maColon));
     126         [ +  - ]:      23847 :             writeBytes(mxFastTokenHandler->getUTF8Identifier(TOKEN(nElement)));
     127                 :            :         } else
     128         [ +  - ]:        345 :             writeBytes(mxFastTokenHandler->getUTF8Identifier(nElement));
     129                 :      24192 :     }
     130                 :            : 
     131                 :       5238 :     void SAL_CALL FastSaxSerializer::startFastElement( ::sal_Int32 Element, const Reference< XFastAttributeList >& Attribs )
     132                 :            :         throw (SAXException, RuntimeException)
     133                 :            :     {
     134         [ -  + ]:       5238 :         if (!mxOutputStream.is())
     135                 :       5238 :             return;
     136                 :            : 
     137         [ +  + ]:       5238 :         if ( !maMarkStack.empty() )
     138                 :       3024 :             maMarkStack.top()->setCurrentElement( Element );
     139                 :            : 
     140         [ +  - ]:       5238 :         writeBytes(toUnoSequence(maOpeningBracket));
     141                 :            : 
     142                 :       5238 :         writeId(Element);
     143                 :       5238 :         writeFastAttributeList(Attribs);
     144                 :            : 
     145         [ +  - ]:       5238 :         writeBytes(toUnoSequence(maClosingBracket));
     146                 :            :     }
     147                 :            : 
     148                 :          0 :     void SAL_CALL FastSaxSerializer::startUnknownElement( const OUString& Namespace, const OUString& Name, const Reference< XFastAttributeList >& Attribs )
     149                 :            :         throw (SAXException, RuntimeException)
     150                 :            :     {
     151         [ #  # ]:          0 :         if (!mxOutputStream.is())
     152                 :          0 :             return;
     153                 :            : 
     154         [ #  # ]:          0 :         writeBytes(toUnoSequence(maOpeningBracket));
     155                 :            : 
     156         [ #  # ]:          0 :         if (!Namespace.isEmpty())
     157                 :            :         {
     158                 :          0 :             write(Namespace);
     159         [ #  # ]:          0 :             writeBytes(toUnoSequence(maColon));
     160                 :            :         }
     161                 :            : 
     162                 :          0 :         write(Name);
     163                 :            : 
     164                 :          0 :         writeFastAttributeList(Attribs);
     165                 :            : 
     166         [ #  # ]:          0 :         writeBytes(toUnoSequence(maClosingBracket));
     167                 :            :     }
     168                 :            : 
     169                 :       5238 :     void SAL_CALL FastSaxSerializer::endFastElement( ::sal_Int32 Element )
     170                 :            :         throw (SAXException, RuntimeException)
     171                 :            :     {
     172         [ -  + ]:       5238 :         if (!mxOutputStream.is())
     173                 :       5238 :             return;
     174                 :            : 
     175         [ +  - ]:       5238 :         writeBytes(toUnoSequence(maOpeningBracketAndSlash));
     176                 :            : 
     177                 :       5238 :         writeId(Element);
     178                 :            : 
     179         [ +  - ]:       5238 :         writeBytes(toUnoSequence(maClosingBracket));
     180                 :            :     }
     181                 :            : 
     182                 :          0 :     void SAL_CALL FastSaxSerializer::endUnknownElement( const OUString& Namespace, const OUString& Name )
     183                 :            :         throw (SAXException, RuntimeException)
     184                 :            :     {
     185         [ #  # ]:          0 :         if (!mxOutputStream.is())
     186                 :          0 :             return;
     187                 :            : 
     188         [ #  # ]:          0 :         writeBytes(toUnoSequence(maOpeningBracketAndSlash));
     189                 :            : 
     190         [ #  # ]:          0 :         if (!Namespace.isEmpty())
     191                 :            :         {
     192                 :          0 :             write(Namespace);
     193         [ #  # ]:          0 :             writeBytes(toUnoSequence(maColon));
     194                 :            :         }
     195                 :            : 
     196                 :          0 :         write(Name);
     197                 :            : 
     198         [ #  # ]:          0 :         writeBytes(toUnoSequence(maClosingBracket));
     199                 :            :     }
     200                 :            : 
     201                 :       4578 :     void SAL_CALL FastSaxSerializer::singleFastElement( ::sal_Int32 Element, const Reference< XFastAttributeList >& Attribs )
     202                 :            :         throw (SAXException, RuntimeException)
     203                 :            :     {
     204         [ -  + ]:       4578 :         if (!mxOutputStream.is())
     205                 :       4578 :             return;
     206                 :            : 
     207         [ +  + ]:       4578 :         if ( !maMarkStack.empty() )
     208                 :       2457 :             maMarkStack.top()->setCurrentElement( Element );
     209                 :            : 
     210         [ +  - ]:       4578 :         writeBytes(toUnoSequence(maOpeningBracket));
     211                 :            : 
     212                 :       4578 :         writeId(Element);
     213                 :       4578 :         writeFastAttributeList(Attribs);
     214                 :            : 
     215         [ +  - ]:       4578 :         writeBytes(toUnoSequence(maSlashAndClosingBracket));
     216                 :            :     }
     217                 :            : 
     218                 :          0 :     void SAL_CALL FastSaxSerializer::singleUnknownElement( const OUString& Namespace, const OUString& Name, const Reference< XFastAttributeList >& Attribs )
     219                 :            :         throw (SAXException, RuntimeException)
     220                 :            :     {
     221         [ #  # ]:          0 :         if (!mxOutputStream.is())
     222                 :          0 :             return;
     223                 :            : 
     224         [ #  # ]:          0 :         writeBytes(toUnoSequence(maOpeningBracket));
     225                 :            : 
     226         [ #  # ]:          0 :         if (!Namespace.isEmpty())
     227                 :            :         {
     228                 :          0 :             write(Namespace);
     229         [ #  # ]:          0 :             writeBytes(toUnoSequence(maColon));
     230                 :            :         }
     231                 :            : 
     232                 :          0 :         write(Name);
     233                 :            : 
     234                 :          0 :         writeFastAttributeList(Attribs);
     235                 :            : 
     236         [ #  # ]:          0 :         writeBytes(toUnoSequence(maSlashAndClosingBracket));
     237                 :            :     }
     238                 :            : 
     239                 :       1086 :     void SAL_CALL FastSaxSerializer::characters( const OUString& aChars )
     240                 :            :         throw (SAXException, RuntimeException)
     241                 :            :     {
     242         [ -  + ]:       1086 :         if (!mxOutputStream.is())
     243                 :       1086 :             return;
     244                 :            : 
     245                 :       1086 :         write( aChars );
     246                 :            :     }
     247                 :            : 
     248                 :        345 :     void SAL_CALL FastSaxSerializer::setOutputStream( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream >& xOutputStream )
     249                 :            :         throw (::com::sun::star::uno::RuntimeException)
     250                 :            :     {
     251                 :        345 :         mxOutputStream = xOutputStream;
     252                 :        345 :     }
     253                 :            : 
     254                 :        345 :     void SAL_CALL FastSaxSerializer::setFastTokenHandler( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastTokenHandler >& xFastTokenHandler )
     255                 :            :         throw (::com::sun::star::uno::RuntimeException)
     256                 :            :     {
     257                 :        345 :         mxFastTokenHandler = xFastTokenHandler;
     258                 :        345 :     }
     259                 :       9816 :     void FastSaxSerializer::writeFastAttributeList( const Reference< XFastAttributeList >& Attribs )
     260                 :            :     {
     261 [ +  - ][ +  - ]:       9816 :         Sequence< Attribute > aAttrSeq = Attribs->getUnknownAttributes();
     262                 :       9816 :         const Attribute *pAttr = aAttrSeq.getConstArray();
     263                 :       9816 :         sal_Int32 nAttrLength = aAttrSeq.getLength();
     264         [ -  + ]:       9816 :         for (sal_Int32 i = 0; i < nAttrLength; i++)
     265                 :            :         {
     266 [ #  # ][ #  # ]:          0 :             writeBytes(toUnoSequence(maSpace));
                 [ #  # ]
     267                 :            : 
     268         [ #  # ]:          0 :             write(pAttr[i].Name);
     269 [ #  # ][ #  # ]:          0 :             writeBytes(toUnoSequence(maEqualSignAndQuote));
                 [ #  # ]
     270 [ #  # ][ #  # ]:          0 :             write(escapeXml(pAttr[i].Value));
     271 [ #  # ][ #  # ]:          0 :             writeBytes(toUnoSequence(maQuote));
                 [ #  # ]
     272                 :            :         }
     273                 :            : 
     274 [ +  - ][ +  - ]:       9816 :         Sequence< FastAttribute > aFastAttrSeq = Attribs->getFastAttributes();
     275                 :       9816 :         const FastAttribute *pFastAttr = aFastAttrSeq.getConstArray();
     276                 :       9816 :         sal_Int32 nFastAttrLength = aFastAttrSeq.getLength();
     277         [ +  + ]:      18954 :         for (sal_Int32 j = 0; j < nFastAttrLength; j++)
     278                 :            :         {
     279 [ +  - ][ +  - ]:       9138 :             writeBytes(toUnoSequence(maSpace));
                 [ +  - ]
     280                 :            : 
     281                 :       9138 :             sal_Int32 nToken = pFastAttr[j].Token;
     282         [ +  - ]:       9138 :             writeId(nToken);
     283                 :            : 
     284 [ +  - ][ +  - ]:       9138 :             writeBytes(toUnoSequence(maEqualSignAndQuote));
                 [ +  - ]
     285                 :            : 
     286 [ +  - ][ +  - ]:       9138 :             write(escapeXml(Attribs->getValue(pFastAttr[j].Token)));
         [ +  - ][ +  - ]
     287                 :            : 
     288 [ +  - ][ +  - ]:       9138 :             writeBytes(toUnoSequence(maQuote));
                 [ +  - ]
     289 [ +  - ][ +  - ]:       9816 :         }
     290                 :       9816 :     }
     291                 :            : 
     292                 :            :     // XServiceInfo
     293                 :          0 :     OUString FastSaxSerializer::getImplementationName() throw (RuntimeException)
     294                 :            :     {
     295                 :          0 :         return OUString( SERIALIZER_IMPLEMENTATION_NAME );
     296                 :            :     }
     297                 :            : 
     298                 :            :     // XServiceInfo
     299                 :          0 :     sal_Bool FastSaxSerializer::supportsService(const OUString& ServiceName) throw (RuntimeException)
     300                 :            :     {
     301         [ #  # ]:          0 :         Sequence< OUString > aSNL = getSupportedServiceNames();
     302                 :          0 :         const OUString * pArray = aSNL.getConstArray();
     303                 :            : 
     304         [ #  # ]:          0 :         for( sal_Int32 i = 0; i < aSNL.getLength(); i++ )
     305         [ #  # ]:          0 :         if( pArray[i] == ServiceName )
     306                 :          0 :             return sal_True;
     307                 :            : 
     308         [ #  # ]:          0 :         return sal_False;
     309                 :            :     }
     310                 :            : 
     311                 :            :     // XServiceInfo
     312                 :          0 :     Sequence< OUString > FastSaxSerializer::getSupportedServiceNames(void) throw (RuntimeException)
     313                 :            :     {
     314                 :          0 :         Sequence<OUString> seq(1);
     315         [ #  # ]:          0 :         seq.getArray()[0] = OUString( SERIALIZER_SERVICE_NAME );
     316                 :          0 :         return seq;
     317                 :            :     }
     318                 :            : 
     319                 :          0 :     Sequence< OUString > FastSaxSerializer::getSupportedServiceNames_Static(void)
     320                 :            :     {
     321                 :          0 :         Sequence<OUString> aRet(1);
     322         [ #  # ]:          0 :         aRet.getArray()[0] = OUString( SERIALIZER_SERVICE_NAME );
     323                 :          0 :         return aRet;
     324                 :            :     }
     325                 :            : 
     326                 :       2061 :     void FastSaxSerializer::mark( Int32Sequence aOrder )
     327                 :            :     {
     328         [ +  + ]:       2061 :         if ( aOrder.hasElements() )
     329                 :            :         {
     330 [ +  - ][ +  - ]:       1068 :             boost::shared_ptr< ForMerge > pSort( new ForSort( aOrder ) );
         [ +  - ][ +  - ]
                 [ +  - ]
     331 [ +  - ][ +  - ]:       1068 :             maMarkStack.push( pSort );
     332                 :            :         }
     333                 :            :         else
     334                 :            :         {
     335 [ +  - ][ +  - ]:        993 :             boost::shared_ptr< ForMerge > pMerge( new ForMerge( ) );
                 [ +  - ]
     336 [ +  - ][ +  - ]:        993 :             maMarkStack.push( pMerge );
     337                 :            :         }
     338                 :       2061 :     }
     339                 :            : 
     340                 :       2061 :     void FastSaxSerializer::mergeTopMarks( sax_fastparser::MergeMarksEnum eMergeType )
     341                 :            :     {
     342         [ +  - ]:       2061 :         if ( maMarkStack.empty() )
     343                 :            :             return;
     344                 :            : 
     345         [ +  + ]:       2061 :         if ( maMarkStack.size() == 1 )
     346                 :            :         {
     347 [ +  - ][ +  - ]:        906 :             mxOutputStream->writeBytes( maMarkStack.top()->getData() );
         [ +  - ][ +  - ]
     348         [ +  - ]:        906 :             maMarkStack.pop();
     349                 :            :             return;
     350                 :            :         }
     351                 :            : 
     352 [ +  - ][ +  - ]:       1155 :         const Int8Sequence aMerge( maMarkStack.top()->getData() );
                 [ +  - ]
     353         [ +  - ]:       1155 :         maMarkStack.pop();
     354                 :            : 
     355   [ +  +  +  - ]:       1155 :         switch ( eMergeType )
     356                 :            :         {
     357 [ +  - ][ +  - ]:        597 :             case MERGE_MARKS_APPEND:   maMarkStack.top()->append( aMerge );   break;
     358 [ +  - ][ +  - ]:        432 :             case MERGE_MARKS_PREPEND:  maMarkStack.top()->prepend( aMerge );  break;
     359 [ +  - ][ +  - ]:        126 :             case MERGE_MARKS_POSTPONE: maMarkStack.top()->postpone( aMerge ); break;
     360         [ +  - ]:       2061 :         }
     361                 :            :     }
     362                 :            : 
     363                 :     139977 :     void FastSaxSerializer::writeBytes( const Sequence< ::sal_Int8 >& aData ) throw ( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException )
     364                 :            :     {
     365         [ +  + ]:     139977 :         if ( maMarkStack.empty() )
     366                 :      63207 :             mxOutputStream->writeBytes( aData );
     367                 :            :         else
     368                 :      76770 :             maMarkStack.top()->append( aData );
     369                 :     139977 :     }
     370                 :            : 
     371                 :       2061 :     FastSaxSerializer::Int8Sequence& FastSaxSerializer::ForMerge::getData()
     372                 :            :     {
     373                 :       2061 :         merge( maData, maPostponed, true );
     374                 :       2061 :         maPostponed.realloc( 0 );
     375                 :            : 
     376                 :       2061 :         return maData;
     377                 :            :     }
     378                 :            : 
     379                 :            : #if DEBUG
     380                 :            :     void FastSaxSerializer::ForMerge::print( )
     381                 :            :     {
     382                 :            :         std::cerr << "Data: ";
     383                 :            :         for ( sal_Int32 i=0, len=maData.getLength(); i < len; i++ )
     384                 :            :         {
     385                 :            :             std::cerr << maData[i];
     386                 :            :         }
     387                 :            : 
     388                 :            :         std::cerr << "\nPostponed: ";
     389                 :            :         for ( sal_Int32 i=0, len=maPostponed.getLength(); i < len; i++ )
     390                 :            :         {
     391                 :            :             std::cerr << maPostponed[i];
     392                 :            :         }
     393                 :            : 
     394                 :            :         std::cerr << "\n";
     395                 :            :     }
     396                 :            : #endif
     397                 :            : 
     398                 :        432 :     void FastSaxSerializer::ForMerge::prepend( const Int8Sequence &rWhat )
     399                 :            :     {
     400                 :        432 :         merge( maData, rWhat, false );
     401                 :        432 :     }
     402                 :            : 
     403                 :      42729 :     void FastSaxSerializer::ForMerge::append( const Int8Sequence &rWhat )
     404                 :            :     {
     405                 :      42729 :         merge( maData, rWhat, true );
     406                 :      42729 :     }
     407                 :            : 
     408                 :        126 :     void FastSaxSerializer::ForMerge::postpone( const Int8Sequence &rWhat )
     409                 :            :     {
     410                 :        126 :         merge( maPostponed, rWhat, true );
     411                 :        126 :     }
     412                 :            : 
     413                 :      82167 :     void FastSaxSerializer::ForMerge::merge( Int8Sequence &rTop, const Int8Sequence &rMerge, bool bAppend )
     414                 :            :     {
     415                 :      82167 :         sal_Int32 nMergeLen = rMerge.getLength();
     416         [ +  + ]:      82167 :         if ( nMergeLen > 0 )
     417                 :            :         {
     418                 :      79815 :             sal_Int32 nTopLen = rTop.getLength();
     419                 :            : 
     420                 :      79815 :             rTop.realloc( nTopLen + nMergeLen );
     421         [ +  + ]:      79815 :             if ( bAppend )
     422                 :            :             {
     423                 :            :                 // append the rMerge to the rTop
     424                 :      79383 :                 memcpy( rTop.getArray() + nTopLen, rMerge.getConstArray(), nMergeLen );
     425                 :            :             }
     426                 :            :             else
     427                 :            :             {
     428                 :            :                 // prepend the rMerge to the rTop
     429                 :        432 :                 memmove( rTop.getArray() + nMergeLen, rTop.getConstArray(), nTopLen );
     430                 :        432 :                 memcpy( rTop.getArray(), rMerge.getConstArray(), nMergeLen );
     431                 :            :             }
     432                 :            :         }
     433                 :      82167 :     }
     434                 :            : 
     435                 :       1068 :     void FastSaxSerializer::ForMerge::resetData( )
     436                 :            :     {
     437         [ +  - ]:       1068 :         maData = Int8Sequence();
     438                 :       1068 :     }
     439                 :            : 
     440                 :       2223 :     void FastSaxSerializer::ForSort::setCurrentElement( sal_Int32 nElement )
     441                 :            :     {
     442         [ +  - ]:       2223 :         SequenceAsVector< sal_Int32 > aOrder( maOrder );
     443 [ +  - ][ +  - ]:       2223 :         if( std::find( aOrder.begin(), aOrder.end(), nElement ) != aOrder.end() )
                 [ +  + ]
     444                 :            :         {
     445                 :       2181 :             mnCurrentElement = nElement;
     446 [ +  - ][ +  - ]:       2181 :             if ( maData.find( nElement ) == maData.end() )
     447 [ +  - ][ +  - ]:       2181 :                 maData[ nElement ] = Int8Sequence();
         [ +  - ][ +  - ]
     448                 :       2223 :         }
     449                 :       2223 :     }
     450                 :            : 
     451                 :          0 :     void FastSaxSerializer::ForSort::prepend( const Int8Sequence &rWhat )
     452                 :            :     {
     453                 :          0 :         append( rWhat );
     454                 :          0 :     }
     455                 :            : 
     456                 :      36819 :     void FastSaxSerializer::ForSort::append( const Int8Sequence &rWhat )
     457                 :            :     {
     458                 :      36819 :         merge( maData[mnCurrentElement], rWhat, true );
     459                 :      36819 :     }
     460                 :            : 
     461                 :       1068 :     void FastSaxSerializer::ForSort::sort()
     462                 :            :     {
     463                 :            :         // Clear the ForMerge data to avoid duplicate items
     464         [ +  - ]:       1068 :         resetData();
     465                 :            : 
     466                 :            :         // Sort it all
     467                 :       1068 :         std::map< sal_Int32, Int8Sequence >::iterator iter;
     468         [ +  + ]:      40926 :         for ( sal_Int32 i=0, len=maOrder.getLength(); i < len; i++ )
     469                 :            :         {
     470 [ +  - ][ +  - ]:      39858 :             iter = maData.find( maOrder[i] );
     471         [ +  + ]:      39858 :             if ( iter != maData.end() )
     472         [ +  - ]:       2181 :                 ForMerge::append( iter->second );
     473                 :            :         }
     474                 :       1068 :     }
     475                 :            : 
     476                 :       1068 :     FastSaxSerializer::Int8Sequence& FastSaxSerializer::ForSort::getData()
     477                 :            :     {
     478                 :       1068 :         sort( );
     479                 :       1068 :         return ForMerge::getData();
     480                 :            :     }
     481                 :            : 
     482                 :            : #if DEBUG
     483                 :            :     void FastSaxSerializer::ForSort::print( )
     484                 :            :     {
     485                 :            :         std::map< sal_Int32, Int8Sequence >::iterator iter = maData.begin();
     486                 :            :         while ( iter != maData.end( ) )
     487                 :            :         {
     488                 :            :             std::cerr << "pair: " << iter->first;
     489                 :            :             for ( sal_Int32 i=0, len=iter->second.getLength(); i < len; ++i )
     490                 :            :                 std::cerr << iter->second[i];
     491                 :            :             std::cerr << "\n";
     492                 :            :             ++iter;
     493                 :            :         }
     494                 :            : 
     495                 :            :         sort( );
     496                 :            :         ForMerge::print();
     497                 :            :     }
     498                 :            : #endif
     499                 :            : 
     500                 :            : } // namespace sax_fastparser
     501                 :            : 
     502                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10