LibreOffice Module sc (master) 1
xestring.hxx
Go to the documentation of this file.
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#pragma once
21
22#include <sal/config.h>
23
24#include <string_view>
25
26#include "xlstring.hxx"
27#include "ftools.hxx"
28
29class XclExpStream;
30class XclExpXmlStream;
31
48{
49public:
50 // constructors -----------------------------------------------------------
51
55 explicit XclExpString(
57 sal_uInt16 nMaxLen = EXC_STR_MAXLEN );
58
62 explicit XclExpString(
63 const OUString& rString,
65 sal_uInt16 nMaxLen = EXC_STR_MAXLEN );
66
67 // assign -----------------------------------------------------------------
68
72 void Assign(
73 const OUString& rString,
75 sal_uInt16 nMaxLen = EXC_STR_MAXLEN );
76
78 void Assign( sal_Unicode cChar );
79
83 void AssignByte(
84 std::u16string_view rString,
85 rtl_TextEncoding eTextEnc,
87 sal_uInt16 nMaxLen = EXC_STR_MAXLEN );
88
89 // append -----------------------------------------------------------------
90
93 void Append( std::u16string_view rString );
94
97 void AppendByte( std::u16string_view rString, rtl_TextEncoding eTextEnc );
100 void AppendByte( sal_Unicode cChar, rtl_TextEncoding eTextEnc );
101
102 // formatting runs --------------------------------------------------------
103
105 void AppendFormat( sal_uInt16 nChar, sal_uInt16 nFontIdx, bool bDropDuplicate = true );
107 void AppendTrailingFormat( sal_uInt16 nFontIdx );
109 void LimitFormatCount( sal_uInt16 nMaxCount );
111 sal_uInt16 GetLeadingFont();
113 sal_uInt16 RemoveLeadingFont();
114
115 // get data ---------------------------------------------------------------
116
118 sal_uInt16 Len() const { return mnLen; }
120 bool IsEmpty() const { return mnLen == 0; }
122 bool IsWrapped() const { return mbWrapped; }
124 bool IsEqual( const XclExpString& rCmp ) const;
126 bool IsLessThan( const XclExpString& rCmp ) const;
127
129 bool IsRich() const { return !maFormats.empty(); }
131 sal_uInt16 GetFormatsCount() const;
133 const XclFormatRunVec& GetFormats() const { return maFormats; }
134
136 sal_uInt8 GetFlagField() const;
138 sal_uInt16 GetHeaderSize() const;
140 std::size_t GetBufferSize() const;
142 std::size_t GetSize() const;
143
145 sal_uInt16 GetChar( sal_uInt16 nCharIdx ) const;
147 sal_uInt16 GetHash() const;
148
149 const ScfUInt16Vec& GetUnicodeBuffer() const { return maUniBuffer; }
150
151 // streaming --------------------------------------------------------------
152
154 void WriteLenField( XclExpStream& rStrm ) const;
156 void WriteFlagField( XclExpStream& rStrm ) const;
158 void WriteHeader( XclExpStream& rStrm ) const;
160 void WriteBuffer( XclExpStream& rStrm ) const;
162 void WriteFormats( XclExpStream& rStrm, bool bWriteSize = false ) const;
164 void Write( XclExpStream& rStrm ) const;
165
167 void WriteHeaderToMem( sal_uInt8* pnMem ) const;
169 void WriteBufferToMem( sal_uInt8* pnMem ) const;
171 void WriteToMem( sal_uInt8* pnMem ) const;
172
173 void WriteXml( XclExpXmlStream& rStrm ) const;
174
175private:
177 bool IsWriteFlags() const;
179 bool IsWriteFormats() const;
180
182 void SetStrLen( sal_Int32 nNewLen );
186 void CharsToBuffer( const sal_Unicode* pcSource, sal_Int32 nBegin, sal_Int32 nLen );
190 void CharsToBuffer( const char* pcSource, sal_Int32 nBegin, sal_Int32 nLen );
191
197 void Init( sal_Int32 nCurrLen, XclStrFlags nFlags, sal_uInt16 nMaxLen, bool bBiff8 );
203 void Build(
204 const sal_Unicode* pcSource, sal_Int32 nCurrLen,
205 XclStrFlags nFlags, sal_uInt16 nMaxLen );
211 void Build(
212 const char* pcSource, sal_Int32 nCurrLen,
213 XclStrFlags nFlags, sal_uInt16 nMaxLen );
214
217 void InitAppend( sal_Int32 nAddLen );
220 void BuildAppend( std::u16string_view );
223 void BuildAppend( std::string_view );
224
226 void PrepareWrite( XclExpStream& rStrm, sal_uInt16 nBytes ) const;
227
228private:
232 sal_uInt16 mnLen;
233 sal_uInt16 mnMaxLen;
241};
242
243inline bool operator==( const XclExpString& rLeft, const XclExpString& rRight )
244{
245 return rLeft.IsEqual( rRight );
246}
247
248inline bool operator!=( const XclExpString& rLeft, const XclExpString& rRight )
249{
250 return !(rLeft == rRight);
251}
252
253inline bool operator<( const XclExpString& rLeft, const XclExpString& rRight )
254{
255 return rLeft.IsLessThan( rRight );
256}
257
258inline XclExpStream& operator<<( XclExpStream& rStrm, const XclExpString& rString )
259{
260 rString.Write( rStrm );
261 return rStrm;
262}
263
264/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
This class is used to export Excel record streams.
Definition: xestream.hxx:73
This class stores an unformatted or formatted string for Excel export.
Definition: xestring.hxx:48
void WriteHeader(XclExpStream &rStrm) const
Writes 8-bit or 16-bit length field and string flags field.
Definition: xestring.cxx:289
bool mb8BitLen
true, if at least one character is >0xFF.
Definition: xestring.hxx:236
bool IsEmpty() const
Returns true, if the string is empty.
Definition: xestring.hxx:120
void WriteFlagField(XclExpStream &rStrm) const
Writes the string flags field (1 byte).
Definition: xestring.cxx:279
void AppendByte(std::u16string_view rString, rtl_TextEncoding eTextEnc)
Appends a string.
Definition: xestring.cxx:137
sal_uInt8 GetFlagField() const
Returns the current string flags field to export.
Definition: xestring.cxx:230
void InitAppend(sal_Int32 nAddLen)
Initializes string length and resizes character buffers for appending operation.
Definition: xestring.cxx:528
void Build(const sal_Unicode *pcSource, sal_Int32 nCurrLen, XclStrFlags nFlags, sal_uInt16 nMaxLen)
Creates the character buffer from the given Unicode array.
Definition: xestring.cxx:516
ScfUInt8Vec maCharBuffer
The Unicode character buffer.
Definition: xestring.hxx:230
void AppendFormat(sal_uInt16 nChar, sal_uInt16 nFontIdx, bool bDropDuplicate=true)
Appends a formatting run.
Definition: xestring.cxx:162
void WriteLenField(XclExpStream &rStrm) const
Writes the string length field (1 byte or 2 bytes).
Definition: xestring.cxx:271
void WriteBufferToMem(sal_uInt8 *pnMem) const
Writes the raw character buffer to memory (8-bit or 16-bit little-endian).
Definition: xestring.cxx:366
void WriteToMem(sal_uInt8 *pnMem) const
Writes the entire string to memory.
Definition: xestring.cxx:389
bool mbSmartFlags
true = write 8-bit string length; false = 16-bit.
Definition: xestring.hxx:237
bool mbSkipHeader
true = text contains several paragraphs.
Definition: xestring.hxx:240
sal_uInt16 GetFormatsCount() const
Returns the current count of formatting runs for rich strings.
Definition: xestring.cxx:225
XclExpString(XclStrFlags nFlags=XclStrFlags::NONE, sal_uInt16 nMaxLen=EXC_STR_MAXLEN)
Constructs an empty BIFF8 Unicode string.
Definition: xestring.cxx:99
const XclFormatRunVec & GetFormats() const
Returns the vector with all formatting runs.
Definition: xestring.hxx:133
void Append(std::u16string_view rString)
Appends a string.
Definition: xestring.cxx:132
void AssignByte(std::u16string_view rString, rtl_TextEncoding eTextEnc, XclStrFlags nFlags=XclStrFlags::NONE, sal_uInt16 nMaxLen=EXC_STR_MAXLEN)
Assigns an unformatted string, converts this object to a BIFF2-BIFF7 byte string.
Definition: xestring.cxx:121
void Init(sal_Int32 nCurrLen, XclStrFlags nFlags, sal_uInt16 nMaxLen, bool bBiff8)
Initializes flags, string length, and resizes character buffer.
Definition: xestring.cxx:491
void CharsToBuffer(const sal_Unicode *pcSource, sal_Int32 nBegin, sal_Int32 nLen)
Inserts the passed character array into the internal character buffer.
Definition: xestring.cxx:460
void SetStrLen(sal_Int32 nNewLen)
Sets the string length but regards the limit given in mnMaxLen.
Definition: xestring.cxx:454
void PrepareWrite(XclExpStream &rStrm, sal_uInt16 nBytes) const
Initializes write process on stream.
Definition: xestring.cxx:559
ScfUInt16Vec maUniBuffer
Definition: xestring.hxx:229
sal_uInt16 GetHeaderSize() const
Returns the byte count the header will take on export.
Definition: xestring.cxx:235
void Assign(const OUString &rString, XclStrFlags nFlags=XclStrFlags::NONE, sal_uInt16 nMaxLen=EXC_STR_MAXLEN)
Assigns an unformatted string, converts this object to a BIFF8 Unicode string.
Definition: xestring.cxx:111
sal_uInt16 mnLen
All formatting runs.
Definition: xestring.hxx:232
bool mbIsUnicode
true = BIFF8 Unicode string, false = BIFF2-7 bytestring.
Definition: xestring.hxx:235
bool IsEqual(const XclExpString &rCmp) const
Returns true, if this string is equal to the passed string.
Definition: xestring.cxx:201
sal_uInt16 mnMaxLen
Character count to export.
Definition: xestring.hxx:233
bool mbWrapped
true = skip formats on export; false = write complete formatted string.
Definition: xestring.hxx:239
bool IsLessThan(const XclExpString &rCmp) const
Returns true, if this string is less than the passed string.
Definition: xestring.cxx:215
bool IsRich() const
Returns true, if the string contains formatting information.
Definition: xestring.hxx:129
void WriteFormats(XclExpStream &rStrm, bool bWriteSize=false) const
Writes the raw formatting run buffer.
Definition: xestring.cxx:312
std::size_t GetSize() const
Returns the byte count the whole string will take on export.
Definition: xestring.cxx:248
void LimitFormatCount(sal_uInt16 nMaxCount)
Removes formatting runs at the end, if the string contains too much.
Definition: xestring.cxx:175
sal_uInt16 GetLeadingFont()
Returns the font index of the first char in the formatting run, or EXC_FONT_NOTFOUND.
Definition: xestring.cxx:181
void BuildAppend(std::u16string_view)
Appends the given Unicode array to the character buffer.
Definition: xestring.cxx:537
XclFormatRunVec maFormats
The byte character buffer.
Definition: xestring.hxx:231
sal_uInt16 GetHash() const
Returns a hash value for the string.
Definition: xestring.cxx:262
std::size_t GetBufferSize() const
Returns the byte count the character buffer will take on export.
Definition: xestring.cxx:243
void WriteXml(XclExpXmlStream &rStrm) const
Definition: xestring.cxx:417
void WriteBuffer(XclExpStream &rStrm) const
Writes the raw character buffer.
Definition: xestring.cxx:304
sal_uInt16 Len() const
Returns the character count of the string.
Definition: xestring.hxx:118
void AppendTrailingFormat(sal_uInt16 nFontIdx)
Appends a trailing formatting run with the passed font index.
Definition: xestring.cxx:170
sal_uInt16 RemoveLeadingFont()
The same as above + additionally remove the given font from the formatting run.
Definition: xestring.cxx:191
bool mbSkipFormats
true = omit flags on empty string; false = always write flags.
Definition: xestring.hxx:238
bool IsWrapped() const
Returns true, if the string contains line breaks.
Definition: xestring.hxx:122
bool mbIsBiff8
Maximum allowed number of characters.
Definition: xestring.hxx:234
sal_uInt16 GetChar(sal_uInt16 nCharIdx) const
Returns the specified character from the (already encoded) string.
Definition: xestring.cxx:256
void WriteHeaderToMem(sal_uInt8 *pnMem) const
Writes the string header to memory.
Definition: xestring.cxx:345
bool IsWriteFormats() const
Returns true, if the formatting run vector should be written.
Definition: xestring.cxx:449
const ScfUInt16Vec & GetUnicodeBuffer() const
Definition: xestring.hxx:149
bool IsWriteFlags() const
Returns true, if the flag field should be written.
Definition: xestring.cxx:444
void Write(XclExpStream &rStrm) const
Writes the complete Unicode string.
Definition: xestring.cxx:336
::std::vector< sal_uInt8 > ScfUInt8Vec
Definition: ftools.hxx:253
::std::vector< sal_uInt16 > ScfUInt16Vec
Definition: ftools.hxx:255
void SvStream & rStrm
unsigned char sal_uInt8
sal_uInt16 sal_Unicode
bool operator!=(const XclExpString &rLeft, const XclExpString &rRight)
Definition: xestring.hxx:248
bool operator<(const XclExpString &rLeft, const XclExpString &rRight)
Definition: xestring.hxx:253
XclExpStream & operator<<(XclExpStream &rStrm, const XclExpString &rString)
Definition: xestring.hxx:258
bool operator==(const XclExpString &rLeft, const XclExpString &rRight)
Definition: xestring.hxx:243
const sal_uInt16 EXC_STR_MAXLEN
Definition: xlstring.hxx:43
::std::vector< XclFormatRun > XclFormatRunVec
A vector with all formatting runs for a rich-string.
Definition: xlstring.hxx:85
XclStrFlags
Flags used to specify import/export mode of strings.
Definition: xlstring.hxx:29