diff options
author | Arkadiy Illarionov <qarkai@gmail.com> | 2019-08-29 00:51:02 +0300 |
---|---|---|
committer | Arkadiy Illarionov <qarkai@gmail.com> | 2019-08-30 14:15:57 +0200 |
commit | 760a377f7148e623e9e16d24e66f54a401ecb946 (patch) | |
tree | c9ea106618e4b9f6bb2c20d8817603c7556a9ef6 /linguistic | |
parent | cc4edc0f29c034722f10ab289eb0d8d563a8632c (diff) |
Simplify Sequence iterations in lingucomponent..lotuswordpro
Use range-based loops, STL and comphelper functions.
Change-Id: I975a9c09265976d5ce4a1d7ac2023cbb75bb7f28
Reviewed-on: https://gerrit.libreoffice.org/78242
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Tested-by: Jenkins
Reviewed-by: Arkadiy Illarionov <qarkai@gmail.com>
Diffstat (limited to 'linguistic')
-rw-r--r-- | linguistic/source/convdic.cxx | 47 | ||||
-rw-r--r-- | linguistic/source/convdiclist.cxx | 34 | ||||
-rw-r--r-- | linguistic/source/dlistimp.cxx | 13 | ||||
-rw-r--r-- | linguistic/source/gciterator.cxx | 19 | ||||
-rw-r--r-- | linguistic/source/hyphdsp.cxx | 18 | ||||
-rw-r--r-- | linguistic/source/lngopt.cxx | 30 | ||||
-rw-r--r-- | linguistic/source/lngprophelp.cxx | 149 | ||||
-rw-r--r-- | linguistic/source/lngsvcmgr.cxx | 279 | ||||
-rw-r--r-- | linguistic/source/misc.cxx | 65 | ||||
-rw-r--r-- | linguistic/source/misc2.cxx | 26 | ||||
-rw-r--r-- | linguistic/source/spelldsp.cxx | 38 | ||||
-rw-r--r-- | linguistic/source/spelldta.cxx | 8 | ||||
-rw-r--r-- | linguistic/source/thesdsp.cxx | 29 |
13 files changed, 277 insertions, 478 deletions
diff --git a/linguistic/source/convdic.cxx b/linguistic/source/convdic.cxx index 31de419bfbcd..3e9ec1ba7152 100644 --- a/linguistic/source/convdic.cxx +++ b/linguistic/source/convdic.cxx @@ -28,6 +28,7 @@ #include <tools/urlobj.hxx> #include <ucbhelper/content.hxx> #include <comphelper/processfactory.hxx> +#include <comphelper/sequence.hxx> #include <cppuhelper/supportsservice.hxx> #include <unotools/streamwrap.hxx> #include <unotools/ucbstreamhelper.hxx> @@ -405,39 +406,17 @@ uno::Sequence< OUString > SAL_CALL ConvDic::getConversions( pair< ConvMap::iterator, ConvMap::iterator > aRange = rConvMap.equal_range( aLookUpText ); - sal_Int32 nCount = 0; - ConvMap::iterator aIt; - for (aIt = aRange.first; aIt != aRange.second; ++aIt) - ++nCount; + std::vector<OUString> aRes; + auto nCount = static_cast<size_t>(std::distance(aRange.first, aRange.second)); + aRes.reserve(nCount); - uno::Sequence< OUString > aRes( nCount ); - OUString *pRes = aRes.getArray(); - sal_Int32 i = 0; - for (aIt = aRange.first; aIt != aRange.second; ++aIt) - pRes[i++] = (*aIt).second; + std::transform(aRange.first, aRange.second, std::back_inserter(aRes), + [](ConvMap::const_reference rEntry) { return rEntry.second; }); - return aRes; + return comphelper::containerToSequence(aRes); } -static bool lcl_SeqHasEntry( - const OUString *pSeqStart, // first element to check - sal_Int32 nToCheck, // number of elements to check - const OUString &rText) -{ - bool bRes = false; - if (pSeqStart && nToCheck > 0) - { - const OUString *pDone = pSeqStart + nToCheck; // one behind last to check - while (!bRes && pSeqStart != pDone) - { - if (*pSeqStart++ == rText) - bRes = true; - } - } - return bRes; -} - uno::Sequence< OUString > SAL_CALL ConvDic::getConversionEntries( ConversionDirection eDirection ) { @@ -451,9 +430,8 @@ uno::Sequence< OUString > SAL_CALL ConvDic::getConversionEntries( ConvMap &rConvMap = eDirection == ConversionDirection_FROM_LEFT ? aFromLeft : *pFromRight; - uno::Sequence< OUString > aRes( rConvMap.size() ); - OUString *pRes = aRes.getArray(); - sal_Int32 nIdx = 0; + std::vector<OUString> aRes; + aRes.reserve(rConvMap.size()); for (auto const& elem : rConvMap) { OUString aCurEntry( elem.first ); @@ -461,12 +439,11 @@ uno::Sequence< OUString > SAL_CALL ConvDic::getConversionEntries( // respective to the evaluated side (FROM_LEFT or FROM_RIGHT). // Thus if FROM_LEFT is evaluated for pairs (A,B) and (A,C) // only one entry for A will be returned in the result) - if (nIdx == 0 || !lcl_SeqHasEntry( pRes, nIdx, aCurEntry )) - pRes[ nIdx++ ] = aCurEntry; + if (std::find(aRes.begin(), aRes.end(), aCurEntry) == aRes.end()) + aRes.push_back(aCurEntry); } - aRes.realloc( nIdx ); - return aRes; + return comphelper::containerToSequence(aRes); } diff --git a/linguistic/source/convdiclist.cxx b/linguistic/source/convdiclist.cxx index f9d46bc03f7f..d110dd4afe60 100644 --- a/linguistic/source/convdiclist.cxx +++ b/linguistic/source/convdiclist.cxx @@ -197,12 +197,13 @@ uno::Sequence< OUString > SAL_CALL ConvDicNameContainer::getElementNames( ) { MutexGuard aGuard( GetLinguMutex() ); - sal_Int32 nLen = aConvDics.size(); - uno::Sequence< OUString > aRes( nLen ); - OUString *pName = aRes.getArray(); - for (sal_Int32 i = 0; i < nLen; ++i) - pName[i] = aConvDics[i]->getName(); - return aRes; + std::vector<OUString> aRes; + aRes.reserve(aConvDics.size()); + + std::transform(aConvDics.begin(), aConvDics.end(), std::back_inserter(aRes), + [](const uno::Reference<XConversionDictionary>& rDic) { return rDic->getName(); }); + + return comphelper::containerToSequence(aRes); } sal_Bool SAL_CALL ConvDicNameContainer::hasByName( const OUString& rName ) @@ -281,13 +282,9 @@ void ConvDicNameContainer::AddConvDics( { const Sequence< OUString > aDirCnt( utl::LocalFileHelper::GetFolderContents( rSearchDirPathURL, false ) ); - const OUString *pDirCnt = aDirCnt.getConstArray(); - sal_Int32 nEntries = aDirCnt.getLength(); - for (sal_Int32 i = 0; i < nEntries; ++i) + for (const OUString& aURL : aDirCnt) { - OUString aURL( pDirCnt[i] ); - sal_Int32 nPos = aURL.lastIndexOf('.'); OUString aExt( aURL.copy(nPos + 1).toAsciiLowerCase() ); OUString aSearchExt( rExtension.toAsciiLowerCase() ); @@ -374,12 +371,10 @@ ConvDicNameContainer & ConvDicList::GetNameContainer() // access list of text conversion dictionaries to activate SvtLinguOptions aOpt; SvtLinguConfig().GetOptions( aOpt ); - sal_Int32 nLen = aOpt.aActiveConvDics.getLength(); - const OUString *pActiveConvDics = aOpt.aActiveConvDics.getConstArray(); - for (sal_Int32 i = 0; i < nLen; ++i) + for (const OUString& rActiveConvDic : std::as_const(aOpt.aActiveConvDics)) { uno::Reference< XConversionDictionary > xDic = - mxNameContainer->GetByName( pActiveConvDics[i] ); + mxNameContainer->GetByName( rActiveConvDic ); if (xDic.is()) xDic->setActive( true ); } @@ -464,15 +459,10 @@ uno::Sequence< OUString > SAL_CALL ConvDicList::queryConversions( bSupported |= bMatch; if (bMatch && xDic->isActive()) { - Sequence< OUString > aNewConv( xDic->getConversions( + const Sequence< OUString > aNewConv( xDic->getConversions( rText, nStartPos, nLength, eDirection, nTextConversionOptions ) ); - sal_Int32 nNewLen = aNewConv.getLength(); - if (nNewLen > 0) - { - for (sal_Int32 k = 0; k < nNewLen; ++k) - aRes.push_back(aNewConv[k]); - } + std::copy(aNewConv.begin(), aNewConv.end(), std::back_inserter(aRes)); } } diff --git a/linguistic/source/dlistimp.cxx b/linguistic/source/dlistimp.cxx index 34eb79294ec2..c876a5eb3c7c 100644 --- a/linguistic/source/dlistimp.cxx +++ b/linguistic/source/dlistimp.cxx @@ -279,12 +279,9 @@ void DicList::SearchForDictionaries( const uno::Sequence< OUString > aDirCnt( utl::LocalFileHelper:: GetFolderContents( rDicDirURL, false ) ); - const OUString *pDirCnt = aDirCnt.getConstArray(); - sal_Int32 nEntries = aDirCnt.getLength(); - for (sal_Int32 i = 0; i < nEntries; ++i) + for (const OUString& aURL : aDirCnt) { - OUString aURL( pDirCnt[i] ); LanguageType nLang = LANGUAGE_NONE; bool bNeg = false; OUString aDicTitle = ""; @@ -622,13 +619,11 @@ void DicList::CreateDicList() //! activation of the dictionaries mxDicEvtLstnrHelper->BeginCollectEvents(); const uno::Sequence< OUString > aActiveDics( aOpt.GetActiveDics() ); - const OUString *pActiveDic = aActiveDics.getConstArray(); - sal_Int32 nLen = aActiveDics.getLength(); - for (sal_Int32 i = 0; i < nLen; ++i) + for (const OUString& rActiveDic : aActiveDics) { - if (!pActiveDic[i].isEmpty()) + if (!rActiveDic.isEmpty()) { - uno::Reference< XDictionary > xDic( getDictionaryByName( pActiveDic[i] ) ); + uno::Reference< XDictionary > xDic( getDictionaryByName( rActiveDic ) ); if (xDic.is()) xDic->setActive( true ); } diff --git a/linguistic/source/gciterator.cxx b/linguistic/source/gciterator.cxx index 0b284d660abc..d0c51f90b464 100644 --- a/linguistic/source/gciterator.cxx +++ b/linguistic/source/gciterator.cxx @@ -417,10 +417,9 @@ void GrammarCheckingIterator::ProcessResult( text::TextMarkupDescriptor * pDescriptors = aDescriptors.getArray(); // at pos 0 .. nErrors-1 -> all grammar errors - for (sal_Int32 i = 0; i < nErrors; ++i) + for (const linguistic2::SingleProofreadingError &rError : rRes.aErrors) { - const linguistic2::SingleProofreadingError &rError = rRes.aErrors[i]; - text::TextMarkupDescriptor &rDesc = aDescriptors[i]; + text::TextMarkupDescriptor &rDesc = *pDescriptors++; rDesc.nType = rError.nErrorType; rDesc.nOffset = rError.nErrorStart; @@ -455,9 +454,9 @@ void GrammarCheckingIterator::ProcessResult( // at pos nErrors -> sentence markup // nSentenceLength: includes the white-spaces following the sentence end... const sal_Int32 nSentenceLength = rRes.nStartOfNextSentencePosition - rRes.nStartOfSentencePosition; - pDescriptors[ nErrors ].nType = text::TextMarkupType::SENTENCE; - pDescriptors[ nErrors ].nOffset = rRes.nStartOfSentencePosition; - pDescriptors[ nErrors ].nLength = nSentenceLength; + pDescriptors->nType = text::TextMarkupType::SENTENCE; + pDescriptors->nOffset = rRes.nStartOfSentencePosition; + pDescriptors->nLength = nSentenceLength; xMulti->commitMultiTextMarkup( aDescriptors ) ; } @@ -1081,20 +1080,18 @@ void GrammarCheckingIterator::GetConfiguredGCSvcs_Impl() uno::Reference< container::XNameAccess > xNA( GetUpdateAccess(), uno::UNO_QUERY_THROW ); xNA.set( xNA->getByName( "GrammarCheckerList" ), uno::UNO_QUERY_THROW ); const uno::Sequence< OUString > aElementNames( xNA->getElementNames() ); - const OUString *pElementNames = aElementNames.getConstArray(); - sal_Int32 nLen = aElementNames.getLength(); - for (sal_Int32 i = 0; i < nLen; ++i) + for (const OUString& rElementName : aElementNames) { uno::Sequence< OUString > aImplNames; - uno::Any aTmp( xNA->getByName( pElementNames[i] ) ); + uno::Any aTmp( xNA->getByName( rElementName ) ); if (aTmp >>= aImplNames) { if (aImplNames.hasElements()) { // only the first entry is used, there should be only one grammar checker per language const OUString aImplName( aImplNames[0] ); - const LanguageType nLang = LanguageTag::convertToLanguageType( pElementNames[i] ); + const LanguageType nLang = LanguageTag::convertToLanguageType( rElementName ); aTmpGCImplNamesByLang[ nLang ] = aImplName; } } diff --git a/linguistic/source/hyphdsp.cxx b/linguistic/source/hyphdsp.cxx index fa0a77ff20a5..f2665b653561 100644 --- a/linguistic/source/hyphdsp.cxx +++ b/linguistic/source/hyphdsp.cxx @@ -33,6 +33,7 @@ #include <tools/debug.hxx> #include <svl/lngmisc.hxx> #include <comphelper/processfactory.hxx> +#include <comphelper/sequence.hxx> #include <osl/mutex.hxx> #include "hyphdsp.hxx" @@ -251,13 +252,13 @@ Sequence< Locale > SAL_CALL HyphenatorDispatcher::getLocales() { MutexGuard aGuard( GetLinguMutex() ); - Sequence< Locale > aLocales( static_cast< sal_Int32 >(aSvcMap.size()) ); - Locale *pLocales = aLocales.getArray(); - for (auto const& elem : aSvcMap) - { - *pLocales++ = LanguageTag::convertToLocale(elem.first); - } - return aLocales; + std::vector<Locale> aLocales; + aLocales.reserve(aSvcMap.size()); + + std::transform(aSvcMap.begin(), aSvcMap.end(), std::back_inserter(aLocales), + [](HyphSvcByLangMap_t::const_reference elem) { return LanguageTag::convertToLocale(elem.first); }); + + return comphelper::containerToSequence(aLocales); } @@ -661,8 +662,7 @@ void HyphenatorDispatcher::SetServiceList( const Locale &rLocale, LanguageType nLanguage = LinguLocaleToLanguage( rLocale ); - sal_Int32 nLen = rSvcImplNames.getLength(); - if (0 == nLen) + if (!rSvcImplNames.hasElements()) // remove entry aSvcMap.erase( nLanguage ); else diff --git a/linguistic/source/lngopt.cxx b/linguistic/source/lngopt.cxx index f97cb6cf5073..9473a8da2b77 100644 --- a/linguistic/source/lngopt.cxx +++ b/linguistic/source/lngopt.cxx @@ -26,6 +26,7 @@ #include <tools/debug.hxx> #include <unotools/lingucfg.hxx> +#include <comphelper/sequence.hxx> #include <cppuhelper/factory.hxx> #include <cppuhelper/supportsservice.hxx> #include <com/sun/star/container/XNameAccess.hpp> @@ -328,22 +329,16 @@ Sequence< PropertyValue > SAL_CALL { MutexGuard aGuard( GetLinguMutex() ); - sal_Int32 nLen = aPropertyMap.getSize(); - Sequence< PropertyValue > aProps( nLen ); - PropertyValue *pProp = aProps.getArray(); PropertyEntryVector_t aPropEntries = aPropertyMap.getPropertyEntries(); - PropertyEntryVector_t::const_iterator aIt = aPropEntries.begin(); - for (sal_Int32 i = 0; i < nLen; ++i, ++aIt) - { - PropertyValue &rVal = pProp[i]; - Any aAny( aConfig.GetProperty( aIt->nWID ) ); - - rVal.Name = aIt->sName; - rVal.Handle = aIt->nWID; - rVal.Value = aAny; - rVal.State = PropertyState_DIRECT_VALUE ; - } - return aProps; + std::vector<PropertyValue> aProps; + aProps.reserve(aPropertyMap.getSize()); + + std::transform(aPropEntries.begin(), aPropEntries.end(), std::back_inserter(aProps), + [this](PropertyEntryVector_t::const_reference rPropEntry) { + return PropertyValue(rPropEntry.sName, rPropEntry.nWID, + aConfig.GetProperty(rPropEntry.nWID), + css::beans::PropertyState_DIRECT_VALUE); }); + return comphelper::containerToSequence(aProps); } void SAL_CALL @@ -351,11 +346,8 @@ void SAL_CALL { MutexGuard aGuard( GetLinguMutex() ); - sal_Int32 nLen = rProps.getLength(); - const PropertyValue *pVal = rProps.getConstArray(); - for (sal_Int32 i = 0; i < nLen; ++i) + for (const PropertyValue &rVal : rProps) { - const PropertyValue &rVal = pVal[i]; setPropertyValue( rVal.Name, rVal.Value ); } } diff --git a/linguistic/source/lngprophelp.cxx b/linguistic/source/lngprophelp.cxx index 608020f8f3b3..ed0006c8962b 100644 --- a/linguistic/source/lngprophelp.cxx +++ b/linguistic/source/lngprophelp.cxx @@ -107,21 +107,20 @@ void PropertyChgHelper::SetDefaultValues() void PropertyChgHelper::GetCurrentValues() { - sal_Int32 nLen = GetPropNames().getLength(); - if (GetPropSet().is() && nLen) + const auto& rPropNames = GetPropNames(); + if (GetPropSet().is() && rPropNames.hasElements()) { - const OUString *pPropName = GetPropNames().getConstArray(); - for (sal_Int32 i = 0; i < nLen; ++i) + for (const OUString& rPropName : rPropNames) { bool *pbVal = nullptr, *pbResVal = nullptr; - if ( pPropName[i] == UPN_IS_IGNORE_CONTROL_CHARACTERS ) + if ( rPropName == UPN_IS_IGNORE_CONTROL_CHARACTERS ) { pbVal = &bIsIgnoreControlCharacters; pbResVal = &bResIsIgnoreControlCharacters; } - else if ( pPropName[i] == UPN_IS_USE_DICTIONARY_LIST ) + else if ( rPropName == UPN_IS_USE_DICTIONARY_LIST ) { pbVal = &bIsUseDictionaryList; pbResVal = &bResIsUseDictionaryList; @@ -129,7 +128,7 @@ void PropertyChgHelper::GetCurrentValues() if (pbVal && pbResVal) { - GetPropSet()->getPropertyValue( pPropName[i] ) >>= *pbVal; + GetPropSet()->getPropertyValue( rPropName ) >>= *pbVal; *pbResVal = *pbVal; } } @@ -144,25 +143,20 @@ void PropertyChgHelper::SetTmpPropVals( const PropertyValues &rPropVals ) bResIsIgnoreControlCharacters = bIsIgnoreControlCharacters; bResIsUseDictionaryList = bIsUseDictionaryList; - sal_Int32 nLen = rPropVals.getLength(); - if (nLen) + for (const PropertyValue& rVal : rPropVals) { - const PropertyValue *pVal = rPropVals.getConstArray(); - for (sal_Int32 i = 0; i < nLen; ++i) + bool *pbResVal = nullptr; + switch (rVal.Handle) { - bool *pbResVal = nullptr; - switch (pVal[i].Handle) - { - case UPH_IS_IGNORE_CONTROL_CHARACTERS : - pbResVal = &bResIsIgnoreControlCharacters; break; - case UPH_IS_USE_DICTIONARY_LIST : - pbResVal = &bResIsUseDictionaryList; break; - default: - ; - } - if (pbResVal) - pVal[i].Value >>= *pbResVal; + case UPH_IS_IGNORE_CONTROL_CHARACTERS : + pbResVal = &bResIsIgnoreControlCharacters; break; + case UPH_IS_USE_DICTIONARY_LIST : + pbResVal = &bResIsUseDictionaryList; break; + default: + ; } + if (pbResVal) + rVal.Value >>= *pbResVal; } } @@ -229,12 +223,10 @@ void PropertyChgHelper::AddAsPropListener() { if (xPropSet.is()) { - sal_Int32 nLen = aPropNames.getLength(); - const OUString *pPropName = aPropNames.getConstArray(); - for (sal_Int32 i = 0; i < nLen; ++i) + for (const OUString& rPropName : std::as_const(aPropNames)) { - if (!pPropName[i].isEmpty()) - xPropSet->addPropertyChangeListener( pPropName[i], this ); + if (!rPropName.isEmpty()) + xPropSet->addPropertyChangeListener( rPropName, this ); } } } @@ -243,12 +235,10 @@ void PropertyChgHelper::RemoveAsPropListener() { if (xPropSet.is()) { - sal_Int32 nLen = aPropNames.getLength(); - const OUString *pPropName = aPropNames.getConstArray(); - for (sal_Int32 i = 0; i < nLen; ++i) + for (const OUString& rPropName : std::as_const(aPropNames)) { - if (!pPropName[i].isEmpty()) - xPropSet->removePropertyChangeListener( pPropName[i], this ); + if (!rPropName.isEmpty()) + xPropSet->removePropertyChangeListener( rPropName, this ); } } } @@ -367,26 +357,25 @@ void PropertyHelper_Spell::GetCurrentValues() { PropertyChgHelper::GetCurrentValues(); - sal_Int32 nLen = GetPropNames().getLength(); - if (GetPropSet().is() && nLen) + const auto& rPropNames = GetPropNames(); + if (GetPropSet().is() && rPropNames.hasElements()) { - const OUString *pPropName = GetPropNames().getConstArray(); - for (sal_Int32 i = 0; i < nLen; ++i) + for (const OUString& rPropName : rPropNames) { bool *pbVal = nullptr, *pbResVal = nullptr; - if ( pPropName[i] == UPN_IS_SPELL_UPPER_CASE ) + if ( rPropName == UPN_IS_SPELL_UPPER_CASE ) { pbVal = &bIsSpellUpperCase; pbResVal = &bResIsSpellUpperCase; } - else if ( pPropName[i] == UPN_IS_SPELL_WITH_DIGITS ) + else if ( rPropName == UPN_IS_SPELL_WITH_DIGITS ) { pbVal = &bIsSpellWithDigits; pbResVal = &bResIsSpellWithDigits; } - else if ( pPropName[i] == UPN_IS_SPELL_CAPITALIZATION ) + else if ( rPropName == UPN_IS_SPELL_CAPITALIZATION ) { pbVal = &bIsSpellCapitalization; pbResVal = &bResIsSpellCapitalization; @@ -394,7 +383,7 @@ void PropertyHelper_Spell::GetCurrentValues() if (pbVal && pbResVal) { - GetPropSet()->getPropertyValue( pPropName[i] ) >>= *pbVal; + GetPropSet()->getPropertyValue( rPropName ) >>= *pbVal; *pbResVal = *pbVal; } } @@ -479,30 +468,25 @@ void PropertyHelper_Spell::SetTmpPropVals( const PropertyValues &rPropVals ) bResIsSpellCapitalization = bIsSpellCapitalization; bResIsSpellUpperCase = bIsSpellUpperCase; - sal_Int32 nLen = rPropVals.getLength(); - if (nLen) + for (const PropertyValue& rVal : rPropVals) { - const PropertyValue *pVal = rPropVals.getConstArray(); - for (sal_Int32 i = 0; i < nLen; ++i) + if ( rVal.Name == UPN_MAX_NUMBER_OF_SUGGESTIONS ) { - if ( pVal[i].Name == UPN_MAX_NUMBER_OF_SUGGESTIONS ) - { - // special value that is not part of the property set and thus needs to be handled differently - } - else + // special value that is not part of the property set and thus needs to be handled differently + } + else + { + bool *pbResVal = nullptr; + switch (rVal.Handle) { - bool *pbResVal = nullptr; - switch (pVal[i].Handle) - { - case UPH_IS_SPELL_UPPER_CASE : pbResVal = &bResIsSpellUpperCase; break; - case UPH_IS_SPELL_WITH_DIGITS : pbResVal = &bResIsSpellWithDigits; break; - case UPH_IS_SPELL_CAPITALIZATION : pbResVal = &bResIsSpellCapitalization; break; - default: - SAL_WARN( "linguistic", "unknown property" ); - } - if (pbResVal) - pVal[i].Value >>= *pbResVal; + case UPH_IS_SPELL_UPPER_CASE : pbResVal = &bResIsSpellUpperCase; break; + case UPH_IS_SPELL_WITH_DIGITS : pbResVal = &bResIsSpellWithDigits; break; + case UPH_IS_SPELL_CAPITALIZATION : pbResVal = &bResIsSpellCapitalization; break; + default: + SAL_WARN( "linguistic", "unknown property" ); } + if (pbResVal) + rVal.Value >>= *pbResVal; } } } @@ -545,26 +529,25 @@ void PropertyHelper_Hyphen::GetCurrentValues() { PropertyChgHelper::GetCurrentValues(); - sal_Int32 nLen = GetPropNames().getLength(); - if (GetPropSet().is() && nLen) + const auto& rPropNames = GetPropNames(); + if (GetPropSet().is() && rPropNames.hasElements()) { - const OUString *pPropName = GetPropNames().getConstArray(); - for (sal_Int32 i = 0; i < nLen; ++i) + for (const OUString& rPropName : rPropNames) { sal_Int16 *pnVal = nullptr, *pnResVal = nullptr; - if ( pPropName[i] == UPN_HYPH_MIN_LEADING ) + if ( rPropName == UPN_HYPH_MIN_LEADING ) { pnVal = &nHyphMinLeading; pnResVal = &nResHyphMinLeading; } - else if ( pPropName[i] == UPN_HYPH_MIN_TRAILING ) + else if ( rPropName == UPN_HYPH_MIN_TRAILING ) { pnVal = &nHyphMinTrailing; pnResVal = &nResHyphMinTrailing; } - else if ( pPropName[i] == UPN_HYPH_MIN_WORD_LENGTH ) + else if ( rPropName == UPN_HYPH_MIN_WORD_LENGTH ) { pnVal = &nHyphMinWordLength; pnResVal = &nResHyphMinWordLength; @@ -572,7 +555,7 @@ void PropertyHelper_Hyphen::GetCurrentValues() if (pnVal && pnResVal) { - GetPropSet()->getPropertyValue( pPropName[i] ) >>= *pnVal; + GetPropSet()->getPropertyValue( rPropName ) >>= *pnVal; *pnResVal = *pnVal; } } @@ -628,27 +611,21 @@ void PropertyHelper_Hyphen::SetTmpPropVals( const PropertyValues &rPropVals ) nResHyphMinTrailing = nHyphMinTrailing; nResHyphMinWordLength = nHyphMinWordLength; - sal_Int32 nLen = rPropVals.getLength(); - - if (nLen) + for (const PropertyValue& rVal : rPropVals) { - const PropertyValue *pVal = rPropVals.getConstArray(); - for (sal_Int32 i = 0; i < nLen; ++i) - { - sal_Int16 *pnResVal = nullptr; + sal_Int16 *pnResVal = nullptr; - if ( pVal[i].Name == UPN_HYPH_MIN_LEADING ) - pnResVal = &nResHyphMinLeading; - else if ( pVal[i].Name == UPN_HYPH_MIN_TRAILING ) - pnResVal = &nResHyphMinTrailing; - else if ( pVal[i].Name == UPN_HYPH_MIN_WORD_LENGTH ) - pnResVal = &nResHyphMinWordLength; + if ( rVal.Name == UPN_HYPH_MIN_LEADING ) + pnResVal = &nResHyphMinLeading; + else if ( rVal.Name == UPN_HYPH_MIN_TRAILING ) + pnResVal = &nResHyphMinTrailing; + else if ( rVal.Name == UPN_HYPH_MIN_WORD_LENGTH ) + pnResVal = &nResHyphMinWordLength; - DBG_ASSERT( pnResVal, "unknown property" ); + DBG_ASSERT( pnResVal, "unknown property" ); - if (pnResVal) - pVal[i].Value >>= *pnResVal; - } + if (pnResVal) + rVal.Value >>= *pnResVal; } } diff --git a/linguistic/source/lngsvcmgr.cxx b/linguistic/source/lngsvcmgr.cxx index 4b7c65ac2761..c54a212b3d3f 100644 --- a/linguistic/source/lngsvcmgr.cxx +++ b/linguistic/source/lngsvcmgr.cxx @@ -37,6 +37,7 @@ #include <unotools/lingucfg.hxx> #include <vcl/svapp.hxx> #include <comphelper/processfactory.hxx> +#include <comphelper/sequence.hxx> #include <i18nlangtag/lang.h> #include <i18nlangtag/languagetag.hxx> #include <cppuhelper/factory.hxx> @@ -60,19 +61,8 @@ uno::Sequence< OUString > static GetLangSvc( const uno::Any &rVal ); static bool lcl_SeqHasString( const uno::Sequence< OUString > &rSeq, const OUString &rText ) { - bool bRes = false; - - sal_Int32 nLen = rSeq.getLength(); - if (nLen == 0 || rText.isEmpty()) - return bRes; - - const OUString *pSeq = rSeq.getConstArray(); - for (sal_Int32 i = 0; i < nLen && !bRes; ++i) - { - if (rText == pSeq[i]) - bRes = true; - } - return bRes; + return !rText.isEmpty() + && comphelper::findValue(rSeq, rText) != -1; } @@ -82,8 +72,7 @@ static uno::Sequence< lang::Locale > GetAvailLocales( uno::Sequence< lang::Locale > aRes; uno::Reference< uno::XComponentContext > xContext( comphelper::getProcessComponentContext() ); - sal_Int32 nNames = rSvcImplNames.getLength(); - if( nNames ) + if( rSvcImplNames.hasElements() ) { std::set< LanguageType > aLanguages; @@ -94,16 +83,14 @@ static uno::Sequence< lang::Locale > GetAvailLocales( // check all services for the supported languages and new // languages to the result - const OUString *pImplNames = rSvcImplNames.getConstArray(); - sal_Int32 i; - for (i = 0; i < nNames; ++i) + for (const OUString& rImplName : rSvcImplNames) { uno::Reference< linguistic2::XSupportedLocales > xSuppLoc; try { xSuppLoc.set( xContext->getServiceManager()->createInstanceWithArgumentsAndContext( - pImplNames[i], aArgs, xContext ), + rImplName, aArgs, xContext ), uno::UNO_QUERY ); } catch (uno::Exception &) @@ -113,12 +100,10 @@ static uno::Sequence< lang::Locale > GetAvailLocales( if (xSuppLoc.is()) { - uno::Sequence< lang::Locale > aLoc( xSuppLoc->getLocales() ); - sal_Int32 nLoc = aLoc.getLength(); - for (sal_Int32 k = 0; k < nLoc; ++k) + const uno::Sequence< lang::Locale > aLoc( xSuppLoc->getLocales() ); + for (const lang::Locale& rLoc : aLoc) { - const lang::Locale *pLoc = aLoc.getConstArray(); - LanguageType nLang = LinguLocaleToLanguage( pLoc[k] ); + LanguageType nLang = LinguLocaleToLanguage( rLoc ); // It's a set, so insertion fails if language was already added. aLanguages.insert( nLang ); @@ -131,14 +116,13 @@ static uno::Sequence< lang::Locale > GetAvailLocales( } // build return sequence - sal_Int32 nLanguages = static_cast< sal_Int32 >(aLanguages.size()); - aRes.realloc( nLanguages ); - lang::Locale *pRes = aRes.getArray(); - i=0; - for (auto const& language : aLanguages) - { - pRes[i++] = LanguageTag::convertToLocale(language); - } + std::vector<lang::Locale> aVec; + aVec.reserve(aLanguages.size()); + + std::transform(aLanguages.begin(), aLanguages.end(), std::back_inserter(aVec), + [](const LanguageType& rLang) -> lang::Locale { return LanguageTag::convertToLocale(rLang); }); + + aRes = comphelper::containerToSequence(aVec); } return aRes; @@ -420,12 +404,12 @@ LngSvcMgr::LngSvcMgr() bDisposing = false; // request notify events when properties (i.e. something in the subtree) changes - uno::Sequence< OUString > aNames(4); - OUString *pNames = aNames.getArray(); - pNames[0] = "ServiceManager/SpellCheckerList"; - pNames[1] = "ServiceManager/GrammarCheckerList"; - pNames[2] = "ServiceManager/HyphenatorList"; - pNames[3] = "ServiceManager/ThesaurusList"; + uno::Sequence< OUString > aNames{ + "ServiceManager/SpellCheckerList", + "ServiceManager/GrammarCheckerList", + "ServiceManager/HyphenatorList", + "ServiceManager/ThesaurusList" + }; EnableNotification( aNames ); UpdateAll(); @@ -540,15 +524,12 @@ namespace bool lcl_FindEntry( const OUString &rEntry, const Sequence< OUString > &rCfgSvcs ) { - sal_Int32 nRes = -1; - sal_Int32 nEntries = rCfgSvcs.getLength(); - const OUString *pEntry = rCfgSvcs.getConstArray(); - for (sal_Int32 i = 0; i < nEntries && nRes == -1; ++i) - { - if (rEntry == pEntry[i]) - nRes = i; - } - return nRes != -1; + return comphelper::findValue(rCfgSvcs, rEntry) != -1; + } + + bool lcl_FindEntry( const OUString &rEntry, const std::vector< OUString > &rCfgSvcs ) + { + return std::find(rCfgSvcs.begin(), rCfgSvcs.end(), rEntry) != rCfgSvcs.end(); } Sequence< OUString > lcl_GetLastFoundSvcs( @@ -585,65 +566,47 @@ namespace const Sequence< OUString > &rCfgSvcs, const Sequence< OUString > &rAvailSvcs ) { - Sequence< OUString > aRes( rCfgSvcs.getLength() ); - OUString *pRes = aRes.getArray(); - sal_Int32 nCnt = 0; + std::vector<OUString> aRes; + aRes.reserve(rCfgSvcs.getLength()); - for (OUString const & entry : rCfgSvcs) - { - if (!entry.isEmpty() && lcl_FindEntry( entry, rAvailSvcs )) - pRes[ nCnt++ ] = entry; - } + std::copy_if(rCfgSvcs.begin(), rCfgSvcs.end(), std::back_inserter(aRes), + [&rAvailSvcs](const OUString& entry) { return lcl_SeqHasString(rAvailSvcs, entry); }); - aRes.realloc( nCnt ); - return aRes; + return comphelper::containerToSequence(aRes); } Sequence< OUString > lcl_GetNewEntries( const Sequence< OUString > &rLastFoundSvcs, const Sequence< OUString > &rAvailSvcs ) { - sal_Int32 nLen = rAvailSvcs.getLength(); - Sequence< OUString > aRes( nLen ); - OUString *pRes = aRes.getArray(); - sal_Int32 nCnt = 0; + std::vector<OUString> aRes; + aRes.reserve(rAvailSvcs.getLength()); - const OUString *pEntry = rAvailSvcs.getConstArray(); - for (sal_Int32 i = 0; i < nLen; ++i) - { - if (!pEntry[i].isEmpty() && !lcl_FindEntry( pEntry[i], rLastFoundSvcs )) - pRes[ nCnt++ ] = pEntry[i]; - } + std::copy_if(rAvailSvcs.begin(), rAvailSvcs.end(), std::back_inserter(aRes), + [&rLastFoundSvcs](const OUString& rEntry) { + return !rEntry.isEmpty() && !lcl_FindEntry( rEntry, rLastFoundSvcs ); }); - aRes.realloc( nCnt ); - return aRes; + return comphelper::containerToSequence(aRes); } Sequence< OUString > lcl_MergeSeq( const Sequence< OUString > &rCfgSvcs, const Sequence< OUString > &rNewSvcs ) { - Sequence< OUString > aRes( rCfgSvcs.getLength() + rNewSvcs.getLength() ); - OUString *pRes = aRes.getArray(); - sal_Int32 nCnt = 0; + std::vector<OUString> aRes; + aRes.reserve(rCfgSvcs.getLength() + rNewSvcs.getLength()); - for (sal_Int32 k = 0; k < 2; ++k) - { - // add previously configured service first and append - // new found services at the end - const Sequence< OUString > &rSeq = k == 0 ? rCfgSvcs : rNewSvcs; + auto lVecNotHasString = [&aRes](const OUString& rEntry) + { return !rEntry.isEmpty() && !lcl_FindEntry(rEntry, aRes); }; - sal_Int32 nLen = rSeq.getLength(); - const OUString *pEntry = rSeq.getConstArray(); - for (sal_Int32 i = 0; i < nLen; ++i) - { - if (!pEntry[i].isEmpty() && !lcl_FindEntry( pEntry[i], aRes )) - pRes[ nCnt++ ] = pEntry[i]; - } + // add previously configured service first and append + // new found services at the end + for (const Sequence< OUString > &rSeq : { rCfgSvcs, rNewSvcs }) + { + std::copy_if(rSeq.begin(), rSeq.end(), std::back_inserter(aRes), lVecNotHasString); } - aRes.realloc( nCnt ); - return aRes; + return comphelper::containerToSequence(aRes); } } @@ -672,23 +635,20 @@ void LngSvcMgr::UpdateAll() OUString aService( OUString::createFromAscii( apServices[k] ) ); OUString aActiveList( OUString::createFromAscii( apCurLists[k] ) ); OUString aLastFoundList( OUString::createFromAscii( apLastFoundLists[k] ) ); - sal_Int32 i; // remove configured but not available language/services entries - Sequence< OUString > aNodeNames( aCfg.GetNodeNames( aActiveList ) ); // list of configured locales - sal_Int32 nNodeNames = aNodeNames.getLength(); - const OUString *pNodeName = aNodeNames.getConstArray(); - for (i = 0; i < nNodeNames; ++i) + const Sequence< OUString > aNodeNames( aCfg.GetNodeNames( aActiveList ) ); // list of configured locales + for (const OUString& rNodeName : aNodeNames) { - Locale aLocale( LanguageTag::convertToLocale( pNodeName[i])); + Locale aLocale( LanguageTag::convertToLocale( rNodeName)); Sequence< OUString > aCfgSvcs( getConfiguredServices( aService, aLocale )); Sequence< OUString > aAvailSvcs( getAvailableServices( aService, aLocale )); aCfgSvcs = lcl_RemoveMissingEntries( aCfgSvcs, aAvailSvcs ); - aCurSvcs[k][ pNodeName[i] ] = aCfgSvcs; + aCurSvcs[k][ rNodeName ] = aCfgSvcs; } @@ -696,14 +656,12 @@ void LngSvcMgr::UpdateAll() // and // set last found services to currently available ones - Sequence< Locale > aAvailLocales( getAvailableLocales(aService) ); - sal_Int32 nAvailLocales = aAvailLocales.getLength(); - const Locale *pAvailLocale = aAvailLocales.getConstArray(); - for (i = 0; i < nAvailLocales; ++i) + const Sequence< Locale > aAvailLocales( getAvailableLocales(aService) ); + for (const Locale& rAvailLocale : aAvailLocales) { - OUString aCfgLocaleStr( LanguageTag::convertToBcp47( pAvailLocale[i])); + OUString aCfgLocaleStr( LanguageTag::convertToBcp47( rAvailLocale)); - Sequence< OUString > aAvailSvcs( getAvailableServices( aService, pAvailLocale[i] )); + Sequence< OUString > aAvailSvcs( getAvailableServices( aService, rAvailLocale )); aLastFoundSvcs[k][ aCfgLocaleStr ] = aAvailSvcs; @@ -741,7 +699,7 @@ void LngSvcMgr::UpdateAll() pNewValue->Value <<= elem.second; ++pNewValue; } - OSL_ENSURE( pNewValue - aNewValues.getArray() == nVals, + OSL_ENSURE( pNewValue - aNewValues.getConstArray() == nVals, "possible mismatch of sequence size and property number" ); { @@ -773,14 +731,11 @@ void LngSvcMgr::Notify( const uno::Sequence< OUString > &rPropertyNames ) uno::Sequence< OUString > aNames( 1 ); OUString *pNames = aNames.getArray(); - sal_Int32 nLen = rPropertyNames.getLength(); - const OUString *pPropertyNames = rPropertyNames.getConstArray(); - for (sal_Int32 i = 0; i < nLen; ++i) + for (const OUString& rName : rPropertyNames) { // property names look like // "ServiceManager/ThesaurusList/de-CH" - const OUString &rName = pPropertyNames[i]; sal_Int32 nKeyStart; nKeyStart = rName.lastIndexOf( '/' ); OUString aKeyText; @@ -1201,8 +1156,6 @@ void LngSvcMgr::SetCfgServiceLists( SpellCheckerDispatcher &rSpellDsp ) OUString aNode("ServiceManager/SpellCheckerList"); uno::Sequence< OUString > aNames( /*aCfg.*/GetNodeNames( aNode ) ); - OUString *pNames = aNames.getArray(); - sal_Int32 nLen = aNames.getLength(); // append path prefix need for 'GetProperties' call below OUString aPrefix = aNode + "/"; @@ -1211,16 +1164,16 @@ void LngSvcMgr::SetCfgServiceLists( SpellCheckerDispatcher &rSpellDsp ) name = aPrefix + name; } - uno::Sequence< uno::Any > aValues( /*aCfg.*/GetProperties( aNames ) ); - if (nLen && nLen == aValues.getLength()) + const uno::Sequence< uno::Any > aValues( /*aCfg.*/GetProperties( aNames ) ); + if (aNames.hasElements() && aNames.getLength() == aValues.getLength()) { - const uno::Any *pValues = aValues.getConstArray(); - for (sal_Int32 i = 0; i < nLen; ++i) + const OUString *pNames = aNames.getConstArray(); + for (const uno::Any& rValue : aValues) { uno::Sequence< OUString > aSvcImplNames; - if (pValues[i] >>= aSvcImplNames) + if (rValue >>= aSvcImplNames) { - OUString aLocaleStr( pNames[i] ); + OUString aLocaleStr( *pNames++ ); sal_Int32 nSeparatorPos = aLocaleStr.lastIndexOf( '/' ); aLocaleStr = aLocaleStr.copy( nSeparatorPos + 1 ); rSpellDsp.SetServiceList( LanguageTag::convertToLocale(aLocaleStr), aSvcImplNames ); @@ -1236,8 +1189,6 @@ void LngSvcMgr::SetCfgServiceLists( GrammarCheckingIterator &rGrammarDsp ) OUString aNode("ServiceManager/GrammarCheckerList"); uno::Sequence< OUString > aNames( /*aCfg.*/GetNodeNames( aNode ) ); - OUString *pNames = aNames.getArray(); - sal_Int32 nLen = aNames.getLength(); // append path prefix need for 'GetProperties' call below OUString aPrefix = aNode + "/"; @@ -1246,20 +1197,20 @@ void LngSvcMgr::SetCfgServiceLists( GrammarCheckingIterator &rGrammarDsp ) name = aPrefix + name; } - uno::Sequence< uno::Any > aValues( /*aCfg.*/GetProperties( aNames ) ); - if (nLen && nLen == aValues.getLength()) + const uno::Sequence< uno::Any > aValues( /*aCfg.*/GetProperties( aNames ) ); + if (aNames.hasElements() && aNames.getLength() == aValues.getLength()) { - const uno::Any *pValues = aValues.getConstArray(); - for (sal_Int32 i = 0; i < nLen; ++i) + const OUString *pNames = aNames.getConstArray(); + for (const uno::Any& rValue : aValues) { uno::Sequence< OUString > aSvcImplNames; - if (pValues[i] >>= aSvcImplNames) + if (rValue >>= aSvcImplNames) { // there should only be one grammar checker in use per language... if (aSvcImplNames.getLength() > 1) aSvcImplNames.realloc(1); - OUString aLocaleStr( pNames[i] ); + OUString aLocaleStr( *pNames++ ); sal_Int32 nSeparatorPos = aLocaleStr.lastIndexOf( '/' ); aLocaleStr = aLocaleStr.copy( nSeparatorPos + 1 ); rGrammarDsp.SetServiceList( LanguageTag::convertToLocale(aLocaleStr), aSvcImplNames ); @@ -1275,8 +1226,6 @@ void LngSvcMgr::SetCfgServiceLists( HyphenatorDispatcher &rHyphDsp ) OUString aNode("ServiceManager/HyphenatorList"); uno::Sequence< OUString > aNames( /*aCfg.*/GetNodeNames( aNode ) ); - OUString *pNames = aNames.getArray(); - sal_Int32 nLen = aNames.getLength(); // append path prefix need for 'GetProperties' call below OUString aPrefix = aNode + "/"; @@ -1285,20 +1234,20 @@ void LngSvcMgr::SetCfgServiceLists( HyphenatorDispatcher &rHyphDsp ) name = aPrefix + name; } - uno::Sequence< uno::Any > aValues( /*aCfg.*/GetProperties( aNames ) ); - if (nLen && nLen == aValues.getLength()) + const uno::Sequence< uno::Any > aValues( /*aCfg.*/GetProperties( aNames ) ); + if (aNames.hasElements() && aNames.getLength() == aValues.getLength()) { - const uno::Any *pValues = aValues.getConstArray(); - for (sal_Int32 i = 0; i < nLen; ++i) + const OUString *pNames = aNames.getConstArray(); + for (const uno::Any& rValue : aValues) { uno::Sequence< OUString > aSvcImplNames; - if (pValues[i] >>= aSvcImplNames) + if (rValue >>= aSvcImplNames) { // there should only be one hyphenator in use per language... if (aSvcImplNames.getLength() > 1) aSvcImplNames.realloc(1); - OUString aLocaleStr( pNames[i] ); + OUString aLocaleStr( *pNames++ ); sal_Int32 nSeparatorPos = aLocaleStr.lastIndexOf( '/' ); aLocaleStr = aLocaleStr.copy( nSeparatorPos + 1 ); rHyphDsp.SetServiceList( LanguageTag::convertToLocale(aLocaleStr), aSvcImplNames ); @@ -1314,8 +1263,6 @@ void LngSvcMgr::SetCfgServiceLists( ThesaurusDispatcher &rThesDsp ) OUString aNode("ServiceManager/ThesaurusList"); uno::Sequence< OUString > aNames( /*aCfg.*/GetNodeNames( aNode ) ); - OUString *pNames = aNames.getArray(); - sal_Int32 nLen = aNames.getLength(); // append path prefix need for 'GetProperties' call below OUString aPrefix = aNode + "/"; @@ -1324,16 +1271,16 @@ void LngSvcMgr::SetCfgServiceLists( ThesaurusDispatcher &rThesDsp ) name = aPrefix + name; } - uno::Sequence< uno::Any > aValues( /*aCfg.*/GetProperties( aNames ) ); - if (nLen && nLen == aValues.getLength()) + const uno::Sequence< uno::Any > aValues( /*aCfg.*/GetProperties( aNames ) ); + if (aNames.hasElements() && aNames.getLength() == aValues.getLength()) { - const uno::Any *pValues = aValues.getConstArray(); - for (sal_Int32 i = 0; i < nLen; ++i) + const OUString *pNames = aNames.getConstArray(); + for (const uno::Any& rValue : aValues) { uno::Sequence< OUString > aSvcImplNames; - if (pValues[i] >>= aSvcImplNames) + if (rValue >>= aSvcImplNames) { - OUString aLocaleStr( pNames[i] ); + OUString aLocaleStr( *pNames++ ); sal_Int32 nSeparatorPos = aLocaleStr.lastIndexOf( '/' ); aLocaleStr = aLocaleStr.copy( nSeparatorPos + 1 ); rThesDsp.SetServiceList( LanguageTag::convertToLocale(aLocaleStr), aSvcImplNames ); @@ -1464,26 +1411,20 @@ uno::Sequence< OUString > SAL_CALL if (pInfoArray) { - // resize to max number of entries - size_t nMaxCnt = pInfoArray->size(); - aRes.realloc( nMaxCnt ); - OUString *pImplName = aRes.getArray(); + std::vector<OUString> aVec; + aVec.reserve(pInfoArray->size()); - sal_uInt16 nCnt = 0; LanguageType nLanguage = LinguLocaleToLanguage( rLocale ); - for (size_t i = 0; i < nMaxCnt; ++i) + for (const auto& pInfo : *pInfoArray) { - const SvcInfo &rInfo = *(*pInfoArray)[i].get(); if (LinguIsUnspecified( nLanguage ) - || rInfo.HasLanguage( nLanguage )) + || pInfo->HasLanguage( nLanguage )) { - pImplName[ nCnt++ ] = rInfo.aSvcImplName; + aVec.push_back(pInfo->aSvcImplName); } } - // resize to actual number of entries - if (nCnt != nMaxCnt) - aRes.realloc( nCnt ); + aRes = comphelper::containerToSequence(aVec); } return aRes; @@ -1523,22 +1464,9 @@ uno::Sequence< lang::Locale > SAL_CALL static bool IsEqSvcList( const uno::Sequence< OUString > &rList1, const uno::Sequence< OUString > &rList2 ) { - // returns true iff both sequences are equal - - bool bRes = false; - sal_Int32 nLen = rList1.getLength(); - if (rList2.getLength() == nLen) - { - const OUString *pStr1 = rList1.getConstArray(); - const OUString *pStr2 = rList2.getConstArray(); - bRes = true; - for (sal_Int32 i = 0; i < nLen && bRes; ++i) - { - if (*pStr1++ != *pStr2++) - bRes = false; - } - } - return bRes; + // returns true if both sequences are equal + return rList1.getLength() == rList2.getLength() + && std::equal(rList1.begin(), rList1.end(), rList2.begin(), rList2.end()); } @@ -1660,12 +1588,8 @@ bool LngSvcMgr::SaveCfgSvcs( const OUString &rServiceName ) if (pDsp && aLocales.hasElements()) { - sal_Int32 nLen = aLocales.getLength(); - const lang::Locale *pLocale = aLocales.getConstArray(); - - uno::Sequence< beans::PropertyValue > aValues( nLen ); - beans::PropertyValue *pValues = aValues.getArray(); - beans::PropertyValue *pValue = pValues; + uno::Sequence< beans::PropertyValue > aValues( aLocales.getLength() ); + beans::PropertyValue *pValue = aValues.getArray(); // get node name to be used const char *pNodeName = nullptr; @@ -1683,9 +1607,9 @@ bool LngSvcMgr::SaveCfgSvcs( const OUString &rServiceName ) } OUString aNodeName( OUString::createFromAscii(pNodeName) ); - for (sal_Int32 i = 0; i < nLen; ++i) + for (const lang::Locale& rLocale : std::as_const(aLocales)) { - uno::Sequence< OUString > aSvcImplNames = pDsp->GetServiceList( pLocale[i] ); + uno::Sequence< OUString > aSvcImplNames = pDsp->GetServiceList( rLocale ); // build value to be written back to configuration uno::Any aCfgAny; @@ -1694,7 +1618,7 @@ bool LngSvcMgr::SaveCfgSvcs( const OUString &rServiceName ) aCfgAny <<= aSvcImplNames; DBG_ASSERT( aCfgAny.hasValue(), "missing value for 'Any' type" ); - OUString aCfgLocaleStr( LanguageTag::convertToBcp47( pLocale[i])); + OUString aCfgLocaleStr( LanguageTag::convertToBcp47( rLocale)); pValue->Value = aCfgAny; pValue->Name = aNodeName + "/" + aCfgLocaleStr; pValue++; @@ -1718,14 +1642,9 @@ static uno::Sequence< OUString > GetLangSvcList( const uno::Any &rVal ) { rVal >>= aRes; #if OSL_DEBUG_LEVEL > 0 - sal_Int32 nSvcs = aRes.getLength(); - if (nSvcs) + for (const OUString& rSvcName : std::as_const(aRes)) { - const OUString *pSvcName = aRes.getConstArray(); - for (sal_Int32 j = 0; j < nSvcs; ++j) - { - SAL_WARN_IF( pSvcName[j].isEmpty(), "linguistic", "service impl-name missing" ); - } + SAL_WARN_IF( rSvcName.isEmpty(), "linguistic", "service impl-name missing" ); } #endif } diff --git a/linguistic/source/misc.cxx b/linguistic/source/misc.cxx index 61dc3506aa68..a8ba9b99c3bc 100644 --- a/linguistic/source/misc.cxx +++ b/linguistic/source/misc.cxx @@ -37,6 +37,7 @@ #include <com/sun/star/uno/Sequence.hxx> #include <com/sun/star/uno/Reference.h> #include <comphelper/processfactory.hxx> +#include <comphelper/sequence.hxx> #include <unotools/charclass.hxx> #include <unotools/linguprops.hxx> #include <unotools/localedatawrapper.hxx> @@ -197,19 +198,14 @@ bool IsUseDicList( const PropertyValues &rProperties, { bool bRes = true; - sal_Int32 nLen = rProperties.getLength(); - const PropertyValue *pVal = rProperties.getConstArray(); - sal_Int32 i; + const PropertyValue *pVal = std::find_if(rProperties.begin(), rProperties.end(), + [](const PropertyValue& rVal) { return UPH_IS_USE_DICTIONARY_LIST == rVal.Handle; }); - for ( i = 0; i < nLen; ++i) + if (pVal != rProperties.end()) { - if (UPH_IS_USE_DICTIONARY_LIST == pVal[i].Handle) - { - pVal[i].Value >>= bRes; - break; - } + pVal->Value >>= bRes; } - if (i >= nLen) // no temporary value found in 'rProperties' + else // no temporary value found in 'rProperties' { uno::Reference< XFastPropertySet > xFast( rxProp, UNO_QUERY ); if (xFast.is()) @@ -224,19 +220,14 @@ bool IsIgnoreControlChars( const PropertyValues &rProperties, { bool bRes = true; - sal_Int32 nLen = rProperties.getLength(); - const PropertyValue *pVal = rProperties.getConstArray(); - sal_Int32 i; + const PropertyValue *pVal = std::find_if(rProperties.begin(), rProperties.end(), + [](const PropertyValue& rVal) { return UPH_IS_IGNORE_CONTROL_CHARACTERS == rVal.Handle; }); - for ( i = 0; i < nLen; ++i) + if (pVal != rProperties.end()) { - if (UPH_IS_IGNORE_CONTROL_CHARACTERS == pVal[i].Handle) - { - pVal[i].Value >>= bRes; - break; - } + pVal->Value >>= bRes; } - if (i >= nLen) // no temporary value found in 'rProperties' + else // no temporary value found in 'rProperties' { uno::Reference< XFastPropertySet > xFast( rxProp, UNO_QUERY ); if (xFast.is()) @@ -316,14 +307,12 @@ bool SaveDictionaries( const uno::Reference< XSearchableDictionaryList > &xDicLi bool bRet = true; - Sequence< uno::Reference< XDictionary > > aDics( xDicList->getDictionaries() ); - const uno::Reference< XDictionary > *pDic = aDics.getConstArray(); - sal_Int32 nCount = aDics.getLength(); - for (sal_Int32 i = 0; i < nCount; i++) + const Sequence< uno::Reference< XDictionary > > aDics( xDicList->getDictionaries() ); + for (const uno::Reference<XDictionary>& rDic : aDics) { try { - uno::Reference< frame::XStorable > xStor( pDic[i], UNO_QUERY ); + uno::Reference< frame::XStorable > xStor( rDic, UNO_QUERY ); if (xStor.is()) { if (!xStor->isReadonly() && xStor->hasLocation()) @@ -382,15 +371,11 @@ DictionaryError AddEntryToDic( std::vector< LanguageType > LocaleSeqToLangVec( uno::Sequence< Locale > const &rLocaleSeq ) { - const Locale *pLocale = rLocaleSeq.getConstArray(); - sal_Int32 nCount = rLocaleSeq.getLength(); - std::vector< LanguageType > aLangs; - aLangs.reserve(nCount); - for (sal_Int32 i = 0; i < nCount; ++i) - { - aLangs.push_back( LinguLocaleToLanguage( pLocale[i] ) ); - } + aLangs.reserve(rLocaleSeq.getLength()); + + std::transform(rLocaleSeq.begin(), rLocaleSeq.end(), std::back_inserter(aLangs), + [](const Locale& rLocale) { return LinguLocaleToLanguage(rLocale); }); return aLangs; } @@ -398,17 +383,13 @@ std::vector< LanguageType > uno::Sequence< sal_Int16 > LocaleSeqToLangSeq( uno::Sequence< Locale > const &rLocaleSeq ) { - const Locale *pLocale = rLocaleSeq.getConstArray(); - sal_Int32 nCount = rLocaleSeq.getLength(); + std::vector<sal_Int16> aLangs; + aLangs.reserve(rLocaleSeq.getLength()); - uno::Sequence< sal_Int16 > aLangs( nCount ); - sal_Int16 *pLang = aLangs.getArray(); - for (sal_Int32 i = 0; i < nCount; ++i) - { - pLang[i] = static_cast<sal_uInt16>(LinguLocaleToLanguage( pLocale[i] )); - } + std::transform(rLocaleSeq.begin(), rLocaleSeq.end(), std::back_inserter(aLangs), + [](const Locale& rLocale) { return static_cast<sal_uInt16>(LinguLocaleToLanguage(rLocale)); }); - return aLangs; + return comphelper::containerToSequence(aLangs); } bool IsReadOnly( const OUString &rURL, bool *pbExist ) { diff --git a/linguistic/source/misc2.cxx b/linguistic/source/misc2.cxx index f416a1739fd1..58b315b4392c 100644 --- a/linguistic/source/misc2.cxx +++ b/linguistic/source/misc2.cxx @@ -110,23 +110,17 @@ static std::vector< OUString > GetMultiPaths_Impl( sal_Int32 nMaxEntries = aInternalPaths.getLength() + aUserPaths.getLength(); if (!aWritablePath.isEmpty()) ++nMaxEntries; - aRes.resize( nMaxEntries ); - sal_Int32 nCount = 0; // number of actually added entries + aRes.reserve( nMaxEntries ); if (!aWritablePath.isEmpty()) - aRes[ nCount++ ] = aWritablePath; - for (int i = 0; i < 2; ++i) - { - const uno::Sequence< OUString > &rPathSeq = i == 0 ? aUserPaths : aInternalPaths; - const OUString *pPathSeq = rPathSeq.getConstArray(); - for (sal_Int32 k = 0; k < rPathSeq.getLength(); ++k) - { - const bool bAddUser = &rPathSeq == &aUserPaths && (nPathFlags & DictionaryPathFlags::USER); - const bool bAddInternal = &rPathSeq == &aInternalPaths && (nPathFlags & DictionaryPathFlags::INTERNAL); - if ((bAddUser || bAddInternal) && !pPathSeq[k].isEmpty()) - aRes[ nCount++ ] = pPathSeq[k]; - } - } - aRes.resize( nCount ); + aRes.push_back(aWritablePath); + + auto lPathIsNotEmpty = [](const OUString& rPath) { return !rPath.isEmpty(); }; + + if (nPathFlags & DictionaryPathFlags::USER) + std::copy_if(std::cbegin(aUserPaths), std::cend(aUserPaths), std::back_inserter(aRes), lPathIsNotEmpty); + + if (nPathFlags & DictionaryPathFlags::INTERNAL) + std::copy_if(std::cbegin(aInternalPaths), std::cend(aInternalPaths), std::back_inserter(aRes), lPathIsNotEmpty); } return aRes; diff --git a/linguistic/source/spelldsp.cxx b/linguistic/source/spelldsp.cxx index ecb8ec723610..6bbc664794ef 100644 --- a/linguistic/source/spelldsp.cxx +++ b/linguistic/source/spelldsp.cxx @@ -115,11 +115,8 @@ void ProposalList::Append( const std::vector< OUString > &rNew ) void ProposalList::Append( const Sequence< OUString > &rNew ) { - sal_Int32 nLen = rNew.getLength(); - const OUString *pNew = rNew.getConstArray(); - for (sal_Int32 i = 0; i < nLen; ++i) + for (const OUString& rText : rNew) { - const OUString &rText = pNew[i]; if (!HasEntry( rText )) Append( rText ); } @@ -159,22 +156,11 @@ static bool SvcListHasLanguage( const LangSvcEntries_Spell &rEntry, LanguageType nLanguage ) { - bool bHasLanguage = false; - Locale aTmpLocale; - - const Reference< XSpellChecker > *pRef = rEntry.aSvcRefs .getConstArray(); - sal_Int32 nLen = rEntry.aSvcRefs.getLength(); - for (sal_Int32 k = 0; k < nLen && !bHasLanguage; ++k) - { - if (pRef[k].is()) - { - if (aTmpLocale.Language.isEmpty()) - aTmpLocale = LanguageTag::convertToLocale( nLanguage ); - bHasLanguage = pRef[k]->hasLocale( aTmpLocale ); - } - } + Locale aTmpLocale = LanguageTag::convertToLocale( nLanguage ); - return bHasLanguage; + return std::any_of(rEntry.aSvcRefs.begin(), rEntry.aSvcRefs.end(), + [&aTmpLocale](const Reference<XSpellChecker>& rRef) { + return rRef.is() && rRef->hasLocale( aTmpLocale ); }); } SpellCheckerDispatcher::SpellCheckerDispatcher( LngSvcMgr &rLngSvcMgr ) : @@ -192,13 +178,13 @@ Sequence< Locale > SAL_CALL SpellCheckerDispatcher::getLocales() { MutexGuard aGuard( GetLinguMutex() ); - Sequence< Locale > aLocales( static_cast< sal_Int32 >(m_aSvcMap.size()) ); - Locale *pLocales = aLocales.getArray(); - for (auto const& elem : m_aSvcMap) - { - *pLocales++ = LanguageTag::convertToLocale(elem.first); - } - return aLocales; + std::vector<Locale> aLocales; + aLocales.reserve(m_aSvcMap.size()); + + std::transform(m_aSvcMap.begin(), m_aSvcMap.end(), std::back_inserter(aLocales), + [](SpellSvcByLangMap_t::const_reference elem) { return LanguageTag::convertToLocale(elem.first); }); + + return comphelper::containerToSequence(aLocales); } diff --git a/linguistic/source/spelldta.cxx b/linguistic/source/spelldta.cxx index 8b29c334f12b..0c4570073cb8 100644 --- a/linguistic/source/spelldta.cxx +++ b/linguistic/source/spelldta.cxx @@ -87,15 +87,13 @@ void SearchSimilarText( const OUString &rText, LanguageType nLanguage, assert( eType != DictionaryType_MIXED && "unexpected dictionary type" ); #endif const Sequence< Reference< XDictionaryEntry > > aEntries = xDic->getEntries(); - const Reference< XDictionaryEntry > *pEntries = aEntries.getConstArray(); - sal_Int32 nLen = aEntries.getLength(); - for (sal_Int32 k = 0; k < nLen; ++k) + for (const Reference<XDictionaryEntry>& rEntry : aEntries) { OUString aEntryTxt; - if (pEntries[k].is()) + if (rEntry.is()) { // remove characters used to determine hyphenation positions - aEntryTxt = pEntries[k]->getDictionaryWord().replaceAll("=", ""); + aEntryTxt = rEntry->getDictionaryWord().replaceAll("=", ""); } if (!aEntryTxt.isEmpty() && aEntryTxt.getLength() > 1 && LevDistance( rText, aEntryTxt ) <= 2) rDicListProps.push_back( aEntryTxt ); diff --git a/linguistic/source/thesdsp.cxx b/linguistic/source/thesdsp.cxx index 810729f704b6..49b33c384e75 100644 --- a/linguistic/source/thesdsp.cxx +++ b/linguistic/source/thesdsp.cxx @@ -26,6 +26,7 @@ #include <com/sun/star/registry/XRegistryKey.hpp> #include <com/sun/star/beans/XPropertySet.hpp> #include <comphelper/processfactory.hxx> +#include <comphelper/sequence.hxx> #include <com/sun/star/uno/XComponentContext.hpp> #include <osl/mutex.hxx> #include <sal/log.hxx> @@ -46,17 +47,9 @@ static bool SvcListHasLanguage( const Sequence< Reference< XThesaurus > > &rRefs, const Locale &rLocale ) { - bool bHasLanguage = false; - - const Reference< XThesaurus > *pRef = rRefs.getConstArray(); - sal_Int32 nLen = rRefs.getLength(); - for (sal_Int32 k = 0; k < nLen && !bHasLanguage; ++k) - { - if (pRef[k].is()) - bHasLanguage = pRef[k]->hasLocale( rLocale ); - } - - return bHasLanguage; + return std::any_of(rRefs.begin(), rRefs.end(), + [&rLocale](const Reference<XThesaurus>& rRef) { + return rRef.is() && rRef->hasLocale( rLocale ); }); } @@ -84,13 +77,13 @@ Sequence< Locale > SAL_CALL { MutexGuard aGuard( GetLinguMutex() ); - Sequence< Locale > aLocales( static_cast< sal_Int32 >(aSvcMap.size()) ); - Locale *pLocales = aLocales.getArray(); - for (auto const& elem : aSvcMap) - { - *pLocales++ = LanguageTag::convertToLocale(elem.first); - } - return aLocales; + std::vector<Locale> aLocales; + aLocales.reserve(aSvcMap.size()); + + std::transform(aSvcMap.begin(), aSvcMap.end(), std::back_inserter(aLocales), + [](ThesSvcByLangMap_t::const_reference elem) { return LanguageTag::convertToLocale(elem.first); }); + + return comphelper::containerToSequence(aLocales); } |