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  */
23 #include <sal/config.h>
25 #include <string_view>
27 #include "xlstring.hxx"
28 #include "ftools.hxx"
30 class XclExpStream;
31 class XclExpXmlStream;
49 {
50 public:
51  // constructors -----------------------------------------------------------
56  explicit XclExpString(
58  sal_uInt16 nMaxLen = EXC_STR_MAXLEN );
63  explicit XclExpString(
64  const OUString& rString,
66  sal_uInt16 nMaxLen = EXC_STR_MAXLEN );
68  // assign -----------------------------------------------------------------
73  void Assign(
74  const OUString& rString,
76  sal_uInt16 nMaxLen = EXC_STR_MAXLEN );
79  void Assign( sal_Unicode cChar );
84  void AssignByte(
85  std::u16string_view rString,
86  rtl_TextEncoding eTextEnc,
88  sal_uInt16 nMaxLen = EXC_STR_MAXLEN );
90  // append -----------------------------------------------------------------
94  void Append( const OUString& rString );
98  void AppendByte( std::u16string_view rString, rtl_TextEncoding eTextEnc );
101  void AppendByte( sal_Unicode cChar, rtl_TextEncoding eTextEnc );
103  // formatting runs --------------------------------------------------------
106  void AppendFormat( sal_uInt16 nChar, sal_uInt16 nFontIdx, bool bDropDuplicate = true );
108  void AppendTrailingFormat( sal_uInt16 nFontIdx );
110  void LimitFormatCount( sal_uInt16 nMaxCount );
112  sal_uInt16 GetLeadingFont();
114  sal_uInt16 RemoveLeadingFont();
116  // get data ---------------------------------------------------------------
119  sal_uInt16 Len() const { return mnLen; }
121  bool IsEmpty() const { return mnLen == 0; }
123  bool IsWrapped() const { return mbWrapped; }
125  bool IsEqual( const XclExpString& rCmp ) const;
127  bool IsLessThan( const XclExpString& rCmp ) const;
130  bool IsRich() const { return !maFormats.empty(); }
132  sal_uInt16 GetFormatsCount() const;
134  const XclFormatRunVec& GetFormats() const { return maFormats; }
137  sal_uInt8 GetFlagField() const;
139  sal_uInt16 GetHeaderSize() const;
141  std::size_t GetBufferSize() const;
143  std::size_t GetSize() const;
146  sal_uInt16 GetChar( sal_uInt16 nCharIdx ) const;
148  sal_uInt16 GetHash() const;
150  const ScfUInt16Vec& GetUnicodeBuffer() const { return maUniBuffer; }
152  // streaming --------------------------------------------------------------
155  void WriteLenField( XclExpStream& rStrm ) const;
157  void WriteFlagField( XclExpStream& rStrm ) const;
159  void WriteHeader( XclExpStream& rStrm ) const;
161  void WriteBuffer( XclExpStream& rStrm ) const;
163  void WriteFormats( XclExpStream& rStrm, bool bWriteSize = false ) const;
165  void Write( XclExpStream& rStrm ) const;
168  void WriteHeaderToMem( sal_uInt8* pnMem ) const;
170  void WriteBufferToMem( sal_uInt8* pnMem ) const;
172  void WriteToMem( sal_uInt8* pnMem ) const;
174  void WriteXml( XclExpXmlStream& rStrm ) const;
176 private:
178  bool IsWriteFlags() const;
180  bool IsWriteFormats() const;
183  void SetStrLen( sal_Int32 nNewLen );
187  void CharsToBuffer( const sal_Unicode* pcSource, sal_Int32 nBegin, sal_Int32 nLen );
191  void CharsToBuffer( const char* pcSource, sal_Int32 nBegin, sal_Int32 nLen );
198  void Init( sal_Int32 nCurrLen, XclStrFlags nFlags, sal_uInt16 nMaxLen, bool bBiff8 );
204  void Build(
205  const sal_Unicode* pcSource, sal_Int32 nCurrLen,
206  XclStrFlags nFlags, sal_uInt16 nMaxLen );
212  void Build(
213  const char* pcSource, sal_Int32 nCurrLen,
214  XclStrFlags nFlags, sal_uInt16 nMaxLen );
218  void InitAppend( sal_Int32 nAddLen );
222  void BuildAppend( const sal_Unicode* pcSource, sal_Int32 nAddLen );
226  void BuildAppend( const char* pcSource, sal_Int32 nAddLen );
229  void PrepareWrite( XclExpStream& rStrm, sal_uInt16 nBytes ) const;
231 private:
235  sal_uInt16 mnLen;
236  sal_uInt16 mnMaxLen;
237  bool mbIsBiff8;
238  bool mbIsUnicode;
239  bool mb8BitLen;
242  bool mbWrapped;
244 };
246 inline bool operator==( const XclExpString& rLeft, const XclExpString& rRight )
247 {
248  return rLeft.IsEqual( rRight );
249 }
251 inline bool operator!=( const XclExpString& rLeft, const XclExpString& rRight )
252 {
253  return !(rLeft == rRight);
254 }
256 inline bool operator<( const XclExpString& rLeft, const XclExpString& rRight )
257 {
258  return rLeft.IsLessThan( rRight );
259 }
261 inline XclExpStream& operator<<( XclExpStream& rStrm, const XclExpString& rString )
262 {
263  rString.Write( rStrm );
264  return rStrm;
265 }
267 #endif
269 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
This class stores an unformatted or formatted string for Excel export.
Definition: xestring.hxx:48
::std::vector< sal_uInt8 > ScfUInt8Vec
Definition: ftools.hxx:254
const sal_uInt16 EXC_STR_MAXLEN
Definition: xlstring.hxx:43
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:241
bool operator!=(const XclExpString &rLeft, const XclExpString &rRight)
Definition: xestring.hxx:251
This class is used to export Excel record streams.
Definition: xestream.hxx:73
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:29
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:256
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:134
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:261
bool IsEmpty() const
Returns true, if the string is empty.
Definition: xestring.hxx:121
bool mbSmartFlags
true = write 8-bit string length; false = 16-bit.
Definition: xestring.hxx:240
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:235
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:85
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:238
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:239
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:150
ScfUInt16Vec maUniBuffer
Definition: xestring.hxx:232
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:234
bool IsWrapped() const
Returns true, if the string contains line breaks.
Definition: xestring.hxx:123
sal_uInt16 Len() const
Returns the character count of the string.
Definition: xestring.hxx:119
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:256
bool IsRich() const
Returns true, if the string contains formatting information.
Definition: xestring.hxx:130
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:237
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:246
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:243
sal_uInt16 mnMaxLen
Character count to export.
Definition: xestring.hxx:236
ScfUInt8Vec maCharBuffer
The Unicode character buffer.
Definition: xestring.hxx:233
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:242