Kaydet (Commit) a14892ed authored tarafından Julien Nabet's avatar Julien Nabet

Replace lists by vectors in lingucomponent

+ use loop ranges

Change-Id: I0ae81e3c10a6382d3f5719b2824a70d6e72b1462
Reviewed-on: https://gerrit.libreoffice.org/44169Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarJulien Nabet <serval2412@yahoo.fr>
üst 0b70e6b9
......@@ -47,7 +47,7 @@
#include <string.h>
#include <cassert>
#include <list>
#include <vector>
#include <set>
#include <memory>
......@@ -117,7 +117,7 @@ Sequence< Locale > SAL_CALL Hyphenator::getLocales()
// get list of dictionaries-to-use
// (or better speaking: the list of dictionaries using the
// new configuration entries).
std::list< SvtLinguConfigDictionaryEntry > aDics;
std::vector< SvtLinguConfigDictionaryEntry > aDics;
uno::Sequence< OUString > aFormatList;
aLinguCfg.GetSupportedDictionaryFormatsFor( "Hyphenators",
"org.openoffice.lingu.LibHnjHyphenator", aFormatList );
......@@ -146,10 +146,9 @@ Sequence< Locale > SAL_CALL Hyphenator::getLocales()
// get supported locales from the dictionaries-to-use...
sal_Int32 k = 0;
std::set<OUString> aLocaleNamesSet;
std::list< SvtLinguConfigDictionaryEntry >::const_iterator aDictIt;
for (aDictIt = aDics.begin(); aDictIt != aDics.end(); ++aDictIt)
for (auto const& dict : aDics)
{
uno::Sequence< OUString > aLocaleNames( aDictIt->aLocaleNames );
uno::Sequence< OUString > aLocaleNames( dict.aLocaleNames );
sal_Int32 nLen2 = aLocaleNames.getLength();
for (k = 0; k < nLen2; ++k)
{
......@@ -158,11 +157,10 @@ Sequence< Locale > SAL_CALL Hyphenator::getLocales()
}
// ... and add them to the resulting sequence
aSuppLocales.realloc( aLocaleNamesSet.size() );
std::set<OUString>::const_iterator aItB;
k = 0;
for (aItB = aLocaleNamesSet.begin(); aItB != aLocaleNamesSet.end(); ++aItB)
for (auto const& localeName : aLocaleNamesSet)
{
Locale aTmp( LanguageTag::convertToLocale( *aItB ));
Locale aTmp( LanguageTag::convertToLocale(localeName));
aSuppLocales[k++] = aTmp;
}
......@@ -172,19 +170,19 @@ Sequence< Locale > SAL_CALL Hyphenator::getLocales()
//! In the future the implementation should support using several dictionaries
//! for one locale.
numdict = 0;
for (aDictIt = aDics.begin(); aDictIt != aDics.end(); ++aDictIt)
numdict = numdict + aDictIt->aLocaleNames.getLength();
for (auto const& dict : aDics)
numdict = numdict + dict.aLocaleNames.getLength();
// add dictionary information
aDicts = new HDInfo[numdict];
k = 0;
for (aDictIt = aDics.begin(); aDictIt != aDics.end(); ++aDictIt)
for (auto const& dict : aDics)
{
if (aDictIt->aLocaleNames.getLength() > 0 &&
aDictIt->aLocations.getLength() > 0)
if (dict.aLocaleNames.getLength() > 0 &&
dict.aLocations.getLength() > 0)
{
uno::Sequence< OUString > aLocaleNames( aDictIt->aLocaleNames );
uno::Sequence< OUString > aLocaleNames(dict.aLocaleNames);
sal_Int32 nLocales = aLocaleNames.getLength();
// currently only one language per dictionary is supported in the actual implementation...
......@@ -192,7 +190,7 @@ Sequence< Locale > SAL_CALL Hyphenator::getLocales()
// Once for each of its supported locales.
for (sal_Int32 i = 0; i < nLocales; ++i)
{
LanguageTag aLanguageTag( aDictIt->aLocaleNames[i] );
LanguageTag aLanguageTag(dict.aLocaleNames[i]);
aDicts[k].aPtr = nullptr;
aDicts[k].eEnc = RTL_TEXTENCODING_DONTKNOW;
aDicts[k].aLoc = aLanguageTag.getLocale();
......@@ -200,7 +198,7 @@ Sequence< Locale > SAL_CALL Hyphenator::getLocales()
// also both files have to be in the same directory and the
// file names must only differ in the extension (.aff/.dic).
// Thus we use the first location only and strip the extension part.
OUString aLocation = aDictIt->aLocations[0];
OUString aLocation = dict.aLocations[0];
sal_Int32 nPos = aLocation.lastIndexOf( '.' );
aLocation = aLocation.copy( 0, nPos );
aDicts[k].aName = aLocation;
......
......@@ -230,15 +230,14 @@ std::vector< SvtLinguConfigDictionaryEntry > GetOldStyleDics( const char *pDicTy
}
void MergeNewStyleDicsAndOldStyleDics(
std::list< SvtLinguConfigDictionaryEntry > &rNewStyleDics,
std::vector< SvtLinguConfigDictionaryEntry > &rNewStyleDics,
const std::vector< SvtLinguConfigDictionaryEntry > &rOldStyleDics )
{
// get list of languages supported by new style dictionaries
std::set< OUString > aNewStyleLanguages;
std::list< SvtLinguConfigDictionaryEntry >::const_iterator aIt;
for (aIt = rNewStyleDics.begin() ; aIt != rNewStyleDics.end(); ++aIt)
for (auto const& newStyleDic : rNewStyleDics)
{
const uno::Sequence< OUString > aLocaleNames( aIt->aLocaleNames );
const uno::Sequence< OUString > aLocaleNames(newStyleDic.aLocaleNames);
sal_Int32 nLocaleNames = aLocaleNames.getLength();
for (sal_Int32 k = 0; k < nLocaleNames; ++k)
{
......@@ -248,24 +247,23 @@ void MergeNewStyleDicsAndOldStyleDics(
// now check all old style dictionaries if they will add a not yet
// added language. If so add them to the resulting vector
std::vector< SvtLinguConfigDictionaryEntry >::const_iterator aIt2;
for (aIt2 = rOldStyleDics.begin(); aIt2 != rOldStyleDics.end(); ++aIt2)
for (auto const& oldStyleDic : rOldStyleDics)
{
sal_Int32 nOldStyleDics = aIt2->aLocaleNames.getLength();
sal_Int32 nOldStyleDics = oldStyleDic.aLocaleNames.getLength();
// old style dics should only have one language listed...
DBG_ASSERT( nOldStyleDics, "old style dictionary with more than one language found!");
if (nOldStyleDics > 0)
{
if (linguistic::LinguIsUnspecified( aIt2->aLocaleNames[0]))
if (linguistic::LinguIsUnspecified( oldStyleDic.aLocaleNames[0]))
{
OSL_FAIL( "old style dictionary with invalid language found!" );
continue;
}
// language not yet added?
if (aNewStyleLanguages.find( aIt2->aLocaleNames[0] ) == aNewStyleLanguages.end())
rNewStyleDics.push_back( *aIt2 );
if (aNewStyleLanguages.find( oldStyleDic.aLocaleNames[0] ) == aNewStyleLanguages.end())
rNewStyleDics.push_back(oldStyleDic);
}
else
{
......
......@@ -25,7 +25,6 @@
#include <rtl/ustring.hxx>
#include <vector>
#include <list>
#define OU2ENC(rtlOUString, rtlEncoding) \
OString((rtlOUString).getStr(), (rtlOUString).getLength(), \
......@@ -44,7 +43,7 @@ OString Win_AddLongPathPrefix( const OString &rPathName );
// temporary function, to be removed when new style dictionaries
// using configuration entries are fully implemented and provided
std::vector< SvtLinguConfigDictionaryEntry > GetOldStyleDics( const char * pDicType );
void MergeNewStyleDicsAndOldStyleDics( std::list< SvtLinguConfigDictionaryEntry > &rNewStyleDics, const std::vector< SvtLinguConfigDictionaryEntry > &rOldStyleDics );
void MergeNewStyleDicsAndOldStyleDics( std::vector< SvtLinguConfigDictionaryEntry > &rNewStyleDics, const std::vector< SvtLinguConfigDictionaryEntry > &rOldStyleDics );
//Find an encoding from a charset string, using
//rtl_getTextEncodingFromMimeCharset and falling back to
......
......@@ -45,7 +45,7 @@
#include <rtl/textenc.h>
#include <sal/log.hxx>
#include <list>
#include <vector>
#include <set>
#include <string.h>
......@@ -123,15 +123,14 @@ Sequence< Locale > SAL_CALL SpellChecker::getLocales()
// get list of extension dictionaries-to-use
// (or better speaking: the list of dictionaries using the
// new configuration entries).
std::list< SvtLinguConfigDictionaryEntry > aDics;
std::vector< SvtLinguConfigDictionaryEntry > aDics;
uno::Sequence< OUString > aFormatList;
aLinguCfg.GetSupportedDictionaryFormatsFor( "SpellCheckers",
"org.openoffice.lingu.MySpellSpellChecker", aFormatList );
sal_Int32 nLen = aFormatList.getLength();
for (sal_Int32 i = 0; i < nLen; ++i)
for (auto const& format : aFormatList)
{
std::vector< SvtLinguConfigDictionaryEntry > aTmpDic(
aLinguCfg.GetActiveDictionariesByFormat( aFormatList[i] ) );
aLinguCfg.GetActiveDictionariesByFormat(format) );
aDics.insert( aDics.end(), aTmpDic.begin(), aTmpDic.end() );
}
......@@ -153,11 +152,10 @@ Sequence< Locale > SAL_CALL SpellChecker::getLocales()
// get supported locales from the dictionaries-to-use...
sal_Int32 k = 0;
std::set<OUString> aLocaleNamesSet;
std::list< SvtLinguConfigDictionaryEntry >::const_iterator aDictIt;
for (aDictIt = aDics.begin(); aDictIt != aDics.end(); ++aDictIt)
for (auto const& dict : aDics)
{
uno::Sequence< OUString > aLocaleNames( aDictIt->aLocaleNames );
uno::Sequence< OUString > aLocations( aDictIt->aLocations );
uno::Sequence< OUString > aLocaleNames( dict.aLocaleNames );
uno::Sequence< OUString > aLocations( dict.aLocations );
SAL_WARN_IF(
aLocaleNames.hasElements() && !aLocations.hasElements(),
"lingucomponent", "no locations");
......@@ -165,10 +163,9 @@ Sequence< Locale > SAL_CALL SpellChecker::getLocales()
{
if (xAccess.is() && xAccess->exists(aLocations[0]))
{
sal_Int32 nLen2 = aLocaleNames.getLength();
for (k = 0; k < nLen2; ++k)
for (auto const& locale : aLocaleNames)
{
aLocaleNamesSet.insert( aLocaleNames[k] );
aLocaleNamesSet.insert(locale);
}
}
else
......@@ -181,11 +178,10 @@ Sequence< Locale > SAL_CALL SpellChecker::getLocales()
}
// ... and add them to the resulting sequence
m_aSuppLocales.realloc( aLocaleNamesSet.size() );
std::set<OUString>::const_iterator aItB;
k = 0;
for (aItB = aLocaleNamesSet.begin(); aItB != aLocaleNamesSet.end(); ++aItB)
for (auto const& localeName : aLocaleNamesSet)
{
Locale aTmp( LanguageTag::convertToLocale( *aItB ));
Locale aTmp( LanguageTag::convertToLocale(localeName));
m_aSuppLocales[k++] = aTmp;
}
......@@ -195,8 +191,8 @@ Sequence< Locale > SAL_CALL SpellChecker::getLocales()
//! In the future the implementation should support using several dictionaries
//! for one locale.
m_nNumDict = 0;
for (aDictIt = aDics.begin(); aDictIt != aDics.end(); ++aDictIt)
m_nNumDict = m_nNumDict + aDictIt->aLocaleNames.getLength();
for (auto const& dict : aDics)
m_nNumDict = m_nNumDict + dict.aLocaleNames.getLength();
// add dictionary information
m_aDicts = new Hunspell* [m_nNumDict];
......@@ -204,26 +200,25 @@ Sequence< Locale > SAL_CALL SpellChecker::getLocales()
m_aDLocs = new Locale [m_nNumDict];
m_aDNames.reset( new OUString [m_nNumDict] );
k = 0;
for (aDictIt = aDics.begin(); aDictIt != aDics.end(); ++aDictIt)
for (auto const& dict : aDics)
{
if (aDictIt->aLocaleNames.getLength() > 0 &&
aDictIt->aLocations.getLength() > 0)
if (dict.aLocaleNames.getLength() > 0 &&
dict.aLocations.getLength() > 0)
{
uno::Sequence< OUString > aLocaleNames( aDictIt->aLocaleNames );
sal_Int32 nLocales = aLocaleNames.getLength();
uno::Sequence< OUString > aLocaleNames( dict.aLocaleNames );
// 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 (auto const& localeName : aLocaleNames)
{
m_aDicts[k] = nullptr;
m_aDEncs[k] = RTL_TEXTENCODING_DONTKNOW;
m_aDLocs[k] = LanguageTag::convertToLocale( aLocaleNames[i] );
m_aDLocs[k] = LanguageTag::convertToLocale(localeName);
// also both files have to be in the same directory and the
// file names must only differ in the extension (.aff/.dic).
// Thus we use the first location only and strip the extension part.
OUString aLocation = aDictIt->aLocations[0];
OUString aLocation = dict.aLocations[0];
sal_Int32 nPos = aLocation.lastIndexOf( '.' );
aLocation = aLocation.copy( 0, nPos );
m_aDNames[k] = aLocation;
......@@ -259,11 +254,9 @@ sal_Bool SAL_CALL SpellChecker::hasLocale(const Locale& rLocale)
if (!m_aSuppLocales.getLength())
getLocales();
const Locale *pLocale = m_aSuppLocales.getConstArray();
sal_Int32 nLen = m_aSuppLocales.getLength();
for (sal_Int32 i = 0; i < nLen; ++i)
for (auto const& suppLocale : m_aSuppLocales)
{
if (rLocale == pLocale[i])
if (rLocale == suppLocale)
{
bRes = true;
break;
......
......@@ -43,7 +43,7 @@
#include <linguistic/lngprops.hxx>
#include "nthesdta.hxx"
#include <list>
#include <vector>
#include <set>
#include <string.h>
......@@ -139,7 +139,7 @@ Sequence< Locale > SAL_CALL Thesaurus::getLocales()
SvtLinguConfig aLinguCfg;
// get list of dictionaries-to-use
std::list< SvtLinguConfigDictionaryEntry > aDics;
std::vector< SvtLinguConfigDictionaryEntry > aDics;
uno::Sequence< OUString > aFormatList;
aLinguCfg.GetSupportedDictionaryFormatsFor( "Thesauri",
"org.openoffice.lingu.new.Thesaurus", aFormatList );
......@@ -168,10 +168,9 @@ Sequence< Locale > SAL_CALL Thesaurus::getLocales()
// get supported locales from the dictionaries-to-use...
sal_Int32 k = 0;
std::set<OUString> aLocaleNamesSet;
std::list< SvtLinguConfigDictionaryEntry >::const_iterator aDictIt;
for (aDictIt = aDics.begin(); aDictIt != aDics.end(); ++aDictIt)
for (auto const& dict : aDics)
{
uno::Sequence< OUString > aLocaleNames( aDictIt->aLocaleNames );
uno::Sequence< OUString > aLocaleNames(dict.aLocaleNames);
sal_Int32 nLen2 = aLocaleNames.getLength();
for (k = 0; k < nLen2; ++k)
{
......@@ -182,9 +181,9 @@ Sequence< Locale > SAL_CALL Thesaurus::getLocales()
aSuppLocales.realloc( aLocaleNamesSet.size() );
std::set<OUString>::const_iterator aItB;
k = 0;
for (aItB = aLocaleNamesSet.begin(); aItB != aLocaleNamesSet.end(); ++aItB)
for (auto const& localeName : aLocaleNamesSet)
{
Locale aTmp( LanguageTag::convertToLocale( *aItB ));
Locale aTmp( LanguageTag::convertToLocale(localeName));
aSuppLocales[k++] = aTmp;
}
......@@ -194,8 +193,8 @@ Sequence< Locale > SAL_CALL Thesaurus::getLocales()
//! In the future the implementation should support using several dictionaries
//! for one locale.
numthes = 0;
for (aDictIt = aDics.begin(); aDictIt != aDics.end(); ++aDictIt)
numthes = numthes + aDictIt->aLocaleNames.getLength();
for (auto const& dict : aDics)
numthes = numthes + dict.aLocaleNames.getLength();
// add dictionary information
aThes = new MyThes* [numthes];
......@@ -205,12 +204,12 @@ Sequence< Locale > SAL_CALL Thesaurus::getLocales()
aCharSetInfo = new CharClass* [numthes];
k = 0;
for (aDictIt = aDics.begin(); aDictIt != aDics.end(); ++aDictIt)
for (auto const& dict : aDics)
{
if (aDictIt->aLocaleNames.getLength() > 0 &&
aDictIt->aLocations.getLength() > 0)
if (dict.aLocaleNames.getLength() > 0 &&
dict.aLocations.getLength() > 0)
{
uno::Sequence< OUString > aLocaleNames( aDictIt->aLocaleNames );
uno::Sequence< OUString > aLocaleNames(dict.aLocaleNames);
sal_Int32 nLocales = aLocaleNames.getLength();
// currently only one language per dictionary is supported in the actual implementation...
......@@ -218,7 +217,7 @@ Sequence< Locale > SAL_CALL Thesaurus::getLocales()
// Once for each of its supported locales.
for (sal_Int32 i = 0; i < nLocales; ++i)
{
LanguageTag aLanguageTag( aDictIt->aLocaleNames[i] );
LanguageTag aLanguageTag(dict.aLocaleNames[i]);
aThes[k] = nullptr;
aTEncs[k] = RTL_TEXTENCODING_DONTKNOW;
aTLocs[k] = aLanguageTag.getLocale();
......@@ -226,7 +225,7 @@ Sequence< Locale > SAL_CALL Thesaurus::getLocales()
// also both files have to be in the same directory and the
// file names must only differ in the extension (.aff/.dic).
// Thus we use the first location only and strip the extension part.
OUString aLocation = aDictIt->aLocations[0];
OUString aLocation = dict.aLocations[0];
sal_Int32 nPos = aLocation.lastIndexOf( '.' );
aLocation = aLocation.copy( 0, nPos );
aTNames[k] = aLocation;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment