update dev300-m58
[ooovba.git] / sc / source / filter / inc / xistring.hxx
blob66bc88515d8cc57d9c47037af62ce7c84ca7cfdd
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xistring.hxx,v $
10 * $Revision: 1.4.90.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef SC_XISTRING_HXX
32 #define SC_XISTRING_HXX
34 #include "xlstring.hxx"
36 // Byte/Unicode strings =======================================================
38 class XclImpStream;
40 /** This class represents an unformatted or formatted string and provides importing from stream. */
41 class XclImpString
43 public:
44 /** Constructs an empty string. */
45 explicit XclImpString();
46 /** Constructs an unformatted string. */
47 explicit XclImpString( const String& rString );
49 ~XclImpString();
51 /** Reads a complete string from the passed stream. */
52 void Read( XclImpStream& rStrm, XclStrFlags nFlags = EXC_STR_DEFAULT );
54 /** Sets the passed string data. */
55 inline void SetText( const String& rText ) { maString = rText; }
56 /** Sets the passed formatting buffer. */
57 inline void SetFormats( const XclFormatRunVec& rFormats ) { maFormats = rFormats; }
58 /** Insert a formatting run to the format buffer. */
59 inline void AppendFormat( sal_uInt16 nChar, sal_uInt16 nFontIdx ) { AppendFormat( maFormats, nChar, nFontIdx ); }
60 /** Reads and appends the formatting information (run count and runs) from stream. */
61 inline void ReadFormats( XclImpStream& rStrm ) { ReadFormats( rStrm, maFormats ); }
62 /** Reads and appends nRunCount formatting runs from stream. */
63 inline void ReadFormats( XclImpStream& rStrm, sal_uInt16 nRunCount ) { ReadFormats( rStrm, maFormats, nRunCount ); }
64 /** Reads and appends formatting runs from an OBJ or TXO record. */
65 inline void ReadObjFormats( XclImpStream& rStrm, sal_uInt16 nFormatSize ) { ReadObjFormats( rStrm, maFormats, nFormatSize ); }
67 /** Returns true, if the string is empty. */
68 inline bool IsEmpty() const { return maString.Len() == 0; }
69 /** Returns the pure text data of the string. */
70 inline const String& GetText() const { return maString; }
72 /** Returns true, if the string contains formatting information. */
73 inline bool IsRich() const { return !maFormats.empty(); }
74 /** Returns the formatting run vector. */
75 inline const XclFormatRunVec& GetFormats() const { return maFormats; }
77 /** Insert a formatting run to the passed format buffer. */
78 static void AppendFormat( XclFormatRunVec& rFormats, sal_uInt16 nChar, sal_uInt16 nFontIdx );
79 /** Reads and appends the formatting information (run count and runs) from stream. */
80 static void ReadFormats( XclImpStream& rStrm, XclFormatRunVec& rFormats );
81 /** Reads and appends nRunCount formatting runs from stream. */
82 static void ReadFormats( XclImpStream& rStrm, XclFormatRunVec& rFormats, sal_uInt16 nRunCount );
83 /** Reads and appends formatting runs from an OBJ or TXO record. */
84 static void ReadObjFormats( XclImpStream& rStrm, XclFormatRunVec& rFormats, sal_uInt16 nFormatSize );
86 private:
87 String maString; /// The text data of the string.
88 XclFormatRunVec maFormats; /// All formatting runs.
91 // String iterator ============================================================
93 /** Iterates over formatted string portions. */
94 class XclImpStringIterator
96 public:
97 explicit XclImpStringIterator( const XclImpString& rString );
99 /** Returns true, if the iterator references a valid text portion. */
100 inline bool Is() const { return mnTextBeg < mrText.Len(); }
101 /** Returns the index of the current text portion. */
102 inline size_t GetPortionIndex() const { return mnPortion; }
103 /** Returns the string of the current text portion. */
104 String GetPortionText() const;
105 /** Returns the font index of the current text portion. */
106 sal_uInt16 GetPortionFont() const;
108 /** Moves iterator to next text portion. */
109 XclImpStringIterator& operator++();
111 private:
112 const String& mrText; /// The processed string.
113 const XclFormatRunVec& mrFormats; /// The vector of formatting runs.
114 size_t mnPortion; /// Current text portion.
115 xub_StrLen mnTextBeg; /// First character of current portion.
116 xub_StrLen mnTextEnd; /// First character of next portion.
117 size_t mnFormatsBeg; /// Formatting run index for current portion.
118 size_t mnFormatsEnd; /// Formatting run index for next portion.
121 // ============================================================================
123 #endif