LCOV - code coverage report
Current view: top level - oox/source/token - tokenmap.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 27 29 93.1 %
Date: 2014-04-11 Functions: 6 6 100.0 %
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             : #if defined __clang__
      36             : #if __has_warning("-Wdeprecated-register")
      37             : #pragma GCC diagnostic push
      38             : #pragma GCC diagnostic ignored "-Wdeprecated-register"
      39             : #endif
      40             : #endif
      41             : #include "tokenhash.inc"
      42             : #if defined __clang__
      43             : #if __has_warning("-Wdeprecated-register")
      44             : #pragma GCC diagnostic pop
      45             : #endif
      46             : #endif
      47             : } // namespace
      48             : 
      49             : 
      50             : 
      51          18 : TokenMap::TokenMap() :
      52          18 :     maTokenNames( static_cast< size_t >( XML_TOKEN_COUNT ) )
      53             : {
      54             :     static const sal_Char* sppcTokenNames[] =
      55             :     {
      56             : // include auto-generated C array with token names as C strings
      57             : #include "tokennames.inc"
      58             :         ""
      59             :     };
      60             : 
      61          18 :     const sal_Char* const* ppcTokenName = sppcTokenNames;
      62      103716 :     for( TokenNameVector::iterator aIt = maTokenNames.begin(), aEnd = maTokenNames.end(); aIt != aEnd; ++aIt, ++ppcTokenName )
      63             :     {
      64      103698 :         OString aUtf8Token( *ppcTokenName );
      65      103698 :         aIt->maUniName = OStringToOUString( aUtf8Token, RTL_TEXTENCODING_UTF8 );
      66      103698 :         aIt->maUtf8Name = Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( aUtf8Token.getStr() ), aUtf8Token.getLength() );
      67      103698 :     }
      68             : 
      69             : #if OSL_DEBUG_LEVEL > 0
      70             :     // check that the perfect_hash is in sync with the token name list
      71             :     bool bOk = true;
      72             :     for( sal_Int32 nToken = 0; bOk && (nToken < XML_TOKEN_COUNT); ++nToken )
      73             :     {
      74             :         // check that the getIdentifier <-> getToken roundtrip works
      75             :         OString aUtf8Name = OUStringToOString( maTokenNames[ nToken ].maUniName, RTL_TEXTENCODING_UTF8 );
      76             :         struct xmltoken* pToken = Perfect_Hash::in_word_set( aUtf8Name.getStr(), aUtf8Name.getLength() );
      77             :         bOk = pToken && (pToken->nToken == nToken);
      78             :         OSL_ENSURE( bOk, OStringBuffer( "TokenMap::TokenMap - token list broken, #" ).
      79             :             append( nToken ).append( ", '" ).append( aUtf8Name ).append( '\'' ).getStr() );
      80             :     }
      81             : #endif
      82             : 
      83         486 :     for (unsigned char c = 'a'; c <= 'z'; c++)
      84             :     {
      85             :         struct xmltoken* pToken = Perfect_Hash::in_word_set(
      86         468 :                 reinterpret_cast< const char* >( &c ), 1 );
      87         468 :         mnAlphaTokens[ c - 'a' ] = pToken ? pToken->nToken : XML_TOKEN_INVALID;
      88             :     }
      89          18 : }
      90             : 
      91          18 : TokenMap::~TokenMap()
      92             : {
      93          18 : }
      94             : 
      95         288 : OUString TokenMap::getUnicodeTokenName( sal_Int32 nToken ) const
      96             : {
      97         288 :     if( (0 <= nToken) && (static_cast< size_t >( nToken ) < maTokenNames.size()) )
      98         288 :         return maTokenNames[ static_cast< size_t >( nToken ) ].maUniName;
      99           0 :     return OUString();
     100             : }
     101             : 
     102       28659 : sal_Int32 TokenMap::getTokenFromUnicode( const OUString& rUnicodeName ) const
     103             : {
     104       28659 :     OString aUtf8Name = OUStringToOString( rUnicodeName, RTL_TEXTENCODING_UTF8 );
     105       28659 :     struct xmltoken* pToken = Perfect_Hash::in_word_set( aUtf8Name.getStr(), aUtf8Name.getLength() );
     106       28659 :     return pToken ? pToken->nToken : XML_TOKEN_INVALID;
     107             : }
     108             : 
     109     1476899 : Sequence< sal_Int8 > TokenMap::getUtf8TokenName( sal_Int32 nToken ) const
     110             : {
     111     1476899 :     if( (0 <= nToken) && (static_cast< size_t >( nToken ) < maTokenNames.size()) )
     112     1476899 :         return maTokenNames[ static_cast< size_t >( nToken ) ].maUtf8Name;
     113           0 :     return Sequence< sal_Int8 >();
     114             : }
     115             : 
     116      678367 : sal_Int32 TokenMap::getTokenPerfectHash( const char *pStr, sal_Int32 nLength ) const
     117             : {
     118      678367 :     struct xmltoken* pToken = Perfect_Hash::in_word_set( pStr, nLength );
     119      678367 :     return pToken ? pToken->nToken : XML_TOKEN_INVALID;
     120             : }
     121             : 
     122             : 
     123             : 
     124             : } // namespace oox
     125             : 
     126             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10