Bump version to 4.1-6
[LibreOffice.git] / writerfilter / source / ooxml / OOXMLFastTokenHandler.cxx
blob3dbf3086f20ed5d0f473ea7137984e13f8e80eec
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"
24 #include "gperffasttoken.hxx"
26 namespace writerfilter {
27 namespace ooxml
30 using namespace ::std;
32 OOXMLFastTokenHandler::OOXMLFastTokenHandler
33 (css::uno::Reference< css::uno::XComponentContext > const & context)
34 : m_xContext(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());
48 if (pToken != NULL)
49 nResult = pToken->nToken;
51 #ifdef DEBUG_TOKEN
52 clog << "getToken: "
53 << OUStringToOString(Identifier, RTL_TEXTENCODING_ASCII_US).getStr()
54 << ", " << nResult
55 << endl;
56 #endif
58 return nResult;
61 OUString SAL_CALL OOXMLFastTokenHandler::getIdentifier(::sal_Int32 Token)
62 throw (css::uno::RuntimeException)
64 OUString sResult;
66 #if 0
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);
76 #else
77 (void) Token;
78 #endif
80 return sResult;
83 css::uno::Sequence< ::sal_Int8 > SAL_CALL OOXMLFastTokenHandler::getUTF8Identifier(::sal_Int32 Token)
84 throw (css::uno::RuntimeException)
86 #if 0
87 if ( Token < 0 || Token >= OOXML_FAST_TOKENS_END )
88 #endif
89 return css::uno::Sequence< ::sal_Int8 >();
91 #if 0
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));
94 #else
95 (void) Token;
96 #endif
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());
109 if (pToken != NULL)
110 nResult = pToken->nToken;
112 #ifdef DEBUG_TOKEN
113 clog << "getTokenFromUTF8: "
114 << string(reinterpret_cast<const char *>
115 (Identifier.getConstArray()), Identifier.getLength())
116 << ", " << nResult
117 << (pToken == NULL ? ", failed" : "") << endl;
118 #endif
120 return nResult;
125 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */