1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
10 #include <fasttokenhandler.hxx>
12 #include <xmloff/token/tokens.hxx>
17 // include auto-generated Perfect_Hash
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"
25 #include <tokenhash.inc>
27 #pragma GCC diagnostic pop
35 TokenMap
& StaticTokenMap()
37 static TokenMap SINGLETON
;
41 const css::uno::Sequence
< sal_Int8
> TokenMap::EMPTY_BYTE_SEQ
;
42 const OUString
TokenMap::EMPTY_STRING
;
44 TokenMap::TokenMap() :
45 maTokenNamesUtf8( static_cast< size_t >( XML_TOKEN_COUNT
) ),
46 maTokenNames( static_cast< size_t >( XML_TOKEN_COUNT
) )
48 static const char* sppcTokenNames
[] =
50 #include <tokennames.inc>
54 const char* const* ppcTokenName
= sppcTokenNames
;
56 for( auto& rTokenName
: maTokenNamesUtf8
)
58 std::string_view pStr
= *ppcTokenName
;
59 rTokenName
= uno::Sequence
< sal_Int8
>(
60 reinterpret_cast< const sal_Int8
* >( pStr
.data() ), pStr
.length() );
61 maTokenNames
[i
++] = OStringToOUString( pStr
, RTL_TEXTENCODING_UTF8
);
70 sal_Int32
TokenMap::getTokenPerfectHash( const char *pStr
, sal_Int32 nLength
)
72 const struct xmltoken
*pToken
= Perfect_Hash::in_word_set( pStr
, nLength
);
73 return pToken
? pToken
->nToken
: xmloff::XML_TOKEN_INVALID
;
76 FastTokenHandler::FastTokenHandler() :
77 mrTokenMap( StaticTokenMap() )
81 FastTokenHandler::~FastTokenHandler()
86 uno::Sequence
< sal_Int8
> FastTokenHandler::getUTF8Identifier( sal_Int32 nToken
)
88 return mrTokenMap
.getUtf8TokenName( nToken
);
91 const OUString
& FastTokenHandler::getIdentifier( sal_Int32 nToken
) const
93 return mrTokenMap
.getTokenName( nToken
);
96 sal_Int32
FastTokenHandler::getTokenFromUTF8( const uno::Sequence
< sal_Int8
>& rIdentifier
)
98 return TokenMap::getTokenFromUtf8( rIdentifier
);
101 // Much faster direct C++ shortcut
102 sal_Int32
FastTokenHandler::getTokenDirect( const char* pToken
, sal_Int32 nLength
) const
104 return TokenMap::getTokenFromUTF8( pToken
, nLength
);
108 } // namespace xmloff
110 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */