diff options
author | Arkadiy Illarionov <qarkai@gmail.com> | 2019-02-20 01:10:07 +0300 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2019-02-20 07:17:38 +0100 |
commit | 6a143985bdc5d12d1f9e8cf8592440282986c099 (patch) | |
tree | 346e09d6ba1146b52a6a484a2883f3e898184648 /dtrans | |
parent | d707a5e64ba53ddb7669cca725915527aa788a6b (diff) |
Simplify containers iterations in desktop, dtrans, editeng, extensions
Use range-based loop or replace with STL functions
Change-Id: Ic5389d123d0a6a32a8bb46b081165e94a7c55292
Reviewed-on: https://gerrit.libreoffice.org/68036
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'dtrans')
-rw-r--r-- | dtrans/source/cnttype/mcnttype.cxx | 14 | ||||
-rw-r--r-- | dtrans/source/cnttype/wbench/testcnttype.cxx | 7 | ||||
-rw-r--r-- | dtrans/source/win32/ftransl/ftransl.cxx | 82 |
3 files changed, 38 insertions, 65 deletions
diff --git a/dtrans/source/cnttype/mcnttype.cxx b/dtrans/source/cnttype/mcnttype.cxx index 4ba1a295fd8a..8b35abb23193 100644 --- a/dtrans/source/cnttype/mcnttype.cxx +++ b/dtrans/source/cnttype/mcnttype.cxx @@ -20,6 +20,7 @@ #include <sal/config.h> #include <com/sun/star/container/NoSuchElementException.hpp> +#include <comphelper/sequence.hxx> #include <rtl/ustring.hxx> #include <tools/inetmime.hxx> @@ -51,18 +52,7 @@ OUString SAL_CALL CMimeContentType::getFullMediaType( ) Sequence< OUString > SAL_CALL CMimeContentType::getParameters( ) { - Sequence< OUString > seqParams; - - map< OUString, OUString >::iterator iter; - map< OUString, OUString >::iterator iter_end = m_ParameterMap.end( ); - - for ( iter = m_ParameterMap.begin( ); iter != iter_end; ++iter ) - { - seqParams.realloc( seqParams.getLength( ) + 1 ); - seqParams[seqParams.getLength( ) - 1] = iter->first; - } - - return seqParams; + return comphelper::mapKeysToSequence(m_ParameterMap); } sal_Bool SAL_CALL CMimeContentType::hasParameter( const OUString& aName ) diff --git a/dtrans/source/cnttype/wbench/testcnttype.cxx b/dtrans/source/cnttype/wbench/testcnttype.cxx index 86f2bf969a81..a148348ff6cb 100644 --- a/dtrans/source/cnttype/wbench/testcnttype.cxx +++ b/dtrans/source/cnttype/wbench/testcnttype.cxx @@ -93,14 +93,13 @@ sal_Bool processCntTypesAndWriteResultIntoFile( char* fname, vector< string >& v // set pointer to file start fseek( fstream, 0, SEEK_SET ); - vector< string >::iterator iter_end = vecData.end( ); - for ( vector< string >::iterator iter = vecData.begin( ); iter != iter_end; ++iter ) + for ( const auto& rData : vecData ) { try { - fprintf( fstream, "Read: %s\n", iter->c_str( ) ); + fprintf( fstream, "Read: %s\n", rData.c_str( ) ); - Reference< XMimeContentType > xMCntTyp = cnttypeFactory->createMimeContentType( OUString::createFromAscii( iter->c_str( ) ) ); + Reference< XMimeContentType > xMCntTyp = cnttypeFactory->createMimeContentType( OUString::createFromAscii( rData.c_str( ) ) ); fwprintf( fstream, OUString("Type: %s\n"), xMCntTyp->getMediaType( ).getStr( ) ); fwprintf( fstream, OUString("Subtype: %s\n"), xMCntTyp->getMediaSubtype( ).getStr( ) ); diff --git a/dtrans/source/win32/ftransl/ftransl.cxx b/dtrans/source/win32/ftransl/ftransl.cxx index 1ab6e1c87089..8293e22a8cd8 100644 --- a/dtrans/source/win32/ftransl/ftransl.cxx +++ b/dtrans/source/win32/ftransl/ftransl.cxx @@ -355,38 +355,27 @@ namespace { void findDataFlavorForStandardFormatId( sal_Int32 aStandardFormatId, DataFlavor& aDataFlavor ) { /* - we break the for loop if we find the first CF_INVALID + we stop search if we find the first CF_INVALID because in the translation table the entries with a standard clipboard format id appear before the other entries with CF_INVALID */ - vector< FormatEntry >::const_iterator citer_end = g_TranslTable.end( ); - for ( vector< FormatEntry >::const_iterator citer = g_TranslTable.begin( ); citer != citer_end; ++citer ) - { - sal_Int32 stdId = citer->aStandardFormatId; - if ( aStandardFormatId == stdId ) - { - aDataFlavor = citer->aDataFlavor; - break; - } - else if ( stdId == CF_INVALID ) - break; - } + vector< FormatEntry >::const_iterator citer = std::find_if(g_TranslTable.begin(), g_TranslTable.end(), + [&aStandardFormatId](const FormatEntry& rEntry) { + return rEntry.aStandardFormatId == aStandardFormatId + || rEntry.aStandardFormatId == CF_INVALID; + }); + if (citer != g_TranslTable.end() && citer->aStandardFormatId == aStandardFormatId) + aDataFlavor = citer->aDataFlavor; } void findDataFlavorForNativeFormatName( const OUString& aNativeFormatName, DataFlavor& aDataFlavor ) { - vector< FormatEntry >::const_iterator citer_end = g_TranslTable.end( ); - for ( vector< FormatEntry >::const_iterator citer = g_TranslTable.begin( ); - citer != citer_end; - ++citer ) - { - if ( aNativeFormatName.equalsIgnoreAsciiCase( citer->aNativeFormatName ) ) - { - aDataFlavor = citer->aDataFlavor; - break; - } - } + vector< FormatEntry >::const_iterator citer = std::find_if(g_TranslTable.begin(), g_TranslTable.end(), + [&aNativeFormatName](const FormatEntry& rEntry) { + return aNativeFormatName.equalsIgnoreAsciiCase(rEntry.aNativeFormatName); }); + if (citer != g_TranslTable.end()) + aDataFlavor = citer->aDataFlavor; } void findStandardFormatIdForCharset( const OUString& aCharset, Any& aAny ) @@ -403,16 +392,13 @@ void findStandardFormatIdForCharset( const OUString& aCharset, Any& aAny ) void setStandardFormatIdForNativeFormatName( const OUString& aNativeFormatName, Any& aAny ) { - vector< FormatEntry >::const_iterator citer_end = g_TranslTable.end( ); - for ( vector< FormatEntry >::const_iterator citer = g_TranslTable.begin( ); citer != citer_end; ++citer ) - { - if ( aNativeFormatName.equalsIgnoreAsciiCase( citer->aNativeFormatName ) && - (CF_INVALID != citer->aStandardFormatId) ) - { - aAny <<= citer->aStandardFormatId; - break; - } - } + vector< FormatEntry >::const_iterator citer = std::find_if(g_TranslTable.begin(), g_TranslTable.end(), + [&aNativeFormatName](const FormatEntry& rEntry) { + return aNativeFormatName.equalsIgnoreAsciiCase(rEntry.aNativeFormatName) + && (CF_INVALID != rEntry.aStandardFormatId); + }); + if (citer != g_TranslTable.end()) + aAny <<= citer->aStandardFormatId; } void findStdFormatIdOrNativeFormatNameForFullMediaType( @@ -420,23 +406,21 @@ void findStdFormatIdOrNativeFormatNameForFullMediaType( const OUString& aFullMediaType, Any& aAny ) { - vector< FormatEntry >::const_iterator citer_end = g_TranslTable.end( ); - for ( vector< FormatEntry >::const_iterator citer = g_TranslTable.begin( ); citer != citer_end; ++citer ) + vector< FormatEntry >::const_iterator citer = std::find_if(g_TranslTable.begin(), g_TranslTable.end(), + [&aRefXMimeFactory, &aFullMediaType](const FormatEntry& rEntry) { + Reference<XMimeContentType> refXMime( aRefXMimeFactory->createMimeContentType(rEntry.aDataFlavor.MimeType) ); + return aFullMediaType.equalsIgnoreAsciiCase(refXMime->getFullMediaType()); + }); + if (citer != g_TranslTable.end()) { - Reference< XMimeContentType > - refXMime( aRefXMimeFactory->createMimeContentType( citer->aDataFlavor.MimeType ) ); - if ( aFullMediaType.equalsIgnoreAsciiCase( refXMime->getFullMediaType( ) ) ) + sal_Int32 cf = citer->aStandardFormatId; + if ( CF_INVALID != cf ) + aAny <<= cf; + else { - sal_Int32 cf = citer->aStandardFormatId; - if ( CF_INVALID != cf ) - aAny <<= cf; - else - { - OSL_ENSURE( citer->aNativeFormatName.getLength( ), - "Invalid standard format id and empty native format name in translation table" ); - aAny <<= citer->aNativeFormatName; - } - break; + OSL_ENSURE( citer->aNativeFormatName.getLength( ), + "Invalid standard format id and empty native format name in translation table" ); + aAny <<= citer->aNativeFormatName; } } } |