Version 6.1.4.1, tag libreoffice-6.1.4.1
[LibreOffice.git] / sax / inc / xml2utf.hxx
blob0a26c1f81482924102ad4921194fb7f07ec0c2c1
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 #ifndef INCLUDED_SAX_INC_XML2UTF_HXX
21 #define INCLUDED_SAX_INC_XML2UTF_HXX
23 #include <sal/types.h>
25 namespace sax_expatwrap {
27 class Text2UnicodeConverter
30 public:
31 Text2UnicodeConverter( const OString & sEncoding );
32 ~Text2UnicodeConverter();
34 css::uno::Sequence < sal_Unicode > convert( const css::uno::Sequence<sal_Int8> & );
35 bool canContinue() const { return m_bCanContinue; }
37 private:
38 void init( rtl_TextEncoding encoding );
40 rtl_TextToUnicodeConverter m_convText2Unicode;
41 rtl_TextToUnicodeContext m_contextText2Unicode;
42 bool m_bCanContinue;
43 bool m_bInitialized;
44 css::uno::Sequence<sal_Int8> m_seqSource;
47 /*----------------------------------------
49 * Unicode2TextConverter
51 **-----------------------------------------*/
52 class Unicode2TextConverter
54 public:
55 Unicode2TextConverter( rtl_TextEncoding encoding );
56 ~Unicode2TextConverter();
58 css::uno::Sequence<sal_Int8> convert( const sal_Unicode * , sal_Int32 nLength );
60 private:
61 rtl_UnicodeToTextConverter m_convUnicode2Text;
62 rtl_UnicodeToTextContext m_contextUnicode2Text;
63 css::uno::Sequence<sal_Unicode> m_seqSource;
67 /*----------------------------------------
69 * XMLFile2UTFConverter
71 **-----------------------------------------*/
72 class XMLFile2UTFConverter
74 public:
75 XMLFile2UTFConverter( ):
76 m_bStarted( false ),
77 m_pText2Unicode( nullptr ),
78 m_pUnicode2Text( nullptr )
81 ~XMLFile2UTFConverter();
83 void setInputStream( css::uno::Reference< css::io::XInputStream > const &r ) { m_in = r; }
84 void setEncoding( const OString &s ) { m_sEncoding = s; }
87 // @param nMaxToRead The number of chars, that should be read. Note that this is no exact number. There
88 // may be returned less or more bytes than ordered.
89 /// @throws css::io::IOException
90 /// @throws css::io::NotConnectedException
91 /// @throws css::io::BufferSizeExceededException
92 /// @throws css::uno::RuntimeException
93 sal_Int32 readAndConvert( css::uno::Sequence<sal_Int8> &seq , sal_Int32 nMaxToRead );
95 private:
97 // Called only on first Sequence of bytes. Tries to figure out file format and encoding information.
98 // @return TRUE, when encoding information could be retrieved
99 // @return FALSE, when no encoding information was found in file
100 bool scanForEncoding( css::uno::Sequence<sal_Int8> &seq );
102 // Called only on first Sequence of bytes. Tries to figure out
103 // if enough data is available to scan encoding
104 // @return TRUE, when encoding is retrievable
105 // @return FALSE, when more data is needed
106 static bool isEncodingRecognizable( const css::uno::Sequence< sal_Int8 > & seq );
108 // When encoding attribute is within the text (in the first line), it is removed.
109 static void removeEncoding( css::uno::Sequence<sal_Int8> &seq );
111 // Initializes decoding depending on m_sEncoding setting
112 void initializeDecoding();
113 private:
114 css::uno::Reference< css::io::XInputStream > m_in;
116 bool m_bStarted;
117 OString m_sEncoding;
119 Text2UnicodeConverter *m_pText2Unicode;
120 Unicode2TextConverter *m_pUnicode2Text;
124 #endif // INCLUDED_SAX_INC_XML2UTF_HXX
126 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */