1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_SC_SOURCE_FILTER_INC_XISTRING_HXX
21 #define INCLUDED_SC_SOURCE_FILTER_INC_XISTRING_HXX
23 #include <rtl/ustring.hxx>
24 #include "xlstring.hxx"
26 // Byte/Unicode strings =======================================================
30 /** This class represents an unformatted or formatted string and provides importing from stream. */
34 /** Constructs an empty string. */
35 explicit XclImpString();
36 /** Constructs an unformatted string. */
37 explicit XclImpString( const OUString
& rString
);
41 /** Reads a complete string from the passed stream. */
42 void Read( XclImpStream
& rStrm
, XclStrFlags nFlags
= XclStrFlags::NONE
);
44 /** Sets the passed string data. */
45 void SetText( const OUString
& rText
) { maString
= rText
; }
46 /** Sets the passed formatting buffer. */
47 void SetFormats( const XclFormatRunVec
& rFormats
) { maFormats
= rFormats
; }
48 /** Reads and appends the formatting information (run count and runs) from stream. */
49 void ReadFormats( XclImpStream
& rStrm
) { ReadFormats( rStrm
, maFormats
); }
50 /** Reads and appends formatting runs from an OBJ or TXO record. */
51 void ReadObjFormats( XclImpStream
& rStrm
, sal_uInt16 nFormatSize
) { ReadObjFormats( rStrm
, maFormats
, nFormatSize
); }
53 /** Returns true, if the string is empty. */
54 bool IsEmpty() const { return maString
.isEmpty(); }
55 /** Returns the pure text data of the string. */
56 const OUString
& GetText() const { return maString
; }
58 /** Returns true, if the string contains formatting information. */
59 bool IsRich() const { return !maFormats
.empty(); }
60 /** Returns the formatting run vector. */
61 const XclFormatRunVec
& GetFormats() const { return maFormats
; }
63 /** Insert a formatting run to the passed format buffer. */
64 static void AppendFormat( XclFormatRunVec
& rFormats
, sal_uInt16 nChar
, sal_uInt16 nFontIdx
);
65 /** Reads and appends the formatting information (run count and runs) from stream. */
66 static void ReadFormats( XclImpStream
& rStrm
, XclFormatRunVec
& rFormats
);
67 /** Reads and appends nRunCount formatting runs from stream. */
68 static void ReadFormats( XclImpStream
& rStrm
, XclFormatRunVec
& rFormats
, sal_uInt16 nRunCount
);
69 /** Reads and appends formatting runs from an OBJ or TXO record. */
70 static void ReadObjFormats( XclImpStream
& rStrm
, XclFormatRunVec
& rFormats
, sal_uInt16 nFormatSize
);
73 OUString maString
; /// The text data of the string.
74 XclFormatRunVec maFormats
; /// All formatting runs.
77 // String iterator ============================================================
79 /** Iterates over formatted string portions. */
80 class XclImpStringIterator
83 explicit XclImpStringIterator( const XclImpString
& rString
);
85 /** Returns true, if the iterator references a valid text portion. */
86 bool Is() const { return mnTextBeg
< mrText
.getLength(); }
87 /** Returns the index of the current text portion. */
88 size_t GetPortionIndex() const { return mnPortion
; }
89 /** Returns the string of the current text portion. */
90 OUString
GetPortionText() const;
91 /** Returns the font index of the current text portion. */
92 sal_uInt16
GetPortionFont() const;
94 /** Moves iterator to next text portion. */
95 XclImpStringIterator
& operator++();
98 const OUString
& mrText
; /// The processed string.
99 const XclFormatRunVec
& mrFormats
; /// The vector of formatting runs.
100 size_t mnPortion
; /// Current text portion.
101 sal_Int32 mnTextBeg
; /// First character of current portion.
102 sal_Int32 mnTextEnd
; /// First character of next portion.
103 size_t mnFormatsBeg
; /// Formatting run index for current portion.
104 size_t mnFormatsEnd
; /// Formatting run index for next portion.
109 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */