1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: OOXMLFastTokenHandler.cxx,v $
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 ************************************************************************/
33 #include <ooxml/resourceids.hxx>
34 #include "OOXMLFastTokenHandler.hxx"
35 #include "gperffasttoken.hxx"
37 namespace writerfilter
{
41 using namespace ::std
;
43 OOXMLFastTokenHandler::OOXMLFastTokenHandler
44 (css::uno::Reference
< css::uno::XComponentContext
> const & 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());
60 nResult
= pToken
->nToken
;
64 << OUStringToOString(Identifier
, RTL_TEXTENCODING_ASCII_US
).getStr()
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
);
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());
109 nResult
= pToken
->nToken
;
112 clog
<< "getTokenFromUTF8: "
113 << string(reinterpret_cast<const char *>
114 (Identifier
.getConstArray()), Identifier
.getLength())
116 << (pToken
== NULL
? ", failed" : "") << endl
;