Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #ifndef SC_XISTRING_HXX
21 : #define SC_XISTRING_HXX
22 :
23 : #include "xlstring.hxx"
24 :
25 : // Byte/Unicode strings =======================================================
26 :
27 : class XclImpStream;
28 :
29 : /** This class represents an unformatted or formatted string and provides importing from stream. */
30 2018 : class XclImpString
31 : {
32 : public:
33 : /** Constructs an empty string. */
34 : explicit XclImpString();
35 : /** Constructs an unformatted string. */
36 : explicit XclImpString( const OUString& rString );
37 :
38 : ~XclImpString();
39 :
40 : /** Reads a complete string from the passed stream. */
41 : void Read( XclImpStream& rStrm, XclStrFlags nFlags = EXC_STR_DEFAULT );
42 :
43 : /** Sets the passed string data. */
44 23 : inline void SetText( const OUString& rText ) { maString = rText; }
45 : /** Sets the passed formatting buffer. */
46 0 : inline void SetFormats( const XclFormatRunVec& rFormats ) { maFormats = rFormats; }
47 : /** Insert a formatting run to the format buffer. */
48 : inline void AppendFormat( sal_uInt16 nChar, sal_uInt16 nFontIdx ) { AppendFormat( maFormats, nChar, nFontIdx ); }
49 : /** Reads and appends the formatting information (run count and runs) from stream. */
50 0 : inline void ReadFormats( XclImpStream& rStrm ) { ReadFormats( rStrm, maFormats ); }
51 : /** Reads and appends nRunCount formatting runs from stream. */
52 39 : inline void ReadFormats( XclImpStream& rStrm, sal_uInt16 nRunCount ) { ReadFormats( rStrm, maFormats, nRunCount ); }
53 : /** Reads and appends formatting runs from an OBJ or TXO record. */
54 20 : inline void ReadObjFormats( XclImpStream& rStrm, sal_uInt16 nFormatSize ) { ReadObjFormats( rStrm, maFormats, nFormatSize ); }
55 :
56 : /** Returns true, if the string is empty. */
57 53 : inline bool IsEmpty() const { return maString.isEmpty(); }
58 : /** Returns the pure text data of the string. */
59 24788 : inline const OUString& GetText() const { return maString; }
60 :
61 : /** Returns true, if the string contains formatting information. */
62 10804 : inline bool IsRich() const { return !maFormats.empty(); }
63 : /** Returns the formatting run vector. */
64 81 : inline const XclFormatRunVec& GetFormats() const { return maFormats; }
65 :
66 : /** Insert a formatting run to the passed format buffer. */
67 : static void AppendFormat( XclFormatRunVec& rFormats, sal_uInt16 nChar, sal_uInt16 nFontIdx );
68 : /** Reads and appends the formatting information (run count and runs) from stream. */
69 : static void ReadFormats( XclImpStream& rStrm, XclFormatRunVec& rFormats );
70 : /** Reads and appends nRunCount formatting runs from stream. */
71 : static void ReadFormats( XclImpStream& rStrm, XclFormatRunVec& rFormats, sal_uInt16 nRunCount );
72 : /** Reads and appends formatting runs from an OBJ or TXO record. */
73 : static void ReadObjFormats( XclImpStream& rStrm, XclFormatRunVec& rFormats, sal_uInt16 nFormatSize );
74 :
75 : private:
76 : OUString maString; /// The text data of the string.
77 : XclFormatRunVec maFormats; /// All formatting runs.
78 : };
79 :
80 : // String iterator ============================================================
81 :
82 : /** Iterates over formatted string portions. */
83 : class XclImpStringIterator
84 : {
85 : public:
86 : explicit XclImpStringIterator( const XclImpString& rString );
87 :
88 : /** Returns true, if the iterator references a valid text portion. */
89 84 : inline bool Is() const { return mnTextBeg < mrText.getLength(); }
90 : /** Returns the index of the current text portion. */
91 21 : inline size_t GetPortionIndex() const { return mnPortion; }
92 : /** Returns the string of the current text portion. */
93 : OUString GetPortionText() const;
94 : /** Returns the font index of the current text portion. */
95 : sal_uInt16 GetPortionFont() const;
96 :
97 : /** Moves iterator to next text portion. */
98 : XclImpStringIterator& operator++();
99 :
100 : private:
101 : const OUString& mrText; /// The processed string.
102 : const XclFormatRunVec& mrFormats; /// The vector of formatting runs.
103 : size_t mnPortion; /// Current text portion.
104 : sal_Int32 mnTextBeg; /// First character of current portion.
105 : sal_Int32 mnTextEnd; /// First character of next portion.
106 : size_t mnFormatsBeg; /// Formatting run index for current portion.
107 : size_t mnFormatsEnd; /// Formatting run index for next portion.
108 : };
109 :
110 : #endif
111 :
112 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|