LibreOffice Module xmloff (master) 1
fasttokenhandler.hxx
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
10#pragma once
11
12#include <com/sun/star/xml/sax/XFastTokenHandler.hpp>
14#include <sax/fastattribs.hxx>
15#include <xmloff/token/tokens.hxx>
16#include <sal/log.hxx>
17#include <xmloff/dllapi.h>
18
19namespace xmloff::token {
20
22{
23public:
24 explicit TokenMap();
25 ~TokenMap();
26
28 css::uno::Sequence< sal_Int8 > const & getUtf8TokenName( sal_Int32 nToken ) const
29 {
30 SAL_WARN_IF(nToken < 0 || nToken >= XML_TOKEN_COUNT, "xmloff", "Wrong nToken parameter");
31 if( 0 <= nToken && nToken < XML_TOKEN_COUNT )
32 return maTokenNamesUtf8[ nToken ];
33 return EMPTY_BYTE_SEQ;
34 }
35
36 const OUString& getTokenName( sal_Int32 nToken ) const
37 {
38 SAL_WARN_IF(nToken < 0 || nToken >= XML_TOKEN_COUNT, "xmloff", "Wrong nToken parameter");
39 if( 0 <= nToken && nToken < XML_TOKEN_COUNT )
40 return maTokenNames[ nToken ];
41 return EMPTY_STRING;
42 }
43
45 static sal_Int32 getTokenFromUtf8( const css::uno::Sequence< sal_Int8 >& rUtf8Name )
46 {
47 return getTokenFromUTF8( reinterpret_cast< const char* >(
48 rUtf8Name.getConstArray() ), rUtf8Name.getLength() );
49 }
50
52 static sal_Int32 getTokenFromUTF8( const char *pToken, sal_Int32 nLength )
53 {
54 return getTokenPerfectHash( pToken, nLength );
55 }
56
57private:
58 static sal_Int32 getTokenPerfectHash( const char *pToken, sal_Int32 nLength );
59
60 std::vector< css::uno::Sequence< sal_Int8 > > maTokenNamesUtf8;
61 std::vector< OUString > maTokenNames;
62
63 static const css::uno::Sequence< sal_Int8 > EMPTY_BYTE_SEQ;
64 static const OUString EMPTY_STRING;
65};
66
68
69class FastTokenHandler final :
71{
72public:
73 explicit FastTokenHandler();
74 virtual ~FastTokenHandler() override;
75
76 // XFastTokenHandler
77 virtual css::uno::Sequence< sal_Int8 > SAL_CALL getUTF8Identifier( sal_Int32 nToken ) override;
78 virtual sal_Int32 SAL_CALL getTokenFromUTF8( const css::uno::Sequence< sal_Int8 >& Identifier ) override;
79
80 const OUString & getIdentifier( sal_Int32 nToken ) const;
81
82 // Much faster direct C++ shortcut to the method that matters
83 virtual sal_Int32 getTokenDirect( const char *pToken, sal_Int32 nLength ) const override;
84
85private:
87};
88
89} // namespace xmloff::token
90
91/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual sal_Int32 getTokenDirect(const char *pToken, sal_Int32 nLength) const override
const OUString & getIdentifier(sal_Int32 nToken) const
virtual css::uno::Sequence< sal_Int8 > SAL_CALL getUTF8Identifier(sal_Int32 nToken) override
virtual sal_Int32 SAL_CALL getTokenFromUTF8(const css::uno::Sequence< sal_Int8 > &Identifier) override
css::uno::Sequence< sal_Int8 > const & getUtf8TokenName(sal_Int32 nToken) const
Returns the UTF-8 name of the passed token identifier as byte sequence.
const OUString & getTokenName(sal_Int32 nToken) const
static sal_Int32 getTokenFromUtf8(const css::uno::Sequence< sal_Int8 > &rUtf8Name)
Returns the token identifier for the passed UTF-8 token name.
static sal_Int32 getTokenPerfectHash(const char *pToken, sal_Int32 nLength)
static const OUString EMPTY_STRING
static const css::uno::Sequence< sal_Int8 > EMPTY_BYTE_SEQ
std::vector< css::uno::Sequence< sal_Int8 > > maTokenNamesUtf8
static sal_Int32 getTokenFromUTF8(const char *pToken, sal_Int32 nLength)
Returns the token identifier for a UTF-8 string.
std::vector< OUString > maTokenNames
#define SAL_WARN_IF(condition, area, stream)
Handling of tokens in XML:
TokenMap & StaticTokenMap()
DefTokenId nToken
sal_Int32 nLength
Definition: xmltoken.cxx:38