summaryrefslogtreecommitdiff
path: root/lingucomponent
diff options
context:
space:
mode:
authorArkadiy Illarionov <qarkai@gmail.com>2019-08-29 00:51:02 +0300
committerArkadiy Illarionov <qarkai@gmail.com>2019-08-30 14:15:57 +0200
commit760a377f7148e623e9e16d24e66f54a401ecb946 (patch)
treec9ea106618e4b9f6bb2c20d8817603c7556a9ef6 /lingucomponent
parentcc4edc0f29c034722f10ab289eb0d8d563a8632c (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 'lingucomponent')
-rw-r--r--lingucomponent/source/hyphenator/hyphen/hyphenimp.cxx60
-rw-r--r--lingucomponent/source/languageguessing/guesslang.cxx18
-rw-r--r--lingucomponent/source/spellcheck/spell/sspellimp.cxx7
-rw-r--r--lingucomponent/source/thesaurus/libnth/nthesimp.cxx63
4 files changed, 54 insertions, 94 deletions
diff --git a/lingucomponent/source/hyphenator/hyphen/hyphenimp.cxx b/lingucomponent/source/hyphenator/hyphen/hyphenimp.cxx
index bd38e3d470d4..2008395319e0 100644
--- a/lingucomponent/source/hyphenator/hyphen/hyphenimp.cxx
+++ b/lingucomponent/source/hyphenator/hyphen/hyphenimp.cxx
@@ -19,6 +19,7 @@
#include <com/sun/star/uno/Reference.h>
+#include <comphelper/sequence.hxx>
#include <cppuhelper/factory.hxx>
#include <cppuhelper/supportsservice.hxx>
#include <com/sun/star/registry/XRegistryKey.hpp>
@@ -51,6 +52,7 @@
#include <string.h>
#include <cassert>
+#include <numeric>
#include <vector>
#include <set>
#include <memory>
@@ -113,11 +115,10 @@ Sequence< Locale > SAL_CALL Hyphenator::getLocales()
uno::Sequence< OUString > aFormatList;
aLinguCfg.GetSupportedDictionaryFormatsFor( "Hyphenators",
"org.openoffice.lingu.LibHnjHyphenator", aFormatList );
- sal_Int32 nLen = aFormatList.getLength();
- for (sal_Int32 i = 0; i < nLen; ++i)
+ for (const auto& rFormat : std::as_const(aFormatList))
{
std::vector< SvtLinguConfigDictionaryEntry > aTmpDic(
- aLinguCfg.GetActiveDictionariesByFormat( aFormatList[i] ) );
+ aLinguCfg.GetActiveDictionariesByFormat( rFormat ) );
aDics.insert( aDics.end(), aTmpDic.begin(), aTmpDic.end() );
}
@@ -132,57 +133,50 @@ Sequence< Locale > SAL_CALL Hyphenator::getLocales()
// is not yet supported by the list of new style dictionaries
MergeNewStyleDicsAndOldStyleDics( aDics, aOldStyleDics );
- sal_Int32 numdict = aDics.size();
- if (numdict)
+ if (!aDics.empty())
{
// get supported locales from the dictionaries-to-use...
- sal_Int32 k = 0;
std::set<OUString> aLocaleNamesSet;
for (auto const& dict : aDics)
{
- uno::Sequence< OUString > aLocaleNames( dict.aLocaleNames );
- sal_Int32 nLen2 = aLocaleNames.getLength();
- for (k = 0; k < nLen2; ++k)
+ for (const auto& rLocaleName : dict.aLocaleNames)
{
- aLocaleNamesSet.insert( aLocaleNames[k] );
+ aLocaleNamesSet.insert( rLocaleName );
}
}
// ... and add them to the resulting sequence
- aSuppLocales.realloc( aLocaleNamesSet.size() );
- k = 0;
- for (auto const& localeName : aLocaleNamesSet)
- {
- Locale aTmp( LanguageTag::convertToLocale(localeName));
- aSuppLocales[k++] = aTmp;
- }
+ std::vector<Locale> aLocalesVec;
+ aLocalesVec.reserve(aLocaleNamesSet.size());
+
+ std::transform(aLocaleNamesSet.begin(), aLocaleNamesSet.end(), std::back_inserter(aLocalesVec),
+ [](const OUString& localeName) { return LanguageTag::convertToLocale(localeName); });
+
+ aSuppLocales = comphelper::containerToSequence(aLocalesVec);
//! For each dictionary and each locale we need a separate entry.
//! If this results in more than one dictionary per locale than (for now)
//! it is undefined which dictionary gets used.
//! In the future the implementation should support using several dictionaries
//! for one locale.
- numdict = 0;
- for (auto const& dict : aDics)
- numdict = numdict + dict.aLocaleNames.getLength();
+ sal_Int32 numdict = std::accumulate(aDics.begin(), aDics.end(), 0,
+ [](const sal_Int32 nSum, const SvtLinguConfigDictionaryEntry& dict) {
+ return nSum + dict.aLocaleNames.getLength(); });
// add dictionary information
mvDicts.resize(numdict);
- k = 0;
+ sal_Int32 k = 0;
for (auto const& dict : aDics)
{
if (dict.aLocaleNames.hasElements() &&
dict.aLocations.hasElements())
{
- uno::Sequence< OUString > aLocaleNames(dict.aLocaleNames);
- sal_Int32 nLocales = aLocaleNames.getLength();
-
// currently only one language per dictionary is supported in the actual implementation...
// Thus here we work-around this by adding the same dictionary several times.
// Once for each of its supported locales.
- for (sal_Int32 i = 0; i < nLocales; ++i)
+ for (const auto& rLocaleName : dict.aLocaleNames)
{
- LanguageTag aLanguageTag(dict.aLocaleNames[i]);
+ LanguageTag aLanguageTag(rLocaleName);
mvDicts[k].aPtr = nullptr;
mvDicts[k].eEnc = RTL_TEXTENCODING_DONTKNOW;
mvDicts[k].aLoc = aLanguageTag.getLocale();
@@ -204,7 +198,6 @@ Sequence< Locale > SAL_CALL Hyphenator::getLocales()
else
{
// no dictionary found so register no dictionaries
- numdict = 0;
mvDicts.clear();
aSuppLocales.realloc(0);
}
@@ -217,21 +210,10 @@ sal_Bool SAL_CALL Hyphenator::hasLocale(const Locale& rLocale)
{
MutexGuard aGuard( GetLinguMutex() );
- bool bRes = false;
if (!aSuppLocales.hasElements())
getLocales();
- const Locale *pLocale = aSuppLocales.getConstArray();
- sal_Int32 nLen = aSuppLocales.getLength();
- for (sal_Int32 i = 0; i < nLen; ++i)
- {
- if (rLocale == pLocale[i])
- {
- bRes = true;
- break;
- }
- }
- return bRes;
+ return comphelper::findValue(aSuppLocales, rLocale) != -1;
}
namespace {
diff --git a/lingucomponent/source/languageguessing/guesslang.cxx b/lingucomponent/source/languageguessing/guesslang.cxx
index 5295a4e2902c..e25d51a413fa 100644
--- a/lingucomponent/source/languageguessing/guesslang.cxx
+++ b/lingucomponent/source/languageguessing/guesslang.cxx
@@ -270,15 +270,12 @@ void SAL_CALL LangGuess_Impl::disableLanguages(
EnsureInitialized();
- sal_Int32 nLanguages = rLanguages.getLength();
- const Locale *pLanguages = rLanguages.getConstArray();
-
- for (sal_Int32 i = 0; i < nLanguages; ++i)
+ for (const Locale& rLanguage : rLanguages)
{
string language;
- OString l = OUStringToOString( pLanguages[i].Language, RTL_TEXTENCODING_ASCII_US );
- OString c = OUStringToOString( pLanguages[i].Country, RTL_TEXTENCODING_ASCII_US );
+ OString l = OUStringToOString( rLanguage.Language, RTL_TEXTENCODING_ASCII_US );
+ OString c = OUStringToOString( rLanguage.Country, RTL_TEXTENCODING_ASCII_US );
language += l.getStr();
language += "-";
@@ -294,15 +291,12 @@ void SAL_CALL LangGuess_Impl::enableLanguages(
EnsureInitialized();
- sal_Int32 nLanguages = rLanguages.getLength();
- const Locale *pLanguages = rLanguages.getConstArray();
-
- for (sal_Int32 i = 0; i < nLanguages; ++i)
+ for (const Locale& rLanguage : rLanguages)
{
string language;
- OString l = OUStringToOString( pLanguages[i].Language, RTL_TEXTENCODING_ASCII_US );
- OString c = OUStringToOString( pLanguages[i].Country, RTL_TEXTENCODING_ASCII_US );
+ OString l = OUStringToOString( rLanguage.Language, RTL_TEXTENCODING_ASCII_US );
+ OString c = OUStringToOString( rLanguage.Country, RTL_TEXTENCODING_ASCII_US );
language += l.getStr();
language += "-";
diff --git a/lingucomponent/source/spellcheck/spell/sspellimp.cxx b/lingucomponent/source/spellcheck/spell/sspellimp.cxx
index 1e88d04874c1..e6901af11577 100644
--- a/lingucomponent/source/spellcheck/spell/sspellimp.cxx
+++ b/lingucomponent/source/spellcheck/spell/sspellimp.cxx
@@ -50,6 +50,7 @@
#include <rtl/textenc.h>
#include <sal/log.hxx>
+#include <numeric>
#include <utility>
#include <vector>
#include <set>
@@ -189,9 +190,9 @@ Sequence< Locale > SAL_CALL SpellChecker::getLocales()
//! it is undefined which dictionary gets used.
//! In the future the implementation should support using several dictionaries
//! for one locale.
- sal_uInt32 nDictSize = 0;
- for (auto const& dict : aDics)
- nDictSize += dict.aLocaleNames.getLength();
+ sal_uInt32 nDictSize = std::accumulate(aDics.begin(), aDics.end(), sal_uInt32(0),
+ [](const sal_uInt32 nSum, const SvtLinguConfigDictionaryEntry& dict) {
+ return nSum + dict.aLocaleNames.getLength(); });
// add dictionary information
m_DictItems.reserve(nDictSize);
diff --git a/lingucomponent/source/thesaurus/libnth/nthesimp.cxx b/lingucomponent/source/thesaurus/libnth/nthesimp.cxx
index 396f39e9f05f..260c51f83981 100644
--- a/lingucomponent/source/thesaurus/libnth/nthesimp.cxx
+++ b/lingucomponent/source/thesaurus/libnth/nthesimp.cxx
@@ -30,6 +30,7 @@
#include <tools/debug.hxx>
#include <comphelper/lok.hxx>
#include <comphelper/processfactory.hxx>
+#include <comphelper/sequence.hxx>
#include <osl/mutex.hxx>
#include <osl/thread.h>
#include <unotools/pathoptions.hxx>
@@ -48,6 +49,7 @@
#include "nthesdta.hxx"
#include <vector>
+#include <numeric>
#include <set>
#include <string.h>
@@ -113,11 +115,10 @@ Sequence< Locale > SAL_CALL Thesaurus::getLocales()
uno::Sequence< OUString > aFormatList;
aLinguCfg.GetSupportedDictionaryFormatsFor( "Thesauri",
"org.openoffice.lingu.new.Thesaurus", aFormatList );
- sal_Int32 nLen = aFormatList.getLength();
- for (sal_Int32 i = 0; i < nLen; ++i)
+ for (const auto& rFormat : std::as_const(aFormatList))
{
std::vector< SvtLinguConfigDictionaryEntry > aTmpDic(
- aLinguCfg.GetActiveDictionariesByFormat( aFormatList[i] ) );
+ aLinguCfg.GetActiveDictionariesByFormat( rFormat ) );
aDics.insert( aDics.end(), aTmpDic.begin(), aTmpDic.end() );
}
@@ -132,61 +133,53 @@ Sequence< Locale > SAL_CALL Thesaurus::getLocales()
// is not yet supported by the list of new style dictionaries
MergeNewStyleDicsAndOldStyleDics( aDics, aOldStyleDics );
- sal_Int32 numthes = aDics.size();
- if (numthes)
+ if (!aDics.empty())
{
// get supported locales from the dictionaries-to-use...
- sal_Int32 k = 0;
std::set<OUString> aLocaleNamesSet;
for (auto const& dict : aDics)
{
- uno::Sequence< OUString > aLocaleNames(dict.aLocaleNames);
- sal_Int32 nLen2 = aLocaleNames.getLength();
- for (k = 0; k < nLen2; ++k)
+ for (const auto& rLocaleName : dict.aLocaleNames)
{
- if (!comphelper::LibreOfficeKit::isWhitelistedLanguage(aLocaleNames[k]))
+ if (!comphelper::LibreOfficeKit::isWhitelistedLanguage(rLocaleName))
continue;
- aLocaleNamesSet.insert( aLocaleNames[k] );
+ aLocaleNamesSet.insert( rLocaleName );
}
}
// ... and add them to the resulting sequence
- aSuppLocales.realloc( aLocaleNamesSet.size() );
- std::set<OUString>::const_iterator aItB;
- k = 0;
- for (auto const& localeName : aLocaleNamesSet)
- {
- Locale aTmp( LanguageTag::convertToLocale(localeName));
- aSuppLocales[k++] = aTmp;
- }
+ std::vector<Locale> aLocalesVec;
+ aLocalesVec.reserve(aLocaleNamesSet.size());
+
+ std::transform(aLocaleNamesSet.begin(), aLocaleNamesSet.end(), std::back_inserter(aLocalesVec),
+ [](const OUString& localeName) -> Locale { return LanguageTag::convertToLocale(localeName); });
+
+ aSuppLocales = comphelper::containerToSequence(aLocalesVec);
//! For each dictionary and each locale we need a separate entry.
//! If this results in more than one dictionary per locale than (for now)
//! it is undefined which dictionary gets used.
//! In the future the implementation should support using several dictionaries
//! for one locale.
- numthes = 0;
- for (auto const& dict : aDics)
- numthes = numthes + dict.aLocaleNames.getLength();
+ sal_Int32 numthes = std::accumulate(aDics.begin(), aDics.end(), 0,
+ [](const sal_Int32 nSum, const SvtLinguConfigDictionaryEntry& dict) {
+ return nSum + dict.aLocaleNames.getLength(); });
// add dictionary information
mvThesInfo.resize(numthes);
- k = 0;
+ sal_Int32 k = 0;
for (auto const& dict : aDics)
{
if (dict.aLocaleNames.hasElements() &&
dict.aLocations.hasElements())
{
- uno::Sequence< OUString > aLocaleNames(dict.aLocaleNames);
- sal_Int32 nLocales = aLocaleNames.getLength();
-
// currently only one language per dictionary is supported in the actual implementation...
// Thus here we work-around this by adding the same dictionary several times.
// Once for each of its supported locales.
- for (sal_Int32 i = 0; i < nLocales; ++i)
+ for (const auto& rLocaleName : dict.aLocaleNames)
{
- LanguageTag aLanguageTag(dict.aLocaleNames[i]);
+ LanguageTag aLanguageTag(rLocaleName);
mvThesInfo[k].aEncoding = RTL_TEXTENCODING_DONTKNOW;
mvThesInfo[k].aLocale = aLanguageTag.getLocale();
mvThesInfo[k].aCharSetInfo.reset( new CharClass( aLanguageTag ) );
@@ -219,20 +212,10 @@ sal_Bool SAL_CALL Thesaurus::hasLocale(const Locale& rLocale)
{
MutexGuard aGuard( GetLinguMutex() );
- bool bRes = false;
if (!aSuppLocales.hasElements())
getLocales();
- sal_Int32 nLen = aSuppLocales.getLength();
- for (sal_Int32 i = 0; i < nLen; ++i)
- {
- const Locale *pLocale = aSuppLocales.getConstArray();
- if (rLocale == pLocale[i])
- {
- bRes = true;
- break;
- }
- }
- return bRes;
+
+ return comphelper::findValue(aSuppLocales, rLocale) != -1;
}
Sequence < Reference < css::linguistic2::XMeaning > > SAL_CALL Thesaurus::queryMeanings(