LibreOffice Module sc (master)  1
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
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 .
18  */
20 #pragma once
22 #include <sal/config.h>
24 #include <string_view>
26 #include "xlstring.hxx"
27 #include "ftools.hxx"
29 class XclExpStream;
30 class XclExpXmlStream;
48 {
49 public:
50  // constructors -----------------------------------------------------------
55  explicit XclExpString(
57  sal_uInt16 nMaxLen = EXC_STR_MAXLEN );
62  explicit XclExpString(
63  const OUString& rString,
65  sal_uInt16 nMaxLen = EXC_STR_MAXLEN );
67  // assign -----------------------------------------------------------------
72  void Assign(
73  const OUString& rString,
75  sal_uInt16 nMaxLen = EXC_STR_MAXLEN );
78  void Assign( sal_Unicode cChar );
83  void AssignByte(
84  std::u16string_view rString,
85  rtl_TextEncoding eTextEnc,
87  sal_uInt16 nMaxLen = EXC_STR_MAXLEN );
89  // append -----------------------------------------------------------------
93  void Append( const OUString& rString );
97  void AppendByte( std::u16string_view rString, rtl_TextEncoding eTextEnc );
100  void AppendByte( sal_Unicode cChar, rtl_TextEncoding eTextEnc );
102  // formatting runs --------------------------------------------------------
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();
115  // get data ---------------------------------------------------------------
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;
129  bool IsRich() const { return !maFormats.empty(); }
131  sal_uInt16 GetFormatsCount() const;
133  const XclFormatRunVec& GetFormats() const { return maFormats; }
136  sal_uInt8 GetFlagField() const;
138  sal_uInt16 GetHeaderSize() const;
140  std::size_t GetBufferSize() const;
142  std::size_t GetSize() const;
145  sal_uInt16 GetChar( sal_uInt16 nCharIdx ) const;
147  sal_uInt16 GetHash() const;
149  const ScfUInt16Vec& GetUnicodeBuffer() const { return maUniBuffer; }
151  // streaming --------------------------------------------------------------
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;
167  void WriteHeaderToMem( sal_uInt8* pnMem ) const;
169  void WriteBufferToMem( sal_uInt8* pnMem ) const;
171  void WriteToMem( sal_uInt8* pnMem ) const;
173  void WriteXml( XclExpXmlStream& rStrm ) const;
175 private:
177  bool IsWriteFlags() const;
179  bool IsWriteFormats() const;
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 );
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 );
217  void InitAppend( sal_Int32 nAddLen );
221  void BuildAppend( const sal_Unicode* pcSource, sal_Int32 nAddLen );
225  void BuildAppend( const char* pcSource, sal_Int32 nAddLen );
228  void PrepareWrite( XclExpStream& rStrm, sal_uInt16 nBytes ) const;
230 private:
234  sal_uInt16 mnLen;
235  sal_uInt16 mnMaxLen;
236  bool mbIsBiff8;
237  bool mbIsUnicode;
238  bool mb8BitLen;
241  bool mbWrapped;
243 };
245 inline bool operator==( const XclExpString& rLeft, const XclExpString& rRight )
246 {
247  return rLeft.IsEqual( rRight );
248 }
250 inline bool operator!=( const XclExpString& rLeft, const XclExpString& rRight )
251 {
252  return !(rLeft == rRight);
253 }
255 inline bool operator<( const XclExpString& rLeft, const XclExpString& rRight )
256 {
257  return rLeft.IsLessThan( rRight );
258 }
260 inline XclExpStream& operator<<( XclExpStream& rStrm, const XclExpString& rString )
261 {
262  rString.Write( rStrm );
263  return rStrm;
264 }
266 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
This class stores an unformatted or formatted string for Excel export.
Definition: xestring.hxx:47
::std::vector< sal_uInt8 > ScfUInt8Vec
Definition: ftools.hxx:253
const sal_uInt16 EXC_STR_MAXLEN
Definition: xlstring.hxx:42
void SetStrLen(sal_Int32 nNewLen)
Sets the string length but regards the limit given in mnMaxLen.
Definition: xestring.cxx:455
bool mbSkipFormats
true = omit flags on empty string; false = always write flags.
Definition: xestring.hxx:240
bool operator!=(const XclExpString &rLeft, const XclExpString &rRight)
Definition: xestring.hxx:250
This class is used to export Excel record streams.
Definition: xestream.hxx:72
void WriteToMem(sal_uInt8 *pnMem) const
Writes the entire string to memory.
Definition: xestring.cxx:390
void WriteFormats(XclExpStream &rStrm, bool bWriteSize=false) const
Writes the raw formatting run buffer.
Definition: xestring.cxx:313
void WriteBuffer(XclExpStream &rStrm) const
Writes the raw character buffer.
Definition: xestring.cxx:305
Flags used to specify import/export mode of strings.
Definition: xlstring.hxx:28
bool IsWriteFlags() const
Returns true, if the flag field should be written.
Definition: xestring.cxx:445
bool operator<(const XclExpString &rLeft, const XclExpString &rRight)
Definition: xestring.hxx:255
void AppendFormat(sal_uInt16 nChar, sal_uInt16 nFontIdx, bool bDropDuplicate=true)
Appends a formatting run.
Definition: xestring.cxx:163
const XclFormatRunVec & GetFormats() const
Returns the vector with all formatting runs.
Definition: xestring.hxx:133
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:517
void WriteLenField(XclExpStream &rStrm) const
Writes the string length field (1 byte or 2 bytes).
Definition: xestring.cxx:272
bool IsEqual(const XclExpString &rCmp) const
Returns true, if this string is equal to the passed string.
Definition: xestring.cxx:202
XclExpStream & operator<<(XclExpStream &rStrm, const XclExpString &rString)
Definition: xestring.hxx:260
bool IsEmpty() const
Returns true, if the string is empty.
Definition: xestring.hxx:120
bool mbSmartFlags
true = write 8-bit string length; false = 16-bit.
Definition: xestring.hxx:239
sal_uInt8 GetFlagField() const
Returns the current string flags field to export.
Definition: xestring.cxx:231
sal_uInt16 RemoveLeadingFont()
The same as above + additionally remove the given font from the formatting run.
Definition: xestring.cxx:192
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:461
sal_uInt16 mnLen
All formatting runs.
Definition: xestring.hxx:234
sal_uInt16 sal_Unicode
void WriteBufferToMem(sal_uInt8 *pnMem) const
Writes the raw character buffer to memory (8-bit or 16-bit little-endian).
Definition: xestring.cxx:367
::std::vector< XclFormatRun > XclFormatRunVec
A vector with all formatting runs for a rich-string.
Definition: xlstring.hxx:84
void Append(const OUString &rString)
Appends a string.
Definition: xestring.cxx:132
void WriteXml(XclExpXmlStream &rStrm) const
Definition: xestring.cxx:418
void WriteHeader(XclExpStream &rStrm) const
Writes 8-bit or 16-bit length field and string flags field.
Definition: xestring.cxx:290
bool mbIsUnicode
true = BIFF8 Unicode string, false = BIFF2-7 bytestring.
Definition: xestring.hxx:237
void BuildAppend(const sal_Unicode *pcSource, sal_Int32 nAddLen)
Appends the given Unicode array to the character buffer.
Definition: xestring.cxx:538
void AppendTrailingFormat(sal_uInt16 nFontIdx)
Appends a trailing formatting run with the passed font index.
Definition: xestring.cxx:171
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
bool mb8BitLen
true, if at least one character is >0xFF.
Definition: xestring.hxx:238
void PrepareWrite(XclExpStream &rStrm, sal_uInt16 nBytes) const
Initializes write process on stream.
Definition: xestring.cxx:560
sal_uInt16 GetHash() const
Returns a hash value for the string.
Definition: xestring.cxx:263
const ScfUInt16Vec & GetUnicodeBuffer() const
Definition: xestring.hxx:149
ScfUInt16Vec maUniBuffer
Definition: xestring.hxx:231
sal_uInt16 GetFormatsCount() const
Returns the current count of formatting runs for rich strings.
Definition: xestring.cxx:226
XclFormatRunVec maFormats
The byte character buffer.
Definition: xestring.hxx:233
bool IsWrapped() const
Returns true, if the string contains line breaks.
Definition: xestring.hxx:122
sal_uInt16 Len() const
Returns the character count of the string.
Definition: xestring.hxx:118
sal_uInt16 GetLeadingFont()
Returns the font index of the first char in the formatting run, or EXC_FONT_NOTFOUND.
Definition: xestring.cxx:182
::std::vector< sal_uInt16 > ScfUInt16Vec
Definition: ftools.hxx:255
bool IsRich() const
Returns true, if the string contains formatting information.
Definition: xestring.hxx:129
unsigned char sal_uInt8
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
bool mbIsBiff8
Maximum allowed number of characters.
Definition: xestring.hxx:236
std::size_t GetSize() const
Returns the byte count the whole string will take on export.
Definition: xestring.cxx:249
void LimitFormatCount(sal_uInt16 nMaxCount)
Removes formatting runs at the end, if the string contains too much.
Definition: xestring.cxx:176
XclExpString(XclStrFlags nFlags=XclStrFlags::NONE, sal_uInt16 nMaxLen=EXC_STR_MAXLEN)
Constructs an empty BIFF8 Unicode string.
Definition: xestring.cxx:99
sal_uInt16 GetChar(sal_uInt16 nCharIdx) const
Returns the specified character from the (already encoded) string.
Definition: xestring.cxx:257
bool IsLessThan(const XclExpString &rCmp) const
Returns true, if this string is less than the passed string.
Definition: xestring.cxx:216
bool operator==(const XclExpString &rLeft, const XclExpString &rRight)
Definition: xestring.hxx:245
sal_uInt16 GetHeaderSize() const
Returns the byte count the header will take on export.
Definition: xestring.cxx:236
void AppendByte(std::u16string_view rString, rtl_TextEncoding eTextEnc)
Appends a string.
Definition: xestring.cxx:137
void Init(sal_Int32 nCurrLen, XclStrFlags nFlags, sal_uInt16 nMaxLen, bool bBiff8)
Initializes flags, string length, and resizes character buffer.
Definition: xestring.cxx:492
void InitAppend(sal_Int32 nAddLen)
Initializes string length and resizes character buffers for appending operation.
Definition: xestring.cxx:529
void Write(XclExpStream &rStrm) const
Writes the complete Unicode string.
Definition: xestring.cxx:337
bool mbSkipHeader
true = text contains several paragraphs.
Definition: xestring.hxx:242
sal_uInt16 mnMaxLen
Character count to export.
Definition: xestring.hxx:235
ScfUInt8Vec maCharBuffer
The Unicode character buffer.
Definition: xestring.hxx:232
void WriteFlagField(XclExpStream &rStrm) const
Writes the string flags field (1 byte).
Definition: xestring.cxx:280
void WriteHeaderToMem(sal_uInt8 *pnMem) const
Writes the string header to memory.
Definition: xestring.cxx:346
std::size_t GetBufferSize() const
Returns the byte count the character buffer will take on export.
Definition: xestring.cxx:244
bool IsWriteFormats() const
Returns true, if the formatting run vector should be written.
Definition: xestring.cxx:450
bool mbWrapped
true = skip formats on export; false = write complete formatted string.
Definition: xestring.hxx:241