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/.
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>
23 #include <rtl/strbuf.hxx>
24 #include <rtl/string.hxx>
25 #include <oox/token/tokens.hxx>
29 using ::com::sun::star::uno::Sequence
;
32 // include auto-generated Perfect_Hash
34 #pragma GCC diagnostic push
35 #pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
36 #if __has_warning("-Wdeprecated-register")
37 #pragma GCC diagnostic ignored "-Wdeprecated-register"
40 #include <tokenhash.inc>
42 #pragma GCC diagnostic pop
46 const css::uno::Sequence
< sal_Int8
> TokenMap::EMPTY_BYTE_SEQ
;
48 TokenMap::TokenMap() :
49 maTokenNames( static_cast< size_t >( XML_TOKEN_COUNT
) )
51 static const sal_Char
* sppcTokenNames
[] =
53 // include auto-generated C array with token names as C strings
54 #include <tokennames.inc>
58 const sal_Char
* const* ppcTokenName
= sppcTokenNames
;
59 for (auto & tokenName
: maTokenNames
)
61 OString
aUtf8Token( *ppcTokenName
);
62 tokenName
= Sequence
< sal_Int8
>( reinterpret_cast< const sal_Int8
* >( aUtf8Token
.getStr() ), aUtf8Token
.getLength() );
66 for (unsigned char c
= 'a'; c
<= 'z'; c
++)
68 const struct xmltoken
* pToken
= Perfect_Hash::in_word_set(
69 reinterpret_cast< const char* >( &c
), 1 );
70 mnAlphaTokens
[ c
- 'a' ] = pToken
? pToken
->nToken
: XML_TOKEN_INVALID
;
78 sal_Int32
TokenMap::getTokenFromUnicode( const OUString
& rUnicodeName
)
80 OString aUtf8Name
= OUStringToOString( rUnicodeName
, RTL_TEXTENCODING_UTF8
);
81 const struct xmltoken
* pToken
= Perfect_Hash::in_word_set( aUtf8Name
.getStr(), aUtf8Name
.getLength() );
82 return pToken
? pToken
->nToken
: XML_TOKEN_INVALID
;
85 sal_Int32
TokenMap::getTokenPerfectHash( const char *pStr
, sal_Int32 nLength
)
87 const struct xmltoken
* pToken
= Perfect_Hash::in_word_set( pStr
, nLength
);
88 return pToken
? pToken
->nToken
: XML_TOKEN_INVALID
;
93 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */