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 .
22 #include <rtl/ustring.hxx>
23 #include "xlstring.hxx"
25 // Byte/Unicode strings =======================================================
29 /** This class represents an unformatted or formatted string and provides importing from stream. */
33 /** Constructs an empty string. */
34 explicit XclImpString();
35 /** Constructs an unformatted string. */
36 explicit XclImpString( OUString aString
);
38 /** Reads a complete string from the passed stream. */
39 void Read( XclImpStream
& rStrm
, XclStrFlags nFlags
= XclStrFlags::NONE
);
41 /** Sets the passed string data. */
42 void SetText( const OUString
& rText
) { maString
= rText
; }
43 /** Sets the passed formatting buffer. */
44 void SetFormats( XclFormatRunVec
&& rFormats
) { maFormats
= std::move(rFormats
); }
45 /** Reads and appends the formatting information (run count and runs) from stream. */
46 void ReadFormats( XclImpStream
& rStrm
) { ReadFormats( rStrm
, maFormats
); }
47 /** Reads and appends formatting runs from an OBJ or TXO record. */
48 void ReadObjFormats( XclImpStream
& rStrm
, sal_uInt16 nFormatSize
) { ReadObjFormats( rStrm
, maFormats
, nFormatSize
); }
50 /** Returns true, if the string is empty. */
51 bool IsEmpty() const { return maString
.isEmpty(); }
52 /** Returns the pure text data of the string. */
53 const OUString
& GetText() const { return maString
; }
55 /** Returns true, if the string contains formatting information. */
56 bool IsRich() const { return !maFormats
.empty(); }
57 /** Returns the formatting run vector. */
58 const XclFormatRunVec
& GetFormats() const { return maFormats
; }
60 /** Insert a formatting run to the passed format buffer. */
61 static void AppendFormat( XclFormatRunVec
& rFormats
, sal_uInt16 nChar
, sal_uInt16 nFontIdx
);
62 /** Reads and appends the formatting information (run count and runs) from stream. */
63 static void ReadFormats( XclImpStream
& rStrm
, XclFormatRunVec
& rFormats
);
64 /** Reads and appends nRunCount formatting runs from stream. */
65 static void ReadFormats( XclImpStream
& rStrm
, XclFormatRunVec
& rFormats
, sal_uInt16 nRunCount
);
66 /** Reads and appends formatting runs from an OBJ or TXO record. */
67 static void ReadObjFormats( XclImpStream
& rStrm
, XclFormatRunVec
& rFormats
, sal_uInt16 nFormatSize
);
70 OUString maString
; /// The text data of the string.
71 XclFormatRunVec maFormats
; /// All formatting runs.
74 // String iterator ============================================================
76 /** Iterates over formatted string portions. */
77 class XclImpStringIterator
80 explicit XclImpStringIterator( const XclImpString
& rString
);
82 /** Returns true, if the iterator references a valid text portion. */
83 bool Is() const { return mnTextBeg
< mrText
.getLength(); }
84 /** Returns the index of the current text portion. */
85 size_t GetPortionIndex() const { return mnPortion
; }
86 /** Returns the string of the current text portion. */
87 OUString
GetPortionText() const;
88 /** Returns the font index of the current text portion. */
89 sal_uInt16
GetPortionFont() const;
91 /** Moves iterator to next text portion. */
92 XclImpStringIterator
& operator++();
95 const OUString
& mrText
; /// The processed string.
96 const XclFormatRunVec
& mrFormats
; /// The vector of formatting runs.
97 size_t mnPortion
; /// Current text portion.
98 sal_Int32 mnTextBeg
; /// First character of current portion.
99 sal_Int32 mnTextEnd
; /// First character of next portion.
100 size_t mnFormatsBeg
; /// Formatting run index for current portion.
101 size_t mnFormatsEnd
; /// Formatting run index for next portion.
104 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */