1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #ifndef OOX_HELPER_TEXTINPUTSTREAM_HXX 29 #define OOX_HELPER_TEXTINPUTSTREAM_HXX 30 31 #include <com/sun/star/uno/Reference.hxx> 32 #include <rtl/ustring.hxx> 33 34 namespace com { namespace sun { namespace star { 35 namespace io { class XInputStream; } 36 namespace io { class XTextInputStream; } 37 namespace uno { class XComponentContext; } 38 } } } 39 40 namespace oox { 41 42 class BinaryInputStream; 43 44 // ============================================================================ 45 46 class TextInputStream 47 { 48 public: 49 explicit TextInputStream( 50 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext, 51 const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& rxInStrm, 52 rtl_TextEncoding eTextEnc ); 53 54 explicit TextInputStream( 55 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext, 56 BinaryInputStream& rInStrm, 57 rtl_TextEncoding eTextEnc ); 58 59 ~TextInputStream(); 60 61 /** Returns true, if no more text is available in the stream. 62 */ 63 bool isEof() const; 64 65 /** Reads a text line from the stream. 66 67 If the last line in the stream is not terminated with line-end 68 character(s), the stream will immediately go into EOF state and return 69 the text line. Otherwise, if the last character in the stream is a 70 line-end character, the next call to this function will turn the stream 71 into EOF state and return an empty string. 72 */ 73 ::rtl::OUString readLine(); 74 75 /** Reads a text portion from the stream until the specified character is 76 found. 77 78 If the end of the stream is not terminated with the specified 79 character, the stream will immediately go into EOF state and return the 80 remaining text portion. Otherwise, if the last character in the stream 81 is the specified character (and caller specifies to read and return it, 82 see parameter bIncludeChar), the next call to this function will turn 83 the stream into EOF state and return an empty string. 84 85 @param cChar 86 The separator character to be read to. 87 88 @param bIncludeChar 89 True = if found, the specified character will be read from stream 90 and included in the returned string. 91 False = the specified character will neither be read from the 92 stream nor included in the returned string, but will be 93 returned as first character in the next call of this function 94 or readLine(). 95 */ 96 ::rtl::OUString readToChar( sal_Unicode cChar, bool bIncludeChar ); 97 98 // ------------------------------------------------------------------------ 99 100 /** Creates a UNO text input stream object from the passed UNO input stream. 101 */ 102 static ::com::sun::star::uno::Reference< ::com::sun::star::io::XTextInputStream > 103 createXTextInputStream( 104 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext, 105 const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& rxInStrm, 106 rtl_TextEncoding eTextEnc ); 107 108 // ------------------------------------------------------------------------ 109 private: 110 void init( 111 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext, 112 const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& rxInStrm, 113 rtl_TextEncoding eTextEnc ); 114 115 /** Adds the pending character in front of the passed string, if existing. */ 116 ::rtl::OUString createFinalString( const ::rtl::OUString& rString ); 117 118 private: 119 ::com::sun::star::uno::Reference< ::com::sun::star::io::XTextInputStream > 120 mxTextStrm; 121 sal_Unicode mcPendingChar; 122 }; 123 124 // ============================================================================ 125 126 } // namespace oox 127 128 #endif 129