1*38d50f7bSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*38d50f7bSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*38d50f7bSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*38d50f7bSAndrew Rist * distributed with this work for additional information 6*38d50f7bSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*38d50f7bSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*38d50f7bSAndrew Rist * "License"); you may not use this file except in compliance 9*38d50f7bSAndrew Rist * with the License. You may obtain a copy of the License at 10*38d50f7bSAndrew Rist * 11*38d50f7bSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*38d50f7bSAndrew Rist * 13*38d50f7bSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*38d50f7bSAndrew Rist * software distributed under the License is distributed on an 15*38d50f7bSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*38d50f7bSAndrew Rist * KIND, either express or implied. See the License for the 17*38d50f7bSAndrew Rist * specific language governing permissions and limitations 18*38d50f7bSAndrew Rist * under the License. 19*38d50f7bSAndrew Rist * 20*38d50f7bSAndrew Rist *************************************************************/ 21*38d50f7bSAndrew Rist 22*38d50f7bSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef SC_XISTRING_HXX 25cdf0e10cSrcweir #define SC_XISTRING_HXX 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include "xlstring.hxx" 28cdf0e10cSrcweir 29cdf0e10cSrcweir // Byte/Unicode strings ======================================================= 30cdf0e10cSrcweir 31cdf0e10cSrcweir class XclImpStream; 32cdf0e10cSrcweir 33cdf0e10cSrcweir /** This class represents an unformatted or formatted string and provides importing from stream. */ 34cdf0e10cSrcweir class XclImpString 35cdf0e10cSrcweir { 36cdf0e10cSrcweir public: 37cdf0e10cSrcweir /** Constructs an empty string. */ 38cdf0e10cSrcweir explicit XclImpString(); 39cdf0e10cSrcweir /** Constructs an unformatted string. */ 40cdf0e10cSrcweir explicit XclImpString( const String& rString ); 41cdf0e10cSrcweir 42cdf0e10cSrcweir ~XclImpString(); 43cdf0e10cSrcweir 44cdf0e10cSrcweir /** Reads a complete string from the passed stream. */ 45cdf0e10cSrcweir void Read( XclImpStream& rStrm, XclStrFlags nFlags = EXC_STR_DEFAULT ); 46cdf0e10cSrcweir 47cdf0e10cSrcweir /** Sets the passed string data. */ SetText(const String & rText)48cdf0e10cSrcweir inline void SetText( const String& rText ) { maString = rText; } 49cdf0e10cSrcweir /** Sets the passed formatting buffer. */ SetFormats(const XclFormatRunVec & rFormats)50cdf0e10cSrcweir inline void SetFormats( const XclFormatRunVec& rFormats ) { maFormats = rFormats; } 51cdf0e10cSrcweir /** Insert a formatting run to the format buffer. */ AppendFormat(sal_uInt16 nChar,sal_uInt16 nFontIdx)52cdf0e10cSrcweir inline void AppendFormat( sal_uInt16 nChar, sal_uInt16 nFontIdx ) { AppendFormat( maFormats, nChar, nFontIdx ); } 53cdf0e10cSrcweir /** Reads and appends the formatting information (run count and runs) from stream. */ ReadFormats(XclImpStream & rStrm)54cdf0e10cSrcweir inline void ReadFormats( XclImpStream& rStrm ) { ReadFormats( rStrm, maFormats ); } 55cdf0e10cSrcweir /** Reads and appends nRunCount formatting runs from stream. */ ReadFormats(XclImpStream & rStrm,sal_uInt16 nRunCount)56cdf0e10cSrcweir inline void ReadFormats( XclImpStream& rStrm, sal_uInt16 nRunCount ) { ReadFormats( rStrm, maFormats, nRunCount ); } 57cdf0e10cSrcweir /** Reads and appends formatting runs from an OBJ or TXO record. */ ReadObjFormats(XclImpStream & rStrm,sal_uInt16 nFormatSize)58cdf0e10cSrcweir inline void ReadObjFormats( XclImpStream& rStrm, sal_uInt16 nFormatSize ) { ReadObjFormats( rStrm, maFormats, nFormatSize ); } 59cdf0e10cSrcweir 60cdf0e10cSrcweir /** Returns true, if the string is empty. */ IsEmpty() const61cdf0e10cSrcweir inline bool IsEmpty() const { return maString.Len() == 0; } 62cdf0e10cSrcweir /** Returns the pure text data of the string. */ GetText() const63cdf0e10cSrcweir inline const String& GetText() const { return maString; } 64cdf0e10cSrcweir 65cdf0e10cSrcweir /** Returns true, if the string contains formatting information. */ IsRich() const66cdf0e10cSrcweir inline bool IsRich() const { return !maFormats.empty(); } 67cdf0e10cSrcweir /** Returns the formatting run vector. */ GetFormats() const68cdf0e10cSrcweir inline const XclFormatRunVec& GetFormats() const { return maFormats; } 69cdf0e10cSrcweir 70cdf0e10cSrcweir /** Insert a formatting run to the passed format buffer. */ 71cdf0e10cSrcweir static void AppendFormat( XclFormatRunVec& rFormats, sal_uInt16 nChar, sal_uInt16 nFontIdx ); 72cdf0e10cSrcweir /** Reads and appends the formatting information (run count and runs) from stream. */ 73cdf0e10cSrcweir static void ReadFormats( XclImpStream& rStrm, XclFormatRunVec& rFormats ); 74cdf0e10cSrcweir /** Reads and appends nRunCount formatting runs from stream. */ 75cdf0e10cSrcweir static void ReadFormats( XclImpStream& rStrm, XclFormatRunVec& rFormats, sal_uInt16 nRunCount ); 76cdf0e10cSrcweir /** Reads and appends formatting runs from an OBJ or TXO record. */ 77cdf0e10cSrcweir static void ReadObjFormats( XclImpStream& rStrm, XclFormatRunVec& rFormats, sal_uInt16 nFormatSize ); 78cdf0e10cSrcweir 79cdf0e10cSrcweir private: 80cdf0e10cSrcweir String maString; /// The text data of the string. 81cdf0e10cSrcweir XclFormatRunVec maFormats; /// All formatting runs. 82cdf0e10cSrcweir }; 83cdf0e10cSrcweir 84cdf0e10cSrcweir // String iterator ============================================================ 85cdf0e10cSrcweir 86cdf0e10cSrcweir /** Iterates over formatted string portions. */ 87cdf0e10cSrcweir class XclImpStringIterator 88cdf0e10cSrcweir { 89cdf0e10cSrcweir public: 90cdf0e10cSrcweir explicit XclImpStringIterator( const XclImpString& rString ); 91cdf0e10cSrcweir 92cdf0e10cSrcweir /** Returns true, if the iterator references a valid text portion. */ Is() const93cdf0e10cSrcweir inline bool Is() const { return mnTextBeg < mrText.Len(); } 94cdf0e10cSrcweir /** Returns the index of the current text portion. */ GetPortionIndex() const95cdf0e10cSrcweir inline size_t GetPortionIndex() const { return mnPortion; } 96cdf0e10cSrcweir /** Returns the string of the current text portion. */ 97cdf0e10cSrcweir String GetPortionText() const; 98cdf0e10cSrcweir /** Returns the font index of the current text portion. */ 99cdf0e10cSrcweir sal_uInt16 GetPortionFont() const; 100cdf0e10cSrcweir 101cdf0e10cSrcweir /** Moves iterator to next text portion. */ 102cdf0e10cSrcweir XclImpStringIterator& operator++(); 103cdf0e10cSrcweir 104cdf0e10cSrcweir private: 105cdf0e10cSrcweir const String& mrText; /// The processed string. 106cdf0e10cSrcweir const XclFormatRunVec& mrFormats; /// The vector of formatting runs. 107cdf0e10cSrcweir size_t mnPortion; /// Current text portion. 108cdf0e10cSrcweir xub_StrLen mnTextBeg; /// First character of current portion. 109cdf0e10cSrcweir xub_StrLen mnTextEnd; /// First character of next portion. 110cdf0e10cSrcweir size_t mnFormatsBeg; /// Formatting run index for current portion. 111cdf0e10cSrcweir size_t mnFormatsEnd; /// Formatting run index for next portion. 112cdf0e10cSrcweir }; 113cdf0e10cSrcweir 114cdf0e10cSrcweir // ============================================================================ 115cdf0e10cSrcweir 116cdf0e10cSrcweir #endif 117cdf0e10cSrcweir 118