From fac093e5e63bd53bae3de552fedba927bd5c4561 Mon Sep 17 00:00:00 2001 From: Arkadiy Illarionov Date: Thu, 9 May 2019 15:17:26 +0300 Subject: Simplify Sequence iterations in xmlscript, xmlsecurity Use range-based loops or replace with comphelper or STL functions Change-Id: I3d63811caf80c87a9d560087e1f0d933ebcc0d55 Reviewed-on: https://gerrit.libreoffice.org/72040 Tested-by: Jenkins Reviewed-by: Noel Grandin --- xmlscript/source/xmldlg_imexp/xmldlg_expmodels.cxx | 19 +++++++------------ xmlscript/source/xmldlg_imexp/xmldlg_export.cxx | 5 ++--- 2 files changed, 9 insertions(+), 15 deletions(-) (limited to 'xmlscript/source/xmldlg_imexp') diff --git a/xmlscript/source/xmldlg_imexp/xmldlg_expmodels.cxx b/xmlscript/source/xmldlg_imexp/xmldlg_expmodels.cxx index 186dc6923f61..cf0a13e39235 100644 --- a/xmlscript/source/xmldlg_imexp/xmldlg_expmodels.cxx +++ b/xmlscript/source/xmldlg_imexp/xmldlg_expmodels.cxx @@ -318,11 +318,10 @@ void ElementDescriptor::readComboBoxModel( StyleBag * all_styles ) { ElementDescriptor * popup = new ElementDescriptor( _xProps, _xPropState, XMLNS_DIALOGS_PREFIX ":menupopup", _xDocument ); - OUString const * pItemValues = itemValues.getConstArray(); - for ( sal_Int32 nPos = 0; nPos < itemValues.getLength(); ++nPos ) + for ( const auto& rItemValue : itemValues ) { ElementDescriptor * item = new ElementDescriptor( _xProps, _xPropState, XMLNS_DIALOGS_PREFIX ":menuitem", _xDocument ); - item->addAttribute( XMLNS_DIALOGS_PREFIX ":value", pItemValues[ nPos ] ); + item->addAttribute( XMLNS_DIALOGS_PREFIX ":value", rItemValue ); popup->addSubElement( item ); } @@ -366,12 +365,10 @@ void ElementDescriptor::readListBoxModel( StyleBag * all_styles ) { ElementDescriptor * popup = new ElementDescriptor( _xProps, _xPropState, XMLNS_DIALOGS_PREFIX ":menupopup", _xDocument ); - OUString const * pItemValues = itemValues.getConstArray(); - sal_Int32 nPos; - for ( nPos = 0; nPos < itemValues.getLength(); ++nPos ) + for ( const auto& rItemValue : itemValues ) { ElementDescriptor * item = new ElementDescriptor(_xProps, _xPropState, XMLNS_DIALOGS_PREFIX ":menuitem", _xDocument ); - item->addAttribute( XMLNS_DIALOGS_PREFIX ":value", pItemValues[ nPos ] ); + item->addAttribute( XMLNS_DIALOGS_PREFIX ":value", rItemValue ); popup->addSubElement( item ); } @@ -379,7 +376,7 @@ void ElementDescriptor::readListBoxModel( StyleBag * all_styles ) if (readProp( "SelectedItems" ) >>= selected) { sal_Int16 const * pSelected = selected.getConstArray(); - for ( nPos = selected.getLength(); nPos--; ) + for ( sal_Int32 nPos = selected.getLength(); nPos--; ) { ElementDescriptor * item = static_cast< ElementDescriptor * >( popup->getSubElement( pSelected[ nPos ] ).get() ); @@ -1090,14 +1087,12 @@ void ElementDescriptor::readBullitinBoard( StyleBag * all_styles ) if ( !xDialogModel.is() ) return; // #TODO throw??? Sequence< OUString > aElements( xDialogModel->getElementNames() ); - OUString const * pElements = aElements.getConstArray(); ElementDescriptor * pRadioGroup = nullptr; - sal_Int32 nPos; - for ( nPos = 0; nPos < aElements.getLength(); ++nPos ) + for ( const auto& rElement : aElements ) { - Any aControlModel( xDialogModel->getByName( pElements[ nPos ] ) ); + Any aControlModel( xDialogModel->getByName( rElement ) ); Reference< beans::XPropertySet > xProps; OSL_VERIFY( aControlModel >>= xProps ); if (! xProps.is()) diff --git a/xmlscript/source/xmldlg_imexp/xmldlg_export.cxx b/xmlscript/source/xmldlg_imexp/xmldlg_export.cxx index 9341952eef35..eca2feb26fa0 100644 --- a/xmlscript/source/xmldlg_imexp/xmldlg_export.cxx +++ b/xmlscript/source/xmldlg_imexp/xmldlg_export.cxx @@ -1152,11 +1152,10 @@ void ElementDescriptor::readEvents() if (xEvents.is()) { Sequence< OUString > aNames( xEvents->getElementNames() ); - OUString const * pNames = aNames.getConstArray(); - for ( sal_Int32 nPos = 0; nPos < aNames.getLength(); ++nPos ) + for ( const auto& rName : aNames ) { script::ScriptEventDescriptor descr; - if (xEvents->getByName( pNames[ nPos ] ) >>= descr) + if (xEvents->getByName( rName ) >>= descr) { SAL_WARN_IF( descr.ListenerType.isEmpty() || descr.EventMethod.isEmpty() || -- cgit