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

Generated by: LCOV version 1.10