Bump version to 4.3-4
[LibreOffice.git] / writerfilter / source / ooxml / OOXMLFastTokenHandler.cxx
blobde585f87c6c90c0790e73a7cc65a0a0de7d3614f
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/.
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 <iostream>
21 #include <string.h>
22 #include <ooxml/resourceids.hxx>
23 #include "OOXMLFastTokenHandler.hxx"
25 #if defined __clang__
26 #if __has_warning("-Wdeprecated-register")
27 #pragma GCC diagnostic push
28 #pragma GCC diagnostic ignored "-Wdeprecated-register"
29 #endif
30 #endif
31 #include "gperffasttoken.hxx"
32 #if defined __clang__
33 #if __has_warning("-Wdeprecated-register")
34 #pragma GCC diagnostic pop
35 #endif
36 #endif
38 namespace writerfilter {
39 namespace ooxml
42 using namespace ::std;
44 OOXMLFastTokenHandler::OOXMLFastTokenHandler
45 (css::uno::Reference< css::uno::XComponentContext > const & context)
46 : m_xContext(context)
49 // ::com::sun::star::xml::sax::XFastTokenHandler:
50 ::sal_Int32 SAL_CALL OOXMLFastTokenHandler::getToken(const OUString & Identifier)
51 throw (css::uno::RuntimeException, std::exception)
53 ::sal_Int32 nResult = OOXML_FAST_TOKENS_END;
55 struct tokenmap::token * pToken =
56 tokenmap::Perfect_Hash::in_word_set
57 (OUStringToOString(Identifier, RTL_TEXTENCODING_ASCII_US).getStr(),
58 Identifier.getLength());
60 if (pToken != NULL)
61 nResult = pToken->nToken;
63 #ifdef DEBUG_TOKEN
64 clog << "getToken: "
65 << OUStringToOString(Identifier, RTL_TEXTENCODING_ASCII_US).getStr()
66 << ", " << nResult
67 << endl;
68 #endif
70 return nResult;
73 OUString SAL_CALL OOXMLFastTokenHandler::getIdentifier(::sal_Int32)
74 throw (css::uno::RuntimeException, std::exception)
76 // we use a Boost tokenmap, but tokenmaps cannot be indexed by an integer
77 for (;;) { std::abort(); } // avoid "must return a value" warnings
80 css::uno::Sequence< ::sal_Int8 > SAL_CALL OOXMLFastTokenHandler::getUTF8Identifier(::sal_Int32)
81 throw (css::uno::RuntimeException, std::exception)
83 // we use a Boost tokenmap, but tokenmaps cannot be indexed by an integer
84 for (;;) { std::abort(); } // avoid "must return a value" warnings
87 sal_Int32 OOXMLFastTokenHandler::getTokenDirect( const char *pStr, sal_Int32 nLength ) const
89 struct tokenmap::token * pToken =
90 tokenmap::Perfect_Hash::in_word_set( pStr, nLength );
92 sal_Int32 nResult = pToken != NULL ? pToken->nToken : OOXML_FAST_TOKENS_END;
94 #ifdef DEBUG_TOKEN
95 clog << "getTokenFromUTF8: "
96 << string(pStr, nLength)
97 << ", " << nResult
98 << (pToken == NULL ? ", failed" : "") << endl;
99 #endif
101 return nResult;
104 ::sal_Int32 SAL_CALL OOXMLFastTokenHandler::getTokenFromUTF8
105 (const css::uno::Sequence< ::sal_Int8 > & Identifier) throw (css::uno::RuntimeException, std::exception)
107 return getTokenDirect(reinterpret_cast<const char *>
108 (Identifier.getConstArray()),
109 Identifier.getLength());
114 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */