merged tag ooo/OOO330_m14
[LibreOffice.git] / sc / source / filter / inc / xistring.hxx
bloba6f00d26d2e21749f3ceba882adbd4363c31c076
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
28 #ifndef SC_XISTRING_HXX
29 #define SC_XISTRING_HXX
31 #include "xlstring.hxx"
33 // Byte/Unicode strings =======================================================
35 class XclImpStream;
37 /** This class represents an unformatted or formatted string and provides importing from stream. */
38 class XclImpString
40 public:
41 /** Constructs an empty string. */
42 explicit XclImpString();
43 /** Constructs an unformatted string. */
44 explicit XclImpString( const String& rString );
46 ~XclImpString();
48 /** Reads a complete string from the passed stream. */
49 void Read( XclImpStream& rStrm, XclStrFlags nFlags = EXC_STR_DEFAULT );
51 /** Sets the passed string data. */
52 inline void SetText( const String& rText ) { maString = rText; }
53 /** Sets the passed formatting buffer. */
54 inline void SetFormats( const XclFormatRunVec& rFormats ) { maFormats = rFormats; }
55 /** Insert a formatting run to the format buffer. */
56 inline void AppendFormat( sal_uInt16 nChar, sal_uInt16 nFontIdx ) { AppendFormat( maFormats, nChar, nFontIdx ); }
57 /** Reads and appends the formatting information (run count and runs) from stream. */
58 inline void ReadFormats( XclImpStream& rStrm ) { ReadFormats( rStrm, maFormats ); }
59 /** Reads and appends nRunCount formatting runs from stream. */
60 inline void ReadFormats( XclImpStream& rStrm, sal_uInt16 nRunCount ) { ReadFormats( rStrm, maFormats, nRunCount ); }
61 /** Reads and appends formatting runs from an OBJ or TXO record. */
62 inline void ReadObjFormats( XclImpStream& rStrm, sal_uInt16 nFormatSize ) { ReadObjFormats( rStrm, maFormats, nFormatSize ); }
64 /** Returns true, if the string is empty. */
65 inline bool IsEmpty() const { return maString.Len() == 0; }
66 /** Returns the pure text data of the string. */
67 inline const String& GetText() const { return maString; }
69 /** Returns true, if the string contains formatting information. */
70 inline bool IsRich() const { return !maFormats.empty(); }
71 /** Returns the formatting run vector. */
72 inline const XclFormatRunVec& GetFormats() const { return maFormats; }
74 /** Insert a formatting run to the passed format buffer. */
75 static void AppendFormat( XclFormatRunVec& rFormats, sal_uInt16 nChar, sal_uInt16 nFontIdx );
76 /** Reads and appends the formatting information (run count and runs) from stream. */
77 static void ReadFormats( XclImpStream& rStrm, XclFormatRunVec& rFormats );
78 /** Reads and appends nRunCount formatting runs from stream. */
79 static void ReadFormats( XclImpStream& rStrm, XclFormatRunVec& rFormats, sal_uInt16 nRunCount );
80 /** Reads and appends formatting runs from an OBJ or TXO record. */
81 static void ReadObjFormats( XclImpStream& rStrm, XclFormatRunVec& rFormats, sal_uInt16 nFormatSize );
83 private:
84 String maString; /// The text data of the string.
85 XclFormatRunVec maFormats; /// All formatting runs.
88 // String iterator ============================================================
90 /** Iterates over formatted string portions. */
91 class XclImpStringIterator
93 public:
94 explicit XclImpStringIterator( const XclImpString& rString );
96 /** Returns true, if the iterator references a valid text portion. */
97 inline bool Is() const { return mnTextBeg < mrText.Len(); }
98 /** Returns the index of the current text portion. */
99 inline size_t GetPortionIndex() const { return mnPortion; }
100 /** Returns the string of the current text portion. */
101 String GetPortionText() const;
102 /** Returns the font index of the current text portion. */
103 sal_uInt16 GetPortionFont() const;
105 /** Moves iterator to next text portion. */
106 XclImpStringIterator& operator++();
108 private:
109 const String& mrText; /// The processed string.
110 const XclFormatRunVec& mrFormats; /// The vector of formatting runs.
111 size_t mnPortion; /// Current text portion.
112 xub_StrLen mnTextBeg; /// First character of current portion.
113 xub_StrLen mnTextEnd; /// First character of next portion.
114 size_t mnFormatsBeg; /// Formatting run index for current portion.
115 size_t mnFormatsEnd; /// Formatting run index for next portion.
118 // ============================================================================
120 #endif