LCOV - code coverage report
Current view: top level - sax/source/tools - fastattribs.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 57 77 74.0 %
Date: 2012-08-25 Functions: 13 17 76.5 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 48 96 50.0 %

           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 <algorithm>
      21                 :            : 
      22                 :            : #include <sax/fastattribs.hxx>
      23                 :            : 
      24                 :            : using ::rtl::OUString;
      25                 :            : using ::rtl::OString;
      26                 :            : using namespace ::com::sun::star::uno;
      27                 :            : using namespace ::com::sun::star::xml;
      28                 :            : using namespace ::com::sun::star::xml::sax;
      29                 :            : namespace sax_fastparser
      30                 :            : {
      31                 :            : 
      32                 :        619 : UnknownAttribute::UnknownAttribute( const OUString& rNamespaceURL, const OString& rName, const OString& rValue )
      33                 :        619 :     : maNamespaceURL( rNamespaceURL ), maName( rName ), maValue( rValue )
      34                 :            : {
      35                 :        619 : }
      36                 :            : 
      37                 :          0 : UnknownAttribute::UnknownAttribute( const OString& rName, const OString& rValue )
      38                 :          0 :     : maName( rName ), maValue( rValue )
      39                 :            : {
      40                 :          0 : }
      41                 :            : 
      42                 :          0 : void UnknownAttribute::FillAttribute( Attribute* pAttrib ) const
      43                 :            : {
      44         [ #  # ]:          0 :     if( pAttrib )
      45                 :            :     {
      46                 :          0 :         pAttrib->Name = OStringToOUString( maName, RTL_TEXTENCODING_UTF8 );
      47                 :          0 :         pAttrib->NamespaceURL = maNamespaceURL;
      48                 :          0 :         pAttrib->Value = OStringToOUString( maValue, RTL_TEXTENCODING_UTF8 );
      49                 :            :     }
      50                 :          0 : }
      51                 :            : 
      52                 :      11854 : FastAttributeList::FastAttributeList( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastTokenHandler >& xTokenHandler )
      53 [ +  - ][ +  - ]:      11854 : : mxTokenHandler( xTokenHandler )
      54                 :            : {
      55                 :      11854 :     maLastIter = maAttributes.end();
      56                 :      11854 : }
      57                 :            : 
      58                 :      11854 : FastAttributeList::~FastAttributeList()
      59                 :            : {
      60         [ -  + ]:      23708 : }
      61                 :            : 
      62                 :      74940 : void FastAttributeList::clear()
      63                 :            : {
      64                 :      74940 :     maAttributes.clear();
      65                 :      74940 :     maUnknownAttributes.clear();
      66                 :      74940 :     maLastIter = maAttributes.end();
      67                 :      74940 : }
      68                 :            : 
      69                 :      98397 : void FastAttributeList::add( sal_Int32 nToken, const OString& rValue )
      70                 :            : {
      71                 :      98397 :     maAttributes[nToken] = rValue;
      72                 :      98397 : }
      73                 :            : 
      74                 :        619 : void FastAttributeList::addUnknown( const OUString& rNamespaceURL, const OString& rName, const OString& rValue )
      75                 :            : {
      76         [ +  - ]:        619 :     maUnknownAttributes.push_back( UnknownAttribute( rNamespaceURL, rName, rValue ) );
      77                 :        619 : }
      78                 :            : 
      79                 :          0 : void FastAttributeList::addUnknown( const OString& rName, const OString& rValue )
      80                 :            : {
      81         [ #  # ]:          0 :     maUnknownAttributes.push_back( UnknownAttribute( rName, rValue ) );
      82                 :          0 : }
      83                 :            : 
      84                 :            : // XFastAttributeList
      85                 :      93509 : sal_Bool FastAttributeList::hasAttribute( ::sal_Int32 Token ) throw (RuntimeException)
      86                 :            : {
      87                 :      93509 :     maLastIter = maAttributes.find( Token );
      88         [ +  + ]:      93509 :     return ( maLastIter != maAttributes.end() ) ? sal_True : sal_False;
      89                 :            : }
      90                 :            : 
      91                 :          0 : sal_Int32 FastAttributeList::getValueToken( ::sal_Int32 Token ) throw (SAXException, RuntimeException)
      92                 :            : {
      93 [ #  # ][ #  # ]:          0 :     if( ( maLastIter == maAttributes.end() ) || ( ( *maLastIter ).first != Token ) )
         [ #  # ][ #  # ]
      94         [ #  # ]:          0 :         maLastIter = maAttributes.find( Token );
      95                 :            : 
      96         [ #  # ]:          0 :     if( maLastIter == maAttributes.end() )
      97         [ #  # ]:          0 :         throw SAXException();
      98                 :            : 
      99         [ #  # ]:          0 :     Sequence< sal_Int8 > aSeq( (sal_Int8*)(*maLastIter).second.getStr(), (*maLastIter).second.getLength() ) ;
     100 [ #  # ][ #  # ]:          0 :     return mxTokenHandler->getTokenFromUTF8( aSeq );
                 [ #  # ]
     101                 :            : }
     102                 :            : 
     103                 :      17484 : sal_Int32 FastAttributeList::getOptionalValueToken( ::sal_Int32 Token, ::sal_Int32 Default ) throw (RuntimeException)
     104                 :            : {
     105 [ +  + ][ +  + ]:      17484 :     if( ( maLastIter == maAttributes.end() ) || ( ( *maLastIter ).first != Token ) )
         [ +  - ][ +  + ]
     106         [ +  - ]:      16599 :         maLastIter = maAttributes.find( Token );
     107                 :            : 
     108         [ +  + ]:      17484 :     if( maLastIter == maAttributes.end() )
     109                 :      10128 :         return Default;
     110                 :            : 
     111         [ +  - ]:       7356 :     Sequence< sal_Int8 > aSeq( (sal_Int8*)(*maLastIter).second.getStr(), (*maLastIter).second.getLength() ) ;
     112 [ +  - ][ +  - ]:      17484 :     return mxTokenHandler->getTokenFromUTF8( aSeq );
                 [ +  - ]
     113                 :            : }
     114                 :            : 
     115                 :      64229 : OUString FastAttributeList::getValue( ::sal_Int32 Token ) throw (SAXException, RuntimeException)
     116                 :            : {
     117 [ +  + ][ +  + ]:      64229 :     if( ( maLastIter == maAttributes.end() ) || ( ( *maLastIter ).first != Token ) )
         [ +  - ][ +  + ]
     118                 :      17603 :         maLastIter = maAttributes.find( Token );
     119                 :            : 
     120         [ +  + ]:      64229 :     if( maLastIter == maAttributes.end() )
     121         [ +  - ]:       1935 :         throw SAXException();
     122                 :            : 
     123                 :      62294 :     return OStringToOUString( (*maLastIter).second, RTL_TEXTENCODING_UTF8 );
     124                 :            : }
     125                 :            : 
     126                 :      19818 : OUString FastAttributeList::getOptionalValue( ::sal_Int32 Token ) throw (RuntimeException)
     127                 :            : {
     128 [ +  + ][ +  + ]:      19818 :     if( ( maLastIter == maAttributes.end() ) || ( ( *maLastIter ).first != Token ) )
         [ +  - ][ +  + ]
     129                 :      17373 :         maLastIter = maAttributes.find( Token );
     130                 :            : 
     131                 :      19818 :     OUString aRet;
     132         [ +  + ]:      19818 :     if( maLastIter != maAttributes.end() )
     133         [ +  - ]:      10998 :         aRet = OStringToOUString( (*maLastIter).second, RTL_TEXTENCODING_UTF8 );
     134                 :            : 
     135                 :      19818 :     return aRet;
     136                 :            : }
     137                 :       9816 : Sequence< Attribute > FastAttributeList::getUnknownAttributes(  ) throw (RuntimeException)
     138                 :            : {
     139                 :       9816 :     Sequence< Attribute > aSeq( maUnknownAttributes.size() );
     140         [ +  - ]:       9816 :     Attribute* pAttr = aSeq.getArray();
     141 [ +  - ][ -  + ]:       9816 :     for( UnknownAttributeList::iterator attrIter = maUnknownAttributes.begin(); attrIter != maUnknownAttributes.end(); ++attrIter )
     142         [ #  # ]:          0 :         (*attrIter).FillAttribute( pAttr++ );
     143                 :       9816 :     return aSeq;
     144                 :            : }
     145                 :      16875 : Sequence< FastAttribute > FastAttributeList::getFastAttributes(  ) throw (RuntimeException)
     146                 :            : {
     147         [ +  - ]:      16875 :     Sequence< FastAttribute > aSeq( maAttributes.size() );
     148         [ +  - ]:      16875 :     FastAttribute* pAttr = aSeq.getArray();
     149                 :      16875 :     FastAttributeMap::iterator fastAttrIter = maAttributes.begin();
     150         [ +  + ]:      29502 :     for(; fastAttrIter != maAttributes.end(); ++fastAttrIter )
     151                 :            :     {
     152                 :      12627 :         pAttr->Token = fastAttrIter->first;
     153         [ +  - ]:      12627 :         pAttr->Value = OStringToOUString( fastAttrIter->second, RTL_TEXTENCODING_UTF8 );
     154                 :      12627 :         pAttr++;
     155                 :            :     }
     156                 :      16875 :     return aSeq;
     157                 :            : }
     158                 :            : 
     159                 :            : }
     160                 :            : 
     161                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10