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 "xlstring.hxx"
25 class XclExpStream;
26 class XclExpXmlStream;
44 {
45 public:
46  // constructors -----------------------------------------------------------
51  explicit XclExpString(
53  sal_uInt16 nMaxLen = EXC_STR_MAXLEN );
58  explicit XclExpString(
59  const OUString& rString,
61  sal_uInt16 nMaxLen = EXC_STR_MAXLEN );
63  // assign -----------------------------------------------------------------
68  void Assign(
69  const OUString& rString,
71  sal_uInt16 nMaxLen = EXC_STR_MAXLEN );
74  void Assign( sal_Unicode cChar );
79  void AssignByte(
80  const OUString& rString,
81  rtl_TextEncoding eTextEnc,
83  sal_uInt16 nMaxLen = EXC_STR_MAXLEN );
85  // append -----------------------------------------------------------------
89  void Append( const OUString& rString );
93  void AppendByte( const OUString& rString, rtl_TextEncoding eTextEnc );
96  void AppendByte( sal_Unicode cChar, rtl_TextEncoding eTextEnc );
98  // formatting runs --------------------------------------------------------
101  void AppendFormat( sal_uInt16 nChar, sal_uInt16 nFontIdx, bool bDropDuplicate = true );
103  void AppendTrailingFormat( sal_uInt16 nFontIdx );
105  void LimitFormatCount( sal_uInt16 nMaxCount );
107  sal_uInt16 GetLeadingFont();
109  sal_uInt16 RemoveLeadingFont();
111  // get data ---------------------------------------------------------------
114  sal_uInt16 Len() const { return mnLen; }
116  bool IsEmpty() const { return mnLen == 0; }
118  bool IsWrapped() const { return mbWrapped; }
120  bool IsEqual( const XclExpString& rCmp ) const;
122  bool IsLessThan( const XclExpString& rCmp ) const;
125  bool IsRich() const { return !maFormats.empty(); }
127  sal_uInt16 GetFormatsCount() const;
129  const XclFormatRunVec& GetFormats() const { return maFormats; }
132  sal_uInt8 GetFlagField() const;
134  sal_uInt16 GetHeaderSize() const;
136  std::size_t GetBufferSize() const;
138  std::size_t GetSize() const;
141  sal_uInt16 GetChar( sal_uInt16 nCharIdx ) const;
143  sal_uInt16 GetHash() const;
145  const ScfUInt16Vec& GetUnicodeBuffer() const { return maUniBuffer; }
147  // streaming --------------------------------------------------------------
150  void WriteLenField( XclExpStream& rStrm ) const;
152  void WriteFlagField( XclExpStream& rStrm ) const;
154  void WriteHeader( XclExpStream& rStrm ) const;
156  void WriteBuffer( XclExpStream& rStrm ) const;
158  void WriteFormats( XclExpStream& rStrm, bool bWriteSize = false ) const;
160  void Write( XclExpStream& rStrm ) const;
163  void WriteHeaderToMem( sal_uInt8* pnMem ) const;
165  void WriteBufferToMem( sal_uInt8* pnMem ) const;
167  void WriteToMem( sal_uInt8* pnMem ) const;
169  void WriteXml( XclExpXmlStream& rStrm ) const;
171 private:
173  bool IsWriteFlags() const;
175  bool IsWriteFormats() const;
178  void SetStrLen( sal_Int32 nNewLen );
182  void CharsToBuffer( const sal_Unicode* pcSource, sal_Int32 nBegin, sal_Int32 nLen );
186  void CharsToBuffer( const char* pcSource, sal_Int32 nBegin, sal_Int32 nLen );
193  void Init( sal_Int32 nCurrLen, XclStrFlags nFlags, sal_uInt16 nMaxLen, bool bBiff8 );
199  void Build(
200  const sal_Unicode* pcSource, sal_Int32 nCurrLen,
201  XclStrFlags nFlags, sal_uInt16 nMaxLen );
207  void Build(
208  const char* pcSource, sal_Int32 nCurrLen,
209  XclStrFlags nFlags, sal_uInt16 nMaxLen );
213  void InitAppend( sal_Int32 nAddLen );
217  void BuildAppend( const sal_Unicode* pcSource, sal_Int32 nAddLen );
221  void BuildAppend( const char* pcSource, sal_Int32 nAddLen );
224  void PrepareWrite( XclExpStream& rStrm, sal_uInt16 nBytes ) const;
226 private:
230  sal_uInt16 mnLen;
231  sal_uInt16 mnMaxLen;
232  bool mbIsBiff8;
233  bool mbIsUnicode;
234  bool mb8BitLen;
237  bool mbWrapped;
239 };
241 inline bool operator==( const XclExpString& rLeft, const XclExpString& rRight )
242 {
243  return rLeft.IsEqual( rRight );
244 }
246 inline bool operator!=( const XclExpString& rLeft, const XclExpString& rRight )
247 {
248  return !(rLeft == rRight);
249 }
251 inline bool operator<( const XclExpString& rLeft, const XclExpString& rRight )
252 {
253  return rLeft.IsLessThan( rRight );
254 }
256 inline XclExpStream& operator<<( XclExpStream& rStrm, const XclExpString& rString )
257 {
258  rString.Write( rStrm );
259  return rStrm;
260 }
262 #endif
264 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
This class stores an unformatted or formatted string for Excel export.
Definition: xestring.hxx:43
::std::vector< sal_uInt8 > ScfUInt8Vec
Definition: ftools.hxx:251
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:454
bool mbSkipFormats
true = omit flags on empty string; false = always write flags.
Definition: xestring.hxx:236
bool operator!=(const XclExpString &rLeft, const XclExpString &rRight)
Definition: xestring.hxx:246
This class is used to export Excel record streams.
Definition: xestream.hxx:71
void WriteToMem(sal_uInt8 *pnMem) const
Writes the entire string to memory.
Definition: xestring.cxx:389
void WriteFormats(XclExpStream &rStrm, bool bWriteSize=false) const
Writes the raw formatting run buffer.
Definition: xestring.cxx:312
void WriteBuffer(XclExpStream &rStrm) const
Writes the raw character buffer.
Definition: xestring.cxx:304
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:444
bool operator<(const XclExpString &rLeft, const XclExpString &rRight)
Definition: xestring.hxx:251
void AppendFormat(sal_uInt16 nChar, sal_uInt16 nFontIdx, bool bDropDuplicate=true)
Appends a formatting run.
Definition: xestring.cxx:162
const XclFormatRunVec & GetFormats() const
Returns the vector with all formatting runs.
Definition: xestring.hxx:129
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
void WriteLenField(XclExpStream &rStrm) const
Writes the string length field (1 byte or 2 bytes).
Definition: xestring.cxx:271
bool IsEqual(const XclExpString &rCmp) const
Returns true, if this string is equal to the passed string.
Definition: xestring.cxx:201
XclExpStream & operator<<(XclExpStream &rStrm, const XclExpString &rString)
Definition: xestring.hxx:256
bool IsEmpty() const
Returns true, if the string is empty.
Definition: xestring.hxx:116
bool mbSmartFlags
true = write 8-bit string length; false = 16-bit.
Definition: xestring.hxx:235
sal_uInt8 GetFlagField() const
Returns the current string flags field to export.
Definition: xestring.cxx:230
sal_uInt16 RemoveLeadingFont()
The same as above + additionally remove the given font from the formatting run.
Definition: xestring.cxx:191
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
sal_uInt16 mnLen
All formatting runs.
Definition: xestring.hxx:230
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:366
void AssignByte(const OUString &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
::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:131
void WriteXml(XclExpXmlStream &rStrm) const
Definition: xestring.cxx:417
void WriteHeader(XclExpStream &rStrm) const
Writes 8-bit or 16-bit length field and string flags field.
Definition: xestring.cxx:289
bool mbIsUnicode
true = BIFF8 Unicode string, false = BIFF2-7 bytestring.
Definition: xestring.hxx:233
void BuildAppend(const sal_Unicode *pcSource, sal_Int32 nAddLen)
Appends the given Unicode array to the character buffer.
Definition: xestring.cxx:537
void AppendTrailingFormat(sal_uInt16 nFontIdx)
Appends a trailing formatting run with the passed font index.
Definition: xestring.cxx:170
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:234
void PrepareWrite(XclExpStream &rStrm, sal_uInt16 nBytes) const
Initializes write process on stream.
Definition: xestring.cxx:559
sal_uInt16 GetHash() const
Returns a hash value for the string.
Definition: xestring.cxx:262
const ScfUInt16Vec & GetUnicodeBuffer() const
Definition: xestring.hxx:145
ScfUInt16Vec maUniBuffer
Definition: xestring.hxx:227
sal_uInt16 GetFormatsCount() const
Returns the current count of formatting runs for rich strings.
Definition: xestring.cxx:225
XclFormatRunVec maFormats
The byte character buffer.
Definition: xestring.hxx:229
bool IsWrapped() const
Returns true, if the string contains line breaks.
Definition: xestring.hxx:118
sal_uInt16 Len() const
Returns the character count of the string.
Definition: xestring.hxx:114
sal_uInt16 GetLeadingFont()
Returns the font index of the first char in the formatting run, or EXC_FONT_NOTFOUND.
Definition: xestring.cxx:181
::std::vector< sal_uInt16 > ScfUInt16Vec
Definition: ftools.hxx:253
bool IsRich() const
Returns true, if the string contains formatting information.
Definition: xestring.hxx:125
unsigned char sal_uInt8
bool mbIsBiff8
Maximum allowed number of characters.
Definition: xestring.hxx:232
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
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:256
bool IsLessThan(const XclExpString &rCmp) const
Returns true, if this string is less than the passed string.
Definition: xestring.cxx:215
bool operator==(const XclExpString &rLeft, const XclExpString &rRight)
Definition: xestring.hxx:241
sal_uInt16 GetHeaderSize() const
Returns the byte count the header will take on export.
Definition: xestring.cxx:235
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 InitAppend(sal_Int32 nAddLen)
Initializes string length and resizes character buffers for appending operation.
Definition: xestring.cxx:528
void Write(XclExpStream &rStrm) const
Writes the complete Unicode string.
Definition: xestring.cxx:336
bool mbSkipHeader
true = text contains several paragraphs.
Definition: xestring.hxx:238
sal_uInt16 mnMaxLen
Character count to export.
Definition: xestring.hxx:231
void AppendByte(const OUString &rString, rtl_TextEncoding eTextEnc)
Appends a string.
Definition: xestring.cxx:136
ScfUInt8Vec maCharBuffer
The Unicode character buffer.
Definition: xestring.hxx:228
void WriteFlagField(XclExpStream &rStrm) const
Writes the string flags field (1 byte).
Definition: xestring.cxx:279
void WriteHeaderToMem(sal_uInt8 *pnMem) const
Writes the string header to memory.
Definition: xestring.cxx:345
std::size_t GetBufferSize() const
Returns the byte count the character buffer will take on export.
Definition: xestring.cxx:243
bool IsWriteFormats() const
Returns true, if the formatting run vector should be written.
Definition: xestring.cxx:449
bool mbWrapped
true = skip formats on export; false = write complete formatted string.
Definition: xestring.hxx:237