From 310cbbd5866f19d2a82bef35da66f56af90c2d08 Mon Sep 17 00:00:00 2001 From: Arkadiy Illarionov Date: Thu, 4 Jul 2019 22:34:01 +0300 Subject: Simplify Sequence iterations in sw/source/filter/* Use range-based loops, STL and comphelper functions Change-Id: I8ec58bdd38061936f621cdfdbfde59a38ac86705 Reviewed-on: https://gerrit.libreoffice.org/75103 Tested-by: Jenkins Reviewed-by: Arkadiy Illarionov --- sw/source/filter/html/htmlforw.cxx | 20 +- sw/source/filter/ww8/docxattributeoutput.cxx | 352 ++++++++++++------------ sw/source/filter/ww8/docxexport.cxx | 139 ++++------ sw/source/filter/ww8/docxsdrexport.cxx | 66 ++--- sw/source/filter/ww8/docxtablestyleexport.cxx | 370 ++++++++++++-------------- sw/source/filter/ww8/rtfattributeoutput.cxx | 6 +- sw/source/filter/ww8/ww8par.cxx | 9 +- sw/source/filter/xml/wrtxml.cxx | 3 +- sw/source/filter/xml/xmlimp.cxx | 125 ++++----- sw/source/filter/xml/xmlmeta.cxx | 6 +- 10 files changed, 498 insertions(+), 598 deletions(-) (limited to 'sw/source/filter') diff --git a/sw/source/filter/html/htmlforw.cxx b/sw/source/filter/html/htmlforw.cxx index 3b0715581352..eb8697d99291 100644 --- a/sw/source/filter/html/htmlforw.cxx +++ b/sw/source/filter/html/htmlforw.cxx @@ -127,15 +127,13 @@ static void lcl_html_outEvents( SvStream& rStrm, uno::Sequence< script::ScriptEventDescriptor > aDescs = xEventManager->getScriptEvents( nPos ); - nCount = aDescs.getLength(); - if( !nCount ) + if( !aDescs.hasElements() ) return; - const script::ScriptEventDescriptor *pDescs = aDescs.getConstArray(); - for( sal_Int32 i = 0; i < nCount; i++ ) + for( const script::ScriptEventDescriptor& rDesc : aDescs ) { ScriptType eScriptType = EXTENDED_STYPE; - OUString aScriptType( pDescs[i].ScriptType ); + OUString aScriptType( rDesc.ScriptType ); if( aScriptType.equalsIgnoreAsciiCase(SVX_MACRO_LANGUAGE_JAVASCRIPT) ) eScriptType = JAVASCRIPT; else if( aScriptType.equalsIgnoreAsciiCase(SVX_MACRO_LANGUAGE_STARBASIC ) ) @@ -143,7 +141,7 @@ static void lcl_html_outEvents( SvStream& rStrm, if( JAVASCRIPT != eScriptType && !bCfgStarBasic ) continue; - OUString sListener( pDescs[i].ListenerType ); + OUString sListener( rDesc.ListenerType ); if (!sListener.isEmpty()) { const sal_Int32 nIdx { sListener.lastIndexOf('.')+1 }; @@ -159,7 +157,7 @@ static void lcl_html_outEvents( SvStream& rStrm, } } } - OUString sMethod( pDescs[i].EventMethod ); + OUString sMethod( rDesc.EventMethod ); const sal_Char *pOpt = nullptr; for( int j=0; aEventListenerTable[j]; j++ ) @@ -175,7 +173,7 @@ static void lcl_html_outEvents( SvStream& rStrm, OString sOut = " "; if( pOpt && (EXTENDED_STYPE != eScriptType || - pDescs[i].AddListenerParam.isEmpty()) ) + rDesc.AddListenerParam.isEmpty()) ) sOut += OString(pOpt); else { @@ -185,16 +183,16 @@ static void lcl_html_outEvents( SvStream& rStrm, } sOut += "=\""; rStrm.WriteOString( sOut ); - HTMLOutFuncs::Out_String( rStrm, pDescs[i].ScriptCode, eDestEnc, pNonConvertableChars ); + HTMLOutFuncs::Out_String( rStrm, rDesc.ScriptCode, eDestEnc, pNonConvertableChars ); rStrm.WriteChar( '\"' ); if( EXTENDED_STYPE == eScriptType && - !pDescs[i].AddListenerParam.isEmpty() ) + !rDesc.AddListenerParam.isEmpty() ) { sOut = " " OOO_STRING_SVTOOLS_HTML_O_sdaddparam + OUStringToOString(sListener, RTL_TEXTENCODING_ASCII_US) + "-" + OUStringToOString(sMethod, RTL_TEXTENCODING_ASCII_US) + "=\""; rStrm.WriteOString( sOut ); - HTMLOutFuncs::Out_String( rStrm, pDescs[i].AddListenerParam, + HTMLOutFuncs::Out_String( rStrm, rDesc.AddListenerParam, eDestEnc, pNonConvertableChars ); rStrm.WriteChar( '\"' ); } diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx index 2414c7efcb75..ac88e97d32eb 100644 --- a/sw/source/filter/ww8/docxattributeoutput.cxx +++ b/sw/source/filter/ww8/docxattributeoutput.cxx @@ -616,15 +616,10 @@ bool DocxAttributeOutput::TextBoxIsFramePr(const SwFrameFormat& rFrameFormat) { uno::Sequence< beans::PropertyValue > propList; xPropertySet->getPropertyValue("FrameInteropGrabBag") >>= propList; - for (sal_Int32 nProp=0; nProp < propList.getLength(); ++nProp) - { - OUString propName = propList[nProp].Name; - if (propName == "ParaFrameProperties") - { - aFrameProperties = propList[nProp].Value ; - break; - } - } + auto pProp = std::find_if(propList.begin(), propList.end(), + [](const beans::PropertyValue& rProp) { return rProp.Name == "ParaFrameProperties"; }); + if (pProp != propList.end()) + aFrameProperties = pProp->Value; } bool bFrameProperties = false; aFrameProperties >>= bFrameProperties; @@ -819,9 +814,9 @@ void DocxAttributeOutput::WriteSdtBlock( sal_Int32& nSdtPrToken, if (nSdtPrToken == FSNS( XML_w, XML_date ) || nSdtPrToken == FSNS( XML_w, XML_docPartObj ) || nSdtPrToken == FSNS( XML_w, XML_docPartList ) || nSdtPrToken == FSNS( XML_w14, XML_checkbox )) { uno::Sequence aChildren = pSdtPrTokenChildren->getFastAttributes(); - for( sal_Int32 i=0; i < aChildren.getLength(); ++i ) - m_pSerializer->singleElement( aChildren[i].Token, - FSNS(XML_w, XML_val), aChildren[i].Value.toUtf8() ); + for( const auto& rChild : aChildren ) + m_pSerializer->singleElement( rChild.Token, + FSNS(XML_w, XML_val), rChild.Value.toUtf8() ); } m_pSerializer->endElement( nSdtPrToken ); @@ -2411,17 +2406,17 @@ void lclProcessRecursiveGrabBag(sal_Int32 aElementId, const css::uno::Sequence aAttributes; FastAttributeList* pAttributes = FastSerializerHelper::createAttrList(); - for (sal_Int32 j=0; j < rElements.getLength(); ++j) + for (const auto& rElement : rElements) { - if (rElements[j].Name == "attributes") + if (rElement.Name == "attributes") { - rElements[j].Value >>= aAttributes; + rElement.Value >>= aAttributes; } } - for (sal_Int32 j=0; j < aAttributes.getLength(); ++j) + for (const auto& rAttribute : aAttributes) { - uno::Any aAny = aAttributes[j].Value; + uno::Any aAny = rAttribute.Value; OString aValue; if(aAny.getValueType() == cppu::UnoType::get()) @@ -2433,7 +2428,7 @@ void lclProcessRecursiveGrabBag(sal_Int32 aElementId, const css::uno::Sequence(), RTL_TEXTENCODING_ASCII_US); } - boost::optional aSubElementId = lclGetElementIdForName(aAttributes[j].Name); + boost::optional aSubElementId = lclGetElementIdForName(rAttribute.Name); if(aSubElementId) pAttributes->add(*aSubElementId, aValue.getStr()); } @@ -2442,14 +2437,14 @@ void lclProcessRecursiveGrabBag(sal_Int32 aElementId, const css::uno::SequencestartElement(aElementId, xAttributesList); - for (sal_Int32 j=0; j < rElements.getLength(); ++j) + for (const auto& rElement : rElements) { css::uno::Sequence aSumElements; - boost::optional aSubElementId = lclGetElementIdForName(rElements[j].Name); + boost::optional aSubElementId = lclGetElementIdForName(rElement.Name); if(aSubElementId) { - rElements[j].Value >>= aSumElements; + rElement.Value >>= aSumElements; lclProcessRecursiveGrabBag(*aSubElementId, aSumElements, pSerializer); } } @@ -2557,14 +2552,11 @@ void DocxAttributeOutput::GetSdtEndBefore(const SdrObject* pSdrObj) xPropSet->getPropertyValue("InteropGrabBag") >>= aGrabBag; } - for (sal_Int32 nProp=0; nProp < aGrabBag.getLength(); ++nProp) - { - if ("SdtEndBefore" == aGrabBag[nProp].Name && m_bStartedCharSdt && !m_bEndCharSdt) - { - aGrabBag[nProp].Value >>= m_bEndCharSdt; - break; - } - } + auto pProp = std::find_if(aGrabBag.begin(), aGrabBag.end(), + [this](const beans::PropertyValue& rProp) { + return "SdtEndBefore" == rProp.Name && m_bStartedCharSdt && !m_bEndCharSdt; }); + if (pProp != aGrabBag.end()) + pProp->Value >>= m_bEndCharSdt; } } } @@ -3612,27 +3604,27 @@ sal_Int32 lcl_getWordCompatibilityMode( const SwDoc& rDoc ) uno::Sequence< beans::PropertyValue > propList; xPropSet->getPropertyValue( UNO_NAME_MISC_OBJ_INTEROPGRABBAG ) >>= propList; - for ( sal_Int32 i = 0; i < propList.getLength(); ++i ) + for ( const auto& rProp : propList ) { - if ( propList[i].Name == "CompatSettings" ) + if ( rProp.Name == "CompatSettings" ) { css::uno::Sequence< css::beans::PropertyValue > aCurrentCompatSettings; - propList[i].Value >>= aCurrentCompatSettings; + rProp.Value >>= aCurrentCompatSettings; - for ( sal_Int32 j = 0; j < aCurrentCompatSettings.getLength(); ++j ) + for ( const auto& rCurrentCompatSetting : aCurrentCompatSettings ) { uno::Sequence< beans::PropertyValue > aCompatSetting; - aCurrentCompatSettings[j].Value >>= aCompatSetting; + rCurrentCompatSetting.Value >>= aCompatSetting; OUString sName; OUString sUri; OUString sVal; - for ( sal_Int32 k = 0; k < aCompatSetting.getLength(); ++k ) + for ( const auto& rPropVal : aCompatSetting ) { - if ( aCompatSetting[k].Name == "name" ) aCompatSetting[k].Value >>= sName; - if ( aCompatSetting[k].Name == "uri" ) aCompatSetting[k].Value >>= sUri; - if ( aCompatSetting[k].Name == "val" ) aCompatSetting[k].Value >>= sVal; + if ( rPropVal.Name == "name" ) rPropVal.Value >>= sName; + if ( rPropVal.Name == "uri" ) rPropVal.Value >>= sUri; + if ( rPropVal.Name == "val" ) rPropVal.Value >>= sVal; } if ( sName == "compatibilityMode" && sUri == "http://schemas.microsoft.com/office/word" ) @@ -3758,10 +3750,10 @@ void DocxAttributeOutput::TableDefinition( ww8::WW8TableNodeInfoInner::Pointer_t FastAttributeList* pAttributeList = FastSerializerHelper::createAttrList(); uno::Sequence aAttributeList = rGrabBagElement.second.get< uno::Sequence >(); - for (sal_Int32 i = 0; i < aAttributeList.getLength(); ++i) + for (const auto& rAttribute : aAttributeList) { - if (aAttributeList[i].Name == "val") - pAttributeList->add(FSNS(XML_w, XML_val), lcl_padStartToLength(OString::number(aAttributeList[i].Value.get(), 16), 4, '0')); + if (rAttribute.Name == "val") + pAttributeList->add(FSNS(XML_w, XML_val), lcl_padStartToLength(OString::number(rAttribute.Value.get(), 16), 4, '0')); else { static DocxStringTokenMap const aTokens[] = @@ -3775,8 +3767,8 @@ void DocxAttributeOutput::TableDefinition( ww8::WW8TableNodeInfoInner::Pointer_t {nullptr, 0} }; - if (sal_Int32 nToken = DocxStringGetToken(aTokens, aAttributeList[i].Name)) - pAttributeList->add(FSNS(XML_w, nToken), (aAttributeList[i].Value.get() ? "1" : "0")); + if (sal_Int32 nToken = DocxStringGetToken(aTokens, rAttribute.Name)) + pAttributeList->add(FSNS(XML_w, nToken), (rAttribute.Value.get() ? "1" : "0")); } } @@ -3859,56 +3851,56 @@ void DocxAttributeOutput::TableDefinition( ww8::WW8TableNodeInfoInner::Pointer_t else // ( pFrame = 0 ) { // we export the values from the grabBag - for (sal_Int32 i = 0; i < aTablePosition.getLength(); ++i) + for (const auto& rProp : aTablePosition) { - if (aTablePosition[i].Name == "vertAnchor" && !aTablePosition[i].Value.get().isEmpty()) + if (rProp.Name == "vertAnchor" && !rProp.Value.get().isEmpty()) { - OString sOrientation = OUStringToOString( aTablePosition[i].Value.get(), RTL_TEXTENCODING_UTF8); + OString sOrientation = OUStringToOString( rProp.Value.get(), RTL_TEXTENCODING_UTF8); attrListTablePos->add( FSNS( XML_w, XML_vertAnchor ), sOrientation.getStr() ); } - else if (aTablePosition[i].Name == "tblpYSpec" && !aTablePosition[i].Value.get().isEmpty()) + else if (rProp.Name == "tblpYSpec" && !rProp.Value.get().isEmpty()) { - OString sOrientation = OUStringToOString( aTablePosition[i].Value.get(), RTL_TEXTENCODING_UTF8); + OString sOrientation = OUStringToOString( rProp.Value.get(), RTL_TEXTENCODING_UTF8); attrListTablePos->add( FSNS( XML_w, XML_tblpYSpec ), sOrientation.getStr() ); } - else if (aTablePosition[i].Name == "horzAnchor" && !aTablePosition[i].Value.get().isEmpty()) + else if (rProp.Name == "horzAnchor" && !rProp.Value.get().isEmpty()) { - OString sOrientation = OUStringToOString( aTablePosition[i].Value.get(), RTL_TEXTENCODING_UTF8); + OString sOrientation = OUStringToOString( rProp.Value.get(), RTL_TEXTENCODING_UTF8); attrListTablePos->add( FSNS( XML_w, XML_horzAnchor ), sOrientation.getStr() ); } - else if (aTablePosition[i].Name == "tblpXSpec" && !aTablePosition[i].Value.get().isEmpty()) + else if (rProp.Name == "tblpXSpec" && !rProp.Value.get().isEmpty()) { - OString sOrientation = OUStringToOString( aTablePosition[i].Value.get(), RTL_TEXTENCODING_UTF8); + OString sOrientation = OUStringToOString( rProp.Value.get(), RTL_TEXTENCODING_UTF8); attrListTablePos->add( FSNS( XML_w, XML_tblpXSpec ), sOrientation.getStr() ); } - else if (aTablePosition[i].Name == "bottomFromText") + else if (rProp.Name == "bottomFromText") { - sal_Int32 nValue = aTablePosition[i].Value.get(); + sal_Int32 nValue = rProp.Value.get(); attrListTablePos->add( FSNS( XML_w, XML_bottomFromText ), OString::number( nValue ) ); } - else if (aTablePosition[i].Name == "leftFromText") + else if (rProp.Name == "leftFromText") { - sal_Int32 nValue = aTablePosition[i].Value.get(); + sal_Int32 nValue = rProp.Value.get(); attrListTablePos->add( FSNS( XML_w, XML_leftFromText ), OString::number( nValue ) ); } - else if (aTablePosition[i].Name == "rightFromText") + else if (rProp.Name == "rightFromText") { - sal_Int32 nValue = aTablePosition[i].Value.get(); + sal_Int32 nValue = rProp.Value.get(); attrListTablePos->add( FSNS( XML_w, XML_rightFromText ), OString::number( nValue ) ); } - else if (aTablePosition[i].Name == "topFromText") + else if (rProp.Name == "topFromText") { - sal_Int32 nValue = aTablePosition[i].Value.get(); + sal_Int32 nValue = rProp.Value.get(); attrListTablePos->add( FSNS( XML_w, XML_topFromText ), OString::number( nValue ) ); } - else if (aTablePosition[i].Name == "tblpX") + else if (rProp.Name == "tblpX") { - sal_Int32 nValue = aTablePosition[i].Value.get(); + sal_Int32 nValue = rProp.Value.get(); attrListTablePos->add( FSNS( XML_w, XML_tblpX ), OString::number( nValue ) ); } - else if (aTablePosition[i].Name == "tblpY") + else if (rProp.Name == "tblpY") { - sal_Int32 nValue = aTablePosition[i].Value.get(); + sal_Int32 nValue = rProp.Value.get(); attrListTablePos->add( FSNS( XML_w, XML_tblpY ), OString::number( nValue ) ); } } @@ -4350,26 +4342,22 @@ void DocxAttributeOutput::LatentStyles() uno::Sequence aInteropGrabBag; xPropertySet->getPropertyValue("InteropGrabBag") >>= aInteropGrabBag; uno::Sequence aLatentStyles; - for (sal_Int32 i = 0; i < aInteropGrabBag.getLength(); ++i) - { - if (aInteropGrabBag[i].Name == "latentStyles") - { - aInteropGrabBag[i].Value >>= aLatentStyles; - break; - } - } + auto pProp = std::find_if(aInteropGrabBag.begin(), aInteropGrabBag.end(), + [](const beans::PropertyValue& rProp) { return rProp.Name == "latentStyles"; }); + if (pProp != aInteropGrabBag.end()) + pProp->Value >>= aLatentStyles; if (!aLatentStyles.hasElements()) return; // Extract default attributes first. sax_fastparser::FastAttributeList* pAttributeList = FastSerializerHelper::createAttrList(); uno::Sequence aLsdExceptions; - for (sal_Int32 i = 0; i < aLatentStyles.getLength(); ++i) + for (const auto& rLatentStyle : aLatentStyles) { - if (sal_Int32 nToken = DocxStringGetToken(aDefaultTokens, aLatentStyles[i].Name)) - pAttributeList->add(FSNS(XML_w, nToken), OUStringToOString(aLatentStyles[i].Value.get(), RTL_TEXTENCODING_UTF8)); - else if (aLatentStyles[i].Name == "lsdExceptions") - aLatentStyles[i].Value >>= aLsdExceptions; + if (sal_Int32 nToken = DocxStringGetToken(aDefaultTokens, rLatentStyle.Name)) + pAttributeList->add(FSNS(XML_w, nToken), OUStringToOString(rLatentStyle.Value.get(), RTL_TEXTENCODING_UTF8)); + else if (rLatentStyle.Name == "lsdExceptions") + rLatentStyle.Value >>= aLsdExceptions; } XFastAttributeListRef xAttributeList(pAttributeList); @@ -4377,15 +4365,15 @@ void DocxAttributeOutput::LatentStyles() pAttributeList = nullptr; // Then handle the exceptions. - for (sal_Int32 i = 0; i < aLsdExceptions.getLength(); ++i) + for (const auto& rLsdException : aLsdExceptions) { pAttributeList = FastSerializerHelper::createAttrList(); uno::Sequence aAttributes; - aLsdExceptions[i].Value >>= aAttributes; - for (sal_Int32 j = 0; j < aAttributes.getLength(); ++j) - if (sal_Int32 nToken = DocxStringGetToken(aExceptionTokens, aAttributes[j].Name)) - pAttributeList->add(FSNS(XML_w, nToken), OUStringToOString(aAttributes[j].Value.get(), RTL_TEXTENCODING_UTF8)); + rLsdException.Value >>= aAttributes; + for (const auto& rAttribute : aAttributes) + if (sal_Int32 nToken = DocxStringGetToken(aExceptionTokens, rAttribute.Name)) + pAttributeList->add(FSNS(XML_w, nToken), OUStringToOString(rAttribute.Value.get(), RTL_TEXTENCODING_UTF8)); xAttributeList = pAttributeList; m_pSerializer->singleElementNS(XML_w, XML_lsdException, xAttributeList); @@ -5113,24 +5101,24 @@ void DocxAttributeOutput::WritePostponedFormControl(const SdrObject* pObject) uno::Sequence aCharFormat; if (xShapePropertySet->getPropertyValue(UNO_NAME_MISC_OBJ_INTEROPGRABBAG) >>= aGrabBag) { - for (sal_Int32 i=0; i < aGrabBag.getLength(); ++i) + for (const auto& rProp : aGrabBag) { - if (aGrabBag[i].Name == "DateFormat") - aGrabBag[i].Value >>= sDateFormat; - else if (aGrabBag[i].Name == "Locale") - aGrabBag[i].Value >>= sLocale; - else if (aGrabBag[i].Name == "OriginalContent") - aGrabBag[i].Value >>= sOriginalContent; - else if (aGrabBag[i].Name == "OriginalDate") + if (rProp.Name == "DateFormat") + rProp.Value >>= sDateFormat; + else if (rProp.Name == "Locale") + rProp.Value >>= sLocale; + else if (rProp.Name == "OriginalContent") + rProp.Value >>= sOriginalContent; + else if (rProp.Name == "OriginalDate") { css::util::Date aUNODate; - aGrabBag[i].Value >>= aUNODate; + rProp.Value >>= aUNODate; aOriginalDate = aUNODate; } - else if (aGrabBag[i].Name == "CharFormat") - aGrabBag[i].Value >>= aCharFormat; - else if (aGrabBag[i].Name == "ooxml:CT_SdtPr_alias") - aGrabBag[i].Value >>= sAlias; + else if (rProp.Name == "CharFormat") + rProp.Value >>= aCharFormat; + else if (rProp.Name == "ooxml:CT_SdtPr_alias") + rProp.Value >>= sAlias; } } uno::Reference xPropertySet(xControlModel, uno::UNO_QUERY); @@ -5221,11 +5209,11 @@ void DocxAttributeOutput::WritePostponedFormControl(const SdrObject* pObject) m_pSerializer->startElementNS(XML_w, XML_dropDownList); - for (sal_Int32 i=0; i < aItems.getLength(); ++i) + for (const auto& rItem : aItems) { m_pSerializer->singleElementNS(XML_w, XML_listItem, - FSNS(XML_w, XML_displayText), aItems[i].toUtf8(), - FSNS(XML_w, XML_value), aItems[i].toUtf8()); + FSNS(XML_w, XML_displayText), rItem.toUtf8(), + FSNS(XML_w, XML_value), rItem.toUtf8()); } m_pSerializer->endElementNS(XML_w, XML_dropDownList); @@ -5378,12 +5366,10 @@ void DocxAttributeOutput::WriteOLE( SwOLENode& rNode, const Size& rSize, const S uno::Reference< beans::XPropertySet > xPropSet( m_rExport.m_pDoc->GetDocShell()->GetBaseModel(), uno::UNO_QUERY_THROW ); uno::Sequence< beans::PropertyValue > aGrabBag, aObjectsInteropList,aObjectInteropAttributes; xPropSet->getPropertyValue( UNO_NAME_MISC_OBJ_INTEROPGRABBAG ) >>= aGrabBag; - for( sal_Int32 i=0; i < aGrabBag.getLength(); ++i ) - if ( aGrabBag[i].Name == "EmbeddedObjects" ) - { - aGrabBag[i].Value >>= aObjectsInteropList; - break; - } + auto pProp = std::find_if(aGrabBag.begin(), aGrabBag.end(), + [](const beans::PropertyValue& rProp) { return rProp.Name == "EmbeddedObjects"; }); + if (pProp != aGrabBag.end()) + pProp->Value >>= aObjectsInteropList; SwOLEObj& aObject = rNode.GetOLEObj(); uno::Reference < embed::XEmbeddedObject > xObj( aObject.GetOleRef() ); @@ -5392,23 +5378,21 @@ void DocxAttributeOutput::WriteOLE( SwOLENode& rNode, const Size& rSize, const S // set some attributes according to the type of the embedded object OUString sProgID, sDrawAspect = "Content"; - for( sal_Int32 i=0; i < aObjectsInteropList.getLength(); ++i ) - if ( aObjectsInteropList[i].Name == sObjectName ) - { - aObjectsInteropList[i].Value >>= aObjectInteropAttributes; - break; - } + auto pObjectsInterop = std::find_if(aObjectsInteropList.begin(), aObjectsInteropList.end(), + [&sObjectName](const beans::PropertyValue& rProp) { return rProp.Name == sObjectName; }); + if (pObjectsInterop != aObjectsInteropList.end()) + pObjectsInterop->Value >>= aObjectInteropAttributes; - for( sal_Int32 i=0; i < aObjectInteropAttributes.getLength(); ++i ) + for( const auto& rObjectInteropAttribute : aObjectInteropAttributes ) { - if ( aObjectInteropAttributes[i].Name == "ProgID" ) - { - aObjectInteropAttributes[i].Value >>= sProgID; - } - else if ( aObjectInteropAttributes[i].Name == "DrawAspect" ) - { - aObjectInteropAttributes[i].Value >>= sDrawAspect; - } + if ( rObjectInteropAttribute.Name == "ProgID" ) + { + rObjectInteropAttribute.Value >>= sProgID; + } + else if ( rObjectInteropAttribute.Name == "DrawAspect" ) + { + rObjectInteropAttribute.Value >>= sDrawAspect; + } } // write embedded file @@ -5833,28 +5817,28 @@ void DocxAttributeOutput::StartStyle( const OUString& rName, StyleType eType, } const uno::Sequence& rGrabBag = aAny.get< uno::Sequence >(); - for (sal_Int32 i = 0; i < rGrabBag.getLength(); ++i) + for (const auto& rProp : rGrabBag) { - if (rGrabBag[i].Name == "uiPriority") - aUiPriority = rGrabBag[i].Value.get(); - else if (rGrabBag[i].Name == "qFormat") + if (rProp.Name == "uiPriority") + aUiPriority = rProp.Value.get(); + else if (rProp.Name == "qFormat") bQFormat = true; - else if (rGrabBag[i].Name == "link") - aLink = rGrabBag[i].Value.get(); - else if (rGrabBag[i].Name == "rsid") - aRsid = rGrabBag[i].Value.get(); - else if (rGrabBag[i].Name == "unhideWhenUsed") + else if (rProp.Name == "link") + aLink = rProp.Value.get(); + else if (rProp.Name == "rsid") + aRsid = rProp.Value.get(); + else if (rProp.Name == "unhideWhenUsed") bUnhideWhenUsed = true; - else if (rGrabBag[i].Name == "semiHidden") + else if (rProp.Name == "semiHidden") bSemiHidden = true; - else if (rGrabBag[i].Name == "locked") + else if (rProp.Name == "locked") bLocked = true; - else if (rGrabBag[i].Name == "default") - bDefault = rGrabBag[i].Value.get(); - else if (rGrabBag[i].Name == "customStyle") - bCustomStyle = rGrabBag[i].Value.get(); + else if (rProp.Name == "default") + bDefault = rProp.Value.get(); + else if (rProp.Name == "customStyle") + bCustomStyle = rProp.Value.get(); else - SAL_WARN("sw.ww8", "Unhandled style property: " << rGrabBag[i].Name); + SAL_WARN("sw.ww8", "Unhandled style property: " << rProp.Name); } // MSO exports English names and writerfilter only recognize them. @@ -8733,42 +8717,41 @@ void DocxAttributeOutput::ParaGrabBag(const SfxGrabBagItem& rItem) uno::Sequence aGrabBagSeq; rGrabBagElement.second >>= aGrabBagSeq; - for (sal_Int32 j=0; j < aGrabBagSeq.getLength(); ++j) + for (const auto& rProp : aGrabBagSeq) { - OString sVal = OUStringToOString(aGrabBagSeq[j].Value.get(), RTL_TEXTENCODING_UTF8); + OString sVal = OUStringToOString(rProp.Value.get(), RTL_TEXTENCODING_UTF8); if (sVal.isEmpty()) continue; - if (aGrabBagSeq[j].Name == "val") + if (rProp.Name == "val") AddToAttrList(m_pBackgroundAttrList, FSNS(XML_w, XML_val), sVal.getStr()); - else if (aGrabBagSeq[j].Name == "color") + else if (rProp.Name == "color") AddToAttrList(m_pBackgroundAttrList, FSNS(XML_w, XML_color), sVal.getStr()); - else if (aGrabBagSeq[j].Name == "themeColor") + else if (rProp.Name == "themeColor") AddToAttrList(m_pBackgroundAttrList, FSNS(XML_w, XML_themeColor), sVal.getStr()); - else if (aGrabBagSeq[j].Name == "themeTint") + else if (rProp.Name == "themeTint") AddToAttrList(m_pBackgroundAttrList, FSNS(XML_w, XML_themeTint), sVal.getStr()); - else if (aGrabBagSeq[j].Name == "themeShade") + else if (rProp.Name == "themeShade") AddToAttrList(m_pBackgroundAttrList, FSNS(XML_w, XML_themeShade), sVal.getStr()); - else if (aGrabBagSeq[j].Name == "fill") + else if (rProp.Name == "fill") AddToAttrList(m_pBackgroundAttrList, FSNS(XML_w, XML_fill), sVal.getStr()); - else if (aGrabBagSeq[j].Name == "themeFill") + else if (rProp.Name == "themeFill") AddToAttrList(m_pBackgroundAttrList, FSNS(XML_w, XML_themeFill), sVal.getStr()); - else if (aGrabBagSeq[j].Name == "themeFillTint") + else if (rProp.Name == "themeFillTint") AddToAttrList(m_pBackgroundAttrList, FSNS(XML_w, XML_themeFillTint), sVal.getStr()); - else if (aGrabBagSeq[j].Name == "themeFillShade") + else if (rProp.Name == "themeFillShade") AddToAttrList(m_pBackgroundAttrList, FSNS(XML_w, XML_themeFillShade), sVal.getStr()); - else if (aGrabBagSeq[j].Name == "originalColor") - aGrabBagSeq[j].Value >>= m_sOriginalBackgroundColor; + else if (rProp.Name == "originalColor") + rProp.Value >>= m_sOriginalBackgroundColor; } } else if (rGrabBagElement.first == "SdtPr") { uno::Sequence aGrabBagSdt = rGrabBagElement.second.get< uno::Sequence >(); - for (sal_Int32 k=0; k < aGrabBagSdt.getLength(); ++k) + for (const beans::PropertyValue& aPropertyValue : aGrabBagSdt) { - beans::PropertyValue aPropertyValue = aGrabBagSdt[k]; if (aPropertyValue.Name == "ooxml:CT_SdtPr_docPartObj" || aPropertyValue.Name == "ooxml:CT_SdtPr_docPartList") { @@ -8779,18 +8762,18 @@ void DocxAttributeOutput::ParaGrabBag(const SfxGrabBagItem& rItem) uno::Sequence aGrabBag; aPropertyValue.Value >>= aGrabBag; - for (sal_Int32 j=0; j < aGrabBag.getLength(); ++j) + for (const auto& rProp : aGrabBag) { - OUString sValue = aGrabBag[j].Value.get(); - if (aGrabBag[j].Name == "ooxml:CT_SdtDocPart_docPartGallery") + OUString sValue = rProp.Value.get(); + if (rProp.Name == "ooxml:CT_SdtDocPart_docPartGallery") AddToAttrList( m_pParagraphSdtPrTokenChildren, FSNS( XML_w, XML_docPartGallery ), OUStringToOString( sValue, RTL_TEXTENCODING_UTF8 ).getStr() ); - else if (aGrabBag[j].Name == "ooxml:CT_SdtDocPart_docPartCategory") + else if (rProp.Name == "ooxml:CT_SdtDocPart_docPartCategory") AddToAttrList( m_pParagraphSdtPrTokenChildren, FSNS( XML_w, XML_docPartCategory ), OUStringToOString( sValue, RTL_TEXTENCODING_UTF8 ).getStr() ); - else if (aGrabBag[j].Name == "ooxml:CT_SdtDocPart_docPartUnique") + else if (rProp.Name == "ooxml:CT_SdtDocPart_docPartUnique") { if (sValue.isEmpty()) sValue = "true"; @@ -8813,18 +8796,18 @@ void DocxAttributeOutput::ParaGrabBag(const SfxGrabBagItem& rItem) { uno::Sequence aGrabBag; aPropertyValue.Value >>= aGrabBag; - for (sal_Int32 j = 0; j < aGrabBag.getLength(); ++j) + for (const auto& rProp : aGrabBag) { - OUString sValue = aGrabBag[j].Value.get(); - if (aGrabBag[j].Name == "ooxml:CT_DataBinding_prefixMappings") + OUString sValue = rProp.Value.get(); + if (rProp.Name == "ooxml:CT_DataBinding_prefixMappings") AddToAttrList( m_pParagraphSdtPrDataBindingAttrs, FSNS( XML_w, XML_prefixMappings ), OUStringToOString( sValue, RTL_TEXTENCODING_UTF8 ).getStr() ); - else if (aGrabBag[j].Name == "ooxml:CT_DataBinding_xpath") + else if (rProp.Name == "ooxml:CT_DataBinding_xpath") AddToAttrList( m_pParagraphSdtPrDataBindingAttrs, FSNS( XML_w, XML_xpath ), OUStringToOString( sValue, RTL_TEXTENCODING_UTF8 ).getStr() ); - else if (aGrabBag[j].Name == "ooxml:CT_DataBinding_storeItemID") + else if (rProp.Name == "ooxml:CT_DataBinding_storeItemID") AddToAttrList( m_pParagraphSdtPrDataBindingAttrs, FSNS( XML_w, XML_storeItemID ), OUStringToOString( sValue, RTL_TEXTENCODING_UTF8 ).getStr() ); @@ -8841,18 +8824,18 @@ void DocxAttributeOutput::ParaGrabBag(const SfxGrabBagItem& rItem) m_nParagraphSdtPrToken = FSNS( XML_w14, XML_checkbox ); uno::Sequence aGrabBag; aPropertyValue.Value >>= aGrabBag; - for (sal_Int32 j=0; j < aGrabBag.getLength(); ++j) + for (const auto& rProp : aGrabBag) { - OUString sValue = aGrabBag[j].Value.get(); - if (aGrabBag[j].Name == "ooxml:CT_SdtCheckbox_checked") + OUString sValue = rProp.Value.get(); + if (rProp.Name == "ooxml:CT_SdtCheckbox_checked") AddToAttrList( m_pParagraphSdtPrTokenChildren, FSNS( XML_w14, XML_checked ), OUStringToOString( sValue, RTL_TEXTENCODING_UTF8 ).getStr() ); - else if (aGrabBag[j].Name == "ooxml:CT_SdtCheckbox_checkedState") + else if (rProp.Name == "ooxml:CT_SdtCheckbox_checkedState") AddToAttrList( m_pParagraphSdtPrTokenChildren, FSNS( XML_w14, XML_checkedState ), OUStringToOString( sValue, RTL_TEXTENCODING_UTF8 ).getStr() ); - else if (aGrabBag[j].Name == "ooxml:CT_SdtCheckbox_uncheckedState") + else if (rProp.Name == "ooxml:CT_SdtCheckbox_uncheckedState") AddToAttrList( m_pParagraphSdtPrTokenChildren, FSNS( XML_w14, XML_uncheckedState ), OUStringToOString( sValue, RTL_TEXTENCODING_UTF8 ).getStr() ); @@ -8864,22 +8847,22 @@ void DocxAttributeOutput::ParaGrabBag(const SfxGrabBagItem& rItem) { m_nParagraphSdtPrToken = FSNS(XML_w, XML_date); uno::Sequence aGrabBag = aPropertyValue.Value.get< uno::Sequence >(); - for (sal_Int32 j=0; j < aGrabBag.getLength(); ++j) + for (const auto& rProp : aGrabBag) { - OString sValue = OUStringToOString(aGrabBag[j].Value.get(), RTL_TEXTENCODING_UTF8); + OString sValue = OUStringToOString(rProp.Value.get(), RTL_TEXTENCODING_UTF8); - if (aGrabBag[j].Name == "ooxml:CT_SdtDate_fullDate") + if (rProp.Name == "ooxml:CT_SdtDate_fullDate") AddToAttrList(m_pParagraphSdtPrTokenAttributes, FSNS(XML_w, XML_fullDate), sValue.getStr()); - else if (aGrabBag[j].Name == "ooxml:CT_SdtDate_dateFormat") + else if (rProp.Name == "ooxml:CT_SdtDate_dateFormat") AddToAttrList(m_pParagraphSdtPrTokenChildren, FSNS(XML_w, XML_dateFormat), sValue.getStr()); - else if (aGrabBag[j].Name == "ooxml:CT_SdtDate_lid") + else if (rProp.Name == "ooxml:CT_SdtDate_lid") AddToAttrList(m_pParagraphSdtPrTokenChildren, FSNS(XML_w, XML_lid), sValue.getStr()); - else if (aGrabBag[j].Name == "ooxml:CT_SdtDate_storeMappedDataAs") + else if (rProp.Name == "ooxml:CT_SdtDate_storeMappedDataAs") AddToAttrList(m_pParagraphSdtPrTokenChildren, FSNS(XML_w, XML_storeMappedDataAs), sValue.getStr()); - else if (aGrabBag[j].Name == "ooxml:CT_SdtDate_calendar") + else if (rProp.Name == "ooxml:CT_SdtDate_calendar") AddToAttrList(m_pParagraphSdtPrTokenChildren, FSNS(XML_w, XML_calendar), sValue.getStr()); else - SAL_WARN("sw.ww8", "DocxAttributeOutput::ParaGrabBag: unhandled SdtPr / ooxml:CT_SdtPr_date grab bag property " << aGrabBag[j].Name); + SAL_WARN("sw.ww8", "DocxAttributeOutput::ParaGrabBag: unhandled SdtPr / ooxml:CT_SdtPr_date grab bag property " << rProp.Name); } } else @@ -9022,26 +9005,25 @@ void DocxAttributeOutput::CharGrabBag( const SfxGrabBagItem& rItem ) { uno::Sequence aGrabBagSdt = rGrabBagElement.second.get< uno::Sequence >(); - for (sal_Int32 k=0; k < aGrabBagSdt.getLength(); ++k) + for (const beans::PropertyValue& aPropertyValue : aGrabBagSdt) { - beans::PropertyValue aPropertyValue = aGrabBagSdt[k]; if (aPropertyValue.Name == "ooxml:CT_SdtPr_checkbox") { m_nRunSdtPrToken = FSNS( XML_w14, XML_checkbox ); uno::Sequence aGrabBag; aPropertyValue.Value >>= aGrabBag; - for (sal_Int32 j=0; j < aGrabBag.getLength(); ++j) + for (const auto& rProp : aGrabBag) { - OUString sValue = aGrabBag[j].Value.get(); - if (aGrabBag[j].Name == "ooxml:CT_SdtCheckbox_checked") + OUString sValue = rProp.Value.get(); + if (rProp.Name == "ooxml:CT_SdtCheckbox_checked") AddToAttrList( m_pRunSdtPrTokenChildren, FSNS( XML_w14, XML_checked ), OUStringToOString( sValue, RTL_TEXTENCODING_UTF8 ).getStr() ); - else if (aGrabBag[j].Name == "ooxml:CT_SdtCheckbox_checkedState") + else if (rProp.Name == "ooxml:CT_SdtCheckbox_checkedState") AddToAttrList( m_pRunSdtPrTokenChildren, FSNS( XML_w14, XML_checkedState ), OUStringToOString( sValue, RTL_TEXTENCODING_UTF8 ).getStr() ); - else if (aGrabBag[j].Name == "ooxml:CT_SdtCheckbox_uncheckedState") + else if (rProp.Name == "ooxml:CT_SdtCheckbox_uncheckedState") AddToAttrList( m_pRunSdtPrTokenChildren, FSNS( XML_w14, XML_uncheckedState ), OUStringToOString( sValue, RTL_TEXTENCODING_UTF8 ).getStr() ); @@ -9051,18 +9033,18 @@ void DocxAttributeOutput::CharGrabBag( const SfxGrabBagItem& rItem ) { uno::Sequence aGrabBag; aPropertyValue.Value >>= aGrabBag; - for (sal_Int32 j=0; j < aGrabBag.getLength(); ++j) + for (const auto& rProp : aGrabBag) { - OUString sValue = aGrabBag[j].Value.get(); - if (aGrabBag[j].Name == "ooxml:CT_DataBinding_prefixMappings") + OUString sValue = rProp.Value.get(); + if (rProp.Name == "ooxml:CT_DataBinding_prefixMappings") AddToAttrList( m_pRunSdtPrDataBindingAttrs, FSNS( XML_w, XML_prefixMappings ), OUStringToOString( sValue, RTL_TEXTENCODING_UTF8 ).getStr() ); - else if (aGrabBag[j].Name == "ooxml:CT_DataBinding_xpath") + else if (rProp.Name == "ooxml:CT_DataBinding_xpath") AddToAttrList( m_pRunSdtPrDataBindingAttrs, FSNS( XML_w, XML_xpath ), OUStringToOString( sValue, RTL_TEXTENCODING_UTF8 ).getStr() ); - else if (aGrabBag[j].Name == "ooxml:CT_DataBinding_storeItemID") + else if (rProp.Name == "ooxml:CT_DataBinding_storeItemID") AddToAttrList( m_pRunSdtPrDataBindingAttrs, FSNS( XML_w, XML_storeItemID ), OUStringToOString( sValue, RTL_TEXTENCODING_UTF8 ).getStr() ); diff --git a/sw/source/filter/ww8/docxexport.cxx b/sw/source/filter/ww8/docxexport.cxx index eb10711b6e28..39105ace49f8 100644 --- a/sw/source/filter/ww8/docxexport.cxx +++ b/sw/source/filter/ww8/docxexport.cxx @@ -83,6 +83,7 @@ #include "ww8scan.hxx" #include #include +#include #include #include #include @@ -351,24 +352,18 @@ void DocxExport::DoComboBox(const OUString& rName, m_pDocumentFS->startElementNS(XML_w, XML_ddList); // Output the 0-based index of the selected value - sal_uInt32 nListItems = rListItems.getLength(); - sal_Int32 nId = 0; - sal_uInt32 nI = 0; - while ( ( nI < nListItems ) && ( nId == 0 ) ) - { - if ( rListItems[nI] == rSelected ) - nId = nI; - nI++; - } + sal_Int32 nId = comphelper::findValue(rListItems, rSelected); + if (nId == -1) + nId = 0; m_pDocumentFS->singleElementNS(XML_w, XML_result, FSNS(XML_w, XML_val), OString::number(nId)); // Loop over the entries - for (sal_uInt32 i = 0; i < nListItems; i++) + for (const auto& rItem : rListItems) { m_pDocumentFS->singleElementNS( XML_w, XML_listEntry, - FSNS( XML_w, XML_val ), rListItems[i].toUtf8() ); + FSNS( XML_w, XML_val ), rItem.toUtf8() ); } m_pDocumentFS->endElementNS( XML_w, XML_ddList ); @@ -1044,50 +1039,50 @@ void DocxExport::WriteSettings() uno::Sequence< beans::PropertyValue > propList; xPropSet->getPropertyValue( aGrabBagName ) >>= propList; - for( sal_Int32 i=0; i < propList.getLength(); ++i ) + for( const auto& rProp : propList ) { - if ( propList[i].Name == "ThemeFontLangProps" ) + if ( rProp.Name == "ThemeFontLangProps" ) { uno::Sequence< beans::PropertyValue > themeFontLangProps; - propList[i].Value >>= themeFontLangProps; + rProp.Value >>= themeFontLangProps; OUString aValues[3]; - for( sal_Int32 j=0; j < themeFontLangProps.getLength(); ++j ) + for( const auto& rThemeFontLangProp : themeFontLangProps ) { - if( themeFontLangProps[j].Name == "val" ) - themeFontLangProps[j].Value >>= aValues[0]; - else if( themeFontLangProps[j].Name == "eastAsia" ) - themeFontLangProps[j].Value >>= aValues[1]; - else if( themeFontLangProps[j].Name == "bidi" ) - themeFontLangProps[j].Value >>= aValues[2]; + if( rThemeFontLangProp.Name == "val" ) + rThemeFontLangProp.Value >>= aValues[0]; + else if( rThemeFontLangProp.Name == "eastAsia" ) + rThemeFontLangProp.Value >>= aValues[1]; + else if( rThemeFontLangProp.Name == "bidi" ) + rThemeFontLangProp.Value >>= aValues[2]; } pFS->singleElementNS( XML_w, XML_themeFontLang, FSNS( XML_w, XML_val ), aValues[0].toUtf8(), FSNS( XML_w, XML_eastAsia ), aValues[1].toUtf8(), FSNS( XML_w, XML_bidi ), aValues[2].toUtf8() ); } - else if ( propList[i].Name == "CompatSettings" ) + else if ( rProp.Name == "CompatSettings" ) { pFS->startElementNS(XML_w, XML_compat); uno::Sequence< beans::PropertyValue > aCompatSettingsSequence; - propList[i].Value >>= aCompatSettingsSequence; + rProp.Value >>= aCompatSettingsSequence; - for(sal_Int32 j=0; j < aCompatSettingsSequence.getLength(); ++j) + for(const auto& rCompatSetting : aCompatSettingsSequence) { uno::Sequence< beans::PropertyValue > aCompatSetting; - aCompatSettingsSequence[j].Value >>= aCompatSetting; + rCompatSetting.Value >>= aCompatSetting; OUString aName; OUString aUri; OUString aValue; - for(sal_Int32 k=0; k < aCompatSetting.getLength(); ++k) + for(const auto& rPropVal : aCompatSetting) { - if( aCompatSetting[k].Name == "name" ) - aCompatSetting[k].Value >>= aName; - else if( aCompatSetting[k].Name == "uri" ) - aCompatSetting[k].Value >>= aUri; - else if( aCompatSetting[k].Name == "val" ) - aCompatSetting[k].Value >>= aValue; + if( rPropVal.Name == "name" ) + rPropVal.Value >>= aName; + else if( rPropVal.Name == "uri" ) + rPropVal.Value >>= aUri; + else if( rPropVal.Name == "val" ) + rPropVal.Value >>= aValue; } pFS->singleElementNS( XML_w, XML_compatSetting, FSNS( XML_w, XML_name ), aName.toUtf8(), @@ -1097,16 +1092,16 @@ void DocxExport::WriteSettings() pFS->endElementNS( XML_w, XML_compat ); } - else if (propList[i].Name == "DocumentProtection") + else if (rProp.Name == "DocumentProtection") { uno::Sequence< beans::PropertyValue > rAttributeList; - propList[i].Value >>= rAttributeList; + rProp.Value >>= rAttributeList; if (rAttributeList.hasElements()) { sax_fastparser::FastAttributeList* pAttributeList = sax_fastparser::FastSerializerHelper::createAttrList(); - for (sal_Int32 j = 0; j < rAttributeList.getLength(); ++j) + for (const auto& rAttribute : rAttributeList) { static DocxStringTokenMap const aTokens[] = { @@ -1123,8 +1118,8 @@ void DocxExport::WriteSettings() { nullptr, 0 } }; - if (sal_Int32 nToken = DocxStringGetToken(aTokens, rAttributeList[j].Name)) - pAttributeList->add(FSNS(XML_w, nToken), rAttributeList[j].Value.get().toUtf8()); + if (sal_Int32 nToken = DocxStringGetToken(aTokens, rAttribute.Name)) + pAttributeList->add(FSNS(XML_w, nToken), rAttribute.Value.get().toUtf8()); } // we have document protection from input DOCX file @@ -1169,15 +1164,10 @@ void DocxExport::WriteTheme() uno::Reference themeDom; uno::Sequence< beans::PropertyValue > propList; xPropSet->getPropertyValue( aName ) >>= propList; - for ( sal_Int32 nProp=0; nProp < propList.getLength(); ++nProp ) - { - OUString propName = propList[nProp].Name; - if ( propName == "OOXTheme" ) - { - propList[nProp].Value >>= themeDom; - break; - } - } + auto pProp = std::find_if(propList.begin(), propList.end(), + [](const beans::PropertyValue& rProp) { return rProp.Name == "OOXTheme"; }); + if (pProp != propList.end()) + pProp->Value >>= themeDom; // no theme dom to write if ( !themeDom.is() ) @@ -1209,17 +1199,17 @@ void DocxExport::WriteGlossary() uno::Sequence< beans::PropertyValue > propList; xPropSet->getPropertyValue( aName ) >>= propList; sal_Int32 collectedProperties = 0; - for ( sal_Int32 nProp=0; nProp < propList.getLength(); ++nProp ) + for ( const auto& rProp : propList ) { - OUString propName = propList[nProp].Name; + OUString propName = rProp.Name; if ( propName == "OOXGlossary" ) { - propList[nProp].Value >>= glossaryDocDom; + rProp.Value >>= glossaryDocDom; collectedProperties++; } if (propName == "OOXGlossaryDom") { - propList[nProp].Value >>= glossaryDomList; + rProp.Value >>= glossaryDomList; collectedProperties++; } if (collectedProperties == 2) @@ -1243,10 +1233,8 @@ void DocxExport::WriteGlossary() serializer->serialize( uno::Reference< xml::sax::XDocumentHandler >( writer, uno::UNO_QUERY_THROW ), uno::Sequence< beans::StringPair >() ); - sal_Int32 length = glossaryDomList.getLength(); - for ( int i =0; i < length; i++) + for ( const uno::Sequence< uno::Any>& glossaryElement : glossaryDomList) { - uno::Sequence< uno::Any> glossaryElement = glossaryDomList[i]; OUString gTarget, gType, gId, contentType; uno::Reference xDom; glossaryElement[0] >>= xDom; @@ -1279,25 +1267,15 @@ void DocxExport::WriteCustomXml() uno::Sequence > customXmlDomPropslist; uno::Sequence< beans::PropertyValue > propList; xPropSet->getPropertyValue( aName ) >>= propList; - for ( sal_Int32 nProp=0; nProp < propList.getLength(); ++nProp ) - { - const OUString propName = propList[nProp].Name; - if ( propName == "OOXCustomXml" ) - { - propList[nProp].Value >>= customXmlDomlist; - break; - } - } + auto pProp = std::find_if(propList.begin(), propList.end(), + [](const beans::PropertyValue& rProp) { return rProp.Name == "OOXCustomXml"; }); + if (pProp != propList.end()) + pProp->Value >>= customXmlDomlist; - for ( sal_Int32 nProp=0; nProp < propList.getLength(); ++nProp ) - { - OUString propName = propList[nProp].Name; - if ( propName == "OOXCustomXmlProps" ) - { - propList[nProp].Value >>= customXmlDomPropslist; - break; - } - } + pProp = std::find_if(propList.begin(), propList.end(), + [](const beans::PropertyValue& rProp) { return rProp.Name == "OOXCustomXmlProps"; }); + if (pProp != propList.end()) + pProp->Value >>= customXmlDomPropslist; for (sal_Int32 j = 0; j < customXmlDomlist.getLength(); j++) { @@ -1406,20 +1384,15 @@ void DocxExport::WriteEmbeddings() uno::Sequence< beans::PropertyValue > embeddingsList; uno::Sequence< beans::PropertyValue > propList; xPropSet->getPropertyValue( aName ) >>= propList; - for ( sal_Int32 nProp=0; nProp < propList.getLength(); ++nProp ) - { - OUString propName = propList[nProp].Name; - if ( propName == "OOXEmbeddings" ) - { - propList[nProp].Value >>= embeddingsList; - break; - } - } - for (sal_Int32 j = 0; j < embeddingsList.getLength(); j++) + auto pProp = std::find_if(propList.begin(), propList.end(), + [](const beans::PropertyValue& rProp) { return rProp.Name == "OOXEmbeddings"; }); + if (pProp != propList.end()) + pProp->Value >>= embeddingsList; + for (const auto& rEmbedding : embeddingsList) { - OUString embeddingPath = embeddingsList[j].Name; + OUString embeddingPath = rEmbedding.Name; uno::Reference embeddingsStream; - embeddingsList[j].Value >>= embeddingsStream; + rEmbedding.Value >>= embeddingsStream; OUString contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; // FIXME: this .xlsm hack is silly - if anything the mime-type for an existing embedded object should be read from [Content_Types].xml diff --git a/sw/source/filter/ww8/docxsdrexport.cxx b/sw/source/filter/ww8/docxsdrexport.cxx index cceb53df397a..725ceaaa7cd9 100644 --- a/sw/source/filter/ww8/docxsdrexport.cxx +++ b/sw/source/filter/ww8/docxsdrexport.cxx @@ -70,15 +70,11 @@ OUString lclGetAnchorIdFromGrabBag(const SdrObject* pObj) else aGrabBagName = "InteropGrabBag"; uno::Sequence propList = lclGetProperty(xShape, aGrabBagName); - for (sal_Int32 nProp = 0; nProp < propList.getLength(); ++nProp) - { - OUString aPropName = propList[nProp].Name; - if (aPropName == "AnchorId") - { - propList[nProp].Value >>= aResult; - break; - } - } + auto pProp + = std::find_if(propList.begin(), propList.end(), + [](const beans::PropertyValue& rProp) { return rProp.Name == "AnchorId"; }); + if (pProp != propList.end()) + pProp->Value >>= aResult; return aResult; } @@ -846,22 +842,14 @@ void DocxSdrExport::writeVMLDrawing(const SdrObject* sdrObj, const SwFrameFormat static bool lcl_isLockedCanvas(const uno::Reference& xShape) { - bool bRet = false; uno::Sequence propList = lclGetProperty(xShape, "InteropGrabBag"); - for (sal_Int32 nProp = 0; nProp < propList.getLength(); ++nProp) - { - OUString propName = propList[nProp].Name; - if (propName == "LockedCanvas") - { - /* - * Export as Locked Canvas only if the property - * is in the PropertySet - */ - bRet = true; - break; - } - } - return bRet; + /* + * Export as Locked Canvas only if the property + * is in the PropertySet + */ + return std::any_of(propList.begin(), propList.end(), [](const beans::PropertyValue& rProp) { + return rProp.Name == "LockedCanvas"; + }); } void DocxSdrExport::writeDMLDrawing(const SdrObject* pSdrObject, const SwFrameFormat* pFrameFormat, @@ -1249,15 +1237,12 @@ void DocxSdrExport::writeDMLTextFrame(ww8::Frame const* pParentFrame, int nAncho { uno::Sequence propList; xPropertySet->getPropertyValue("FrameInteropGrabBag") >>= propList; - for (sal_Int32 nProp = 0; nProp < propList.getLength(); ++nProp) - { - OUString propName = propList[nProp].Name; - if (propName == "mso-rotation-angle") - { - aRotation = propList[nProp].Value; - break; - } - } + auto pProp = std::find_if(propList.begin(), propList.end(), + [](const beans::PropertyValue& rProp) { + return rProp.Name == "mso-rotation-angle"; + }); + if (pProp != propList.end()) + aRotation = pProp->Value; } aRotation >>= m_pImpl->getDMLandVMLTextFrameRotation(); OString sRotation(OString::number( @@ -1282,15 +1267,12 @@ void DocxSdrExport::writeDMLTextFrame(ww8::Frame const* pParentFrame, int nAncho { uno::Sequence propList; xPropertySet->getPropertyValue("FrameInteropGrabBag") >>= propList; - for (sal_Int32 nProp = 0; nProp < propList.getLength(); ++nProp) - { - OUString propName = propList[nProp].Name; - if (propName == "mso-orig-shape-type") - { - propList[nProp].Value >>= shapeType; - break; - } - } + auto pProp = std::find_if(propList.begin(), propList.end(), + [](const beans::PropertyValue& rProp) { + return rProp.Name == "mso-orig-shape-type"; + }); + if (pProp != propList.end()) + pProp->Value >>= shapeType; } //Empty shapeType will lead to corruption so to avoid that shapeType is set to default i.e. "rect" if (shapeType.isEmpty()) diff --git a/sw/source/filter/ww8/docxtablestyleexport.cxx b/sw/source/filter/ww8/docxtablestyleexport.cxx index 1057b1b6411e..32aa8b103938 100644 --- a/sw/source/filter/ww8/docxtablestyleexport.cxx +++ b/sw/source/filter/ww8/docxtablestyleexport.cxx @@ -94,11 +94,10 @@ void DocxTableStyleExport::CnfStyle(uno::Sequence& rAttrib sax_fastparser::FastAttributeList* pAttributeList = sax_fastparser::FastSerializerHelper::createAttrList(); - for (sal_Int32 j = 0; j < rAttributeList.getLength(); ++j) + for (const auto& rAttribute : rAttributeList) { - if (rAttributeList[j].Name == "val") - pAttributeList->add(FSNS(XML_w, XML_val), - rAttributeList[j].Value.get().toUtf8()); + if (rAttribute.Name == "val") + pAttributeList->add(FSNS(XML_w, XML_val), rAttribute.Value.get().toUtf8()); else { static DocxStringTokenMap const aTokens[] @@ -116,9 +115,8 @@ void DocxTableStyleExport::CnfStyle(uno::Sequence& rAttrib { "lastRowLastColumn", XML_lastRowLastColumn }, { nullptr, 0 } }; - if (sal_Int32 nToken = DocxStringGetToken(aTokens, rAttributeList[j].Name)) - pAttributeList->add(FSNS(XML_w, nToken), - rAttributeList[j].Value.get().toUtf8()); + if (sal_Int32 nToken = DocxStringGetToken(aTokens, rAttribute.Name)) + pAttributeList->add(FSNS(XML_w, nToken), rAttribute.Value.get().toUtf8()); } } @@ -134,14 +132,11 @@ void DocxTableStyleExport::TableStyles(sal_Int32 nCountStylesToWrite) uno::Sequence aInteropGrabBag; xPropertySet->getPropertyValue("InteropGrabBag") >>= aInteropGrabBag; uno::Sequence aTableStyles; - for (sal_Int32 i = 0; i < aInteropGrabBag.getLength(); ++i) - { - if (aInteropGrabBag[i].Name == "tableStyles") - { - aInteropGrabBag[i].Value >>= aTableStyles; - break; - } - } + auto pProp = std::find_if( + aInteropGrabBag.begin(), aInteropGrabBag.end(), + [](const beans::PropertyValue& rProp) { return rProp.Name == "tableStyles"; }); + if (pProp != aInteropGrabBag.end()) + pProp->Value >>= aTableStyles; if (!aTableStyles.hasElements()) return; @@ -168,12 +163,12 @@ void DocxTableStyleExport::Impl::tableStyleTableCellMar( return; m_pSerializer->startElementNS(XML_w, nType); - for (sal_Int32 i = 0; i < rTableCellMar.getLength(); ++i) + for (const auto& rProp : rTableCellMar) { - if (sal_Int32 nToken = DocxStringGetToken(aTableCellMarTokens, rTableCellMar[i].Name)) + if (sal_Int32 nToken = DocxStringGetToken(aTableCellMarTokens, rProp.Name)) { comphelper::SequenceAsHashMap aMap( - rTableCellMar[i].Value.get>()); + rProp.Value.get>()); m_pSerializer->singleElementNS( XML_w, nToken, FSNS(XML_w, XML_w), OString::number(aMap["w"].get()), FSNS(XML_w, XML_type), aMap["type"].get().toUtf8()); @@ -198,10 +193,9 @@ void DocxTableStyleExport::Impl::tableStyleTcBorder( sax_fastparser::FastAttributeList* pAttributeList = sax_fastparser::FastSerializerHelper::createAttrList(); - for (sal_Int32 i = 0; i < rTcBorder.getLength(); ++i) - if (sal_Int32 nAttrToken = DocxStringGetToken(aTcBorderTokens, rTcBorder[i].Name)) - pAttributeList->add(FSNS(XML_w, nAttrToken), - rTcBorder[i].Value.get().toUtf8()); + for (const auto& rProp : rTcBorder) + if (sal_Int32 nAttrToken = DocxStringGetToken(aTcBorderTokens, rProp.Name)) + pAttributeList->add(FSNS(XML_w, nAttrToken), rProp.Value.get().toUtf8()); sax_fastparser::XFastAttributeListRef xAttributeList(pAttributeList); m_pSerializer->singleElementNS(XML_w, nToken, xAttributeList); @@ -226,10 +220,10 @@ void DocxTableStyleExport::Impl::tableStyleTcBorders( return; m_pSerializer->startElementNS(XML_w, nToken); - for (sal_Int32 i = 0; i < rTcBorders.getLength(); ++i) - if (sal_Int32 nSubToken = DocxStringGetToken(aTcBordersTokens, rTcBorders[i].Name)) + for (const auto& rTcBorder : rTcBorders) + if (sal_Int32 nSubToken = DocxStringGetToken(aTcBordersTokens, rTcBorder.Name)) tableStyleTcBorder(nSubToken, - rTcBorders[i].Value.get>()); + rTcBorder.Value.get>()); m_pSerializer->endElementNS(XML_w, nToken); } @@ -240,22 +234,22 @@ void DocxTableStyleExport::Impl::tableStyleShd(uno::Sequenceadd(FSNS(XML_w, XML_val), rShd[i].Value.get().toUtf8()); - else if (rShd[i].Name == "color") - pAttributeList->add(FSNS(XML_w, XML_color), rShd[i].Value.get().toUtf8()); - else if (rShd[i].Name == "fill") - pAttributeList->add(FSNS(XML_w, XML_fill), rShd[i].Value.get().toUtf8()); - else if (rShd[i].Name == "themeFill") - pAttributeList->add(FSNS(XML_w, XML_themeFill), rShd[i].Value.get().toUtf8()); - else if (rShd[i].Name == "themeFillShade") + if (rProp.Name == "val") + pAttributeList->add(FSNS(XML_w, XML_val), rProp.Value.get().toUtf8()); + else if (rProp.Name == "color") + pAttributeList->add(FSNS(XML_w, XML_color), rProp.Value.get().toUtf8()); + else if (rProp.Name == "fill") + pAttributeList->add(FSNS(XML_w, XML_fill), rProp.Value.get().toUtf8()); + else if (rProp.Name == "themeFill") + pAttributeList->add(FSNS(XML_w, XML_themeFill), rProp.Value.get().toUtf8()); + else if (rProp.Name == "themeFillShade") pAttributeList->add(FSNS(XML_w, XML_themeFillShade), - rShd[i].Value.get().toUtf8()); - else if (rShd[i].Name == "themeFillTint") + rProp.Value.get().toUtf8()); + else if (rProp.Name == "themeFillTint") pAttributeList->add(FSNS(XML_w, XML_themeFillTint), - rShd[i].Value.get().toUtf8()); + rProp.Value.get().toUtf8()); } sax_fastparser::XFastAttributeListRef xAttributeList(pAttributeList); m_pSerializer->singleElementNS(XML_w, XML_shd, xAttributeList); @@ -268,19 +262,16 @@ void DocxTableStyleExport::Impl::tableStyleRColor(uno::Sequenceadd(FSNS(XML_w, XML_val), rColor[i].Value.get().toUtf8()); - else if (rColor[i].Name == "themeColor") - pAttributeList->add(FSNS(XML_w, XML_themeColor), - rColor[i].Value.get().toUtf8()); - else if (rColor[i].Name == "themeTint") - pAttributeList->add(FSNS(XML_w, XML_themeTint), - rColor[i].Value.get().toUtf8()); - else if (rColor[i].Name == "themeShade") - pAttributeList->add(FSNS(XML_w, XML_themeShade), - rColor[i].Value.get().toUtf8()); + if (rProp.Name == "val") + pAttributeList->add(FSNS(XML_w, XML_val), rProp.Value.get().toUtf8()); + else if (rProp.Name == "themeColor") + pAttributeList->add(FSNS(XML_w, XML_themeColor), rProp.Value.get().toUtf8()); + else if (rProp.Name == "themeTint") + pAttributeList->add(FSNS(XML_w, XML_themeTint), rProp.Value.get().toUtf8()); + else if (rProp.Name == "themeShade") + pAttributeList->add(FSNS(XML_w, XML_themeShade), rProp.Value.get().toUtf8()); } sax_fastparser::XFastAttributeListRef xAttributeList(pAttributeList); m_pSerializer->singleElementNS(XML_w, XML_color, xAttributeList); @@ -293,14 +284,14 @@ void DocxTableStyleExport::Impl::tableStyleRLang(uno::Sequenceadd(FSNS(XML_w, XML_eastAsia), rLang[i].Value.get().toUtf8()); - else if (rLang[i].Name == "val") - pAttributeList->add(FSNS(XML_w, XML_val), rLang[i].Value.get().toUtf8()); - else if (rLang[i].Name == "bidi") - pAttributeList->add(FSNS(XML_w, XML_bidi), rLang[i].Value.get().toUtf8()); + if (rProp.Name == "eastAsia") + pAttributeList->add(FSNS(XML_w, XML_eastAsia), rProp.Value.get().toUtf8()); + else if (rProp.Name == "val") + pAttributeList->add(FSNS(XML_w, XML_val), rProp.Value.get().toUtf8()); + else if (rProp.Name == "bidi") + pAttributeList->add(FSNS(XML_w, XML_bidi), rProp.Value.get().toUtf8()); } sax_fastparser::XFastAttributeListRef xAttributeList(pAttributeList); m_pSerializer->singleElementNS(XML_w, XML_lang, xAttributeList); @@ -313,20 +304,17 @@ void DocxTableStyleExport::Impl::tableStyleRRFonts(uno::Sequenceadd(FSNS(XML_w, XML_eastAsiaTheme), - rRFonts[i].Value.get().toUtf8()); - else if (rRFonts[i].Name == "asciiTheme") - pAttributeList->add(FSNS(XML_w, XML_asciiTheme), - rRFonts[i].Value.get().toUtf8()); - else if (rRFonts[i].Name == "cstheme") - pAttributeList->add(FSNS(XML_w, XML_cstheme), - rRFonts[i].Value.get().toUtf8()); - else if (rRFonts[i].Name == "hAnsiTheme") - pAttributeList->add(FSNS(XML_w, XML_hAnsiTheme), - rRFonts[i].Value.get().toUtf8()); + rRFont.Value.get().toUtf8()); + else if (rRFont.Name == "asciiTheme") + pAttributeList->add(FSNS(XML_w, XML_asciiTheme), rRFont.Value.get().toUtf8()); + else if (rRFont.Name == "cstheme") + pAttributeList->add(FSNS(XML_w, XML_cstheme), rRFont.Value.get().toUtf8()); + else if (rRFont.Name == "hAnsiTheme") + pAttributeList->add(FSNS(XML_w, XML_hAnsiTheme), rRFont.Value.get().toUtf8()); } sax_fastparser::XFastAttributeListRef xAttributeList(pAttributeList); m_pSerializer->singleElementNS(XML_w, XML_rFonts, xAttributeList); @@ -339,28 +327,24 @@ void DocxTableStyleExport::Impl::tableStylePSpacing(uno::Sequenceadd(FSNS(XML_w, XML_after), rSpacing[i].Value.get().toUtf8()); - else if (rSpacing[i].Name == "before") - pAttributeList->add(FSNS(XML_w, XML_before), - rSpacing[i].Value.get().toUtf8()); - else if (rSpacing[i].Name == "line") - pAttributeList->add(FSNS(XML_w, XML_line), rSpacing[i].Value.get().toUtf8()); - else if (rSpacing[i].Name == "lineRule") - pAttributeList->add(FSNS(XML_w, XML_lineRule), - rSpacing[i].Value.get().toUtf8()); - else if (rSpacing[i].Name == "beforeLines") - pAttributeList->add(FSNS(XML_w, XML_beforeLines), - rSpacing[i].Value.get().toUtf8()); - else if (rSpacing[i].Name == "ParaTopMarginBeforeAutoSpacing") + if (rProp.Name == "after") + pAttributeList->add(FSNS(XML_w, XML_after), rProp.Value.get().toUtf8()); + else if (rProp.Name == "before") + pAttributeList->add(FSNS(XML_w, XML_before), rProp.Value.get().toUtf8()); + else if (rProp.Name == "line") + pAttributeList->add(FSNS(XML_w, XML_line), rProp.Value.get().toUtf8()); + else if (rProp.Name == "lineRule") + pAttributeList->add(FSNS(XML_w, XML_lineRule), rProp.Value.get().toUtf8()); + else if (rProp.Name == "beforeLines") + pAttributeList->add(FSNS(XML_w, XML_beforeLines), rProp.Value.get().toUtf8()); + else if (rProp.Name == "ParaTopMarginBeforeAutoSpacing") // Auto spacing will be available in grab bag only if it was set to true pAttributeList->add(FSNS(XML_w, XML_beforeAutospacing), "1"); - else if (rSpacing[i].Name == "afterLines") - pAttributeList->add(FSNS(XML_w, XML_afterLines), - rSpacing[i].Value.get().toUtf8()); - else if (rSpacing[i].Name == "ParaBottomMarginAfterAutoSpacing") + else if (rProp.Name == "afterLines") + pAttributeList->add(FSNS(XML_w, XML_afterLines), rProp.Value.get().toUtf8()); + else if (rProp.Name == "ParaBottomMarginAfterAutoSpacing") // Auto spacing will be available in grab bag only if it was set to true pAttributeList->add(FSNS(XML_w, XML_afterAutospacing), "1"); } @@ -375,13 +359,12 @@ void DocxTableStyleExport::Impl::tableStylePInd(uno::Sequenceadd(FSNS(XML_w, XML_rightChars), - rInd[i].Value.get().toUtf8()); - else if (rInd[i].Name == "right") - pAttributeList->add(FSNS(XML_w, XML_right), rInd[i].Value.get().toUtf8()); + if (rProp.Name == "rightChars") + pAttributeList->add(FSNS(XML_w, XML_rightChars), rProp.Value.get().toUtf8()); + else if (rProp.Name == "right") + pAttributeList->add(FSNS(XML_w, XML_right), rProp.Value.get().toUtf8()); } sax_fastparser::XFastAttributeListRef xAttributeList(pAttributeList); m_pSerializer->singleElementNS(XML_w, XML_ind, xAttributeList); @@ -394,13 +377,12 @@ void DocxTableStyleExport::Impl::tableStyleTableInd(uno::Sequenceadd(FSNS(XML_w, XML_w), - OString::number(rTableInd[i].Value.get())); - else if (rTableInd[i].Name == "type") - pAttributeList->add(FSNS(XML_w, XML_type), rTableInd[i].Value.get().toUtf8()); + if (rProp.Name == "w") + pAttributeList->add(FSNS(XML_w, XML_w), OString::number(rProp.Value.get())); + else if (rProp.Name == "type") + pAttributeList->add(FSNS(XML_w, XML_type), rProp.Value.get().toUtf8()); } sax_fastparser::XFastAttributeListRef xAttributeList(pAttributeList); m_pSerializer->singleElementNS(XML_w, XML_tblInd, xAttributeList); @@ -438,37 +420,37 @@ void DocxTableStyleExport::Impl::tableStyleRPr(uno::Sequence>(); - else if (rRPr[i].Name == "lang") - aLang = rRPr[i].Value.get>(); - else if (rRPr[i].Name == "b") - aB = rRPr[i].Value.get(); - else if (rRPr[i].Name == "bCs") - aBCs = rRPr[i].Value.get(); - else if (rRPr[i].Name == "i") - aI = rRPr[i].Value.get(); - else if (rRPr[i].Name == "color") - aColor = rRPr[i].Value.get>(); - else if (rRPr[i].Name == "sz") - aSz = rRPr[i].Value.get(); - else if (rRPr[i].Name == "szCs") - aSzCs = rRPr[i].Value.get(); - else if (rRPr[i].Name == "caps") - aCaps = rRPr[i].Value.get(); - else if (rRPr[i].Name == "smallCaps") - aSmallCaps = rRPr[i].Value.get(); - else if (rRPr[i].Name == "spacing") + if (rProp.Name == "rFonts") + aRFonts = rProp.Value.get>(); + else if (rProp.Name == "lang") + aLang = rProp.Value.get>(); + else if (rProp.Name == "b") + aB = rProp.Value.get(); + else if (rProp.Name == "bCs") + aBCs = rProp.Value.get(); + else if (rProp.Name == "i") + aI = rProp.Value.get(); + else if (rProp.Name == "color") + aColor = rProp.Value.get>(); + else if (rProp.Name == "sz") + aSz = rProp.Value.get(); + else if (rProp.Name == "szCs") + aSzCs = rProp.Value.get(); + else if (rProp.Name == "caps") + aCaps = rProp.Value.get(); + else if (rProp.Name == "smallCaps") + aSmallCaps = rProp.Value.get(); + else if (rProp.Name == "spacing") { - if (rRPr[i].Value.has()) + if (rProp.Value.has()) { - aSpacing = rRPr[i].Value.get(); + aSpacing = rProp.Value.get(); } else { - aSpacingSequence = rRPr[i].Value.get>(); + aSpacingSequence = rProp.Value.get>(); bSequenceFlag = true; // set the uno::Sequence flag. } } @@ -508,18 +490,18 @@ void DocxTableStyleExport::Impl::tableStylePPr(uno::Sequence>(); - else if (rPPr[i].Name == "ind") - aInd = rPPr[i].Value.get>(); - else if (rPPr[i].Name == "wordWrap") + if (rProp.Name == "spacing") + aSpacing = rProp.Value.get>(); + else if (rProp.Name == "ind") + aInd = rProp.Value.get>(); + else if (rProp.Name == "wordWrap") bWordWrap = true; - else if (rPPr[i].Name == "jc") - aJc = rPPr[i].Value.get(); - else if (rPPr[i].Name == "snapToGrid") - aSnapToGrid = rPPr[i].Value.get(); + else if (rProp.Name == "jc") + aJc = rProp.Value.get(); + else if (rProp.Name == "snapToGrid") + aSnapToGrid = rProp.Value.get(); } if (bWordWrap) m_pSerializer->singleElementNS(XML_w, XML_wordWrap); @@ -544,18 +526,18 @@ void DocxTableStyleExport::Impl::tableStyleTablePr(uno::Sequence aTableCellMar; boost::optional oTableStyleRowBandSize; boost::optional oTableStyleColBandSize; - for (sal_Int32 i = 0; i < rTablePr.getLength(); ++i) + for (const auto& rProp : rTablePr) { - if (rTablePr[i].Name == "tblStyleRowBandSize") - oTableStyleRowBandSize = rTablePr[i].Value.get(); - else if (rTablePr[i].Name == "tblStyleColBandSize") - oTableStyleColBandSize = rTablePr[i].Value.get(); - else if (rTablePr[i].Name == "tblInd") - aTableInd = rTablePr[i].Value.get>(); - else if (rTablePr[i].Name == "tblBorders") - aTableBorders = rTablePr[i].Value.get>(); - else if (rTablePr[i].Name == "tblCellMar") - aTableCellMar = rTablePr[i].Value.get>(); + if (rProp.Name == "tblStyleRowBandSize") + oTableStyleRowBandSize = rProp.Value.get(); + else if (rProp.Name == "tblStyleColBandSize") + oTableStyleColBandSize = rProp.Value.get(); + else if (rProp.Name == "tblInd") + aTableInd = rProp.Value.get>(); + else if (rProp.Name == "tblBorders") + aTableBorders = rProp.Value.get>(); + else if (rProp.Name == "tblCellMar") + aTableCellMar = rProp.Value.get>(); } if (oTableStyleRowBandSize) m_pSerializer->singleElementNS(XML_w, XML_tblStyleRowBandSize, FSNS(XML_w, XML_val), @@ -581,16 +563,16 @@ void DocxTableStyleExport::Impl::tableStyleTcPr(uno::Sequence aTcBorders; uno::Sequence aTcMar; OUString aVAlign; - for (sal_Int32 i = 0; i < rTcPr.getLength(); ++i) + for (const auto& rProp : rTcPr) { - if (rTcPr[i].Name == "shd") - aShd = rTcPr[i].Value.get>(); - else if (rTcPr[i].Name == "tcBorders") - aTcBorders = rTcPr[i].Value.get>(); - else if (rTcPr[i].Name == "tcMar") - aTcMar = rTcPr[i].Value.get>(); - else if (rTcPr[i].Name == "vAlign") - aVAlign = rTcPr[i].Value.get(); + if (rProp.Name == "shd") + aShd = rProp.Value.get>(); + else if (rProp.Name == "tcBorders") + aTcBorders = rProp.Value.get>(); + else if (rProp.Name == "tcMar") + aTcMar = rProp.Value.get>(); + else if (rProp.Name == "vAlign") + aVAlign = rProp.Value.get(); } tableStyleTcBorders(aTcBorders); tableStyleTableCellMar(aTcMar, XML_tcMar); @@ -612,18 +594,18 @@ void DocxTableStyleExport::Impl::tableStyleTableStylePr( uno::Sequence aRPr; uno::Sequence aTablePr; uno::Sequence aTcPr; - for (sal_Int32 i = 0; i < rTableStylePr.getLength(); ++i) + for (const auto& rProp : rTableStylePr) { - if (rTableStylePr[i].Name == "type") - aType = rTableStylePr[i].Value.get(); - else if (rTableStylePr[i].Name == "pPr") - aPPr = rTableStylePr[i].Value.get>(); - else if (rTableStylePr[i].Name == "rPr") - aRPr = rTableStylePr[i].Value.get>(); - else if (rTableStylePr[i].Name == "tblPr") - aTablePr = rTableStylePr[i].Value.get>(); - else if (rTableStylePr[i].Name == "tcPr") - aTcPr = rTableStylePr[i].Value.get>(); + if (rProp.Name == "type") + aType = rProp.Value.get(); + else if (rProp.Name == "pPr") + aPPr = rProp.Value.get>(); + else if (rProp.Name == "rPr") + aRPr = rProp.Value.get>(); + else if (rProp.Name == "tblPr") + aTablePr = rProp.Value.get>(); + else if (rProp.Name == "tcPr") + aTcPr = rProp.Value.get>(); } m_pSerializer->startElementNS(XML_w, XML_tblStylePr, FSNS(XML_w, XML_type), aType.toUtf8()); @@ -659,38 +641,38 @@ void DocxTableStyleExport::Impl::TableStyle(uno::Sequence& uno::Sequence aTablePr; uno::Sequence aTcPr; std::vector> aTableStylePrs; - for (sal_Int32 i = 0; i < rStyle.getLength(); ++i) + for (const auto& rProp : rStyle) { - if (rStyle[i].Name == "default") - bDefault = rStyle[i].Value.get(); - else if (rStyle[i].Name == "customStyle") - bCustomStyle = rStyle[i].Value.get(); - else if (rStyle[i].Name == "styleId") - aStyleId = rStyle[i].Value.get(); - else if (rStyle[i].Name == "name") - aName = rStyle[i].Value.get(); - else if (rStyle[i].Name == "basedOn") - aBasedOn = rStyle[i].Value.get(); - else if (rStyle[i].Name == "uiPriority") - aUiPriority = rStyle[i].Value.get(); - else if (rStyle[i].Name == "qFormat") + if (rProp.Name == "default") + bDefault = rProp.Value.get(); + else if (rProp.Name == "customStyle") + bCustomStyle = rProp.Value.get(); + else if (rProp.Name == "styleId") + aStyleId = rProp.Value.get(); + else if (rProp.Name == "name") + aName = rProp.Value.get(); + else if (rProp.Name == "basedOn") + aBasedOn = rProp.Value.get(); + else if (rProp.Name == "uiPriority") + aUiPriority = rProp.Value.get(); + else if (rProp.Name == "qFormat") bQFormat = true; - else if (rStyle[i].Name == "semiHidden") + else if (rProp.Name == "semiHidden") bSemiHidden = true; - else if (rStyle[i].Name == "unhideWhenUsed") + else if (rProp.Name == "unhideWhenUsed") bUnhideWhenUsed = true; - else if (rStyle[i].Name == "rsid") - aRsid = rStyle[i].Value.get(); - else if (rStyle[i].Name == "pPr") - aPPr = rStyle[i].Value.get>(); - else if (rStyle[i].Name == "rPr") - aRPr = rStyle[i].Value.get>(); - else if (rStyle[i].Name == "tblPr") - aTablePr = rStyle[i].Value.get>(); - else if (rStyle[i].Name == "tcPr") - aTcPr = rStyle[i].Value.get>(); - else if (rStyle[i].Name == "tblStylePr") - aTableStylePrs.push_back(rStyle[i].Value.get>()); + else if (rProp.Name == "rsid") + aRsid = rProp.Value.get(); + else if (rProp.Name == "pPr") + aPPr = rProp.Value.get>(); + else if (rProp.Name == "rPr") + aRPr = rProp.Value.get>(); + else if (rProp.Name == "tblPr") + aTablePr = rProp.Value.get>(); + else if (rProp.Name == "tcPr") + aTcPr = rProp.Value.get>(); + else if (rProp.Name == "tblStylePr") + aTableStylePrs.push_back(rProp.Value.get>()); } sax_fastparser::FastAttributeList* pAttributeList diff --git a/sw/source/filter/ww8/rtfattributeoutput.cxx b/sw/source/filter/ww8/rtfattributeoutput.cxx index 01135c7aaba6..11c99b5f29d1 100644 --- a/sw/source/filter/ww8/rtfattributeoutput.cxx +++ b/sw/source/filter/ww8/rtfattributeoutput.cxx @@ -2191,14 +2191,12 @@ void RtfAttributeOutput::OutputFlyFrame_Impl(const ww8::Frame& rFrame, const Poi } xPropSet->getPropertyValue("StringItemList") >>= aStrSeq; - sal_uInt32 nListItems = aStrSeq.getLength(); - for (sal_uInt32 i = 0; i < nListItems; i++) + for (const auto& rStr : aStrSeq) m_aRun ->append( "{" OOO_STRING_SVTOOLS_RTF_IGNORE OOO_STRING_SVTOOLS_RTF_FFL " ") - .append(OUStringToOString(aStrSeq[i], - m_rExport.GetCurrentEncoding())) + .append(OUStringToOString(rStr, m_rExport.GetCurrentEncoding())) .append('}'); m_aRun->append("}}"); diff --git a/sw/source/filter/ww8/ww8par.cxx b/sw/source/filter/ww8/ww8par.cxx index e81e395179ca..f5f474f05541 100644 --- a/sw/source/filter/ww8/ww8par.cxx +++ b/sw/source/filter/ww8/ww8par.cxx @@ -4888,17 +4888,16 @@ void SwWW8ImplReader::ReadGlobalTemplateSettings( const OUString& sCreatedFrom, if( xSFA->isFolder( aAddinPath ) ) sGlobalTemplates = xSFA->getFolderContents( aAddinPath, false ); - sal_Int32 nEntries = sGlobalTemplates.getLength(); - for ( sal_Int32 i=0; i xDocHandler( xSaxWriter,UNO_QUERY); Sequence aArgs( 1 + rArguments.getLength() ); aArgs[0] <<= xDocHandler; - for(sal_Int32 i = 0; i < rArguments.getLength(); i++) - aArgs[i+1] = rArguments[i]; + std::copy(rArguments.begin(), rArguments.end(), std::next(aArgs.begin())); // get filter component uno::Reference< document::XExporter > xExporter( diff --git a/sw/source/filter/xml/xmlimp.cxx b/sw/source/filter/xml/xmlimp.cxx index 4148fd922ac9..0c9f5e84ae84 100644 --- a/sw/source/filter/xml/xmlimp.cxx +++ b/sw/source/filter/xml/xmlimp.cxx @@ -520,11 +520,8 @@ void SwXMLImport::startDocument() if( aAny >>= aFamiliesSeq ) { SfxStyleFamily nFamilyMask = SfxStyleFamily::None; - sal_Int32 nCount = aFamiliesSeq.getLength(); - const OUString *pSeq = aFamiliesSeq.getConstArray(); - for( sal_Int32 i=0; i < nCount; i++ ) + for( const OUString& rFamily : aFamiliesSeq ) { - const OUString& rFamily = pSeq[i]; if( rFamily=="FrameStyles" ) nFamilyMask |= SfxStyleFamily::Frame; else if( rFamily=="PageStyles" ) @@ -1245,9 +1242,6 @@ void SwXMLImport::SetViewSettings(const Sequence < PropertyValue > & aViewProps) //TODO/LATER: why that cast?! //aRect = ((SfxInPlaceObject *)pDoc->GetDocShell())->GetVisArea(); - sal_Int32 nCount = aViewProps.getLength(); - const PropertyValue *pValue = aViewProps.getConstArray(); - sal_Int64 nTmp = 0; bool bShowRedlineChanges = false, bBrowseMode = false; bool bChangeShowRedline = false, bChangeBrowseMode = false; @@ -1256,44 +1250,43 @@ void SwXMLImport::SetViewSettings(const Sequence < PropertyValue > & aViewProps) bool bTwip = pDoc->GetDocShell()->GetMapUnit ( ) == MapUnit::MapTwip; //sal_Bool bTwip = pDoc->GetDocShell()->SfxInPlaceObject::GetMapUnit ( ) == MapUnit::MapTwip; - for (sal_Int32 i = 0; i < nCount ; i++) + for (const PropertyValue& rValue : aViewProps) { - if ( pValue->Name == "ViewAreaTop" ) + if ( rValue.Name == "ViewAreaTop" ) { - pValue->Value >>= nTmp; + rValue.Value >>= nTmp; aRect.setY( static_cast< long >(bTwip ? sanitiseMm100ToTwip(nTmp) : nTmp) ); } - else if ( pValue->Name == "ViewAreaLeft" ) + else if ( rValue.Name == "ViewAreaLeft" ) { - pValue->Value >>= nTmp; + rValue.Value >>= nTmp; aRect.setX( static_cast< long >(bTwip ? sanitiseMm100ToTwip(nTmp) : nTmp) ); } - else if ( pValue->Name == "ViewAreaWidth" ) + else if ( rValue.Name == "ViewAreaWidth" ) { - pValue->Value >>= nTmp; + rValue.Value >>= nTmp; Size aSize( aRect.GetSize() ); aSize.setWidth( static_cast< long >(bTwip ? sanitiseMm100ToTwip(nTmp) : nTmp) ); aRect.SetSize( aSize ); } - else if ( pValue->Name == "ViewAreaHeight" ) + else if ( rValue.Name == "ViewAreaHeight" ) { - pValue->Value >>= nTmp; + rValue.Value >>= nTmp; Size aSize( aRect.GetSize() ); aSize.setHeight( static_cast< long >(bTwip ? sanitiseMm100ToTwip(nTmp) : nTmp) ); aRect.SetSize( aSize ); } - else if ( pValue->Name == "ShowRedlineChanges" ) + else if ( rValue.Name == "ShowRedlineChanges" ) { - bShowRedlineChanges = *o3tl::doAccess(pValue->Value); + bShowRedlineChanges = *o3tl::doAccess(rValue.Value); bChangeShowRedline = true; } // Headers and footers are not displayed in BrowseView anymore - else if ( pValue->Name == "InBrowseMode" ) + else if ( rValue.Name == "InBrowseMode" ) { - bBrowseMode = *o3tl::doAccess(pValue->Value); + bBrowseMode = *o3tl::doAccess(rValue.Value); bChangeBrowseMode = true; } - pValue++; } if( pDoc->GetDocShell() ) pDoc->GetDocShell()->SetVisArea ( aRect ); @@ -1360,9 +1353,6 @@ void SwXMLImport::SetConfigurationSettings(const Sequence < PropertyValue > & aC aExcludeWhenNotLoadingUserSettings.insert("SubtractFlysAnchoredAtFlys"); aExcludeWhenNotLoadingUserSettings.insert("EmptyDbFieldHidesPara"); - sal_Int32 nCount = aConfigProps.getLength(); - const PropertyValue* pValues = aConfigProps.getConstArray(); - SvtSaveOptions aSaveOpt; bool bIsUserSetting = aSaveOpt.IsLoadUserSettings(); @@ -1400,11 +1390,11 @@ void SwXMLImport::SetConfigurationSettings(const Sequence < PropertyValue > & aC const PropertyValue* currentDatabaseCommandType = nullptr; const PropertyValue* embeddedDatabaseName = nullptr; - while( nCount-- ) + for( const PropertyValue& rValue : aConfigProps ) { - bool bSet = aExcludeAlways.find(pValues->Name) == aExcludeAlways.end(); + bool bSet = aExcludeAlways.find(rValue.Name) == aExcludeAlways.end(); if( bSet && !bIsUserSetting - && (aExcludeWhenNotLoadingUserSettings.find(pValues->Name) + && (aExcludeWhenNotLoadingUserSettings.find(rValue.Name) != aExcludeWhenNotLoadingUserSettings.end()) ) { bSet = false; @@ -1414,82 +1404,81 @@ void SwXMLImport::SetConfigurationSettings(const Sequence < PropertyValue > & aC { try { - if( xInfo->hasPropertyByName( pValues->Name ) ) + if( xInfo->hasPropertyByName( rValue.Name ) ) { - if( pValues->Name == "RedlineProtectionKey" ) + if( rValue.Name == "RedlineProtectionKey" ) { Sequence aKey; - pValues->Value >>= aKey; + rValue.Value >>= aKey; GetTextImport()->SetChangesProtectionKey( aKey ); } else { // HACK: Setting these out of order does not work. - if( pValues->Name == "CurrentDatabaseDataSource" ) - currentDatabaseDataSource = pValues; - else if( pValues->Name == "CurrentDatabaseCommand" ) - currentDatabaseCommand = pValues; - else if( pValues->Name == "CurrentDatabaseCommandType" ) - currentDatabaseCommandType = pValues; - else if (pValues->Name == "EmbeddedDatabaseName") - embeddedDatabaseName = pValues; + if( rValue.Name == "CurrentDatabaseDataSource" ) + currentDatabaseDataSource = &rValue; + else if( rValue.Name == "CurrentDatabaseCommand" ) + currentDatabaseCommand = &rValue; + else if( rValue.Name == "CurrentDatabaseCommandType" ) + currentDatabaseCommandType = &rValue; + else if (rValue.Name == "EmbeddedDatabaseName") + embeddedDatabaseName = &rValue; else - xProps->setPropertyValue( pValues->Name, - pValues->Value ); + xProps->setPropertyValue( rValue.Name, rValue.Value ); } } // did we find any of the non-default cases? - if ( pValues->Name == "PrinterIndependentLayout" ) + if ( rValue.Name == "PrinterIndependentLayout" ) bPrinterIndependentLayout = true; - else if ( pValues->Name == "AddExternalLeading" ) + else if ( rValue.Name == "AddExternalLeading" ) bAddExternalLeading = true; - else if ( pValues->Name == "AddParaSpacingToTableCells" ) + else if ( rValue.Name == "AddParaSpacingToTableCells" ) bAddParaSpacingToTableCells = true; - else if ( pValues->Name == "UseFormerLineSpacing" ) + else if ( rValue.Name == "UseFormerLineSpacing" ) bUseFormerLineSpacing = true; - else if ( pValues->Name == "UseFormerObjectPositioning" ) + else if ( rValue.Name == "UseFormerObjectPositioning" ) bUseFormerObjectPositioning = true; - else if ( pValues->Name == "UseFormerTextWrapping" ) + else if ( rValue.Name == "UseFormerTextWrapping" ) bUseFormerTextWrapping = true; - else if ( pValues->Name == "UseOldNumbering" ) + else if ( rValue.Name == "UseOldNumbering" ) bUseOldNumbering = true; - else if ( pValues->Name == "ConsiderTextWrapOnObjPos" ) + else if ( rValue.Name == "ConsiderTextWrapOnObjPos" ) bConsiderWrapOnObjPos = true; - else if ( pValues->Name == "IgnoreFirstLineIndentInNumbering" ) + else if ( rValue.Name == "IgnoreFirstLineIndentInNumbering" ) bIgnoreFirstLineIndentInNumbering = true; - else if ( pValues->Name == "DoNotJustifyLinesWithManualBreak" ) + else if ( rValue.Name == "DoNotJustifyLinesWithManualBreak" ) bDoNotJustifyLinesWithManualBreak = true; - else if ( pValues->Name == "DoNotResetParaAttrsForNumFont" ) + else if ( rValue.Name == "DoNotResetParaAttrsForNumFont" ) bDoNotResetParaAttrsForNumFont = true; - else if ( pValues->Name == "LoadReadonly" ) + else if ( rValue.Name == "LoadReadonly" ) bLoadReadonly = true; - else if ( pValues->Name == "DoNotCaptureDrawObjsOnPage" ) + else if ( rValue.Name == "DoNotCaptureDrawObjsOnPage" ) bDoNotCaptureDrawObjsOnPage = true; - else if ( pValues->Name == "ClipAsCharacterAnchoredWriterFlyFrames" ) + else if ( rValue.Name == "ClipAsCharacterAnchoredWriterFlyFrames" ) bClipAsCharacterAnchoredWriterFlyFrames = true; - else if ( pValues->Name == "UnxForceZeroExtLeading" ) + else if ( rValue.Name == "UnxForceZeroExtLeading" ) bUnixForceZeroExtLeading = true; - else if ( pValues->Name == "SmallCapsPercentage66" ) + else if ( rValue.Name == "SmallCapsPercentage66" ) bSmallCapsPercentage66 = true; - else if ( pValues->Name == "TabOverflow" ) + else if ( rValue.Name == "TabOverflow" ) bTabOverflow = true; - else if ( pValues->Name == "UnbreakableNumberings" ) + else if ( rValue.Name == "UnbreakableNumberings" ) bUnbreakableNumberings = true; - else if ( pValues->Name == "ClippedPictures" ) + else if ( rValue.Name == "ClippedPictures" ) bClippedPictures = true; - else if ( pValues->Name == "BackgroundParaOverDrawings" ) + else if ( rValue.Name == "BackgroundParaOverDrawings" ) bBackgroundParaOverDrawings = true; - else if ( pValues->Name == "TabOverMargin" ) + else if ( rValue.Name == "TabOverMargin" ) { bTabOverMargin = true; - pValues->Value >>= bTabOverMarginValue; + rValue.Value >>= bTabOverMarginValue; } - else if ( pValues->Name == "PropLineSpacingShrinksFirstLine" ) + else if ( rValue.Name == "PropLineSpacingShrinksFirstLine" ) bPropLineSpacingShrinksFirstLine = true; - else if (pValues->Name == "SubtractFlysAnchoredAtFlys") + else if (rValue.Name == "SubtractFlysAnchoredAtFlys") bSubtractFlysAnchoredAtFlys = true; - else if (pValues->Name == "CollapseEmptyCellPara") + else if (rValue.Name == "CollapseEmptyCellPara") bCollapseEmptyCellPara = true; } catch( Exception& ) @@ -1497,7 +1486,6 @@ void SwXMLImport::SetConfigurationSettings(const Sequence < PropertyValue > & aC OSL_FAIL( "SwXMLImport::SetConfigurationSettings: Exception!" ); } } - pValues++; } try @@ -1711,11 +1699,10 @@ void SwXMLImport::initialize( SvXMLImport::initialize(aArguments); // we are only looking for a NamedValue "LateInitSettings" - sal_Int32 nLength = aArguments.getLength(); - for(sal_Int32 i = 0; i < nLength; i++) + for(const auto& rArgument : aArguments) { beans::NamedValue aNamedValue; - if ( aArguments[i] >>= aNamedValue ) + if ( rArgument >>= aNamedValue ) { if (aNamedValue.Name == "LateInitSettings") { diff --git a/sw/source/filter/xml/xmlmeta.cxx b/sw/source/filter/xml/xmlmeta.cxx index b7b17b2e2b65..35ffb9909a1d 100644 --- a/sw/source/filter/xml/xmlmeta.cxx +++ b/sw/source/filter/xml/xmlmeta.cxx @@ -117,12 +117,12 @@ void SwXMLImport::SetStatistics( sal_uInt32 nTokens = 0; - for (sal_Int32 i = 0; i < i_rStats.getLength(); ++i) { + for (const auto& rStat : i_rStats) { for (struct statistic const* pStat = s_stats; pStat->name != nullptr; ++pStat) { - if (i_rStats[i].Name.equalsAscii(pStat->name)) { + if (rStat.Name.equalsAscii(pStat->name)) { sal_Int32 val = 0; - if (i_rStats[i].Value >>= val) { + if (rStat.Value >>= val) { if (pStat->target16 != nullptr) { aDocStat.*(pStat->target16) = static_cast (val); -- cgit