LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/oox/source/token - tokenmap.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 21 26 80.8 %
Date: 2013-07-09 Functions: 5 6 83.3 %
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 "oox/token/tokenmap.hxx"
      21             : 
      22             : #include <string.h>
      23             : #include <rtl/strbuf.hxx>
      24             : #include <rtl/string.hxx>
      25             : #include "oox/token/tokens.hxx"
      26             : 
      27             : namespace oox {
      28             : // ============================================================================
      29             : 
      30             : using ::com::sun::star::uno::Sequence;
      31             : // ============================================================================
      32             : 
      33             : namespace {
      34             : // include auto-generated Perfect_Hash
      35             : #include "tokenhash.inc"
      36             : } // namespace
      37             : 
      38             : // ============================================================================
      39             : 
      40          13 : TokenMap::TokenMap() :
      41          13 :     maTokenNames( static_cast< size_t >( XML_TOKEN_COUNT ) )
      42             : {
      43             :     static const sal_Char* sppcTokenNames[] =
      44             :     {
      45             : // include auto-generated C array with token names as C strings
      46             : #include "tokennames.inc"
      47             :         ""
      48             :     };
      49             : 
      50          13 :     const sal_Char* const* ppcTokenName = sppcTokenNames;
      51       74464 :     for( TokenNameVector::iterator aIt = maTokenNames.begin(), aEnd = maTokenNames.end(); aIt != aEnd; ++aIt, ++ppcTokenName )
      52             :     {
      53       74451 :         OString aUtf8Token( *ppcTokenName );
      54       74451 :         aIt->maUniName = OStringToOUString( aUtf8Token, RTL_TEXTENCODING_UTF8 );
      55       74451 :         aIt->maUtf8Name = Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( aUtf8Token.getStr() ), aUtf8Token.getLength() );
      56       74451 :     }
      57             : 
      58             : #if OSL_DEBUG_LEVEL > 0
      59             :     // check that the perfect_hash is in sync with the token name list
      60             :     bool bOk = true;
      61             :     for( sal_Int32 nToken = 0; bOk && (nToken < XML_TOKEN_COUNT); ++nToken )
      62             :     {
      63             :         // check that the getIdentifier <-> getToken roundtrip works
      64             :         OString aUtf8Name = OUStringToOString( maTokenNames[ nToken ].maUniName, RTL_TEXTENCODING_UTF8 );
      65             :         struct xmltoken* pToken = Perfect_Hash::in_word_set( aUtf8Name.getStr(), aUtf8Name.getLength() );
      66             :         bOk = pToken && (pToken->nToken == nToken);
      67             :         OSL_ENSURE( bOk, OStringBuffer( "TokenMap::TokenMap - token list broken, #" ).
      68             :             append( nToken ).append( ", '" ).append( aUtf8Name ).append( '\'' ).getStr() );
      69             :     }
      70             : #endif
      71          13 : }
      72             : 
      73          13 : TokenMap::~TokenMap()
      74             : {
      75          13 : }
      76             : 
      77           0 : OUString TokenMap::getUnicodeTokenName( sal_Int32 nToken ) const
      78             : {
      79           0 :     if( (0 <= nToken) && (static_cast< size_t >( nToken ) < maTokenNames.size()) )
      80           0 :         return maTokenNames[ static_cast< size_t >( nToken ) ].maUniName;
      81           0 :     return OUString();
      82             : }
      83             : 
      84        1048 : sal_Int32 TokenMap::getTokenFromUnicode( const OUString& rUnicodeName ) const
      85             : {
      86        1048 :     OString aUtf8Name = OUStringToOString( rUnicodeName, RTL_TEXTENCODING_UTF8 );
      87        1048 :     struct xmltoken* pToken = Perfect_Hash::in_word_set( aUtf8Name.getStr(), aUtf8Name.getLength() );
      88        1048 :     return pToken ? pToken->nToken : XML_TOKEN_INVALID;
      89             : }
      90             : 
      91       58245 : Sequence< sal_Int8 > TokenMap::getUtf8TokenName( sal_Int32 nToken ) const
      92             : {
      93       58245 :     if( (0 <= nToken) && (static_cast< size_t >( nToken ) < maTokenNames.size()) )
      94       58245 :         return maTokenNames[ static_cast< size_t >( nToken ) ].maUtf8Name;
      95           0 :     return Sequence< sal_Int8 >();
      96             : }
      97             : 
      98       65362 : sal_Int32 TokenMap::getTokenFromUtf8( const Sequence< sal_Int8 >& rUtf8Name ) const
      99             : {
     100             :     struct xmltoken* pToken = Perfect_Hash::in_word_set(
     101       65362 :         reinterpret_cast< const char* >( rUtf8Name.getConstArray() ), rUtf8Name.getLength() );
     102       65362 :     return pToken ? pToken->nToken : XML_TOKEN_INVALID;
     103             : }
     104             : 
     105             : // ============================================================================
     106             : 
     107             : } // namespace oox
     108             : 
     109             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10