From 5ad9d928c75a66edfc901cfb7a41608237ad9c6b Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Wed, 25 Feb 2026 14:25:49 +0200 Subject: [PATCH] SvStream::WriteUniOrByteChar should not need to specify encoding Instead, rely on the stream being set into the correct encoding during stream initialisation. Change-Id: Ie019e9f7a668b943e418126b14b8bf852a4fa966 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/200459 Tested-by: Jenkins Reviewed-by: Noel Grandin --- include/tools/stream.hxx | 8 +++----- sc/source/filter/dif/difexp.cxx | 10 +++++----- sc/source/ui/docshell/docsh.cxx | 12 ++++++------ tools/source/stream/stream.cxx | 3 ++- 4 files changed, 16 insertions(+), 17 deletions(-) diff --git a/include/tools/stream.hxx b/include/tools/stream.hxx index 6729412bc267..6f450aede485 100644 --- a/include/tools/stream.hxx +++ b/include/tools/stream.hxx @@ -374,14 +374,12 @@ public: bool WriteUnicodeOrByteText(std::u16string_view rStr) { return WriteUnicodeOrByteText(rStr, GetStreamEncoding(), /*bZero*/false); } - /** Write a Unicode character if eDestEncoding==RTL_TEXTENCODING_UNICODE, - otherwise write as Bytecode converted to eDestEncoding. + /** Write a Unicode character if GetStreamEncoding()==RTL_TEXTENCODING_UNICODE, + otherwise write as Bytecode converted to GetStreamEncoding(). This may result in more than one byte being written if a multi byte encoding (e.g. UTF7, UTF8) is chosen. */ - bool WriteUniOrByteChar( sal_Unicode ch, rtl_TextEncoding eDestEncoding ); - bool WriteUniOrByteChar( sal_Unicode ch ) - { return WriteUniOrByteChar( ch, GetStreamEncoding() ); } + bool WriteUniOrByteChar( sal_Unicode ch ); void SetBufferSize( sal_uInt16 m_nBufSize ); sal_uInt16 GetBufferSize() const { return m_nBufSize; } diff --git a/sc/source/filter/dif/difexp.cxx b/sc/source/filter/dif/difexp.cxx index 133372e39660..bb03b8b9532b 100644 --- a/sc/source/filter/dif/difexp.cxx +++ b/sc/source/filter/dif/difexp.cxx @@ -210,9 +210,9 @@ void ScFormatFilterPluginImpl::ScExportDif( SvStream& rOut, ScDocument& rDoc, OUString strFrom(cStrDelim); OUString strTo = strFrom + strFrom; aTmpStr = aTmpStr.replaceAll(strFrom, strTo); - rOut.WriteUniOrByteChar( cStrDelim, eCharSet ); + rOut.WriteUniOrByteChar( cStrDelim ); rOut.WriteUnicodeOrByteText(aTmpStr, eCharSet); - rOut.WriteUniOrByteChar( cStrDelim, eCharSet ); + rOut.WriteUniOrByteChar( cStrDelim ); } else if ( bContextOrNotAsciiEncoding ) { @@ -224,9 +224,9 @@ void ScFormatFilterPluginImpl::ScExportDif( SvStream& rOut, ScDocument& rDoc, OUString aStrTo = aStrDelimDecoded + aStrDelimDecoded; aStrDec = aStrDec.replaceAll(aStrDelimDecoded, aStrTo); // write byte re-encoded - rOut.WriteUniOrByteChar( cStrDelim, eCharSet ); + rOut.WriteUniOrByteChar( cStrDelim ); rOut.WriteUnicodeOrByteText( aStrDec, eCharSet ); - rOut.WriteUniOrByteChar( cStrDelim, eCharSet ); + rOut.WriteUniOrByteChar( cStrDelim ); } else { @@ -239,7 +239,7 @@ void ScFormatFilterPluginImpl::ScExportDif( SvStream& rOut, ScDocument& rDoc, rOut.WriteBytes(aStrEnc.getStr(), aStrEnc.getLength()); rOut.WriteBytes(aStrDelimEncoded.getStr(), aStrDelimEncoded.getLength()); } - rOut.WriteUniOrByteChar( '\n', eCharSet ); + rOut.WriteUniOrByteChar( '\n' ); } } aPrgrsBar.SetState( nRowCnt ); diff --git a/sc/source/ui/docshell/docsh.cxx b/sc/source/ui/docshell/docsh.cxx index b72ef6a16219..dced37e186ad 100644 --- a/sc/source/ui/docshell/docsh.cxx +++ b/sc/source/ui/docshell/docsh.cxx @@ -2099,10 +2099,10 @@ void ScDocShell::AsciiSave( SvStream& rStream, const ScImportOptions& rAsciiOpt, // import. aString = "sep=" + OUStringChar(cDelim); if (cStrDelim != 0) - rStream.WriteUniOrByteChar( '"', eCharSet); + rStream.WriteUniOrByteChar( '"'); rStream.WriteUnicodeOrByteText(aString, eCharSet); if (cStrDelim != 0) - rStream.WriteUniOrByteChar( '"', eCharSet); + rStream.WriteUniOrByteChar( '"'); endlub( rStream ); ++nStartRow; } @@ -2316,10 +2316,10 @@ void ScDocShell::AsciiSave( SvStream& rStream, const ScImportOptions& rAsciiOpt, } if ( bNeedQuotes || bForceQuotes ) - rStream.WriteUniOrByteChar( cStrDelim, eCharSet ); + rStream.WriteUniOrByteChar( cStrDelim ); rStream.WriteUnicodeOrByteText(aUniString, eCharSet); if ( bNeedQuotes || bForceQuotes ) - rStream.WriteUniOrByteChar( cStrDelim, eCharSet ); + rStream.WriteUniOrByteChar( cStrDelim ); } else { @@ -2355,10 +2355,10 @@ void ScDocShell::AsciiSave( SvStream& rStream, const ScImportOptions& rAsciiOpt, // write byte re-encoded if ( bNeedQuotes || bForceQuotes ) - rStream.WriteUniOrByteChar( cStrDelim, eCharSet ); + rStream.WriteUniOrByteChar( cStrDelim ); rStream.WriteUnicodeOrByteText( aStrDec, eCharSet ); if ( bNeedQuotes || bForceQuotes ) - rStream.WriteUniOrByteChar( cStrDelim, eCharSet ); + rStream.WriteUniOrByteChar( cStrDelim ); } else { diff --git a/tools/source/stream/stream.cxx b/tools/source/stream/stream.cxx index 617a02684b40..8a52e03dafb2 100644 --- a/tools/source/stream/stream.cxx +++ b/tools/source/stream/stream.cxx @@ -672,8 +672,9 @@ bool SvStream::WriteLine(std::string_view rStr) return m_nError == ERRCODE_NONE; } -bool SvStream::WriteUniOrByteChar(sal_Unicode ch, rtl_TextEncoding eDestEncoding) +bool SvStream::WriteUniOrByteChar(sal_Unicode ch) { + auto eDestEncoding = GetStreamEncoding(); if (eDestEncoding == RTL_TEXTENCODING_UNICODE) WriteUnicode(ch); else