merge the formfield patch from ooo-build
[ooovba.git] / writerfilter / source / ooxml / OOXMLFastTokenHandler.cxx
blob6b81b1aa0bedd53ff2fded64c918ebe8bb270712
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: OOXMLFastTokenHandler.cxx,v $
10 * $Revision: 1.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include <iostream>
32 #include <string.h>
33 #include <ooxml/resourceids.hxx>
34 #include "OOXMLFastTokenHandler.hxx"
35 #include "gperffasttoken.hxx"
37 namespace writerfilter {
38 namespace ooxml
41 using namespace ::std;
43 OOXMLFastTokenHandler::OOXMLFastTokenHandler
44 (css::uno::Reference< css::uno::XComponentContext > const & context)
45 : m_xContext(context)
48 // ::com::sun::star::xml::sax::XFastTokenHandler:
49 ::sal_Int32 SAL_CALL OOXMLFastTokenHandler::getToken(const ::rtl::OUString & Identifier)
50 throw (css::uno::RuntimeException)
52 ::sal_Int32 nResult = OOXML_FAST_TOKENS_END;
54 struct tokenmap::token * pToken =
55 tokenmap::Perfect_Hash::in_word_set
56 (OUStringToOString(Identifier, RTL_TEXTENCODING_ASCII_US).getStr(),
57 Identifier.getLength());
59 if (pToken != NULL)
60 nResult = pToken->nToken;
62 #ifdef DEBUG_TOKEN
63 clog << "getToken: "
64 << OUStringToOString(Identifier, RTL_TEXTENCODING_ASCII_US).getStr()
65 << ", " << nResult
66 << endl;
67 #endif
69 return nResult;
72 ::rtl::OUString SAL_CALL OOXMLFastTokenHandler::getIdentifier(::sal_Int32 Token)
73 throw (css::uno::RuntimeException)
75 ::rtl::OUString sResult;
77 if ( Token >= 0 || Token < OOXML_FAST_TOKENS_END )
79 static ::rtl::OUString aTokens[OOXML_FAST_TOKENS_END];
81 if (aTokens[Token].getLength() == 0)
82 aTokens[Token] = ::rtl::OUString::createFromAscii
83 (tokenmap::wordlist[Token].name);
86 return sResult;
89 css::uno::Sequence< ::sal_Int8 > SAL_CALL OOXMLFastTokenHandler::getUTF8Identifier(::sal_Int32 Token)
90 throw (css::uno::RuntimeException)
92 if ( Token < 0 || Token >= OOXML_FAST_TOKENS_END )
93 return css::uno::Sequence< ::sal_Int8 >();
95 return css::uno::Sequence< ::sal_Int8 >(reinterpret_cast< const sal_Int8 *>(tokenmap::wordlist[Token].name), strlen(tokenmap::wordlist[Token].name));
98 ::sal_Int32 SAL_CALL OOXMLFastTokenHandler::getTokenFromUTF8
99 (const css::uno::Sequence< ::sal_Int8 > & Identifier) throw (css::uno::RuntimeException)
101 ::sal_Int32 nResult = OOXML_FAST_TOKENS_END;
103 struct tokenmap::token * pToken =
104 tokenmap::Perfect_Hash::in_word_set
105 (reinterpret_cast<const char *>(Identifier.getConstArray()),
106 Identifier.getLength());
108 if (pToken != NULL)
109 nResult = pToken->nToken;
111 #ifdef DEBUG_TOKEN
112 clog << "getTokenFromUTF8: "
113 << string(reinterpret_cast<const char *>
114 (Identifier.getConstArray()), Identifier.getLength())
115 << ", " << nResult
116 << (pToken == NULL ? ", failed" : "") << endl;
117 #endif
119 return nResult;