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 .
22 #include <ooxml/resourceids.hxx>
23 #include "OOXMLFastTokenHandler.hxx"
26 #if __has_warning("-Wdeprecated-register")
27 #pragma GCC diagnostic push
28 #pragma GCC diagnostic ignored "-Wdeprecated-register"
31 #include "gperffasttoken.hxx"
33 #if __has_warning("-Wdeprecated-register")
34 #pragma GCC diagnostic pop
38 namespace writerfilter
{
42 using namespace ::std
;
44 OOXMLFastTokenHandler::OOXMLFastTokenHandler
45 (css::uno::Reference
< css::uno::XComponentContext
> const & 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());
61 nResult
= pToken
->nToken
;
65 << OUStringToOString(Identifier
, RTL_TEXTENCODING_ASCII_US
).getStr()
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
;
95 clog
<< "getTokenFromUTF8: "
96 << string(pStr
, nLength
)
98 << (pToken
== NULL
? ", failed" : "") << endl
;
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: */