24#include <osl/diagnose.h>
30#include <oox/token/tokens.hxx>
41template<
typename Type >
42int lclCompareVectors( const ::std::vector< Type >& rLeft, const ::std::vector< Type >& rRight )
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 );
52 nResult =
static_cast< int >( rLeft.size() ) -
static_cast< int >( rRight.size() );
61template<
typename Type >
64template<
typename Type >
65struct XclDirectHasher :
public XclHasher< Type >
67 sal_uInt32 operator()(
Type nVal )
const {
return nVal; }
70struct XclFormatRunHasher :
public XclHasher< const XclFormatRun& >
79template<
typename Type,
typename ValueHasher >
80sal_uInt16 lclHashVector( const ::std::vector< Type >& rVec,
const ValueHasher& rHasher )
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) );
89template<
typename Type >
90sal_uInt16 lclHashVector( const ::std::vector< Type >& rVec )
92 return lclHashVector( rVec, XclDirectHasher< Type >() );
101 Init( 0, nFlags, nMaxLen,
true );
106 Assign( rString, nFlags, nMaxLen );
113 Build( rString.getStr(), rString.getLength(), nFlags, nMaxLen );
122 std::u16string_view rString, rtl_TextEncoding eTextEnc,
XclStrFlags nFlags,
127 Build(aByteStr.getStr(), aByteStr.getLength(), nFlags, nMaxLen);
139 if (!rString.empty())
156 OString aByteStr( &cChar, 1, eTextEnc );
165 OSL_ENSURE(
maFormats.empty() || (
maFormats.back().mnChar < nChar),
"XclExpString::AppendFormat - invalid char index" );
168 maFormats.emplace_back( nChar, nFontIdx );
228 return static_cast< sal_uInt16
>(
maFormats.size() );
259 OSL_ENSURE( nCharIdx <
Len(),
"XclExpString::GetChar - invalid character index" );
267 lclHashVector(
maFormats, XclFormatRunHasher() );
275 rStrm << static_cast< sal_uInt8 >(
mnLen );
286 rStrm.SetSliceSize( 0 );
292 OSL_ENSURE( !
mb8BitLen || (
mnLen < 256),
"XclExpString::WriteHeader - string too long" );
302 rStrm.SetSliceSize( 0 );
322 rStrm.SetSliceSize( 4 );
324 rStrm << rFormat.mnChar << rFormat.mnFontIdx;
330 rStrm.SetSliceSize( 2 );
332 rStrm << static_cast< sal_uInt8 >( rFormat.mnChar ) <<
static_cast< sal_uInt8 >( rFormat.mnFontIdx );
334 rStrm.SetSliceSize( 0 );
349 OSL_ENSURE( !
mb8BitLen || (
mnLen < 256),
"XclExpString::WriteHeaderToMem - string too long" );
350 OSL_ENSURE( !
IsWriteFormats(),
"XclExpString::WriteHeaderToMem - formatted strings not supported" );
359 ShortToSVBT16(
mnLen, pnMem );
377 *pnMem =
static_cast< sal_uInt8 >( nChar );
381 *pnMem =
static_cast< sal_uInt8 >( nChar >> 8 );
403 rWorksheet->startElement(XML_r);
407 rWorksheet->startElement(XML_rPr);
409 rWorksheet->endElement( XML_rPr );
411 rWorksheet->startElement(XML_t,
FSNS(XML_xml, XML_space),
"preserve");
413 rWorksheet->endElement( XML_t );
414 rWorksheet->endElement( XML_r );
424 rWorksheet->startElement(XML_t,
FSNS(XML_xml, XML_space),
"preserve");
426 rWorksheet->endElement( XML_t );
432 sal_uInt16 nStart = 0;
437 nStart, rFormat.mnChar-nStart, pFont );
438 pFont = rFonts.
GetFont( rFormat.mnFontIdx );
458 mnLen = limit_cast< sal_uInt16 >( nNewLen, 0, nAllowedLen );
464 "XclExpString::CharsToBuffer - char buffer invalid" );
465 ScfUInt16Vec::iterator aBeg =
maUniBuffer.begin() + nBegin;
466 ScfUInt16Vec::iterator aEnd = aBeg + nLen;
468 for( ScfUInt16Vec::iterator aIt = aBeg; aIt != aEnd; ++aIt, ++pcSrcChar )
470 *aIt =
static_cast< sal_uInt16
>( *pcSrcChar );
481 "XclExpString::CharsToBuffer - char buffer invalid" );
482 ScfUInt8Vec::iterator aBeg =
maCharBuffer.begin() + nBegin;
483 ScfUInt8Vec::iterator aEnd = aBeg + nLen;
484 const char* pcSrcChar = pcSource;
485 for( ScfUInt8Vec::iterator aIt = aBeg; aIt != aEnd; ++aIt, ++pcSrcChar )
486 *aIt =
static_cast< sal_uInt8 >( *pcSrcChar );
519 Init( nCurrLen, nFlags, nMaxLen,
true );
525 Init( nCurrLen, nFlags, nMaxLen,
false );
540 OSL_ENSURE(
mbIsBiff8,
"XclExpString::BuildAppend - must not be called at byte strings" );
543 sal_uInt16 nOldLen =
mnLen;
551 OSL_ENSURE( !
mbIsBiff8,
"XclExpString::BuildAppend - must not be called at unicode strings" );
554 sal_uInt16 nOldLen =
mnLen;
Stores the data of all fonts used in the document.
const XclExpFont * GetFont(sal_uInt16 nXclFont) const
Returns the specified font from font list.
Stores all data of an Excel font and provides export of FONT records.
const XclFontData & GetFontData() const
Returns read-only access to font data.
This class is used to export Excel record streams.
This class stores an unformatted or formatted string for Excel export.
void WriteHeader(XclExpStream &rStrm) const
Writes 8-bit or 16-bit length field and string flags field.
bool mb8BitLen
true, if at least one character is >0xFF.
bool IsEmpty() const
Returns true, if the string is empty.
void WriteFlagField(XclExpStream &rStrm) const
Writes the string flags field (1 byte).
void AppendByte(std::u16string_view rString, rtl_TextEncoding eTextEnc)
Appends a string.
sal_uInt8 GetFlagField() const
Returns the current string flags field to export.
void InitAppend(sal_Int32 nAddLen)
Initializes string length and resizes character buffers for appending operation.
void Build(const sal_Unicode *pcSource, sal_Int32 nCurrLen, XclStrFlags nFlags, sal_uInt16 nMaxLen)
Creates the character buffer from the given Unicode array.
ScfUInt8Vec maCharBuffer
The Unicode character buffer.
void AppendFormat(sal_uInt16 nChar, sal_uInt16 nFontIdx, bool bDropDuplicate=true)
Appends a formatting run.
void WriteLenField(XclExpStream &rStrm) const
Writes the string length field (1 byte or 2 bytes).
void WriteBufferToMem(sal_uInt8 *pnMem) const
Writes the raw character buffer to memory (8-bit or 16-bit little-endian).
void WriteToMem(sal_uInt8 *pnMem) const
Writes the entire string to memory.
bool mbSmartFlags
true = write 8-bit string length; false = 16-bit.
bool mbSkipHeader
true = text contains several paragraphs.
sal_uInt16 GetFormatsCount() const
Returns the current count of formatting runs for rich strings.
XclExpString(XclStrFlags nFlags=XclStrFlags::NONE, sal_uInt16 nMaxLen=EXC_STR_MAXLEN)
Constructs an empty BIFF8 Unicode string.
void Append(std::u16string_view rString)
Appends a string.
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.
void Init(sal_Int32 nCurrLen, XclStrFlags nFlags, sal_uInt16 nMaxLen, bool bBiff8)
Initializes flags, string length, and resizes character buffer.
void CharsToBuffer(const sal_Unicode *pcSource, sal_Int32 nBegin, sal_Int32 nLen)
Inserts the passed character array into the internal character buffer.
void SetStrLen(sal_Int32 nNewLen)
Sets the string length but regards the limit given in mnMaxLen.
void PrepareWrite(XclExpStream &rStrm, sal_uInt16 nBytes) const
Initializes write process on stream.
sal_uInt16 GetHeaderSize() const
Returns the byte count the header will take on export.
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.
sal_uInt16 mnLen
All formatting runs.
bool mbIsUnicode
true = BIFF8 Unicode string, false = BIFF2-7 bytestring.
bool IsEqual(const XclExpString &rCmp) const
Returns true, if this string is equal to the passed string.
sal_uInt16 mnMaxLen
Character count to export.
bool mbWrapped
true = skip formats on export; false = write complete formatted string.
bool IsLessThan(const XclExpString &rCmp) const
Returns true, if this string is less than the passed string.
bool IsRich() const
Returns true, if the string contains formatting information.
void WriteFormats(XclExpStream &rStrm, bool bWriteSize=false) const
Writes the raw formatting run buffer.
std::size_t GetSize() const
Returns the byte count the whole string will take on export.
void LimitFormatCount(sal_uInt16 nMaxCount)
Removes formatting runs at the end, if the string contains too much.
sal_uInt16 GetLeadingFont()
Returns the font index of the first char in the formatting run, or EXC_FONT_NOTFOUND.
void BuildAppend(std::u16string_view)
Appends the given Unicode array to the character buffer.
XclFormatRunVec maFormats
The byte character buffer.
sal_uInt16 GetHash() const
Returns a hash value for the string.
std::size_t GetBufferSize() const
Returns the byte count the character buffer will take on export.
void WriteXml(XclExpXmlStream &rStrm) const
void WriteBuffer(XclExpStream &rStrm) const
Writes the raw character buffer.
sal_uInt16 Len() const
Returns the character count of the string.
void AppendTrailingFormat(sal_uInt16 nFontIdx)
Appends a trailing formatting run with the passed font index.
sal_uInt16 RemoveLeadingFont()
The same as above + additionally remove the given font from the formatting run.
bool mbSkipFormats
true = omit flags on empty string; false = always write flags.
bool mbIsBiff8
Maximum allowed number of characters.
sal_uInt16 GetChar(sal_uInt16 nCharIdx) const
Returns the specified character from the (already encoded) string.
void WriteHeaderToMem(sal_uInt8 *pnMem) const
Writes the string header to memory.
bool IsWriteFormats() const
Returns true, if the formatting run vector should be written.
const ScfUInt16Vec & GetUnicodeBuffer() const
bool IsWriteFlags() const
Returns true, if the flag field should be written.
void Write(XclExpStream &rStrm) const
Writes the complete Unicode string.
static sax_fastparser::FSHelperPtr WriteFontData(sax_fastparser::FSHelperPtr pStream, const XclFontData &rFontData, sal_Int32 nNameId)
static OUString ToOUString(const char *s)
constexpr sal_Int32 FSNS(sal_Int32 namespc, sal_Int32 element)
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
std::shared_ptr< FastSerializerHelper > FSHelperPtr
This struct helps reading and writing Excel fonts.
static sal_uInt16 lcl_WriteRun(XclExpXmlStream &rStrm, const ScfUInt16Vec &rBuffer, sal_uInt16 nStart, sal_Int32 nLength, const XclExpFont *pFont)
const sal_uInt16 EXC_LF
LF character (used for line break).
const sal_uInt8 EXC_STRF_RICH
const sal_uInt16 EXC_STR_MAXLEN_8BIT
const sal_uInt16 EXC_STR_MAXLEN
XclStrFlags
Flags used to specify import/export mode of strings.
@ EightBitLength
Always use UCS-2 characters (default: try to compress). BIFF8 only.
@ NoHeader
Import: Keep old formats when reading unformatted string (default: clear formats); Export: Write unfo...
@ SeparateFormats
Omit flags on empty string (default: read/write always). BIFF8 only.
@ ForceUnicode
Default string settings.
@ SmartFlags
8-bit string length field (default: 16-bit).
const sal_uInt8 EXC_STRF_16BIT
const sal_uInt16 EXC_FONT_NOTFOUND
Application font index.