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 <mike.kaganski@collabora.com>
This commit is contained in:
Mike Kaganski
2025-06-25 17:22:45 +02:00
parent 3b12495e48
commit 12c6fc8afa
10 changed files with 15 additions and 52 deletions
+2
View File
@@ -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; }
+1 -5
View File
@@ -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);
}
+4 -18
View File
@@ -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,
-3
View File
@@ -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; }
+1 -1
View File
@@ -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);
+1 -6
View File
@@ -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() )
+1 -6
View File
@@ -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 );
+3 -6
View File
@@ -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();
+1 -6
View File
@@ -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 );
+1 -1
View File
@@ -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