LibreOffice Module sc (master)  1
xestring.cxx
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 #include <algorithm>
21 #include <cassert>
22 
23 #include <o3tl/safeint.hxx>
24 #include <osl/diagnose.h>
25 #include <tools/solar.h>
26 #include <xlstyle.hxx>
27 #include <xestyle.hxx>
28 #include <xestream.hxx>
29 #include <xestring.hxx>
30 #include <oox/token/tokens.hxx>
31 
32 using namespace ::oox;
33 
34 namespace {
35 
36 // compare vectors
37 
41 template< typename Type >
42 int lclCompareVectors( const ::std::vector< Type >& rLeft, const ::std::vector< Type >& rRight )
43 {
44  int nResult = 0;
45 
46  // 1st: compare all elements of the vectors
47  auto [aItL, aItR] = std::mismatch(rLeft.begin(), rLeft.end(), rRight.begin(), rRight.end());
48  if ((aItL != rLeft.end()) && (aItR != rRight.end()))
49  nResult = static_cast< int >( *aItL ) - static_cast< int >( *aItR );
50  else
51  // 2nd: compare the vector sizes. Shorter vector is less
52  nResult = static_cast< int >( rLeft.size() ) - static_cast< int >( rRight.size() );
53 
54  return nResult;
55 }
56 
57 // hashing helpers
58 
61 template< typename Type >
62 struct XclHasher {};
63 
64 template< typename Type >
65 struct XclDirectHasher : public XclHasher< Type >
66 {
67  sal_uInt32 operator()( Type nVal ) const { return nVal; }
68 };
69 
70 struct XclFormatRunHasher : public XclHasher< const XclFormatRun& >
71 {
72  sal_uInt32 operator()( const XclFormatRun& rRun ) const
73  { return (rRun.mnChar << 8) ^ rRun.mnFontIdx; }
74 };
75 
79 template< typename Type, typename ValueHasher >
80 sal_uInt16 lclHashVector( const ::std::vector< Type >& rVec, const ValueHasher& rHasher )
81 {
82  sal_uInt32 nHash = rVec.size();
83  for( const auto& rItem : rVec )
84  nHash = (nHash * 31) + rHasher( rItem );
85  return static_cast< sal_uInt16 >( nHash ^ (nHash >> 16) );
86 }
87 
89 template< typename Type >
90 sal_uInt16 lclHashVector( const ::std::vector< Type >& rVec )
91 {
92  return lclHashVector( rVec, XclDirectHasher< Type >() );
93 }
94 
95 } // namespace
96 
97 // constructors ---------------------------------------------------------------
98 
99 XclExpString::XclExpString( XclStrFlags nFlags, sal_uInt16 nMaxLen )
100 {
101  Init( 0, nFlags, nMaxLen, true );
102 }
103 
104 XclExpString::XclExpString( const OUString& rString, XclStrFlags nFlags, sal_uInt16 nMaxLen )
105 {
106  Assign( rString, nFlags, nMaxLen );
107 }
108 
109 // assign ---------------------------------------------------------------------
110 
111 void XclExpString::Assign( const OUString& rString, XclStrFlags nFlags, sal_uInt16 nMaxLen )
112 {
113  Build( rString.getStr(), rString.getLength(), nFlags, nMaxLen );
114 }
115 
117 {
118  Build( &cChar, 1, XclStrFlags::NONE, EXC_STR_MAXLEN );
119 }
120 
122  const OUString& rString, rtl_TextEncoding eTextEnc, XclStrFlags nFlags, sal_uInt16 nMaxLen )
123 {
124  // length may differ from length of rString
125  OString aByteStr(OUStringToOString(rString, eTextEnc));
126  Build(aByteStr.getStr(), aByteStr.getLength(), nFlags, nMaxLen);
127 }
128 
129 // append ---------------------------------------------------------------------
130 
131 void XclExpString::Append( const OUString& rString )
132 {
133  BuildAppend( rString.getStr(), rString.getLength() );
134 }
135 
136 void XclExpString::AppendByte( const OUString& rString, rtl_TextEncoding eTextEnc )
137 {
138  if (!rString.isEmpty())
139  {
140  // length may differ from length of rString
141  OString aByteStr(OUStringToOString(rString, eTextEnc));
142  BuildAppend(aByteStr.getStr(), aByteStr.getLength());
143  }
144 }
145 
146 void XclExpString::AppendByte( sal_Unicode cChar, rtl_TextEncoding eTextEnc )
147 {
148  if( !cChar )
149  {
150  char cByteChar = 0;
151  BuildAppend( &cByteChar, 1 );
152  }
153  else
154  {
155  OString aByteStr( &cChar, 1, eTextEnc ); // length may be >1
156  BuildAppend( aByteStr.getStr(), aByteStr.getLength() );
157  }
158 }
159 
160 // formatting runs ------------------------------------------------------------
161 
162 void XclExpString::AppendFormat( sal_uInt16 nChar, sal_uInt16 nFontIdx, bool bDropDuplicate )
163 {
164  OSL_ENSURE( maFormats.empty() || (maFormats.back().mnChar < nChar), "XclExpString::AppendFormat - invalid char index" );
165  size_t nMaxSize = static_cast< size_t >( mbIsBiff8 ? EXC_STR_MAXLEN : EXC_STR_MAXLEN_8BIT );
166  if( maFormats.empty() || ((maFormats.size() < nMaxSize) && (!bDropDuplicate || (maFormats.back().mnFontIdx != nFontIdx))) )
167  maFormats.emplace_back( nChar, nFontIdx );
168 }
169 
170 void XclExpString::AppendTrailingFormat( sal_uInt16 nFontIdx )
171 {
172  AppendFormat( mnLen, nFontIdx, false );
173 }
174 
175 void XclExpString::LimitFormatCount( sal_uInt16 nMaxCount )
176 {
177  if( maFormats.size() > nMaxCount )
178  maFormats.erase( maFormats.begin() + nMaxCount, maFormats.end() );
179 }
180 
182 {
183  sal_uInt16 nFontIdx = EXC_FONT_NOTFOUND;
184  if( !maFormats.empty() && (maFormats.front().mnChar == 0) )
185  {
186  nFontIdx = maFormats.front().mnFontIdx;
187  }
188  return nFontIdx;
189 }
190 
192 {
193  sal_uInt16 nFontIdx = GetLeadingFont();
194  if( nFontIdx != EXC_FONT_NOTFOUND )
195  {
196  maFormats.erase( maFormats.begin() );
197  }
198  return nFontIdx;
199 }
200 
201 bool XclExpString::IsEqual( const XclExpString& rCmp ) const
202 {
203  return
204  (mnLen == rCmp.mnLen) &&
205  (mbIsBiff8 == rCmp.mbIsBiff8) &&
206  (mbIsUnicode == rCmp.mbIsUnicode) &&
207  (mbWrapped == rCmp.mbWrapped) &&
208  (
209  ( mbIsBiff8 && (maUniBuffer == rCmp.maUniBuffer)) ||
210  (!mbIsBiff8 && (maCharBuffer == rCmp.maCharBuffer))
211  ) &&
212  (maFormats == rCmp.maFormats);
213 }
214 
215 bool XclExpString::IsLessThan( const XclExpString& rCmp ) const
216 {
217  int nResult = mbIsBiff8 ?
218  lclCompareVectors( maUniBuffer, rCmp.maUniBuffer ) :
219  lclCompareVectors( maCharBuffer, rCmp.maCharBuffer );
220  return (nResult != 0) ? (nResult < 0) : (maFormats < rCmp.maFormats);
221 }
222 
223 // get data -------------------------------------------------------------------
224 
226 {
227  return static_cast< sal_uInt16 >( maFormats.size() );
228 }
229 
231 {
232  return (mbIsUnicode ? EXC_STRF_16BIT : 0) | (IsWriteFormats() ? EXC_STRF_RICH : 0);
233 }
234 
235 sal_uInt16 XclExpString::GetHeaderSize() const
236 {
237  return
238  (mb8BitLen ? 1 : 2) + // length field
239  (IsWriteFlags() ? 1 : 0) + // flag field
240  (IsWriteFormats() ? 2 : 0); // richtext formatting count
241 }
242 
243 std::size_t XclExpString::GetBufferSize() const
244 {
245  return static_cast<std::size_t>(mnLen) * (mbIsUnicode ? 2 : 1);
246 }
247 
248 std::size_t XclExpString::GetSize() const
249 {
250  return
251  GetHeaderSize() + // header
252  GetBufferSize() + // character buffer
253  (IsWriteFormats() ? (4 * GetFormatsCount()) : 0); // richtext formatting
254 }
255 
256 sal_uInt16 XclExpString::GetChar( sal_uInt16 nCharIdx ) const
257 {
258  OSL_ENSURE( nCharIdx < Len(), "XclExpString::GetChar - invalid character index" );
259  return static_cast< sal_uInt16 >( mbIsBiff8 ? maUniBuffer[ nCharIdx ] : maCharBuffer[ nCharIdx ] );
260 }
261 
262 sal_uInt16 XclExpString::GetHash() const
263 {
264  return
265  (mbIsBiff8 ? lclHashVector( maUniBuffer ) : lclHashVector( maCharBuffer )) ^
266  lclHashVector( maFormats, XclFormatRunHasher() );
267 }
268 
269 // streaming ------------------------------------------------------------------
270 
272 {
273  if( mb8BitLen )
274  rStrm << static_cast< sal_uInt8 >( mnLen );
275  else
276  rStrm << mnLen;
277 }
278 
280 {
281  if( mbIsBiff8 )
282  {
283  PrepareWrite( rStrm, 1 );
284  rStrm << GetFlagField();
285  rStrm.SetSliceSize( 0 );
286  }
287 }
288 
290 {
291  OSL_ENSURE( !mb8BitLen || (mnLen < 256), "XclExpString::WriteHeader - string too long" );
292  PrepareWrite( rStrm, GetHeaderSize() );
293  // length
294  WriteLenField( rStrm );
295  // flag field
296  if( IsWriteFlags() )
297  rStrm << GetFlagField();
298  // format run count
299  if( IsWriteFormats() )
300  rStrm << GetFormatsCount();
301  rStrm.SetSliceSize( 0 );
302 }
303 
305 {
306  if( mbIsBiff8 )
308  else
309  rStrm.WriteCharBuffer( maCharBuffer );
310 }
311 
312 void XclExpString::WriteFormats( XclExpStream& rStrm, bool bWriteSize ) const
313 {
314  if( !IsRich() )
315  return;
316 
317  if( mbIsBiff8 )
318  {
319  if( bWriteSize )
320  rStrm << GetFormatsCount();
321  rStrm.SetSliceSize( 4 );
322  for( const auto& rFormat : maFormats )
323  rStrm << rFormat.mnChar << rFormat.mnFontIdx;
324  }
325  else
326  {
327  if( bWriteSize )
328  rStrm << static_cast< sal_uInt8 >( GetFormatsCount() );
329  rStrm.SetSliceSize( 2 );
330  for( const auto& rFormat : maFormats )
331  rStrm << static_cast< sal_uInt8 >( rFormat.mnChar ) << static_cast< sal_uInt8 >( rFormat.mnFontIdx );
332  }
333  rStrm.SetSliceSize( 0 );
334 }
335 
336 void XclExpString::Write( XclExpStream& rStrm ) const
337 {
338  if (!mbSkipHeader)
339  WriteHeader( rStrm );
340  WriteBuffer( rStrm );
341  if( IsWriteFormats() ) // only in BIFF8 included in string
342  WriteFormats( rStrm );
343 }
344 
346 {
347  assert(pnMem);
348  OSL_ENSURE( !mb8BitLen || (mnLen < 256), "XclExpString::WriteHeaderToMem - string too long" );
349  OSL_ENSURE( !IsWriteFormats(), "XclExpString::WriteHeaderToMem - formatted strings not supported" );
350  // length
351  if( mb8BitLen )
352  {
353  *pnMem = static_cast< sal_uInt8 >( mnLen );
354  ++pnMem;
355  }
356  else
357  {
358  ShortToSVBT16( mnLen, pnMem );
359  pnMem += 2;
360  }
361  // flag field
362  if( IsWriteFlags() )
363  *pnMem = GetFlagField();
364 }
365 
367 {
368  assert(pnMem);
369  if( IsEmpty() )
370  return;
371 
372  if( mbIsBiff8 )
373  {
374  for( const sal_uInt16 nChar : maUniBuffer )
375  {
376  *pnMem = static_cast< sal_uInt8 >( nChar );
377  ++pnMem;
378  if( mbIsUnicode )
379  {
380  *pnMem = static_cast< sal_uInt8 >( nChar >> 8 );
381  ++pnMem;
382  }
383  }
384  }
385  else
386  memcpy( pnMem, maCharBuffer.data(), mnLen );
387 }
388 
390 {
391  WriteHeaderToMem( pnMem );
392  WriteBufferToMem( pnMem + GetHeaderSize() );
393 }
394 
395 static sal_uInt16 lcl_WriteRun( XclExpXmlStream& rStrm, const ScfUInt16Vec& rBuffer, sal_uInt16 nStart, sal_Int32 nLength, const XclExpFont* pFont )
396 {
397  if( nLength == 0 )
398  return nStart;
399 
400  sax_fastparser::FSHelperPtr& rWorksheet = rStrm.GetCurrentStream();
401 
402  rWorksheet->startElement(XML_r);
403  if( pFont )
404  {
405  const XclFontData& rFontData = pFont->GetFontData();
406  rWorksheet->startElement(XML_rPr);
407  XclXmlUtils::WriteFontData( rWorksheet, rFontData, XML_rFont );
408  rWorksheet->endElement( XML_rPr );
409  }
410  rWorksheet->startElement(XML_t, FSNS(XML_xml, XML_space), "preserve");
411  rWorksheet->writeEscaped( XclXmlUtils::ToOUString( rBuffer, nStart, nLength ) );
412  rWorksheet->endElement( XML_t );
413  rWorksheet->endElement( XML_r );
414  return nStart + nLength;
415 }
416 
418 {
419  sax_fastparser::FSHelperPtr rWorksheet = rStrm.GetCurrentStream();
420 
421  if( !IsWriteFormats() )
422  {
423  rWorksheet->startElement(XML_t, FSNS(XML_xml, XML_space), "preserve");
424  rWorksheet->writeEscaped( XclXmlUtils::ToOUString( *this ) );
425  rWorksheet->endElement( XML_t );
426  }
427  else
428  {
429  XclExpFontBuffer& rFonts = rStrm.GetRoot().GetFontBuffer();
430 
431  sal_uInt16 nStart = 0;
432  const XclExpFont* pFont = nullptr;
433  for ( const auto& rFormat : maFormats )
434  {
435  nStart = lcl_WriteRun( rStrm, GetUnicodeBuffer(),
436  nStart, rFormat.mnChar-nStart, pFont );
437  pFont = rFonts.GetFont( rFormat.mnFontIdx );
438  }
439  lcl_WriteRun( rStrm, GetUnicodeBuffer(),
440  nStart, GetUnicodeBuffer().size() - nStart, pFont );
441  }
442 }
443 
445 {
446  return mbIsBiff8 && (!IsEmpty() || !mbSmartFlags);
447 }
448 
450 {
451  return mbIsBiff8 && !mbSkipFormats && IsRich();
452 }
453 
454 void XclExpString::SetStrLen( sal_Int32 nNewLen )
455 {
456  sal_uInt16 nAllowedLen = (mb8BitLen && (mnMaxLen > 255)) ? 255 : mnMaxLen;
457  mnLen = limit_cast< sal_uInt16 >( nNewLen, 0, nAllowedLen );
458 }
459 
460 void XclExpString::CharsToBuffer( const sal_Unicode* pcSource, sal_Int32 nBegin, sal_Int32 nLen )
461 {
462  OSL_ENSURE( maUniBuffer.size() >= o3tl::make_unsigned( nBegin + nLen ),
463  "XclExpString::CharsToBuffer - char buffer invalid" );
464  ScfUInt16Vec::iterator aBeg = maUniBuffer.begin() + nBegin;
465  ScfUInt16Vec::iterator aEnd = aBeg + nLen;
466  const sal_Unicode* pcSrcChar = pcSource;
467  for( ScfUInt16Vec::iterator aIt = aBeg; aIt != aEnd; ++aIt, ++pcSrcChar )
468  {
469  *aIt = static_cast< sal_uInt16 >( *pcSrcChar );
470  if( *aIt & 0xFF00 )
471  mbIsUnicode = true;
472  }
473  if( !mbWrapped )
474  mbWrapped = ::std::find( aBeg, aEnd, EXC_LF ) != aEnd;
475 }
476 
477 void XclExpString::CharsToBuffer( const char* pcSource, sal_Int32 nBegin, sal_Int32 nLen )
478 {
479  OSL_ENSURE( maCharBuffer.size() >= o3tl::make_unsigned( nBegin + nLen ),
480  "XclExpString::CharsToBuffer - char buffer invalid" );
481  ScfUInt8Vec::iterator aBeg = maCharBuffer.begin() + nBegin;
482  ScfUInt8Vec::iterator aEnd = aBeg + nLen;
483  const char* pcSrcChar = pcSource;
484  for( ScfUInt8Vec::iterator aIt = aBeg; aIt != aEnd; ++aIt, ++pcSrcChar )
485  *aIt = static_cast< sal_uInt8 >( *pcSrcChar );
486  mbIsUnicode = false;
487  if( !mbWrapped )
488  mbWrapped = ::std::find( aBeg, aEnd, EXC_LF_C ) != aEnd;
489 }
490 
491 void XclExpString::Init( sal_Int32 nCurrLen, XclStrFlags nFlags, sal_uInt16 nMaxLen, bool bBiff8 )
492 {
493  mbIsBiff8 = bBiff8;
494  mbIsUnicode = bBiff8 && ( nFlags & XclStrFlags::ForceUnicode );
495  mb8BitLen = bool( nFlags & XclStrFlags::EightBitLength );
496  mbSmartFlags = bBiff8 && ( nFlags & XclStrFlags::SmartFlags );
497  mbSkipFormats = bool( nFlags & XclStrFlags::SeparateFormats );
498  mbWrapped = false;
499  mbSkipHeader = bool( nFlags & XclStrFlags::NoHeader );
500  mnMaxLen = nMaxLen;
501  SetStrLen( nCurrLen );
502 
503  maFormats.clear();
504  if( mbIsBiff8 )
505  {
506  maCharBuffer.clear();
507  maUniBuffer.resize( mnLen );
508  }
509  else
510  {
511  maUniBuffer.clear();
512  maCharBuffer.resize( mnLen );
513  }
514 }
515 
516 void XclExpString::Build( const sal_Unicode* pcSource, sal_Int32 nCurrLen, XclStrFlags nFlags, sal_uInt16 nMaxLen )
517 {
518  Init( nCurrLen, nFlags, nMaxLen, true );
519  CharsToBuffer( pcSource, 0, mnLen );
520 }
521 
522 void XclExpString::Build( const char* pcSource, sal_Int32 nCurrLen, XclStrFlags nFlags, sal_uInt16 nMaxLen )
523 {
524  Init( nCurrLen, nFlags, nMaxLen, false );
525  CharsToBuffer( pcSource, 0, mnLen );
526 }
527 
528 void XclExpString::InitAppend( sal_Int32 nAddLen )
529 {
530  SetStrLen( static_cast< sal_Int32 >( mnLen ) + nAddLen );
531  if( mbIsBiff8 )
532  maUniBuffer.resize( mnLen );
533  else
534  maCharBuffer.resize( mnLen );
535 }
536 
537 void XclExpString::BuildAppend( const sal_Unicode* pcSource, sal_Int32 nAddLen )
538 {
539  OSL_ENSURE( mbIsBiff8, "XclExpString::BuildAppend - must not be called at byte strings" );
540  if( mbIsBiff8 )
541  {
542  sal_uInt16 nOldLen = mnLen;
543  InitAppend( nAddLen );
544  CharsToBuffer( pcSource, nOldLen, mnLen - nOldLen );
545  }
546 }
547 
548 void XclExpString::BuildAppend( const char* pcSource, sal_Int32 nAddLen )
549 {
550  OSL_ENSURE( !mbIsBiff8, "XclExpString::BuildAppend - must not be called at unicode strings" );
551  if( !mbIsBiff8 )
552  {
553  sal_uInt16 nOldLen = mnLen;
554  InitAppend( nAddLen );
555  CharsToBuffer( pcSource, nOldLen, mnLen - nOldLen );
556  }
557 }
558 
559 void XclExpString::PrepareWrite( XclExpStream& rStrm, sal_uInt16 nBytes ) const
560 {
561  rStrm.SetSliceSize( nBytes + (mbIsUnicode ? 2 : 1) );
562 }
563 
564 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
This class stores an unformatted or formatted string for Excel export.
Definition: xestring.hxx:43
Type
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
const XclExpRoot & GetRoot() const
Returns the filter root data.
Definition: xestream.hxx:290
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
XclStrFlags
Flags used to specify import/export mode of strings.
Definition: xlstring.hxx:29
const sal_uInt8 EXC_LF_C
Definition: xlstring.hxx:51
static OUString ToOUString(const char *s)
Definition: xestream.cxx:783
This struct helps reading and writing Excel fonts.
Definition: xlstyle.hxx:286
bool IsWriteFlags() const
Returns true, if the flag field should be written.
Definition: xestring.cxx:444
void AppendFormat(sal_uInt16 nChar, sal_uInt16 nFontIdx, bool bDropDuplicate=true)
Appends a formatting run.
Definition: xestring.cxx:162
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
ReturnType limit_cast(Type nValue, ReturnType nMin, ReturnType nMax)
Returns the value, if it is not less than nMin and not greater than nMax, otherwise one of the limits...
Definition: ftools.hxx:61
const sal_uInt16 EXC_STR_MAXLEN_8BIT
Definition: xlstring.hxx:42
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
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
const XclExpFont * GetFont(sal_uInt16 nXclFont) const
Returns the specified font from font list.
Definition: xestyle.cxx:1180
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
const sal_uInt16 EXC_FONT_NOTFOUND
Application font index.
Definition: xlstyle.hxx:78
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
NUL character (unicode).
Definition: xlstring.hxx:64
Omit flags on empty string (default: read/write always). BIFF8 only.
void WriteBufferToMem(sal_uInt8 *pnMem) const
Writes the raw character buffer to memory (8-bit or 16-bit little-endian).
Definition: xestring.cxx:366
Import: Keep old formats when reading unformatted string (default: clear formats); Export: Write unfo...
static sax_fastparser::FSHelperPtr WriteFontData(sax_fastparser::FSHelperPtr pStream, const XclFontData &rFontData, sal_Int32 nNameId)
Definition: xestream.cxx:866
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
sax_fastparser::FSHelperPtr & GetCurrentStream()
Definition: xestream.cxx:910
void Append(const OUString &rString)
Appends a string.
Definition: xestring.cxx:131
void SetSliceSize(sal_uInt16 nSize)
Sets data slice length.
Definition: xestream.cxx:129
void WriteXml(XclExpXmlStream &rStrm) const
Definition: xestring.cxx:417
static sal_uInt16 lcl_WriteRun(XclExpXmlStream &rStrm, const ScfUInt16Vec &rBuffer, sal_uInt16 nStart, sal_Int32 nLength, const XclExpFont *pFont)
Definition: xestring.cxx:395
const XclFontData & GetFontData() const
Returns read-only access to font data.
Definition: xestyle.hxx:162
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
Stores all data of an Excel font and provides export of FONT records.
Definition: xestyle.hxx:155
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
8-bit string length field (default: 16-bit).
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
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
size
const ScfUInt16Vec & GetUnicodeBuffer() const
Definition: xestring.hxx:145
ScfUInt16Vec maUniBuffer
Definition: xestring.hxx:227
const sal_uInt8 EXC_STRF_16BIT
Definition: xlstring.hxx:45
sal_uInt16 GetFormatsCount() const
Returns the current count of formatting runs for rich strings.
Definition: xestring.cxx:225
std::shared_ptr< FastSerializerHelper > FSHelperPtr
XclFormatRunVec maFormats
The byte character buffer.
Definition: xestring.hxx:229
const sal_uInt8 EXC_STRF_RICH
Definition: xlstring.hxx:47
Default string settings.
OString OUStringToOString(const OUString &str, ConnectionSettings const *settings)
const sal_uInt16 EXC_LF
LF character (used for line break).
Definition: xlstring.hxx:52
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
Always use UCS-2 characters (default: try to compress). BIFF8 only.
void LimitFormatCount(sal_uInt16 nMaxCount)
Removes formatting runs at the end, if the string contains too much.
Definition: xestring.cxx:175
Stores the data of all fonts used in the document.
Definition: xestyle.hxx:208
XclExpString(XclStrFlags nFlags=XclStrFlags::NONE, sal_uInt16 nMaxLen=EXC_STR_MAXLEN)
Constructs an empty BIFF8 Unicode string.
Definition: xestring.cxx:99
void WriteCharBuffer(const ScfUInt8Vec &rBuffer)
Writes 8-bit character buffer.
Definition: xestream.cxx:342
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
constexpr sal_Int32 FSNS(sal_Int32 namespc, sal_Int32 element)
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 mnFontIdx
First character this format applies to.
Definition: xlstring.hxx:67
void WriteUnicodeBuffer(const ScfUInt16Vec &rBuffer, sal_uInt8 nFlags)
Writes Unicode buffer as 8/16 bit, repeats nFlags at start of a CONTINUE record.
Definition: xestream.cxx:305
sal_uInt16 mnChar
Definition: xlstring.hxx:66
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
XclExpFontBuffer & GetFontBuffer() const
Returns the font buffer.
Definition: xeroot.cxx:111
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