LibreOffice Module oox (master) 1
tokenmap.cxx
Go to the documentation of this file.
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
21
22#include <string.h>
23#include <rtl/string.hxx>
24#include <oox/token/tokens.hxx>
25
26namespace oox {
27
28using ::com::sun::star::uno::Sequence;
29
30namespace {
31// include auto-generated Perfect_Hash
32#if defined __clang__
33#pragma GCC diagnostic push
34#pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
35#if __has_warning("-Wdeprecated-register")
36#pragma GCC diagnostic ignored "-Wdeprecated-register"
37#endif
38#endif
39#include <tokenhash.inc>
40#if defined __clang__
41#pragma GCC diagnostic pop
42#endif
43} // namespace
44
45const css::uno::Sequence< sal_Int8 > TokenMap::EMPTY_BYTE_SEQ;
46
48 maTokenNames( static_cast< size_t >( XML_TOKEN_COUNT ) )
49{
50 static const char* sppcTokenNames[] =
51 {
52// include auto-generated C array with token names as C strings
53#include <tokennames.inc>
54 ""
55 };
56
57 const char* const* ppcTokenName = sppcTokenNames;
58 for (auto & tokenName : maTokenNames)
59 {
60 OString aUtf8Token( *ppcTokenName );
61 tokenName = Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( aUtf8Token.getStr() ), aUtf8Token.getLength() );
62 ++ppcTokenName;
63 }
64
65 for (unsigned char c = 'a'; c <= 'z'; c++)
66 {
67 const struct xmltoken* pToken = Perfect_Hash::in_word_set(
68 reinterpret_cast< const char* >( &c ), 1 );
69 mnAlphaTokens[ c - 'a' ] = pToken ? pToken->nToken : XML_TOKEN_INVALID;
70 }
71}
72
74{
75}
76
77sal_Int32 TokenMap::getTokenFromUnicode( std::u16string_view rUnicodeName )
78{
79 OString aUtf8Name = OUStringToOString( rUnicodeName, RTL_TEXTENCODING_UTF8 );
80 const struct xmltoken* pToken = Perfect_Hash::in_word_set( aUtf8Name.getStr(), aUtf8Name.getLength() );
81 return pToken ? pToken->nToken : XML_TOKEN_INVALID;
82}
83
84sal_Int32 TokenMap::getTokenPerfectHash( const char *pStr, sal_Int32 nLength )
85{
86 const struct xmltoken* pToken = Perfect_Hash::in_word_set( pStr, nLength );
87 return pToken ? pToken->nToken : XML_TOKEN_INVALID;
88}
89
91{
92 static TokenMap SINGLETON;
93 return SINGLETON;
94}
95
96} // namespace oox
97
98/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::vector< css::uno::Sequence< sal_Int8 > > maTokenNames
Definition: tokenmap.hxx:84
static sal_Int32 getTokenFromUnicode(std::u16string_view rUnicodeName)
Returns the token identifier for the passed Unicode token name.
Definition: tokenmap.cxx:77
sal_Int32 mnAlphaTokens[26]
Definition: tokenmap.hxx:85
static sal_Int32 getTokenPerfectHash(const char *pToken, sal_Int32 nLength)
Definition: tokenmap.cxx:84
static const css::uno::Sequence< sal_Int8 > EMPTY_BYTE_SEQ
Definition: tokenmap.hxx:81
TokenMap & StaticTokenMap()
Definition: tokenmap.cxx:90
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
XML_TOKEN_INVALID
signed char sal_Int8
sal_Int32 nLength