diff options
author | Noel Grandin <noelgrandin@gmail.com> | 2018-10-11 18:49:34 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-10-15 07:56:42 +0200 |
commit | 9ec8bf8f22fe74884185492ef2576ce79b41e4f1 (patch) | |
tree | 0b162c71c51a55125a2ce6055632d4f96180f431 /sw | |
parent | a84e3df74eecc8778e3d5be5dd80ad4ddb511edf (diff) |
add SvStream::TellEnd
and simplify callsites to use it instead of the current
"seek to end, find pos, seek back to original pos"
pattern
Change-Id: Ib5828868f73c341891efc759af8bd4695ae2f33c
Reviewed-on: https://gerrit.libreoffice.org/61738
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sw')
-rw-r--r-- | sw/qa/extras/htmlexport/htmlexport.cxx | 32 | ||||
-rw-r--r-- | sw/source/core/doc/swserv.cxx | 2 | ||||
-rw-r--r-- | sw/source/filter/ascii/parasc.cxx | 4 | ||||
-rw-r--r-- | sw/source/filter/html/htmlcss1.cxx | 3 | ||||
-rw-r--r-- | sw/source/filter/html/htmlreqifreader.cxx | 3 | ||||
-rw-r--r-- | sw/source/filter/ww8/rtfattributeoutput.cxx | 18 | ||||
-rw-r--r-- | sw/source/filter/ww8/rtfsdrexport.cxx | 3 | ||||
-rw-r--r-- | sw/source/filter/ww8/wrtww8.cxx | 6 | ||||
-rw-r--r-- | sw/source/filter/ww8/ww8par.cxx | 10 | ||||
-rw-r--r-- | sw/source/filter/ww8/ww8scan.cxx | 8 | ||||
-rw-r--r-- | sw/source/uibase/dbui/mailmergehelper.cxx | 3 | ||||
-rw-r--r-- | sw/source/uibase/uno/SwXDocumentSettings.cxx | 3 |
12 files changed, 28 insertions, 67 deletions
diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx b/sw/qa/extras/htmlexport/htmlexport.cxx index 861054868ec1..1c5effbac61b 100644 --- a/sw/qa/extras/htmlexport/htmlexport.cxx +++ b/sw/qa/extras/htmlexport/htmlexport.cxx @@ -356,9 +356,7 @@ DECLARE_HTMLEXPORT_TEST(testReqIfParagraph, "reqif-p.xhtml") { SvStream* pStream = maTempFile.GetStream(StreamMode::READ); CPPUNIT_ASSERT(pStream); - pStream->Seek(STREAM_SEEK_TO_END); - sal_uInt64 nLength = pStream->Tell(); - pStream->Seek(0); + sal_uInt64 nLength = pStream->TellEnd(); OString aExpected("<reqif-xhtml:div><reqif-xhtml:p>aaa<reqif-xhtml:br/>\nbbb" "</reqif-xhtml:p>" SAL_NEWLINE_STRING); @@ -444,9 +442,7 @@ DECLARE_HTMLEXPORT_ROUNDTRIP_TEST(testReqIfOleImg, "reqif-ole-img.xhtml") // "type" attribute was missing for the inner <object> element. SvStream* pStream = maTempFile.GetStream(StreamMode::READ); CPPUNIT_ASSERT(pStream); - pStream->Seek(STREAM_SEEK_TO_END); - sal_uInt64 nLength = pStream->Tell(); - pStream->Seek(0); + sal_uInt64 nLength = pStream->TellEnd(); OString aStream(read_uInt8s_ToOString(*pStream, nLength)); CPPUNIT_ASSERT(aStream.indexOf("type=\"image/png\"") != -1); } @@ -470,9 +466,7 @@ DECLARE_HTMLEXPORT_ROUNDTRIP_TEST(testReqIfPngImg, "reqif-png-img.xhtml") // subset. SvStream* pStream = maTempFile.GetStream(StreamMode::READ); CPPUNIT_ASSERT(pStream); - pStream->Seek(STREAM_SEEK_TO_END); - sal_uInt64 nLength = pStream->Tell(); - pStream->Seek(0); + sal_uInt64 nLength = pStream->TellEnd(); OString aStream(read_uInt8s_ToOString(*pStream, nLength)); CPPUNIT_ASSERT(aStream.indexOf("<reqif-xhtml:object") != -1); @@ -487,9 +481,7 @@ DECLARE_HTMLEXPORT_TEST(testReqIfJpgImg, "reqif-jpg-img.xhtml") { SvStream* pStream = maTempFile.GetStream(StreamMode::READ); CPPUNIT_ASSERT(pStream); - pStream->Seek(STREAM_SEEK_TO_END); - sal_uInt64 nLength = pStream->Tell(); - pStream->Seek(0); + sal_uInt64 nLength = pStream->TellEnd(); OString aStream(read_uInt8s_ToOString(*pStream, nLength)); // This was image/jpeg, JPG was not converted to PNG in ReqIF mode. CPPUNIT_ASSERT(aStream.indexOf("type=\"image/png\"") != -1); @@ -514,9 +506,7 @@ DECLARE_HTMLEXPORT_TEST(testReqIfTable2, "reqif-table2.odt") { SvStream* pStream = maTempFile.GetStream(StreamMode::READ); CPPUNIT_ASSERT(pStream); - pStream->Seek(STREAM_SEEK_TO_END); - sal_uInt64 nLength = pStream->Tell(); - pStream->Seek(0); + sal_uInt64 nLength = pStream->TellEnd(); OString aStream(read_uInt8s_ToOString(*pStream, nLength)); // This failed, <reqif-xhtml:td width="..."> was written. CPPUNIT_ASSERT(aStream.indexOf("<reqif-xhtml:td>") != -1); @@ -526,9 +516,7 @@ DECLARE_HTMLEXPORT_TEST(testReqIfWellFormed, "reqif.odt") { SvStream* pStream = maTempFile.GetStream(StreamMode::READ); CPPUNIT_ASSERT(pStream); - pStream->Seek(STREAM_SEEK_TO_END); - sal_uInt64 nLength = pStream->Tell(); - pStream->Seek(0); + sal_uInt64 nLength = pStream->TellEnd(); OString aStream(read_uInt8s_ToOString(*pStream, nLength)); // This failed, <font face="..."> was written. CPPUNIT_ASSERT(aStream.indexOf("<reqif-xhtml:span style=\"font-family:") != -1); @@ -540,9 +528,7 @@ DECLARE_HTMLEXPORT_TEST(testReqIfList, "reqif-list.xhtml") { SvStream* pStream = maTempFile.GetStream(StreamMode::READ); CPPUNIT_ASSERT(pStream); - pStream->Seek(STREAM_SEEK_TO_END); - sal_uInt64 nLength = pStream->Tell(); - pStream->Seek(0); + sal_uInt64 nLength = pStream->TellEnd(); OString aStream(read_uInt8s_ToOString(*pStream, nLength)); // This failed, <ul> was written. CPPUNIT_ASSERT(aStream.indexOf("<reqif-xhtml:ul>") != -1); @@ -594,9 +580,7 @@ DECLARE_HTMLEXPORT_TEST(testList, "list.html") { SvStream* pStream = maTempFile.GetStream(StreamMode::READ); CPPUNIT_ASSERT(pStream); - pStream->Seek(STREAM_SEEK_TO_END); - sal_uInt64 nLength = pStream->Tell(); - pStream->Seek(0); + sal_uInt64 nLength = pStream->TellEnd(); OString aStream(read_uInt8s_ToOString(*pStream, nLength)); // This failed, it was <li/>, i.e. list item was closed before content // started. diff --git a/sw/source/core/doc/swserv.cxx b/sw/source/core/doc/swserv.cxx index 8d00223b680f..288db677587c 100644 --- a/sw/source/core/doc/swserv.cxx +++ b/sw/source/core/doc/swserv.cxx @@ -97,7 +97,7 @@ bool SwServerObject::GetData( uno::Any & rData, aMemStm.WriteChar( '\0' ); // append a zero char rData <<= uno::Sequence< sal_Int8 >( static_cast<sal_Int8 const *>(aMemStm.GetData()), - aMemStm.Seek( STREAM_SEEK_TO_END ) ); + aMemStm.Tell() ); bRet = true; } delete pPam; diff --git a/sw/source/filter/ascii/parasc.cxx b/sw/source/filter/ascii/parasc.cxx index 183f32a148d3..a6b41a588aae 100644 --- a/sw/source/filter/ascii/parasc.cxx +++ b/sw/source/filter/ascii/parasc.cxx @@ -134,10 +134,8 @@ SwASCIIParser::SwASCIIParser(SwDoc* pD, const SwPaM& rCursor, SvStream& rIn, // Calling the parser ErrCode SwASCIIParser::CallParser() { - rInput.Seek(STREAM_SEEK_TO_END); rInput.ResetError(); - - nFileSize = rInput.Tell(); + nFileSize = rInput.TellEnd(); rInput.Seek(STREAM_SEEK_TO_BEGIN); rInput.ResetError(); diff --git a/sw/source/filter/html/htmlcss1.cxx b/sw/source/filter/html/htmlcss1.cxx index 316dc4516011..36bbdbafce18 100644 --- a/sw/source/filter/html/htmlcss1.cxx +++ b/sw/source/filter/html/htmlcss1.cxx @@ -1701,8 +1701,7 @@ bool SwHTMLParser::FileDownload( const OUString& rURL, SvMemoryStream aStream; aStream.WriteStream( *pStream ); - aStream.Seek( STREAM_SEEK_TO_END ); - rStr = OUString(static_cast<const sal_Char *>(aStream.GetData()), aStream.Tell(), + rStr = OUString(static_cast<const sal_Char *>(aStream.GetData()), aStream.TellEnd(), GetSrcEncoding()); } diff --git a/sw/source/filter/html/htmlreqifreader.cxx b/sw/source/filter/html/htmlreqifreader.cxx index 3b5c2f65f4d9..cdc443f42cee 100644 --- a/sw/source/filter/html/htmlreqifreader.cxx +++ b/sw/source/filter/html/htmlreqifreader.cxx @@ -124,8 +124,7 @@ OString InsertOLE1Header(SvStream& rOle2, SvStream& rOle1) rOle1.WriteUInt32(0); // NativeDataSize - rOle2.Seek(STREAM_SEEK_TO_END); - rOle1.WriteUInt32(rOle2.Tell()); + rOle1.WriteUInt32(rOle2.TellEnd()); // Write the actual native data. rOle2.Seek(0); diff --git a/sw/source/filter/ww8/rtfattributeoutput.cxx b/sw/source/filter/ww8/rtfattributeoutput.cxx index efbec3e6cf0a..05bcce08dfcf 100644 --- a/sw/source/filter/ww8/rtfattributeoutput.cxx +++ b/sw/source/filter/ww8/rtfattributeoutput.cxx @@ -3829,8 +3829,7 @@ void RtfAttributeOutput::FlyFrameOLEReplacement(const SwFlyFrameFormat* pFlyFram SvMemoryStream aStream; if (GraphicConverter::Export(aStream, *pGraphic, ConvertDataFormat::PNG) != ERRCODE_NONE) SAL_WARN("sw.rtf", "failed to export the graphic"); - aStream.Seek(STREAM_SEEK_TO_END); - sal_uInt32 nSize = aStream.Tell(); + sal_uInt32 nSize = aStream.TellEnd(); pGraphicAry = static_cast<sal_uInt8 const*>(aStream.GetData()); m_aRunText->append(ExportPICT(pFlyFrameFormat, aSize, aRendered, aMapped, rCr, pBLIPType, pGraphicAry, nSize, m_rExport)); @@ -3840,8 +3839,7 @@ void RtfAttributeOutput::FlyFrameOLEReplacement(const SwFlyFrameFormat* pFlyFram SvMemoryStream aWmfStream; if (GraphicConverter::Export(aWmfStream, *pGraphic, ConvertDataFormat::WMF) != ERRCODE_NONE) SAL_WARN("sw.rtf", "failed to export the graphic"); - aWmfStream.Seek(STREAM_SEEK_TO_END); - nSize = aWmfStream.Tell(); + nSize = aWmfStream.TellEnd(); pGraphicAry = static_cast<sal_uInt8 const*>(aWmfStream.GetData()); m_aRunText->append(ExportPICT(pFlyFrameFormat, aSize, aRendered, aMapped, rCr, pBLIPType, pGraphicAry, nSize, m_rExport)); @@ -3960,8 +3958,7 @@ void RtfAttributeOutput::FlyFrameGraphic(const SwFlyFrameFormat* pFlyFrameFormat { pBLIPType = (eGraphicType == GraphicType::Bitmap) ? OOO_STRING_SVTOOLS_RTF_PNGBLIP : OOO_STRING_SVTOOLS_RTF_WMETAFILE; - aStream.Seek(STREAM_SEEK_TO_END); - nSize = aStream.Tell(); + nSize = aStream.TellEnd(); pGraphicAry = static_cast<sal_uInt8 const*>(aStream.GetData()); } } @@ -4079,8 +4076,7 @@ void RtfAttributeOutput::FlyFrameGraphic(const SwFlyFrameFormat* pFlyFrameFormat if (GraphicConverter::Export(aStream, rGraphic, aConvertDestinationFormat) != ERRCODE_NONE) SAL_WARN("sw.rtf", "failed to export the graphic"); pBLIPType = pConvertDestinationBLIPType; - aStream.Seek(STREAM_SEEK_TO_END); - nSize = aStream.Tell(); + nSize = aStream.TellEnd(); pGraphicAry = static_cast<sal_uInt8 const*>(aStream.GetData()); ExportPICT(pFlyFrameFormat, aSize, aRendered, aMapped, rCr, pBLIPType, pGraphicAry, nSize, @@ -4098,8 +4094,7 @@ void RtfAttributeOutput::FlyFrameGraphic(const SwFlyFrameFormat* pFlyFrameFormat if (GraphicConverter::Export(aStream, rGraphic, ConvertDataFormat::WMF) != ERRCODE_NONE) SAL_WARN("sw.rtf", "failed to export the graphic"); pBLIPType = OOO_STRING_SVTOOLS_RTF_WMETAFILE; - aStream.Seek(STREAM_SEEK_TO_END); - nSize = aStream.Tell(); + nSize = aStream.TellEnd(); pGraphicAry = static_cast<sal_uInt8 const*>(aStream.GetData()); ExportPICT(pFlyFrameFormat, aSize, aRendered, aMapped, rCr, pBLIPType, pGraphicAry, @@ -4129,8 +4124,7 @@ void RtfAttributeOutput::BulletDefinition(int /*nId*/, const Graphic& rGraphic, SvMemoryStream aStream; if (GraphicConverter::Export(aStream, rGraphic, ConvertDataFormat::PNG) != ERRCODE_NONE) SAL_WARN("sw.rtf", "failed to export the numbering picture bullet"); - aStream.Seek(STREAM_SEEK_TO_END); - sal_uInt32 nSize = aStream.Tell(); + sal_uInt32 nSize = aStream.TellEnd(); pGraphicAry = static_cast<sal_uInt8 const*>(aStream.GetData()); msfilter::rtfutil::WriteHex(pGraphicAry, nSize, &m_rExport.Strm()); m_rExport.Strm().WriteCharPtr("}}"); // pict, shppict diff --git a/sw/source/filter/ww8/rtfsdrexport.cxx b/sw/source/filter/ww8/rtfsdrexport.cxx index 6d2ed207fff6..51ec0f3f638e 100644 --- a/sw/source/filter/ww8/rtfsdrexport.cxx +++ b/sw/source/filter/ww8/rtfsdrexport.cxx @@ -523,8 +523,7 @@ void RtfSdrExport::impl_writeGraphic() // Export it to a stream. SvMemoryStream aStream; (void)GraphicConverter::Export(aStream, aGraphic, ConvertDataFormat::PNG); - aStream.Seek(STREAM_SEEK_TO_END); - sal_uInt32 nSize = aStream.Tell(); + sal_uInt32 nSize = aStream.TellEnd(); auto pGraphicAry = static_cast<sal_uInt8 const*>(aStream.GetData()); Size aMapped(aGraphic.GetPrefSize()); diff --git a/sw/source/filter/ww8/wrtww8.cxx b/sw/source/filter/ww8/wrtww8.cxx index c6dda312b4b1..ca6c7dc4db8f 100644 --- a/sw/source/filter/ww8/wrtww8.cxx +++ b/sw/source/filter/ww8/wrtww8.cxx @@ -3122,8 +3122,7 @@ namespace ErrCode EncryptRC4(msfilter::MSCodec_Std97& rCtx, SvStream &rIn, SvStream &rOut) { - rIn.Seek(STREAM_SEEK_TO_END); - sal_uLong nLen = rIn.Tell(); + sal_uLong nLen = rIn.TellEnd(); rIn.Seek(0); sal_uInt8 in[WW_BLOCKSIZE]; @@ -3793,8 +3792,7 @@ void WW8Export::RestoreMacroCmds() if ( pStream && ERRCODE_NONE == pStream->GetError()) { - pStream->Seek(STREAM_SEEK_TO_END); - pFib->m_lcbCmds = pStream->Tell(); + pFib->m_lcbCmds = pStream->TellEnd(); pStream->Seek(0); std::unique_ptr<sal_uInt8[]> pBuffer( new sal_uInt8[pFib->m_lcbCmds] ); diff --git a/sw/source/filter/ww8/ww8par.cxx b/sw/source/filter/ww8/ww8par.cxx index 707953b16c5a..32638e8cd51e 100644 --- a/sw/source/filter/ww8/ww8par.cxx +++ b/sw/source/filter/ww8/ww8par.cxx @@ -1071,8 +1071,7 @@ SdrObject* SwMSDffManager::ProcessObj(SvStream& rSt, if (rSt.ReadBytes(aBuffer.data(), nBufferSize) == nBufferSize) { aMemStream.WriteBytes(aBuffer.data(), nBufferSize); - aMemStream.Seek( STREAM_SEEK_TO_END ); - sal_uInt8 nStreamSize = aMemStream.Tell(); + sal_uInt8 nStreamSize = aMemStream.TellEnd(); aMemStream.Seek( STREAM_SEEK_TO_BEGIN ); bool bRet = 4 <= nStreamSize; if( bRet ) @@ -5466,8 +5465,7 @@ namespace void DecryptRC4(msfilter::MSCodec97& rCtx, SvStream &rIn, SvStream &rOut) { - rIn.Seek(STREAM_SEEK_TO_END); - const std::size_t nLen = rIn.Tell(); + const std::size_t nLen = rIn.TellEnd(); rIn.Seek(0); sal_uInt8 in[WW_BLOCKSIZE]; @@ -5484,9 +5482,7 @@ namespace void DecryptXOR(msfilter::MSCodec_XorWord95 &rCtx, SvStream &rIn, SvStream &rOut) { std::size_t nSt = rIn.Tell(); - rIn.Seek(STREAM_SEEK_TO_END); - std::size_t nLen = rIn.Tell(); - rIn.Seek(nSt); + std::size_t nLen = rIn.TellEnd(); rCtx.InitCipher(); rCtx.Skip(nSt); diff --git a/sw/source/filter/ww8/ww8scan.cxx b/sw/source/filter/ww8/ww8scan.cxx index 0200cc99e4b9..569912912c0d 100644 --- a/sw/source/filter/ww8/ww8scan.cxx +++ b/sw/source/filter/ww8/ww8scan.cxx @@ -6264,9 +6264,7 @@ void WW8Fib::WriteHeader(SvStream& rStrm) sal_uInt8 *pData = pDataPtr.get(); memset( pData, 0, nUnencryptedHdr ); - const sal_uInt64 nPos = rStrm.Tell(); - m_cbMac = rStrm.Seek( STREAM_SEEK_TO_END ); - rStrm.Seek(nPos); + m_cbMac = rStrm.TellEnd(); Set_UInt16( pData, m_wIdent ); Set_UInt16( pData, m_nFib ); @@ -6351,9 +6349,7 @@ void WW8Fib::Write(SvStream& rStrm) sal_uInt8 *pData = pDataPtr.get(); memset( pData, 0, m_fcMin - nUnencryptedHdr ); - const sal_uInt64 nPos = rStrm.Tell(); - m_cbMac = rStrm.Seek( STREAM_SEEK_TO_END ); - rStrm.Seek(nPos); + m_cbMac = rStrm.TellEnd(); // ignore 2 longs, because they are unimportant pData += 2 * sizeof( sal_Int32); diff --git a/sw/source/uibase/dbui/mailmergehelper.cxx b/sw/source/uibase/dbui/mailmergehelper.cxx index 9768744eeca6..c5ccb9a3c16d 100644 --- a/sw/source/uibase/dbui/mailmergehelper.cxx +++ b/sw/source/uibase/dbui/mailmergehelper.cxx @@ -694,8 +694,7 @@ uno::Any SwMailTransferable::getTransferData( const datatransfer::DataFlavor& /* SvStream* pStream = aMedium.GetInStream(); if ( aMedium.GetErrorCode() == ERRCODE_NONE && pStream) { - pStream->Seek(STREAM_SEEK_TO_END); - aData.realloc(pStream->Tell()); + aData.realloc(pStream->TellEnd()); pStream->Seek(0); sal_Int8 * pData = aData.getArray(); pStream->ReadBytes( pData, aData.getLength() ); diff --git a/sw/source/uibase/uno/SwXDocumentSettings.cxx b/sw/source/uibase/uno/SwXDocumentSettings.cxx index 12ac99b6fbcd..37caae8f406d 100644 --- a/sw/source/uibase/uno/SwXDocumentSettings.cxx +++ b/sw/source/uibase/uno/SwXDocumentSettings.cxx @@ -1021,8 +1021,7 @@ void SwXDocumentSettings::_getSingleValue( const comphelper::PropertyInfo & rInf { SvMemoryStream aStream; pPrinter->Store( aStream ); - aStream.Seek ( STREAM_SEEK_TO_END ); - sal_uInt32 nSize = aStream.Tell(); + sal_uInt32 nSize = aStream.TellEnd(); aStream.Seek ( STREAM_SEEK_TO_BEGIN ); Sequence < sal_Int8 > aSequence( nSize ); aStream.ReadBytes(aSequence.getArray(), nSize); |