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"
24 #include "gperffasttoken.hxx"
26 namespace writerfilter
{
30 using namespace ::std
;
32 OOXMLFastTokenHandler::OOXMLFastTokenHandler
33 (css::uno::Reference
< css::uno::XComponentContext
> const & context
)
37 // ::com::sun::star::xml::sax::XFastTokenHandler:
38 ::sal_Int32 SAL_CALL
OOXMLFastTokenHandler::getToken(const OUString
& Identifier
)
39 throw (css::uno::RuntimeException
)
41 ::sal_Int32 nResult
= OOXML_FAST_TOKENS_END
;
43 struct tokenmap::token
* pToken
=
44 tokenmap::Perfect_Hash::in_word_set
45 (OUStringToOString(Identifier
, RTL_TEXTENCODING_ASCII_US
).getStr(),
46 Identifier
.getLength());
49 nResult
= pToken
->nToken
;
53 << OUStringToOString(Identifier
, RTL_TEXTENCODING_ASCII_US
).getStr()
61 OUString SAL_CALL
OOXMLFastTokenHandler::getIdentifier(::sal_Int32 Token
)
62 throw (css::uno::RuntimeException
)
67 //FIXME this is broken: tokenmap::wordlist is not indexed by Token!
68 if ( Token
>= 0 || Token
< OOXML_FAST_TOKENS_END
)
70 static OUString aTokens
[OOXML_FAST_TOKENS_END
];
72 if (aTokens
[Token
].getLength() == 0)
73 aTokens
[Token
] = OUString::createFromAscii
74 (tokenmap::wordlist
[Token
].name
);
83 css::uno::Sequence
< ::sal_Int8
> SAL_CALL
OOXMLFastTokenHandler::getUTF8Identifier(::sal_Int32 Token
)
84 throw (css::uno::RuntimeException
)
87 if ( Token
< 0 || Token
>= OOXML_FAST_TOKENS_END
)
89 return css::uno::Sequence
< ::sal_Int8
>();
92 //FIXME this is broken: tokenmap::wordlist is not indexed by Token!
93 return css::uno::Sequence
< ::sal_Int8
>(reinterpret_cast< const sal_Int8
*>(tokenmap::wordlist
[Token
].name
), strlen(tokenmap::wordlist
[Token
].name
));
99 ::sal_Int32 SAL_CALL
OOXMLFastTokenHandler::getTokenFromUTF8
100 (const css::uno::Sequence
< ::sal_Int8
> & Identifier
) throw (css::uno::RuntimeException
)
102 ::sal_Int32 nResult
= OOXML_FAST_TOKENS_END
;
104 struct tokenmap::token
* pToken
=
105 tokenmap::Perfect_Hash::in_word_set
106 (reinterpret_cast<const char *>(Identifier
.getConstArray()),
107 Identifier
.getLength());
110 nResult
= pToken
->nToken
;
113 clog
<< "getTokenFromUTF8: "
114 << string(reinterpret_cast<const char *>
115 (Identifier
.getConstArray()), Identifier
.getLength())
117 << (pToken
== NULL
? ", failed" : "") << endl
;
125 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */