summaryrefslogtreecommitdiff
path: root/xmlscript
diff options
context:
space:
mode:
authorArkadiy Illarionov <qarkai@gmail.com>2019-05-09 15:17:26 +0300
committerNoel Grandin <noel.grandin@collabora.co.uk>2019-05-09 18:21:59 +0200
commitfac093e5e63bd53bae3de552fedba927bd5c4561 (patch)
tree7b921dc813a6d6e0df55ef6d15edabb76e52bd40 /xmlscript
parent2479ab8b788ca000f2e979d0858de8d05de8e858 (diff)
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 <noel.grandin@collabora.co.uk>
Diffstat (limited to 'xmlscript')
-rw-r--r--xmlscript/source/xmldlg_imexp/xmldlg_expmodels.cxx19
-rw-r--r--xmlscript/source/xmldlg_imexp/xmldlg_export.cxx5
-rw-r--r--xmlscript/source/xmlflat_imexp/xmlbas_export.cxx39
-rw-r--r--xmlscript/source/xmllib_imexp/xmllib_export.cxx19
4 files changed, 32 insertions, 50 deletions
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() ||
diff --git a/xmlscript/source/xmlflat_imexp/xmlbas_export.cxx b/xmlscript/source/xmlflat_imexp/xmlbas_export.cxx
index 872f47a7e2df..74db5079a8cc 100644
--- a/xmlscript/source/xmlflat_imexp/xmlbas_export.cxx
+++ b/xmlscript/source/xmlflat_imexp/xmlbas_export.cxx
@@ -153,17 +153,13 @@ sal_Bool XMLBasicExporterBase::filter( const Sequence< beans::PropertyValue >& /
if ( xLibContainer.is() )
{
Sequence< OUString > aLibNames = xLibContainer->getElementNames();
- sal_Int32 nLibCount = aLibNames.getLength();
- const OUString* pLibNames = aLibNames.getConstArray();
- for ( sal_Int32 i = 0 ; i < nLibCount ; ++i )
+ for ( const OUString& rLibName : aLibNames )
{
- OUString aLibName( pLibNames[i] );
-
- if ( xLibContainer->hasByName( aLibName ) )
+ if ( xLibContainer->hasByName( rLibName ) )
{
OUString aTrueStr( "true" );
- if ( xLibContainer->isLibraryLink( aLibName ) )
+ if ( xLibContainer->isLibraryLink( rLibName ) )
{
// ooo/script:library-linked element
OUString aLibElementName( aPrefix );
@@ -173,9 +169,9 @@ sal_Bool XMLBasicExporterBase::filter( const Sequence< beans::PropertyValue >& /
xLibAttribs = static_cast< xml::sax::XAttributeList* >( pLibElement );
// ooo/script:name attribute
- pLibElement->addAttribute( aPrefix + ":name", aLibName );
+ pLibElement->addAttribute( aPrefix + ":name", rLibName );
- OUString aLinkURL( xLibContainer->getLibraryLinkURL( aLibName ) );
+ OUString aLinkURL( xLibContainer->getLibraryLinkURL( rLibName ) );
if ( !aLinkURL.isEmpty() )
{
// xlink:href attribute
@@ -185,7 +181,7 @@ sal_Bool XMLBasicExporterBase::filter( const Sequence< beans::PropertyValue >& /
pLibElement->addAttribute( XMLNS_XLINK_PREFIX ":type", "simple" );
}
- if ( xLibContainer->isLibraryReadOnly( aLibName ) )
+ if ( xLibContainer->isLibraryReadOnly( rLibName ) )
{
// ooo/script:readonly attribute
pLibElement->addAttribute( aPrefix + ":readonly", aTrueStr );
@@ -209,9 +205,9 @@ sal_Bool XMLBasicExporterBase::filter( const Sequence< beans::PropertyValue >& /
xLibAttribs = static_cast< xml::sax::XAttributeList* >( pLibElement );
// ooo/script:name attribute
- pLibElement->addAttribute( aPrefix + ":name", aLibName );
+ pLibElement->addAttribute( aPrefix + ":name", rLibName );
- if ( xLibContainer->isLibraryReadOnly( aLibName ) )
+ if ( xLibContainer->isLibraryReadOnly( rLibName ) )
{
// ooo/script:readonly attribute
pLibElement->addAttribute( aPrefix + ":readonly", aTrueStr );
@@ -219,28 +215,25 @@ sal_Bool XMLBasicExporterBase::filter( const Sequence< beans::PropertyValue >& /
// TODO: password protected libraries
Reference< script::XLibraryContainerPassword > xPasswd( xLibContainer, UNO_QUERY );
- if ( xPasswd.is() && xPasswd->isLibraryPasswordProtected( aLibName ) )
+ if ( xPasswd.is() && xPasswd->isLibraryPasswordProtected( rLibName ) )
continue;
// <ooo/script:library-embedded...
m_xHandler->ignorableWhitespace( OUString() );
m_xHandler->startElement( aLibElementName, xLibAttribs );
- if ( !xLibContainer->isLibraryLoaded( aLibName ) )
- xLibContainer->loadLibrary( aLibName );
+ if ( !xLibContainer->isLibraryLoaded( rLibName ) )
+ xLibContainer->loadLibrary( rLibName );
Reference< container::XNameContainer > xLib;
- xLibContainer->getByName( aLibName ) >>= xLib;
+ xLibContainer->getByName( rLibName ) >>= xLib;
if ( xLib.is() )
{
Sequence< OUString > aModNames = xLib->getElementNames();
- sal_Int32 nModCount = aModNames.getLength();
- const OUString* pModNames = aModNames.getConstArray();
- for ( sal_Int32 j = 0 ; j < nModCount ; ++j )
+ for ( const OUString& rModName : aModNames )
{
- OUString aModName( pModNames[j] );
- if ( xLib->hasByName( aModName ) )
+ if ( xLib->hasByName( rModName ) )
{
// ooo/script:module element
OUString aModElementName( aPrefix );
@@ -250,7 +243,7 @@ sal_Bool XMLBasicExporterBase::filter( const Sequence< beans::PropertyValue >& /
xModAttribs = static_cast< xml::sax::XAttributeList* >( pModElement );
// ooo/script:name attribute
- pModElement->addAttribute( aPrefix + ":name", aModName );
+ pModElement->addAttribute( aPrefix + ":name", rModName );
// <ooo/script:module...
m_xHandler->ignorableWhitespace( OUString() );
@@ -270,7 +263,7 @@ sal_Bool XMLBasicExporterBase::filter( const Sequence< beans::PropertyValue >& /
// module data
// TODO: write encrypted data for password protected libraries
OUString aSource;
- xLib->getByName( aModName ) >>= aSource;
+ xLib->getByName( rModName ) >>= aSource;
m_xHandler->characters( aSource );
// TODO: <ooo/script:byte-code>
diff --git a/xmlscript/source/xmllib_imexp/xmllib_export.cxx b/xmlscript/source/xmllib_imexp/xmllib_export.cxx
index 270377fbc759..5353c1c245ec 100644
--- a/xmlscript/source/xmllib_imexp/xmllib_export.cxx
+++ b/xmlscript/source/xmllib_imexp/xmllib_export.cxx
@@ -118,21 +118,16 @@ exportLibrary(
if( rLib.bPreload )
pLibElement->addAttribute( XMLNS_LIBRARY_PREFIX ":preload", sTrueStr );
- sal_Int32 nElementCount = rLib.aElementNames.getLength();
- if( nElementCount )
+ for( const auto& rElementName : rLib.aElementNames )
{
- const OUString* pElementNames = rLib.aElementNames.getConstArray();
- for( sal_Int32 i = 0 ; i < nElementCount ; i++ )
- {
- XMLElement* pElement = new XMLElement( XMLNS_LIBRARY_PREFIX ":element" );
- Reference< xml::sax::XAttributeList > xElementAttribs;
- xElementAttribs = static_cast< xml::sax::XAttributeList* >( pElement );
+ XMLElement* pElement = new XMLElement( XMLNS_LIBRARY_PREFIX ":element" );
+ Reference< xml::sax::XAttributeList > xElementAttribs;
+ xElementAttribs = static_cast< xml::sax::XAttributeList* >( pElement );
- pElement->addAttribute( XMLNS_LIBRARY_PREFIX ":name",
- pElementNames[i] );
+ pElement->addAttribute( XMLNS_LIBRARY_PREFIX ":name",
+ rElementName );
- pLibElement->addSubElement( pElement );
- }
+ pLibElement->addSubElement( pElement );
}
pLibElement->dump( xOut.get() );