fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / oox / source / token / tokenmap.cxx
blobbd2657ce007b53db6a3ba4fd228247269eb655fe
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "oox/token/tokenmap.hxx"
22 #include <string.h>
23 #include <rtl/strbuf.hxx>
24 #include <rtl/string.hxx>
25 #include "oox/token/tokens.hxx"
27 namespace oox {
28 // ============================================================================
30 using ::com::sun::star::uno::Sequence;
31 // ============================================================================
33 namespace {
34 // include auto-generated Perfect_Hash
35 #include "tokenhash.inc"
36 } // namespace
38 // ============================================================================
40 TokenMap::TokenMap() :
41 maTokenNames( static_cast< size_t >( XML_TOKEN_COUNT ) )
43 static const sal_Char* sppcTokenNames[] =
45 // include auto-generated C array with token names as C strings
46 #include "tokennames.inc"
50 const sal_Char* const* ppcTokenName = sppcTokenNames;
51 for( TokenNameVector::iterator aIt = maTokenNames.begin(), aEnd = maTokenNames.end(); aIt != aEnd; ++aIt, ++ppcTokenName )
53 OString aUtf8Token( *ppcTokenName );
54 aIt->maUniName = OStringToOUString( aUtf8Token, RTL_TEXTENCODING_UTF8 );
55 aIt->maUtf8Name = Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( aUtf8Token.getStr() ), aUtf8Token.getLength() );
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 )
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() );
70 #endif
73 TokenMap::~TokenMap()
77 OUString TokenMap::getUnicodeTokenName( sal_Int32 nToken ) const
79 if( (0 <= nToken) && (static_cast< size_t >( nToken ) < maTokenNames.size()) )
80 return maTokenNames[ static_cast< size_t >( nToken ) ].maUniName;
81 return OUString();
84 sal_Int32 TokenMap::getTokenFromUnicode( const OUString& rUnicodeName ) const
86 OString aUtf8Name = OUStringToOString( rUnicodeName, RTL_TEXTENCODING_UTF8 );
87 struct xmltoken* pToken = Perfect_Hash::in_word_set( aUtf8Name.getStr(), aUtf8Name.getLength() );
88 return pToken ? pToken->nToken : XML_TOKEN_INVALID;
91 Sequence< sal_Int8 > TokenMap::getUtf8TokenName( sal_Int32 nToken ) const
93 if( (0 <= nToken) && (static_cast< size_t >( nToken ) < maTokenNames.size()) )
94 return maTokenNames[ static_cast< size_t >( nToken ) ].maUtf8Name;
95 return Sequence< sal_Int8 >();
98 sal_Int32 TokenMap::getTokenFromUtf8( const Sequence< sal_Int8 >& rUtf8Name ) const
100 struct xmltoken* pToken = Perfect_Hash::in_word_set(
101 reinterpret_cast< const char* >( rUtf8Name.getConstArray() ), rUtf8Name.getLength() );
102 return pToken ? pToken->nToken : XML_TOKEN_INVALID;
105 // ============================================================================
107 } // namespace oox
109 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */