Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <iostream>
21 : #include <string.h>
22 : #include <ooxml/resourceids.hxx>
23 : #include "OOXMLFastTokenHandler.hxx"
24 : #include "gperffasttoken.hxx"
25 :
26 : namespace writerfilter {
27 : namespace ooxml
28 : {
29 :
30 : using namespace ::std;
31 :
32 1464 : OOXMLFastTokenHandler::OOXMLFastTokenHandler
33 : (css::uno::Reference< css::uno::XComponentContext > const & context)
34 1464 : : m_xContext(context)
35 1464 : {}
36 :
37 : // ::com::sun::star::xml::sax::XFastTokenHandler:
38 0 : ::sal_Int32 SAL_CALL OOXMLFastTokenHandler::getToken(const OUString & Identifier)
39 : throw (css::uno::RuntimeException)
40 : {
41 0 : ::sal_Int32 nResult = OOXML_FAST_TOKENS_END;
42 :
43 : struct tokenmap::token * pToken =
44 : tokenmap::Perfect_Hash::in_word_set
45 : (OUStringToOString(Identifier, RTL_TEXTENCODING_ASCII_US).getStr(),
46 0 : Identifier.getLength());
47 :
48 0 : if (pToken != NULL)
49 0 : nResult = pToken->nToken;
50 :
51 : #ifdef DEBUG_TOKEN
52 : clog << "getToken: "
53 : << OUStringToOString(Identifier, RTL_TEXTENCODING_ASCII_US).getStr()
54 : << ", " << nResult
55 : << endl;
56 : #endif
57 :
58 0 : return nResult;
59 : }
60 :
61 0 : OUString SAL_CALL OOXMLFastTokenHandler::getIdentifier(::sal_Int32 Token)
62 : throw (css::uno::RuntimeException)
63 : {
64 0 : OUString sResult;
65 :
66 : #if 0
67 : //FIXME this is broken: tokenmap::wordlist is not indexed by Token!
68 : if ( Token >= 0 || Token < OOXML_FAST_TOKENS_END )
69 : {
70 : static OUString aTokens[OOXML_FAST_TOKENS_END];
71 :
72 : if (aTokens[Token].getLength() == 0)
73 : aTokens[Token] = OUString::createFromAscii
74 : (tokenmap::wordlist[Token].name);
75 : }
76 : #else
77 : (void) Token;
78 : #endif
79 :
80 0 : return sResult;
81 : }
82 :
83 0 : css::uno::Sequence< ::sal_Int8 > SAL_CALL OOXMLFastTokenHandler::getUTF8Identifier(::sal_Int32 Token)
84 : throw (css::uno::RuntimeException)
85 : {
86 : #if 0
87 : if ( Token < 0 || Token >= OOXML_FAST_TOKENS_END )
88 : #endif
89 0 : return css::uno::Sequence< ::sal_Int8 >();
90 :
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
97 : }
98 :
99 143959 : ::sal_Int32 SAL_CALL OOXMLFastTokenHandler::getTokenFromUTF8
100 : (const css::uno::Sequence< ::sal_Int8 > & Identifier) throw (css::uno::RuntimeException)
101 : {
102 143959 : ::sal_Int32 nResult = OOXML_FAST_TOKENS_END;
103 :
104 : struct tokenmap::token * pToken =
105 : tokenmap::Perfect_Hash::in_word_set
106 143959 : (reinterpret_cast<const char *>(Identifier.getConstArray()),
107 287918 : Identifier.getLength());
108 :
109 143959 : if (pToken != NULL)
110 143812 : nResult = pToken->nToken;
111 :
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
119 :
120 143959 : return nResult;
121 : }
122 :
123 24 : }}
124 :
125 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|