nss: upgrade to release 3.73
[LibreOffice.git] / xmloff / source / core / fasttokenhandler.cxx
blob8d63cb74f8fc0e7da530438e060516f44b6b9afd
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/.
8 */
10 #include <fasttokenhandler.hxx>
12 #include <xmloff/token/tokens.hxx>
14 namespace xmloff {
16 namespace {
17 // include auto-generated Perfect_Hash
18 #if defined __clang__
19 #pragma GCC diagnostic push
20 #pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
21 #if __has_warning("-Wdeprecated-register")
22 #pragma GCC diagnostic ignored "-Wdeprecated-register"
23 #endif
24 #endif
25 #include <tokenhash.inc>
26 #if defined __clang__
27 #pragma GCC diagnostic pop
28 #endif
29 } // namespace
31 namespace token {
33 using namespace css;
35 const css::uno::Sequence< sal_Int8 > TokenMap::EMPTY_BYTE_SEQ;
36 const OUString TokenMap::EMPTY_STRING;
38 TokenMap::TokenMap() :
39 maTokenNamesUtf8( static_cast< size_t >( XML_TOKEN_COUNT ) ),
40 maTokenNames( static_cast< size_t >( XML_TOKEN_COUNT ) )
42 static const char* sppcTokenNames[] =
44 #include <tokennames.inc>
48 const char* const* ppcTokenName = sppcTokenNames;
49 int i = 0;
50 for( auto& rTokenName : maTokenNamesUtf8 )
52 OString aUtf8Token( *ppcTokenName );
53 rTokenName = uno::Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >(
54 aUtf8Token.getStr() ), aUtf8Token.getLength() );
55 maTokenNames[i++] = OUString( aUtf8Token.getStr(), aUtf8Token.getLength(), RTL_TEXTENCODING_UTF8 );
56 ++ppcTokenName;
60 TokenMap::~TokenMap()
64 sal_Int32 TokenMap::getTokenPerfectHash( const char *pStr, sal_Int32 nLength )
66 const struct xmltoken *pToken = Perfect_Hash::in_word_set( pStr, nLength );
67 return pToken ? pToken->nToken : xmloff::XML_TOKEN_INVALID;
70 FastTokenHandler::FastTokenHandler() :
71 mrTokenMap( StaticTokenMap::get() )
75 FastTokenHandler::~FastTokenHandler()
79 // XFastTokenHandler
80 uno::Sequence< sal_Int8 > FastTokenHandler::getUTF8Identifier( sal_Int32 nToken )
82 return mrTokenMap.getUtf8TokenName( nToken );
85 const OUString& FastTokenHandler::getIdentifier( sal_Int32 nToken ) const
87 return mrTokenMap.getTokenName( nToken );
90 sal_Int32 FastTokenHandler::getTokenFromUTF8( const uno::Sequence< sal_Int8 >& rIdentifier )
92 return TokenMap::getTokenFromUtf8( rIdentifier );
95 // Much faster direct C++ shortcut
96 sal_Int32 FastTokenHandler::getTokenDirect( const char* pToken, sal_Int32 nLength ) const
98 return TokenMap::getTokenFromUTF8( pToken, nLength );
101 } // namespace token
102 } // namespace xmloff
104 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */