include/tools/stream.hxx | 2 ++ sc/qa/unit/screenshots/screenshots.cxx | 6 +----- sc/source/ui/docshell/impex.cxx | 22 ++++------------------ sc/source/ui/inc/impex.hxx | 3 --- sc/source/ui/view/cellsh2.cxx | 2 +- sw/source/core/edit/edglss.cxx | 7 +------ sw/source/core/unocore/unoobj.cxx | 7 +------ sw/source/filter/ascii/wrtasc.cxx | 9 +++------ sw/source/uibase/dochdl/swdtflvr.cxx | 7 +------ tools/source/stream/stream.cxx | 2 +- 10 files changed, 15 insertions(+), 52 deletions(-)
New commits: commit 12c6fc8afab02de570d42ad90004cee24d1bc338 Author: Mike Kaganski <[email protected]> AuthorDate: Wed Jun 25 12:07:35 2025 +0500 Commit: Mike Kaganski <[email protected]> CommitDate: Wed Jun 25 17:22:45 2025 +0200 Introduce SvStream::ResetEndianSwap to reset to native endianness Used in several places; avoids inclusion of osl/endian.h and use of ifdefs for the task. Change-Id: I87a7b41ef6d0edc3fee39cc192f7abe09f7e45df Reviewed-on: https://gerrit.libreoffice.org/c/core/+/186928 Tested-by: Jenkins Reviewed-by: Mike Kaganski <[email protected]> diff --git a/include/tools/stream.hxx b/include/tools/stream.hxx index 1ea019866e7e..38c072fe038a 100644 --- a/include/tools/stream.hxx +++ b/include/tools/stream.hxx @@ -205,6 +205,8 @@ public: SvStreamEndian GetEndian() const; /// returns status of endian swap flag bool IsEndianSwap() const { return m_isSwap; } + /// sets native endianness + void ResetEndianSwap() { m_isSwap = false; } void SetCompressMode( SvStreamCompressFlags nNewMode ) { m_nCompressMode = nNewMode; } diff --git a/sc/qa/unit/screenshots/screenshots.cxx b/sc/qa/unit/screenshots/screenshots.cxx index 0b0edfbd7343..19b6e25a0cc2 100644 --- a/sc/qa/unit/screenshots/screenshots.cxx +++ b/sc/qa/unit/screenshots/screenshots.cxx @@ -100,11 +100,7 @@ void ScScreenshotTest::initialize() SvMemoryStream* pNewMemStream = new SvMemoryStream(const_cast<sal_Unicode *>(mCsv.getStr()), mCsv.getLength() * sizeof(sal_Unicode), StreamMode::READ); pNewMemStream->SetStreamCharSet( RTL_TEXTENCODING_UNICODE ); -#ifdef OSL_BIGENDIAN - pNewMemStream->SetEndian(SvStreamEndian::BIG); -#else - pNewMemStream->SetEndian(SvStreamEndian::LITTLE); -#endif + pNewMemStream->ResetEndianSwap(); mpStream.reset(pNewMemStream); } diff --git a/sc/source/ui/docshell/impex.cxx b/sc/source/ui/docshell/impex.cxx index f97fb3dc8fe1..6872b359b6ac 100644 --- a/sc/source/ui/docshell/impex.cxx +++ b/sc/source/ui/docshell/impex.cxx @@ -72,7 +72,6 @@ #include <unicode/uchar.h> -#include <osl/endian.h> #include <osl/file.hxx> // We don't want to end up with 2GB read in one line just because of malformed @@ -323,7 +322,7 @@ bool ScImportExport::ImportString( const OUString& rText, SotClipboardFormatId n OString aTmp( rText.getStr(), rText.getLength(), eEnc ); SvMemoryStream aStrm( const_cast<char *>(aTmp.getStr()), aTmp.getLength() * sizeof(char), StreamMode::READ ); aStrm.SetStreamCharSet( eEnc ); - SetNoEndianSwap( aStrm ); //! no swapping in memory + aStrm.ResetEndianSwap(); //! no swapping in memory return ImportStream( aStrm, OUString(), nFmt ); } } @@ -344,7 +343,7 @@ bool ScImportExport::ExportString( OUString& rText, SotClipboardFormatId nFmt ) SvMemoryStream aStrm; aStrm.SetStreamCharSet( RTL_TEXTENCODING_UNICODE ); - SetNoEndianSwap( aStrm ); //! no swapping in memory + aStrm.ResetEndianSwap(); //! no swapping in memory // mba: no BaseURL for data exc if( ExportStream( aStrm, OUString(), nFmt ) ) { @@ -369,7 +368,7 @@ bool ScImportExport::ExportByteString( OString& rText, rtl_TextEncoding eEnc, So SvMemoryStream aStrm; aStrm.SetStreamCharSet( eEnc ); - SetNoEndianSwap( aStrm ); //! no swapping in memory + aStrm.ResetEndianSwap(); //! no swapping in memory // mba: no BaseURL for data exchange if( ExportStream( aStrm, OUString(), nFmt ) ) { @@ -522,15 +521,6 @@ sal_Int32 ScImportExport::CountVisualWidth(std::u16string_view rStr) return CountVisualWidth(rStr, nIdx, SAL_MAX_INT32); } -void ScImportExport::SetNoEndianSwap( SvStream& rStrm ) -{ -#ifdef OSL_BIGENDIAN - rStrm.SetEndian( SvStreamEndian::BIG ); -#else - rStrm.SetEndian( SvStreamEndian::LITTLE ); -#endif -} - static inline bool lcl_isFieldEnd( sal_Unicode c, const sal_Unicode* pSeps ) { return !c || ScGlobal::UnicodeStrChr( pSeps, c); @@ -2694,11 +2684,7 @@ ScImportStringStream::ScImportStringStream( const OUString& rStr ) rStr.getLength() * sizeof(sal_Unicode), StreamMode::READ) { SetStreamCharSet( RTL_TEXTENCODING_UNICODE ); -#ifdef OSL_BIGENDIAN - SetEndian(SvStreamEndian::BIG); -#else - SetEndian(SvStreamEndian::LITTLE); -#endif + ResetEndianSwap(); } OUString ReadCsvLine( SvStream &rStream, bool bEmbeddedLineBreak, diff --git a/sc/source/ui/inc/impex.hxx b/sc/source/ui/inc/impex.hxx index 28e948f44499..13e0ef04346f 100644 --- a/sc/source/ui/inc/impex.hxx +++ b/sc/source/ui/inc/impex.hxx @@ -125,9 +125,6 @@ public: **/ static sal_Int32 CountVisualWidth(std::u16string_view rStr); - //! only if stream is only used in own (!) memory - static void SetNoEndianSwap( SvStream& rStrm ); - void SetSeparator( sal_Unicode c ) { cSep = c; } void SetDelimiter( sal_Unicode c ) { cStr = c; } void SetFormulas( bool b ) { bFormulas = b; } diff --git a/sc/source/ui/view/cellsh2.cxx b/sc/source/ui/view/cellsh2.cxx index a8e494abeeae..9d67cdc59c1b 100644 --- a/sc/source/ui/view/cellsh2.cxx +++ b/sc/source/ui/view/cellsh2.cxx @@ -1077,7 +1077,7 @@ void ScCellShell::ExecuteDB( SfxRequest& rReq ) SvMemoryStream aStream; aStream.SetStreamCharSet( RTL_TEXTENCODING_UNICODE ); - ScImportExport::SetNoEndianSwap( aStream ); + aStream.ResetEndianSwap(); aExport.ExportStream( aStream, OUString(), SotClipboardFormatId::STRING ); aStream.Seek(0); diff --git a/sw/source/core/edit/edglss.cxx b/sw/source/core/edit/edglss.cxx index 2e18d1fdaf02..7e5a41a73a0d 100644 --- a/sw/source/core/edit/edglss.cxx +++ b/sw/source/core/edit/edglss.cxx @@ -21,7 +21,6 @@ #include <o3tl/safeint.hxx> #include <osl/diagnose.h> -#include <osl/endian.h> #include <tools/urlobj.hxx> #include <doc.hxx> #include <IDocumentRedlineAccess.hxx> @@ -273,11 +272,7 @@ void SwEditShell::GetSelectedText( OUString &rBuf, ParaBreakType nHndlParaBrk ) else if( IsSelection() ) { SvMemoryStream aStream; -#ifdef OSL_BIGENDIAN - aStream.SetEndian( SvStreamEndian::BIG ); -#else - aStream.SetEndian( SvStreamEndian::LITTLE ); -#endif + aStream.ResetEndianSwap(); WriterRef xWrt; SwReaderWriter::GetWriter( FILTER_TEXT, OUString(), xWrt ); if( xWrt.is() ) diff --git a/sw/source/core/unocore/unoobj.cxx b/sw/source/core/unocore/unoobj.cxx index bdcaebdb7f2a..57aac3b5e258 100644 --- a/sw/source/core/unocore/unoobj.cxx +++ b/sw/source/core/unocore/unoobj.cxx @@ -23,7 +23,6 @@ #include <svl/itemprop.hxx> #include <o3tl/any.hxx> #include <o3tl/safeint.hxx> -#include <osl/endian.h> #include <unotools/collatorwrapper.hxx> #include <editeng/memberids.h> @@ -143,11 +142,7 @@ void SwUnoCursorHelper::GetTextFromPam(SwPaM & rPam, OUString & rBuffer, return; } SvMemoryStream aStream; -#ifdef OSL_BIGENDIAN - aStream.SetEndian( SvStreamEndian::BIG ); -#else - aStream.SetEndian( SvStreamEndian::LITTLE ); -#endif + aStream.ResetEndianSwap(); WriterRef xWrt; // TODO/MBA: looks like a BaseURL doesn't make sense here SwReaderWriter::GetWriter( FILTER_TEXT_DLG, OUString(), xWrt ); diff --git a/sw/source/filter/ascii/wrtasc.cxx b/sw/source/filter/ascii/wrtasc.cxx index 6b7ada9bd87e..9570dda31e2b 100644 --- a/sw/source/filter/ascii/wrtasc.cxx +++ b/sw/source/filter/ascii/wrtasc.cxx @@ -17,7 +17,8 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#include <osl/endian.h> +#include <sal/config.h> + #include <tools/stream.hxx> #include <pam.hxx> #include <doc.hxx> @@ -172,11 +173,7 @@ ErrCode SwASCWriter::WriteStream() break; case RTL_TEXTENCODING_UCS2: -#ifdef OSL_LITENDIAN - Strm().SetEndian(SvStreamEndian::LITTLE); -#else - Strm().SetEndian(SvStreamEndian::BIG); -#endif + Strm().ResetEndianSwap(); if( bIncludeBOM ) { Strm().StartWritingUnicodeText(); diff --git a/sw/source/uibase/dochdl/swdtflvr.cxx b/sw/source/uibase/dochdl/swdtflvr.cxx index 9473bd5d0928..fe615cc1e8cd 100644 --- a/sw/source/uibase/dochdl/swdtflvr.cxx +++ b/sw/source/uibase/dochdl/swdtflvr.cxx @@ -41,7 +41,6 @@ #include <sot/filelist.hxx> #include <svx/svxdlg.hxx> #include <toolkit/helper/vclunohelper.hxx> -#include <osl/endian.h> #include <sfx2/linkmgr.hxx> #include <tools/urlobj.hxx> #include <vcl/weld.hxx> @@ -2207,11 +2206,7 @@ bool SwTransferable::PasteFileContent( const TransferableDataHelper& rData, pStream = new SvMemoryStream( const_cast<sal_Unicode *>(sData.getStr()), sData.getLength() * sizeof( sal_Unicode ), StreamMode::READ ); -#ifdef OSL_BIGENDIAN - pStream->SetEndian( SvStreamEndian::BIG ); -#else - pStream->SetEndian( SvStreamEndian::LITTLE ); -#endif + pStream->ResetEndianSwap(); SwAsciiOptions aAOpt; aAOpt.SetCharSet( RTL_TEXTENCODING_UCS2 ); diff --git a/tools/source/stream/stream.cxx b/tools/source/stream/stream.cxx index 16857b9c4145..74926734138d 100644 --- a/tools/source/stream/stream.cxx +++ b/tools/source/stream/stream.cxx @@ -675,7 +675,7 @@ bool SvStream::WriteUniOrByteChar( sal_Unicode ch, rtl_TextEncoding eDestCharSet void SvStream::StartWritingUnicodeText() { - m_isSwap = false; // Switch to no endian swapping + ResetEndianSwap(); // Switch to no endian swapping // BOM, Byte Order Mark, U+FEFF, see // http://www.unicode.org/faq/utf_bom.html#BOM // Upon read: 0xfeff(-257) => no swap; 0xfffe(-2) => swap
