loplugin:flatten in lingucomponent

Change-Id: Ic0bf912a22e8efeae1a4f4864397f3f3d474c632
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/91803
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
This commit is contained in:
Noel Grandin
2020-04-07 10:55:00 +02:00
parent 27d04f6dbf
commit 35f9dec364
7 changed files with 196 additions and 197 deletions

View File

@@ -736,25 +736,25 @@ void SAL_CALL Hyphenator::initialize( const Sequence< Any >& rArguments )
{ {
MutexGuard aGuard( GetLinguMutex() ); MutexGuard aGuard( GetLinguMutex() );
if (!pPropHelper) if (pPropHelper)
{ return;
sal_Int32 nLen = rArguments.getLength();
if (2 == nLen)
{
Reference< XLinguProperties > xPropSet;
rArguments.getConstArray()[0] >>= xPropSet;
// rArguments.getConstArray()[1] >>= xDicList;
//! Pointer allows for access of the non-UNO functions. sal_Int32 nLen = rArguments.getLength();
//! And the reference to the UNO-functions while increasing if (2 == nLen)
//! the ref-count and will implicitly free the memory {
//! when the object is no longer used. Reference< XLinguProperties > xPropSet;
pPropHelper.reset( new PropertyHelper_Hyphenation( static_cast<XHyphenator *>(this), xPropSet ) ); rArguments.getConstArray()[0] >>= xPropSet;
pPropHelper->AddAsPropListener(); //! after a reference is established // rArguments.getConstArray()[1] >>= xDicList;
}
else { //! Pointer allows for access of the non-UNO functions.
OSL_FAIL( "wrong number of arguments in sequence" ); //! And the reference to the UNO-functions while increasing
} //! the ref-count and will implicitly free the memory
//! when the object is no longer used.
pPropHelper.reset( new PropertyHelper_Hyphenation( static_cast<XHyphenator *>(this), xPropSet ) );
pPropHelper->AddAsPropListener(); //! after a reference is established
}
else {
OSL_FAIL( "wrong number of arguments in sequence" );
} }
} }

View File

@@ -58,47 +58,46 @@ Guess::Guess(const char * guess_str)
, country_str(DEFAULT_COUNTRY) , country_str(DEFAULT_COUNTRY)
{ {
//if the guess is not like "UNKNOWN" or "SHORT", go into the brackets //if the guess is not like "UNKNOWN" or "SHORT", go into the brackets
if(strcmp(guess_str + 1, TEXTCAT_RESULT_UNKNOWN_STR) != 0 if(strcmp(guess_str + 1, TEXTCAT_RESULT_UNKNOWN_STR) == 0
&& || strcmp(guess_str + 1, TEXTCAT_RESULT_SHORT_STR) == 0)
strcmp(guess_str + 1, TEXTCAT_RESULT_SHORT_STR) != 0) return;
{
// From how this ctor is called from SimpleGuesser::GuessLanguage and // From how this ctor is called from SimpleGuesser::GuessLanguage and
// SimpleGuesser::GetManagedLanguages in // SimpleGuesser::GetManagedLanguages in
// lingucomponent/source/languageguessing/simpleguesser.cxx, guess_str must start with "[": // lingucomponent/source/languageguessing/simpleguesser.cxx, guess_str must start with "[":
assert(guess_str[0] == GUESS_SEPARATOR_OPEN); assert(guess_str[0] == GUESS_SEPARATOR_OPEN);
auto const start = guess_str + 1; auto const start = guess_str + 1;
// Only look at the prefix of guess_str, delimited by the next "]" or "[" or end-of-string; // Only look at the prefix of guess_str, delimited by the next "]" or "[" or end-of-string;
// split it into at most three segments separated by "-" (where excess occurrences of "-" // split it into at most three segments separated by "-" (where excess occurrences of "-"
// would become part of the third segment), like "en-US-utf8"; the first segment denotes the // would become part of the third segment), like "en-US-utf8"; the first segment denotes the
// language; if there are three segments, the second denotes the country and the third the // language; if there are three segments, the second denotes the country and the third the
// encoding; otherwise, the second segment, if any (e.g., in "haw-utf8"), denotes the // encoding; otherwise, the second segment, if any (e.g., in "haw-utf8"), denotes the
// encoding: // encoding:
char const * dash1 = nullptr; char const * dash1 = nullptr;
char const * dash2 = nullptr; char const * dash2 = nullptr;
auto p = start; auto p = start;
for (;; ++p) { for (;; ++p) {
auto const c = *p; auto const c = *p;
if (c == '\0' || c == GUESS_SEPARATOR_OPEN || c == GUESS_SEPARATOR_CLOSE) { if (c == '\0' || c == GUESS_SEPARATOR_OPEN || c == GUESS_SEPARATOR_CLOSE) {
break;
}
if (c == GUESS_SEPARATOR_SEP) {
if (dash1 == nullptr) {
dash1 = p;
} else {
dash2 = p;
// The encoding is ignored, so we can stop as soon as we found the second "-":
break; break;
} }
if (c == GUESS_SEPARATOR_SEP) {
if (dash1 == nullptr) {
dash1 = p;
} else {
dash2 = p;
// The encoding is ignored, so we can stop as soon as we found the second "-":
break;
}
}
}
auto const langLen = (dash1 == nullptr ? p : dash1) - start;
if (langLen != 0) { // if not we use the default value
language_str.assign(start, langLen);
}
if (dash2 != nullptr) {
country_str.assign(dash1 + 1, dash2 - (dash1 + 1));
} }
} }
auto const langLen = (dash1 == nullptr ? p : dash1) - start;
if (langLen != 0) { // if not we use the default value
language_str.assign(start, langLen);
}
if (dash2 != nullptr) {
country_str.assign(dash1 + 1, dash2 - (dash1 + 1));
}
} }
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View File

@@ -117,54 +117,54 @@ LangGuess_Impl::LangGuess_Impl() :
void LangGuess_Impl::EnsureInitialized() void LangGuess_Impl::EnsureInitialized()
{ {
if (!m_bInitialized) if (m_bInitialized)
{ return;
// set this to true at the very start to prevent loops because of
// implicitly called functions below
m_bInitialized = true;
// set default fingerprint path to where those get installed // set this to true at the very start to prevent loops because of
OUString aPhysPath; // implicitly called functions below
OUString aURL( SvtPathOptions().GetFingerprintPath() ); m_bInitialized = true;
osl::FileBase::getSystemPathFromFileURL( aURL, aPhysPath );
// set default fingerprint path to where those get installed
OUString aPhysPath;
OUString aURL( SvtPathOptions().GetFingerprintPath() );
osl::FileBase::getSystemPathFromFileURL( aURL, aPhysPath );
#ifdef _WIN32 #ifdef _WIN32
aPhysPath += "\\"; aPhysPath += "\\";
#else #else
aPhysPath += "/"; aPhysPath += "/";
#endif #endif
SetFingerPrintsDB( aPhysPath ); SetFingerPrintsDB( aPhysPath );
#if !defined(EXTTEXTCAT_VERSION_MAJOR) #if !defined(EXTTEXTCAT_VERSION_MAJOR)
// disable currently not functional languages... // disable currently not functional languages...
struct LangCountry struct LangCountry
{ {
const char *pLang; const char *pLang;
const char *pCountry; const char *pCountry;
}; };
LangCountry aDisable[] = LangCountry aDisable[] =
{ {
// not functional in modified libtextcat, but fixed in >= libexttextcat 3.1.0 // not functional in modified libtextcat, but fixed in >= libexttextcat 3.1.0
// which is the first with EXTTEXTCAT_VERSION_MAJOR defined // which is the first with EXTTEXTCAT_VERSION_MAJOR defined
{"sco", ""}, {"zh", "CN"}, {"zh", "TW"}, {"ja", ""}, {"ko", ""}, {"sco", ""}, {"zh", "CN"}, {"zh", "TW"}, {"ja", ""}, {"ko", ""},
{"ka", ""}, {"hi", ""}, {"mr", ""}, {"ne", ""}, {"sa", ""}, {"ka", ""}, {"hi", ""}, {"mr", ""}, {"ne", ""}, {"sa", ""},
{"ta", ""}, {"th", ""}, {"qu", ""}, {"yi", ""} {"ta", ""}, {"th", ""}, {"qu", ""}, {"yi", ""}
}; };
sal_Int32 nNum = SAL_N_ELEMENTS(aDisable); sal_Int32 nNum = SAL_N_ELEMENTS(aDisable);
Sequence< Locale > aDisableSeq( nNum ); Sequence< Locale > aDisableSeq( nNum );
Locale *pDisableSeq = aDisableSeq.getArray(); Locale *pDisableSeq = aDisableSeq.getArray();
for (sal_Int32 i = 0; i < nNum; ++i) for (sal_Int32 i = 0; i < nNum; ++i)
{ {
Locale aLocale; Locale aLocale;
aLocale.Language = OUString::createFromAscii( aDisable[i].pLang ); aLocale.Language = OUString::createFromAscii( aDisable[i].pLang );
aLocale.Country = OUString::createFromAscii( aDisable[i].pCountry ); aLocale.Country = OUString::createFromAscii( aDisable[i].pCountry );
pDisableSeq[i] = aLocale; pDisableSeq[i] = aLocale;
}
disableLanguages( aDisableSeq );
DBG_ASSERT( nNum == getDisabledLanguages().getLength(), "size mismatch" );
#endif
} }
disableLanguages( aDisableSeq );
DBG_ASSERT( nNum == getDisabledLanguages().getLength(), "size mismatch" );
#endif
} }
Locale SAL_CALL LangGuess_Impl::guessPrimaryLanguage( Locale SAL_CALL LangGuess_Impl::guessPrimaryLanguage(

View File

@@ -67,64 +67,64 @@ static void GetOldStyleDicsInDir(
std::vector< SvtLinguConfigDictionaryEntry >& aRes ) std::vector< SvtLinguConfigDictionaryEntry >& aRes )
{ {
osl::Directory aSystemDicts(aSystemDir); osl::Directory aSystemDicts(aSystemDir);
if (aSystemDicts.open() == osl::FileBase::E_None) if (aSystemDicts.open() != osl::FileBase::E_None)
return;
osl::DirectoryItem aItem;
osl::FileStatus aFileStatus(osl_FileStatus_Mask_FileURL);
while (aSystemDicts.getNextItem(aItem) == osl::FileBase::E_None)
{ {
osl::DirectoryItem aItem; aItem.getFileStatus(aFileStatus);
osl::FileStatus aFileStatus(osl_FileStatus_Mask_FileURL); OUString sPath = aFileStatus.getFileURL();
while (aSystemDicts.getNextItem(aItem) == osl::FileBase::E_None) if (sPath.endsWith(aSystemSuffix))
{ {
aItem.getFileStatus(aFileStatus); sal_Int32 nStartIndex = sPath.lastIndexOf('/') + 1;
OUString sPath = aFileStatus.getFileURL(); if (!sPath.match(aSystemPrefix, nStartIndex))
if (sPath.endsWith(aSystemSuffix)) continue;
OUString sChunk = sPath.copy(nStartIndex + aSystemPrefix.getLength(),
sPath.getLength() - aSystemSuffix.getLength() -
nStartIndex - aSystemPrefix.getLength());
if (sChunk.isEmpty())
continue;
// We prefer (now) to use language tags.
// Avoid feeding in the older LANG_REGION scheme to the BCP47
// ctor as that triggers use of liblangtag and initializes its
// database which we do not want during startup. Convert
// instead.
sChunk = sChunk.replace( '_', '-');
// There's a known exception to the rule, the dreaded
// hu_HU_u8.dic of the myspell-hu package, see
// http://packages.debian.org/search?arch=any&searchon=contents&keywords=hu_HU_u8.dic
// This was ignored because unknown in the old implementation,
// truncate to the known locale and either insert because hu_HU
// wasn't encountered yet, or skip because it was. It doesn't
// really matter because the proper new-style hu_HU dictionary
// will take precedence anyway if installed with a Hungarian
// languagepack. Again, this is only to not pull in all
// liblangtag and stuff during startup, the result would be
// !isValidBcp47() and the dictionary ignored.
if (sChunk == "hu-HU-u8")
sChunk = "hu-HU";
LanguageTag aLangTag(sChunk, true);
if (!aLangTag.isValidBcp47())
continue;
// Thus we first get the language of the dictionary
const OUString& aLocaleName(aLangTag.getBcp47());
if (aDicLangInUse.insert(aLocaleName).second)
{ {
sal_Int32 nStartIndex = sPath.lastIndexOf('/') + 1; // add the dictionary to the resulting vector
if (!sPath.match(aSystemPrefix, nStartIndex)) SvtLinguConfigDictionaryEntry aDicEntry;
continue; aDicEntry.aLocations.realloc(1);
OUString sChunk = sPath.copy(nStartIndex + aSystemPrefix.getLength(), aDicEntry.aLocaleNames.realloc(1);
sPath.getLength() - aSystemSuffix.getLength() - aDicEntry.aLocations[0] = sPath;
nStartIndex - aSystemPrefix.getLength()); aDicEntry.aFormatName = aFormatName;
if (sChunk.isEmpty()) aDicEntry.aLocaleNames[0] = aLocaleName;
continue; aRes.push_back( aDicEntry );
// We prefer (now) to use language tags.
// Avoid feeding in the older LANG_REGION scheme to the BCP47
// ctor as that triggers use of liblangtag and initializes its
// database which we do not want during startup. Convert
// instead.
sChunk = sChunk.replace( '_', '-');
// There's a known exception to the rule, the dreaded
// hu_HU_u8.dic of the myspell-hu package, see
// http://packages.debian.org/search?arch=any&searchon=contents&keywords=hu_HU_u8.dic
// This was ignored because unknown in the old implementation,
// truncate to the known locale and either insert because hu_HU
// wasn't encountered yet, or skip because it was. It doesn't
// really matter because the proper new-style hu_HU dictionary
// will take precedence anyway if installed with a Hungarian
// languagepack. Again, this is only to not pull in all
// liblangtag and stuff during startup, the result would be
// !isValidBcp47() and the dictionary ignored.
if (sChunk == "hu-HU-u8")
sChunk = "hu-HU";
LanguageTag aLangTag(sChunk, true);
if (!aLangTag.isValidBcp47())
continue;
// Thus we first get the language of the dictionary
const OUString& aLocaleName(aLangTag.getBcp47());
if (aDicLangInUse.insert(aLocaleName).second)
{
// add the dictionary to the resulting vector
SvtLinguConfigDictionaryEntry aDicEntry;
aDicEntry.aLocations.realloc(1);
aDicEntry.aLocaleNames.realloc(1);
aDicEntry.aLocations[0] = sPath;
aDicEntry.aFormatName = aFormatName;
aDicEntry.aLocaleNames[0] = aLocaleName;
aRes.push_back( aDicEntry );
}
} }
} }
} }

View File

@@ -102,26 +102,26 @@ NumberText_Impl::NumberText_Impl()
void NumberText_Impl::EnsureInitialized() void NumberText_Impl::EnsureInitialized()
{ {
if (!m_bInitialized) if (m_bInitialized)
{ return;
// set this to true at the very start to prevent loops because of
// implicitly called functions below
m_bInitialized = true;
// set default numbertext path to where those get installed // set this to true at the very start to prevent loops because of
OUString aPhysPath; // implicitly called functions below
OUString aURL(SvtPathOptions().GetNumbertextPath()); m_bInitialized = true;
osl::FileBase::getSystemPathFromFileURL(aURL, aPhysPath);
// set default numbertext path to where those get installed
OUString aPhysPath;
OUString aURL(SvtPathOptions().GetNumbertextPath());
osl::FileBase::getSystemPathFromFileURL(aURL, aPhysPath);
#ifdef _WIN32 #ifdef _WIN32
aPhysPath += "\\"; aPhysPath += "\\";
#else #else
aPhysPath += "/"; aPhysPath += "/";
#endif #endif
#if ENABLE_LIBNUMBERTEXT #if ENABLE_LIBNUMBERTEXT
OString path = OUStringToOString(aPhysPath, osl_getThreadTextEncoding()); OString path = OUStringToOString(aPhysPath, osl_getThreadTextEncoding());
m_aNumberText.set_prefix(path.getStr()); m_aNumberText.set_prefix(path.getStr());
#endif #endif
}
} }
OUString SAL_CALL NumberText_Impl::getNumberText(const OUString& rText, const Locale& OUString SAL_CALL NumberText_Impl::getNumberText(const OUString& rText, const Locale&

View File

@@ -569,25 +569,25 @@ void SAL_CALL SpellChecker::initialize( const Sequence< Any >& rArguments )
{ {
MutexGuard aGuard( GetLinguMutex() ); MutexGuard aGuard( GetLinguMutex() );
if (!m_pPropHelper) if (m_pPropHelper)
{ return;
sal_Int32 nLen = rArguments.getLength();
if (2 == nLen)
{
Reference< XLinguProperties > xPropSet;
rArguments.getConstArray()[0] >>= xPropSet;
// rArguments.getConstArray()[1] >>= xDicList;
//! Pointer allows for access of the non-UNO functions. sal_Int32 nLen = rArguments.getLength();
//! And the reference to the UNO-functions while increasing if (2 == nLen)
//! the ref-count and will implicitly free the memory {
//! when the object is no longer used. Reference< XLinguProperties > xPropSet;
m_pPropHelper.reset( new PropertyHelper_Spelling( static_cast<XSpellChecker *>(this), xPropSet ) ); rArguments.getConstArray()[0] >>= xPropSet;
m_pPropHelper->AddAsPropListener(); //! after a reference is established // rArguments.getConstArray()[1] >>= xDicList;
}
else { //! Pointer allows for access of the non-UNO functions.
OSL_FAIL( "wrong number of arguments in sequence" ); //! And the reference to the UNO-functions while increasing
} //! the ref-count and will implicitly free the memory
//! when the object is no longer used.
m_pPropHelper.reset( new PropertyHelper_Spelling( static_cast<XSpellChecker *>(this), xPropSet ) );
m_pPropHelper->AddAsPropListener(); //! after a reference is established
}
else {
OSL_FAIL( "wrong number of arguments in sequence" );
} }
} }

View File

@@ -470,24 +470,24 @@ void SAL_CALL Thesaurus::initialize( const Sequence< Any >& rArguments )
{ {
MutexGuard aGuard( GetLinguMutex() ); MutexGuard aGuard( GetLinguMutex() );
if (!pPropHelper) if (pPropHelper)
{ return;
sal_Int32 nLen = rArguments.getLength();
if (1 == nLen)
{
Reference< XLinguProperties > xPropSet;
rArguments.getConstArray()[0] >>= xPropSet;
//! Pointer allows for access of the non-UNO functions. sal_Int32 nLen = rArguments.getLength();
//! And the reference to the UNO-functions while increasing if (1 == nLen)
//! the ref-count and will implicitly free the memory {
//! when the object is no longer used. Reference< XLinguProperties > xPropSet;
pPropHelper = new PropertyHelper_Thesaurus( static_cast<XThesaurus *>(this), xPropSet ); rArguments.getConstArray()[0] >>= xPropSet;
pPropHelper->AddAsPropListener(); //! after a reference is established
} //! Pointer allows for access of the non-UNO functions.
else //! And the reference to the UNO-functions while increasing
OSL_FAIL( "wrong number of arguments in sequence" ); //! the ref-count and will implicitly free the memory
//! when the object is no longer used.
pPropHelper = new PropertyHelper_Thesaurus( static_cast<XThesaurus *>(this), xPropSet );
pPropHelper->AddAsPropListener(); //! after a reference is established
} }
else
OSL_FAIL( "wrong number of arguments in sequence" );
} }
OUString Thesaurus::makeLowerCase(const OUString& aTerm, CharClass const * pCC) OUString Thesaurus::makeLowerCase(const OUString& aTerm, CharClass const * pCC)