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 .
20 #ifndef INCLUDED_SAX_INC_XML2UTF_HXX
21 #define INCLUDED_SAX_INC_XML2UTF_HXX
23 #include <sal/config.h>
27 #include <sal/types.h>
28 #include <rtl/string.hxx>
30 #include <com/sun/star/io/XInputStream.hpp>
32 namespace sax_expatwrap
{
34 class Text2UnicodeConverter
38 Text2UnicodeConverter( const OString
& sEncoding
);
39 ~Text2UnicodeConverter();
41 css::uno::Sequence
< sal_Unicode
> convert( const css::uno::Sequence
<sal_Int8
> & );
42 bool canContinue() const { return m_bCanContinue
; }
45 void init( rtl_TextEncoding encoding
);
47 rtl_TextToUnicodeConverter m_convText2Unicode
;
48 rtl_TextToUnicodeContext m_contextText2Unicode
;
51 css::uno::Sequence
<sal_Int8
> m_seqSource
;
54 /*----------------------------------------
56 * Unicode2TextConverter
58 **-----------------------------------------*/
59 class Unicode2TextConverter
62 Unicode2TextConverter( rtl_TextEncoding encoding
);
63 ~Unicode2TextConverter();
65 css::uno::Sequence
<sal_Int8
> convert( const sal_Unicode
* , sal_Int32 nLength
);
68 rtl_UnicodeToTextConverter m_convUnicode2Text
;
69 rtl_UnicodeToTextContext m_contextUnicode2Text
;
70 css::uno::Sequence
<sal_Unicode
> m_seqSource
;
74 /*----------------------------------------
76 * XMLFile2UTFConverter
78 **-----------------------------------------*/
79 class XMLFile2UTFConverter
82 XMLFile2UTFConverter( ):
86 void setInputStream( css::uno::Reference
< css::io::XInputStream
> const &r
) { m_in
= r
; }
87 void setEncoding( const OString
&s
) { m_sEncoding
= s
; }
90 // @param nMaxToRead The number of chars, that should be read. Note that this is no exact number. There
91 // may be returned less or more bytes than ordered.
92 /// @throws css::io::IOException
93 /// @throws css::io::NotConnectedException
94 /// @throws css::io::BufferSizeExceededException
95 /// @throws css::uno::RuntimeException
96 sal_Int32
readAndConvert( css::uno::Sequence
<sal_Int8
> &seq
, sal_Int32 nMaxToRead
);
100 // Called only on first Sequence of bytes. Tries to figure out file format and encoding information.
101 // @return TRUE, when encoding information could be retrieved
102 // @return FALSE, when no encoding information was found in file
103 bool scanForEncoding( css::uno::Sequence
<sal_Int8
> &seq
);
105 // Called only on first Sequence of bytes. Tries to figure out
106 // if enough data is available to scan encoding
107 // @return TRUE, when encoding is retrievable
108 // @return FALSE, when more data is needed
109 static bool isEncodingRecognizable( const css::uno::Sequence
< sal_Int8
> & seq
);
111 // When encoding attribute is within the text (in the first line), it is removed.
112 static void removeEncoding( css::uno::Sequence
<sal_Int8
> &seq
);
114 // Initializes decoding depending on m_sEncoding setting
115 void initializeDecoding();
117 css::uno::Reference
< css::io::XInputStream
> m_in
;
122 std::unique_ptr
<Text2UnicodeConverter
> m_pText2Unicode
;
123 std::unique_ptr
<Unicode2TextConverter
> m_pUnicode2Text
;
127 #endif // INCLUDED_SAX_INC_XML2UTF_HXX
129 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */