build fix: no comphelper/profilezone.hxx in this branch
[LibreOffice.git] / include / xmloff / fasttokenhandler.hxx
blobec6ac79073b3eb61c6161df73197d9778da8ad36
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 #ifndef INCLUDED_XMLOFF_FASTTOKENHANDLER_HXX
11 #define INCLUDED_XMLOFF_FASTTOKENHANDLER_HXX
13 #include <com/sun/star/xml/sax/XFastTokenHandler.hpp>
14 #include <cppuhelper/implbase1.hxx>
15 #include <sax/fastattribs.hxx>
16 #include <xmloff/token/tokens.hxx>
17 #include <rtl/instance.hxx>
18 #include <xmloff/dllapi.h>
20 namespace xmloff {
21 namespace token {
23 class TokenMap
25 public:
26 explicit TokenMap();
27 ~TokenMap();
29 /** Returns the token identifier for the passed OUString (UTF-16) token name. */
30 static sal_Int32 getTokenFromUnicode( const OUString& rUnicodeName );
32 /** Returns the UTF-8 name of the passed token identifier as byte sequence. */
33 css::uno::Sequence< sal_Int8 > getUtf8TokenName( sal_Int32 nToken ) const
35 SAL_WARN_IF(nToken < 0 || nToken >= XML_TOKEN_COUNT, "xmloff", "Wrong nToken parameter");
36 if( 0 <= nToken && nToken < XML_TOKEN_COUNT )
37 return maTokenNames[ nToken ];
38 return css::uno::Sequence< sal_Int8 >();
41 /** Returns the token identifier for the passed UTF-8 token name. */
42 static sal_Int32 getTokenFromUtf8( const css::uno::Sequence< sal_Int8 >& rUtf8Name )
44 return getTokenFromUTF8( reinterpret_cast< const char* >(
45 rUtf8Name.getConstArray() ), rUtf8Name.getLength() );
48 /** Returns the token identifier for a UTF-8 string */
49 static sal_Int32 getTokenFromUTF8( const char *pToken, sal_Int32 nLength )
51 return getTokenPerfectHash( pToken, nLength );
54 private:
55 static sal_Int32 getTokenPerfectHash( const char *pToken, sal_Int32 nLength );
57 std::vector< css::uno::Sequence< sal_Int8 > > maTokenNames;
60 struct StaticTokenMap : public rtl::Static< TokenMap, StaticTokenMap > {};
62 class XMLOFF_DLLPUBLIC FastTokenHandler : public cppu::WeakImplHelper1<
63 css::xml::sax::XFastTokenHandler >,
64 public sax_fastparser::FastTokenHandlerBase
66 public:
67 explicit FastTokenHandler();
68 virtual ~FastTokenHandler() override;
70 // XFastTokenHandler
71 virtual css::uno::Sequence< sal_Int8 > SAL_CALL getUTF8Identifier( sal_Int32 nToken )
72 throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
73 virtual sal_Int32 SAL_CALL getTokenFromUTF8( const css::uno::Sequence< sal_Int8 >& Identifier )
74 throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
76 // Much faster direct C++ shortcut to the method that matters
77 virtual sal_Int32 getTokenDirect( const char *pToken, sal_Int32 nLength ) const SAL_OVERRIDE;
79 private:
80 TokenMap& mrTokenMap;
83 } // namespace token
84 } // namespace xmloff
86 #endif
88 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */