1*e3508121SAndrew Rist /************************************************************** 2*e3508121SAndrew Rist * 3*e3508121SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*e3508121SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*e3508121SAndrew Rist * distributed with this work for additional information 6*e3508121SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*e3508121SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*e3508121SAndrew Rist * "License"); you may not use this file except in compliance 9*e3508121SAndrew Rist * with the License. You may obtain a copy of the License at 10*e3508121SAndrew Rist * 11*e3508121SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*e3508121SAndrew Rist * 13*e3508121SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*e3508121SAndrew Rist * software distributed under the License is distributed on an 15*e3508121SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*e3508121SAndrew Rist * KIND, either express or implied. See the License for the 17*e3508121SAndrew Rist * specific language governing permissions and limitations 18*e3508121SAndrew Rist * under the License. 19*e3508121SAndrew Rist * 20*e3508121SAndrew Rist *************************************************************/ 21*e3508121SAndrew Rist 22*e3508121SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef OOX_HELPER_TEXTINPUTSTREAM_HXX 25cdf0e10cSrcweir #define OOX_HELPER_TEXTINPUTSTREAM_HXX 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <com/sun/star/uno/Reference.hxx> 28cdf0e10cSrcweir #include <rtl/ustring.hxx> 29cdf0e10cSrcweir 30cdf0e10cSrcweir namespace com { namespace sun { namespace star { 31cdf0e10cSrcweir namespace io { class XInputStream; } 32cdf0e10cSrcweir namespace io { class XTextInputStream; } 33cdf0e10cSrcweir namespace uno { class XComponentContext; } 34cdf0e10cSrcweir } } } 35cdf0e10cSrcweir 36cdf0e10cSrcweir namespace oox { 37cdf0e10cSrcweir 38cdf0e10cSrcweir class BinaryInputStream; 39cdf0e10cSrcweir 40cdf0e10cSrcweir // ============================================================================ 41cdf0e10cSrcweir 42cdf0e10cSrcweir class TextInputStream 43cdf0e10cSrcweir { 44cdf0e10cSrcweir public: 45cdf0e10cSrcweir explicit TextInputStream( 46cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext, 47cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& rxInStrm, 48cdf0e10cSrcweir rtl_TextEncoding eTextEnc ); 49cdf0e10cSrcweir 50cdf0e10cSrcweir explicit TextInputStream( 51cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext, 52cdf0e10cSrcweir BinaryInputStream& rInStrm, 53cdf0e10cSrcweir rtl_TextEncoding eTextEnc ); 54cdf0e10cSrcweir 55cdf0e10cSrcweir ~TextInputStream(); 56cdf0e10cSrcweir 57cdf0e10cSrcweir /** Returns true, if no more text is available in the stream. 58cdf0e10cSrcweir */ 59cdf0e10cSrcweir bool isEof() const; 60cdf0e10cSrcweir 61cdf0e10cSrcweir /** Reads a text line from the stream. 62cdf0e10cSrcweir 63cdf0e10cSrcweir If the last line in the stream is not terminated with line-end 64cdf0e10cSrcweir character(s), the stream will immediately go into EOF state and return 65cdf0e10cSrcweir the text line. Otherwise, if the last character in the stream is a 66cdf0e10cSrcweir line-end character, the next call to this function will turn the stream 67cdf0e10cSrcweir into EOF state and return an empty string. 68cdf0e10cSrcweir */ 69cdf0e10cSrcweir ::rtl::OUString readLine(); 70cdf0e10cSrcweir 71cdf0e10cSrcweir /** Reads a text portion from the stream until the specified character is 72cdf0e10cSrcweir found. 73cdf0e10cSrcweir 74cdf0e10cSrcweir If the end of the stream is not terminated with the specified 75cdf0e10cSrcweir character, the stream will immediately go into EOF state and return the 76cdf0e10cSrcweir remaining text portion. Otherwise, if the last character in the stream 77cdf0e10cSrcweir is the specified character (and caller specifies to read and return it, 78cdf0e10cSrcweir see parameter bIncludeChar), the next call to this function will turn 79cdf0e10cSrcweir the stream into EOF state and return an empty string. 80cdf0e10cSrcweir 81cdf0e10cSrcweir @param cChar 82cdf0e10cSrcweir The separator character to be read to. 83cdf0e10cSrcweir 84cdf0e10cSrcweir @param bIncludeChar 85cdf0e10cSrcweir True = if found, the specified character will be read from stream 86cdf0e10cSrcweir and included in the returned string. 87cdf0e10cSrcweir False = the specified character will neither be read from the 88cdf0e10cSrcweir stream nor included in the returned string, but will be 89cdf0e10cSrcweir returned as first character in the next call of this function 90cdf0e10cSrcweir or readLine(). 91cdf0e10cSrcweir */ 92cdf0e10cSrcweir ::rtl::OUString readToChar( sal_Unicode cChar, bool bIncludeChar ); 93cdf0e10cSrcweir 94cdf0e10cSrcweir // ------------------------------------------------------------------------ 95cdf0e10cSrcweir 96cdf0e10cSrcweir /** Creates a UNO text input stream object from the passed UNO input stream. 97cdf0e10cSrcweir */ 98cdf0e10cSrcweir static ::com::sun::star::uno::Reference< ::com::sun::star::io::XTextInputStream > 99cdf0e10cSrcweir createXTextInputStream( 100cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext, 101cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& rxInStrm, 102cdf0e10cSrcweir rtl_TextEncoding eTextEnc ); 103cdf0e10cSrcweir 104cdf0e10cSrcweir // ------------------------------------------------------------------------ 105cdf0e10cSrcweir private: 106cdf0e10cSrcweir void init( 107cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext, 108cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& rxInStrm, 109cdf0e10cSrcweir rtl_TextEncoding eTextEnc ); 110cdf0e10cSrcweir 111cdf0e10cSrcweir /** Adds the pending character in front of the passed string, if existing. */ 112cdf0e10cSrcweir ::rtl::OUString createFinalString( const ::rtl::OUString& rString ); 113cdf0e10cSrcweir 114cdf0e10cSrcweir private: 115cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::io::XTextInputStream > 116cdf0e10cSrcweir mxTextStrm; 117cdf0e10cSrcweir sal_Unicode mcPendingChar; 118cdf0e10cSrcweir }; 119cdf0e10cSrcweir 120cdf0e10cSrcweir // ============================================================================ 121cdf0e10cSrcweir 122cdf0e10cSrcweir } // namespace oox 123cdf0e10cSrcweir 124cdf0e10cSrcweir #endif 125