From 429e327d14aaaa3a913b93b5788129b33bd26a43 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Mon, 10 Oct 2022 11:49:26 +0200 Subject: [PATCH] use more string_view in sd Change-Id: Iafcab8d5b21f9562838c3494cbfd75090dd6e010 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141152 Tested-by: Jenkins Reviewed-by: Noel Grandin --- sd/inc/drawdoc.hxx | 2 +- sd/qa/unit/export-tests-ooxml2.cxx | 4 ++-- sd/source/core/drawdoc2.cxx | 16 ++++++------- sd/source/filter/eppt/eppt.hxx | 4 ++-- sd/source/filter/eppt/epptso.cxx | 24 ++++++++++---------- sd/source/filter/eppt/pptexanimations.cxx | 19 ++++++++-------- sd/source/filter/eppt/pptexanimations.hxx | 4 ++-- sd/source/filter/eppt/pptx-epptooxml.cxx | 10 ++++---- sd/source/filter/sdpptwrp.cxx | 6 ++--- sd/source/ui/presenter/PresenterTextView.cxx | 12 +++++----- 10 files changed, 50 insertions(+), 51 deletions(-) diff --git a/sd/inc/drawdoc.hxx b/sd/inc/drawdoc.hxx index a99c27c49bd1..9637e8f26cc2 100644 --- a/sd/inc/drawdoc.hxx +++ b/sd/inc/drawdoc.hxx @@ -598,7 +598,7 @@ public: SdStyleSheetPool* GetSdStyleSheetPool() const; SAL_DLLPRIVATE void UpdatePageRelativeURLs( - const OUString& rOldName, std::u16string_view rNewName); + std::u16string_view aOldName, std::u16string_view aNewName); SAL_DLLPRIVATE static void SetCalcFieldValueHdl( ::Outliner* pOutliner); diff --git a/sd/qa/unit/export-tests-ooxml2.cxx b/sd/qa/unit/export-tests-ooxml2.cxx index 4366d26fddd1..928ecab95997 100644 --- a/sd/qa/unit/export-tests-ooxml2.cxx +++ b/sd/qa/unit/export-tests-ooxml2.cxx @@ -33,9 +33,9 @@ using namespace css::animations; namespace { -bool checkBeginWithNumber(const OUString& rStr) +bool checkBeginWithNumber(std::u16string_view aStr) { - sal_Unicode aChar = (rStr.getLength() > 1) ? rStr[0] : '\0'; + sal_Unicode aChar = (aStr.size() > 1) ? aStr[0] : '\0'; return aChar == '.' || aChar == '-' || rtl::isAsciiDigit(aChar); } diff --git a/sd/source/core/drawdoc2.cxx b/sd/source/core/drawdoc2.cxx index d0187bab0f8c..d591113fcca9 100644 --- a/sd/source/core/drawdoc2.cxx +++ b/sd/source/core/drawdoc2.cxx @@ -264,9 +264,9 @@ void SdDrawDocument::UpdatePageObjectsInNotes(sal_uInt16 nStartPos) } } -void SdDrawDocument::UpdatePageRelativeURLs(const OUString& rOldName, std::u16string_view rNewName) +void SdDrawDocument::UpdatePageRelativeURLs(std::u16string_view aOldName, std::u16string_view aNewName) { - if (rNewName.empty()) + if (aNewName.empty()) return; SfxItemPool& rPool(GetPool()); @@ -282,22 +282,22 @@ void SdDrawDocument::UpdatePageRelativeURLs(const OUString& rOldName, std::u16st { OUString aURL = pURLField->GetURL(); - if (!aURL.isEmpty() && (aURL[0] == 35) && (aURL.indexOf(rOldName, 1) == 1)) + if (!aURL.isEmpty() && (aURL[0] == 35) && (aURL.indexOf(aOldName, 1) == 1)) { - if (aURL.getLength() == rOldName.getLength() + 1) // standard page name + if (aURL.getLength() == sal_Int32(aOldName.size() + 1)) // standard page name { aURL = aURL.replaceAt(1, aURL.getLength() - 1, u"") + - rNewName; + aNewName; pURLField->SetURL(aURL); } else { const OUString sNotes(SdResId(STR_NOTES)); - if (aURL.getLength() == rOldName.getLength() + 2 + sNotes.getLength() - && aURL.indexOf(sNotes, rOldName.getLength() + 2) == rOldName.getLength() + 2) + if (aURL.getLength() == sal_Int32(aOldName.size()) + 2 + sNotes.getLength() + && aURL.indexOf(sNotes, aOldName.size() + 2) == sal_Int32(aOldName.size() + 2)) { aURL = aURL.replaceAt(1, aURL.getLength() - 1, u"") + - rNewName + " " + sNotes; + aNewName + " " + sNotes; pURLField->SetURL(aURL); } } diff --git a/sd/source/filter/eppt/eppt.hxx b/sd/source/filter/eppt/eppt.hxx index ee2219ddd316..635d5a2223a1 100644 --- a/sd/source/filter/eppt/eppt.hxx +++ b/sd/source/filter/eppt/eppt.hxx @@ -164,7 +164,7 @@ class PPTWriter final : public PPTWriterBase, public PPTExBulletProvider sal_uInt32 ImplMasterSlideListContainer( SvStream* pOutStrm ); public: - static void WriteCString( SvStream&, const OUString&, sal_uInt32 nInstance = 0 ); + static void WriteCString( SvStream&, std::u16string_view, sal_uInt32 nInstance = 0 ); private: @@ -176,7 +176,7 @@ class PPTWriter final : public PPTWriterBase, public PPTExBulletProvider virtual bool ImplCreateDocument() override; void ImplCreateHyperBlob( SvMemoryStream& rStream ); sal_uInt32 ImplInsertBookmarkURL( const OUString& rBookmark, const sal_uInt32 nType, - const OUString& rStringVer0, const OUString& rStringVer1, const OUString& rStringVer2, const OUString& rStringVer3 ); + std::u16string_view aStringVer0, std::u16string_view aStringVer1, std::u16string_view aStringVer2, std::u16string_view aStringVer3 ); virtual bool ImplCreateMainNotes() override; void ImplWriteBackground( css::uno::Reference< css::beans::XPropertySet > const & rXBackgroundPropSet ); void ImplWriteVBA(); diff --git a/sd/source/filter/eppt/epptso.cxx b/sd/source/filter/eppt/epptso.cxx index eae0e5d8c4ab..15e013713001 100644 --- a/sd/source/filter/eppt/epptso.cxx +++ b/sd/source/filter/eppt/epptso.cxx @@ -337,7 +337,7 @@ sal_uInt32 PPTWriter::ImplMasterSlideListContainer( SvStream* pStrm ) } sal_uInt32 PPTWriter::ImplInsertBookmarkURL( const OUString& rBookmarkURL, const sal_uInt32 nType, - const OUString& rStringVer0, const OUString& rStringVer1, const OUString& rStringVer2, const OUString& rStringVer3 ) + std::u16string_view aStringVer0, std::u16string_view aStringVer1, std::u16string_view aStringVer2, std::u16string_view aStringVer3 ) { sal_uInt32 nHyperId = ++mnExEmbed; @@ -361,10 +361,10 @@ sal_uInt32 PPTWriter::ImplInsertBookmarkURL( const OUString& rBookmarkURL, const .WriteUInt32( 4 ) .WriteUInt32( nHyperId ); - PPTWriter::WriteCString( *mpExEmbed, rStringVer0 ); - PPTWriter::WriteCString( *mpExEmbed, rStringVer1, 1 ); - PPTWriter::WriteCString( *mpExEmbed, rStringVer2, 2 ); - PPTWriter::WriteCString( *mpExEmbed, rStringVer3, 3 ); + PPTWriter::WriteCString( *mpExEmbed, aStringVer0 ); + PPTWriter::WriteCString( *mpExEmbed, aStringVer1, 1 ); + PPTWriter::WriteCString( *mpExEmbed, aStringVer2, 2 ); + PPTWriter::WriteCString( *mpExEmbed, aStringVer3, 3 ); nHyperSize = mpExEmbed->Tell() - nHyperStart; mpExEmbed->SeekRel( - ( static_cast(nHyperSize) + 4 ) ); @@ -1119,9 +1119,9 @@ void PPTWriter::ImplWriteTextStyleAtom( SvStream& rOut, int nTextInstance, sal_u } sal_uInt32 nHyperId(0); if ( !aPageUrl.isEmpty() ) - nHyperId = ImplInsertBookmarkURL( aPageUrl, 1 | ( nPageIndex << 8 ) | ( 1U << 31 ), pFieldEntry->aRepresentation, "", "", aPageUrl ); + nHyperId = ImplInsertBookmarkURL( aPageUrl, 1 | ( nPageIndex << 8 ) | ( 1U << 31 ), pFieldEntry->aRepresentation, u"", u"", aPageUrl ); else - nHyperId = ImplInsertBookmarkURL( pFieldEntry->aFieldUrl, 2 | ( nHyperId << 8 ), aFile, aTarget, "", "" ); + nHyperId = ImplInsertBookmarkURL( pFieldEntry->aFieldUrl, 2 | ( nHyperId << 8 ), aFile, aTarget, u"", u"" ); rOut.WriteUInt32( ( EPP_InteractiveInfo << 16 ) | 0xf ).WriteUInt32( 24 ) .WriteUInt32( EPP_InteractiveInfoAtom << 16 ).WriteUInt32( 16 ) @@ -1435,7 +1435,7 @@ void PPTWriter::ImplWriteClickAction( SvStream& rSt, css::presentation::ClickAct OUString::number(nIndex + 1) + ",Slide " + OUString::number(nIndex + 1); - nHyperLinkID = ImplInsertBookmarkURL( aHyperString, 1 | ( nIndex << 8 ) | ( 1U << 31 ), aBookmark, "", "", aHyperString ); + nHyperLinkID = ImplInsertBookmarkURL( aHyperString, 1 | ( nIndex << 8 ) | ( 1U << 31 ), aBookmark, u"", u"", aHyperString ); } nIndex++; } @@ -1457,7 +1457,7 @@ void PPTWriter::ImplWriteClickAction( SvStream& rSt, css::presentation::ClickAct INetURLObject aUrl( aBookmark ); if ( INetProtocol::File == aUrl.GetProtocol() ) aBookmarkFile = aUrl.PathToFileName(); - nHyperLinkID = ImplInsertBookmarkURL( aBookmark, sal_uInt32(2 | ( 1U << 31 )), aBookmarkFile, aBookmark, "", "" ); + nHyperLinkID = ImplInsertBookmarkURL( aBookmark, sal_uInt32(2 | ( 1U << 31 )), aBookmarkFile, aBookmark, u"", u"" ); } } } @@ -3029,15 +3029,15 @@ static sal_Int32 GetCellBottom( sal_Int32 nRow, return nBottom; } -void PPTWriter::WriteCString( SvStream& rSt, const OUString& rString, sal_uInt32 nInstance ) +void PPTWriter::WriteCString( SvStream& rSt, std::u16string_view aString, sal_uInt32 nInstance ) { - sal_Int32 nLen = rString.getLength(); + sal_Int32 nLen = aString.size(); if ( nLen ) { rSt.WriteUInt32( ( nInstance << 4 ) | ( EPP_CString << 16 ) ) .WriteUInt32( nLen << 1 ); for ( sal_Int32 i = 0; i < nLen; i++ ) - rSt.WriteUInt16( rString[i] ); + rSt.WriteUInt16( aString[i] ); } } diff --git a/sd/source/filter/eppt/pptexanimations.cxx b/sd/source/filter/eppt/pptexanimations.cxx index 4e126422e7c5..faef2b48522e 100644 --- a/sd/source/filter/eppt/pptexanimations.cxx +++ b/sd/source/filter/eppt/pptexanimations.cxx @@ -881,17 +881,17 @@ void AnimationExporter::GetUserData( const Sequence< NamedValue >& rUserData, co } } -sal_uInt32 AnimationExporter::GetPresetID( const OUString& rPreset, sal_uInt32 nAPIPresetClass, bool& bPresetId ) +sal_uInt32 AnimationExporter::GetPresetID( std::u16string_view aPreset, sal_uInt32 nAPIPresetClass, bool& bPresetId ) { sal_uInt32 nPresetId = 0; bPresetId = false; - if ( rPreset.match("ppt_", 0) ) + if ( o3tl::starts_with(aPreset, u"ppt_") ) { - sal_Int32 nLast = rPreset.lastIndexOf( '_' ); - if ( ( nLast != -1 ) && ( ( nLast + 1 ) < rPreset.getLength() ) ) + size_t nLast = aPreset.rfind( '_' ); + if ( ( nLast != std::u16string_view::npos ) && ( ( nLast + 1 ) < aPreset.size() ) ) { - std::u16string_view aNumber( rPreset.subView( nLast + 1 ) ); + std::u16string_view aNumber( aPreset.substr( nLast + 1 ) ); nPresetId = o3tl::toUInt32(aNumber); bPresetId = true; } @@ -899,7 +899,7 @@ sal_uInt32 AnimationExporter::GetPresetID( const OUString& rPreset, sal_uInt32 n else { const oox::ppt::preset_mapping* p = oox::ppt::preset_mapping::getList(); - while( p->mpStrPresetId && ((p->mnPresetClass != static_cast(nAPIPresetClass)) || !rPreset.equalsAscii( p->mpStrPresetId )) ) + while( p->mpStrPresetId && ((p->mnPresetClass != static_cast(nAPIPresetClass)) || !o3tl::equalsAscii(aPreset, p->mpStrPresetId )) ) p++; if( p->mpStrPresetId ) @@ -1186,11 +1186,10 @@ void AnimationExporter::exportAnimPropertyByte( SvStream& rStrm, const sal_uInt1 .WriteUChar( nVal ); } -void AnimationExporter::writeZString( SvStream& rStrm, const OUString& rVal ) +void AnimationExporter::writeZString( SvStream& rStrm, std::u16string_view aVal ) { - sal_Int32 i; - for ( i = 0; i < rVal.getLength(); i++ ) - rStrm.WriteUInt16( rVal[ i ] ); + for ( size_t i = 0; i < aVal.size(); i++ ) + rStrm.WriteUInt16( aVal[ i ] ); rStrm.WriteUInt16( 0 ); } diff --git a/sd/source/filter/eppt/pptexanimations.hxx b/sd/source/filter/eppt/pptexanimations.hxx index aa05ec60b904..b898c0de0a93 100644 --- a/sd/source/filter/eppt/pptexanimations.hxx +++ b/sd/source/filter/eppt/pptexanimations.hxx @@ -75,7 +75,7 @@ class AnimationExporter std::vector< AfterEffectNodePtr > maAfterEffectNodes; sal_Int32 mnCurrentGroup; - static void writeZString( SvStream& rStrm, const OUString& rVal ); + static void writeZString( SvStream& rStrm, std::u16string_view aVal ); static bool getColorAny( const css::uno::Any& rAny, const sal_Int16 nColorSpace, sal_Int32& rMode, sal_Int32& rA, sal_Int32& rB, sal_Int32& rC ); static bool exportAnimProperty( SvStream& rStrm, const sal_uInt16 nPropertyId, const css::uno::Any& rAny, const TranslateMode eTranslateMode ); static void exportAnimPropertyString( SvStream& rStrm, const sal_uInt16 nPropertyId, const OUString& rVal, const TranslateMode eTranslateMode ); @@ -124,7 +124,7 @@ public: static sal_Int16 GetFillMode( const css::uno::Reference< css::animations::XAnimationNode >& xNode, const sal_Int16 nFillDefault ); static void GetUserData( const css::uno::Sequence< css::beans::NamedValue >& rUserData, const css::uno::Any ** pAny, std::size_t nLen ); static sal_uInt32 TranslatePresetSubType( const sal_uInt32 nPresetClass, const sal_uInt32 nPresetId, std::u16string_view rPresetSubType ); - static sal_uInt32 GetPresetID( const OUString& rPreset, sal_uInt32 nAPIPresetClass, bool& bPresetId ); + static sal_uInt32 GetPresetID( std::u16string_view aPreset, sal_uInt32 nAPIPresetClass, bool& bPresetId ); static sal_uInt32 GetValueTypeForAttributeName( const OUString& rAttributeName ); static const char* FindTransitionName( const sal_Int16 nType, const sal_Int16 nSubType, const bool bDirection ); diff --git a/sd/source/filter/eppt/pptx-epptooxml.cxx b/sd/source/filter/eppt/pptx-epptooxml.cxx index 7679fc2fa1ec..cddb923f7e9e 100644 --- a/sd/source/filter/eppt/pptx-epptooxml.cxx +++ b/sd/source/filter/eppt/pptx-epptooxml.cxx @@ -1042,18 +1042,18 @@ void PowerPointExport::WriteTransition(const FSHelperPtr& pFS) } } -static OUString lcl_GetInitials(const OUString& sName) +static OUString lcl_GetInitials(std::u16string_view sName) { OUStringBuffer sRet; - if (!sName.isEmpty()) + if (!sName.empty()) { sRet.append(sName[0]); - sal_Int32 nStart = 0, nOffset; + size_t nStart = 0, nOffset; - while ((nOffset = sName.indexOf(' ', nStart)) != -1) + while ((nOffset = sName.find(' ', nStart)) != std::u16string_view::npos) { - if (nOffset + 1 < sName.getLength()) + if (nOffset + 1 < sName.size()) sRet.append(sName[ nOffset + 1 ]); nStart = nOffset + 1; } diff --git a/sd/source/filter/sdpptwrp.cxx b/sd/source/filter/sdpptwrp.cxx index 168fe11ffa1a..da2032816393 100644 --- a/sd/source/filter/sdpptwrp.cxx +++ b/sd/source/filter/sdpptwrp.cxx @@ -51,13 +51,13 @@ SdPPTFilter::~SdPPTFilter() delete pBas; // deleting the compressed basic storage } -static void lcl_getListOfStreams(SotStorage * pStorage, comphelper::SequenceAsHashMap& aStreamsData, const OUString& sPrefix) +static void lcl_getListOfStreams(SotStorage * pStorage, comphelper::SequenceAsHashMap& aStreamsData, std::u16string_view sPrefix) { SvStorageInfoList aElements; pStorage->FillInfoList(&aElements); for (const auto & aElement : aElements) { - OUString sStreamFullName = sPrefix.getLength() ? sPrefix + "/" + aElement.GetName() : aElement.GetName(); + OUString sStreamFullName = sPrefix.size() ? OUString::Concat(sPrefix) + "/" + aElement.GetName() : aElement.GetName(); if (aElement.IsStorage()) { tools::SvRef xSubStorage = pStorage->OpenSotStorage(aElement.GetName(), StreamMode::STD_READ | StreamMode::SHARE_DENYALL); @@ -98,7 +98,7 @@ static tools::SvRef lcl_DRMDecrypt(const SfxMedium& rMedium, const t } comphelper::SequenceAsHashMap aStreamsData; - lcl_getListOfStreams(rStorage.get(), aStreamsData, ""); + lcl_getListOfStreams(rStorage.get(), aStreamsData, u""); try { Sequence aStreams = aStreamsData.getAsConstNamedValueList(); diff --git a/sd/source/ui/presenter/PresenterTextView.cxx b/sd/source/ui/presenter/PresenterTextView.cxx index affa21b03978..d8abea74547a 100644 --- a/sd/source/ui/presenter/PresenterTextView.cxx +++ b/sd/source/ui/presenter/PresenterTextView.cxx @@ -70,7 +70,7 @@ public: sal_Int32 GetTop() const { return mnTop;} void SetTop (const sal_Int32 nTop); void SetText (const OUString& Text); - sal_Int32 ParseDistance (const OUString& rsDistance) const; + sal_Int32 ParseDistance (std::u16string_view sDistance) const; Reference const & GetBitmap(); sal_Int32 GetTotalHeight(); @@ -364,17 +364,17 @@ void PresenterTextView::Implementation::SetText (const OUString& rText) mxBitmap = nullptr; } -sal_Int32 PresenterTextView::Implementation::ParseDistance (const OUString& rsDistance) const +sal_Int32 PresenterTextView::Implementation::ParseDistance (std::u16string_view sDistance) const { DBG_ASSERT(mpEditEngine!=nullptr, "EditEngine missing"); sal_Int32 nDistance (0); - if (rsDistance.endsWith("px")) + if (o3tl::ends_with(sDistance, u"px")) { - nDistance = o3tl::toInt32(rsDistance.subView(0,rsDistance.getLength()-2)); + nDistance = o3tl::toInt32(sDistance.substr(0,sDistance.size()-2)); } - else if (rsDistance.endsWith("l")) + else if (o3tl::ends_with(sDistance, u"l")) { - const sal_Int32 nLines (o3tl::toInt32(rsDistance.subView(0,rsDistance.getLength()-1))); + const sal_Int32 nLines (o3tl::toInt32(sDistance.substr(0,sDistance.size()-1))); // Take the height of the first line as the height of every line. const sal_uInt32 nFirstLineHeight (mpEditEngine->GetLineHeight(0)); nDistance = nFirstLineHeight * nLines;