LCOV - code coverage report
Current view: top level - libreoffice/sax/source/tools - fastattribs.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 57 77 74.0 %
Date: 2012-12-17 Functions: 13 17 76.5 %
Legend: Lines: hit not hit

          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         710 : UnknownAttribute::UnknownAttribute( const OUString& rNamespaceURL, const OString& rName, const OString& rValue )
      33         710 :     : maNamespaceURL( rNamespaceURL ), maName( rName ), maValue( rValue )
      34             : {
      35         710 : }
      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       12952 : FastAttributeList::FastAttributeList( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastTokenHandler >& xTokenHandler )
      53       12952 : : mxTokenHandler( xTokenHandler )
      54             : {
      55       12952 :     maLastIter = maAttributes.end();
      56       12952 : }
      57             : 
      58       25904 : FastAttributeList::~FastAttributeList()
      59             : {
      60       25904 : }
      61             : 
      62       82676 : void FastAttributeList::clear()
      63             : {
      64       82676 :     maAttributes.clear();
      65       82676 :     maUnknownAttributes.clear();
      66       82676 :     maLastIter = maAttributes.end();
      67       82676 : }
      68             : 
      69      109006 : void FastAttributeList::add( sal_Int32 nToken, const OString& rValue )
      70             : {
      71      109006 :     maAttributes[nToken] = rValue;
      72      109006 : }
      73             : 
      74         710 : void FastAttributeList::addUnknown( const OUString& rNamespaceURL, const OString& rName, const OString& rValue )
      75             : {
      76         710 :     maUnknownAttributes.push_back( UnknownAttribute( rNamespaceURL, rName, rValue ) );
      77         710 : }
      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      105108 : sal_Bool FastAttributeList::hasAttribute( ::sal_Int32 Token ) throw (RuntimeException)
      86             : {
      87      105108 :     maLastIter = maAttributes.find( Token );
      88      105108 :     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       21500 : sal_Int32 FastAttributeList::getOptionalValueToken( ::sal_Int32 Token, ::sal_Int32 Default ) throw (RuntimeException)
     104             : {
     105       21500 :     if( ( maLastIter == maAttributes.end() ) || ( ( *maLastIter ).first != Token ) )
     106       20594 :         maLastIter = maAttributes.find( Token );
     107             : 
     108       21500 :     if( maLastIter == maAttributes.end() )
     109       14214 :         return Default;
     110             : 
     111        7286 :     Sequence< sal_Int8 > aSeq( (sal_Int8*)(*maLastIter).second.getStr(), (*maLastIter).second.getLength() ) ;
     112        7286 :     return mxTokenHandler->getTokenFromUTF8( aSeq );
     113             : }
     114             : 
     115       64724 : OUString FastAttributeList::getValue( ::sal_Int32 Token ) throw (SAXException, RuntimeException)
     116             : {
     117       64724 :     if( ( maLastIter == maAttributes.end() ) || ( ( *maLastIter ).first != Token ) )
     118       11748 :         maLastIter = maAttributes.find( Token );
     119             : 
     120       64724 :     if( maLastIter == maAttributes.end() )
     121          40 :         throw SAXException();
     122             : 
     123       64684 :     return OStringToOUString( (*maLastIter).second, RTL_TEXTENCODING_UTF8 );
     124             : }
     125             : 
     126       31432 : OUString FastAttributeList::getOptionalValue( ::sal_Int32 Token ) throw (RuntimeException)
     127             : {
     128       31432 :     if( ( maLastIter == maAttributes.end() ) || ( ( *maLastIter ).first != Token ) )
     129       28688 :         maLastIter = maAttributes.find( Token );
     130             : 
     131       31432 :     OUString aRet;
     132       31432 :     if( maLastIter != maAttributes.end() )
     133       18732 :         aRet = OStringToOUString( (*maLastIter).second, RTL_TEXTENCODING_UTF8 );
     134             : 
     135       31432 :     return aRet;
     136             : }
     137       10956 : Sequence< Attribute > FastAttributeList::getUnknownAttributes(  ) throw (RuntimeException)
     138             : {
     139       10956 :     Sequence< Attribute > aSeq( maUnknownAttributes.size() );
     140       10956 :     Attribute* pAttr = aSeq.getArray();
     141       10956 :     for( UnknownAttributeList::iterator attrIter = maUnknownAttributes.begin(); attrIter != maUnknownAttributes.end(); ++attrIter )
     142           0 :         (*attrIter).FillAttribute( pAttr++ );
     143       10956 :     return aSeq;
     144             : }
     145       15662 : Sequence< FastAttribute > FastAttributeList::getFastAttributes(  ) throw (RuntimeException)
     146             : {
     147       15662 :     Sequence< FastAttribute > aSeq( maAttributes.size() );
     148       15662 :     FastAttribute* pAttr = aSeq.getArray();
     149       15662 :     FastAttributeMap::iterator fastAttrIter = maAttributes.begin();
     150       29446 :     for(; fastAttrIter != maAttributes.end(); ++fastAttrIter )
     151             :     {
     152       13784 :         pAttr->Token = fastAttrIter->first;
     153       13784 :         pAttr->Value = OStringToOUString( fastAttrIter->second, RTL_TEXTENCODING_UTF8 );
     154       13784 :         pAttr++;
     155             :     }
     156       15662 :     return aSeq;
     157             : }
     158             : 
     159             : }
     160             : 
     161             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10