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