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() );
if (!pPropHelper)
{
sal_Int32 nLen = rArguments.getLength();
if (2 == nLen)
{
Reference< XLinguProperties > xPropSet;
rArguments.getConstArray()[0] >>= xPropSet;
// rArguments.getConstArray()[1] >>= xDicList;
if (pPropHelper)
return;
//! Pointer allows for access of the non-UNO functions.
//! 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" );
}
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.
//! 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)
{
//if the guess is not like "UNKNOWN" or "SHORT", go into the brackets
if(strcmp(guess_str + 1, TEXTCAT_RESULT_UNKNOWN_STR) != 0
&&
strcmp(guess_str + 1, TEXTCAT_RESULT_SHORT_STR) != 0)
{
// From how this ctor is called from SimpleGuesser::GuessLanguage and
// SimpleGuesser::GetManagedLanguages in
// lingucomponent/source/languageguessing/simpleguesser.cxx, guess_str must start with "[":
assert(guess_str[0] == GUESS_SEPARATOR_OPEN);
auto const start = guess_str + 1;
// 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 "-"
// 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
// encoding; otherwise, the second segment, if any (e.g., in "haw-utf8"), denotes the
// encoding:
char const * dash1 = nullptr;
char const * dash2 = nullptr;
auto p = start;
for (;; ++p) {
auto const c = *p;
if (c == '\0' || c == GUESS_SEPARATOR_OPEN || c == GUESS_SEPARATOR_CLOSE) {
if(strcmp(guess_str + 1, TEXTCAT_RESULT_UNKNOWN_STR) == 0
|| strcmp(guess_str + 1, TEXTCAT_RESULT_SHORT_STR) == 0)
return;
// From how this ctor is called from SimpleGuesser::GuessLanguage and
// SimpleGuesser::GetManagedLanguages in
// lingucomponent/source/languageguessing/simpleguesser.cxx, guess_str must start with "[":
assert(guess_str[0] == GUESS_SEPARATOR_OPEN);
auto const start = guess_str + 1;
// 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 "-"
// 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
// encoding; otherwise, the second segment, if any (e.g., in "haw-utf8"), denotes the
// encoding:
char const * dash1 = nullptr;
char const * dash2 = nullptr;
auto p = start;
for (;; ++p) {
auto const c = *p;
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;
}
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: */

View File

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

View File

@@ -67,64 +67,64 @@ static void GetOldStyleDicsInDir(
std::vector< SvtLinguConfigDictionaryEntry >& aRes )
{
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;
osl::FileStatus aFileStatus(osl_FileStatus_Mask_FileURL);
while (aSystemDicts.getNextItem(aItem) == osl::FileBase::E_None)
aItem.getFileStatus(aFileStatus);
OUString sPath = aFileStatus.getFileURL();
if (sPath.endsWith(aSystemSuffix))
{
aItem.getFileStatus(aFileStatus);
OUString sPath = aFileStatus.getFileURL();
if (sPath.endsWith(aSystemSuffix))
sal_Int32 nStartIndex = sPath.lastIndexOf('/') + 1;
if (!sPath.match(aSystemPrefix, nStartIndex))
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;
if (!sPath.match(aSystemPrefix, nStartIndex))
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)
{
// 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 );
}
// 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()
{
if (!m_bInitialized)
{
// set this to true at the very start to prevent loops because of
// implicitly called functions below
m_bInitialized = true;
if (m_bInitialized)
return;
// set default numbertext path to where those get installed
OUString aPhysPath;
OUString aURL(SvtPathOptions().GetNumbertextPath());
osl::FileBase::getSystemPathFromFileURL(aURL, aPhysPath);
// 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
OUString aPhysPath;
OUString aURL(SvtPathOptions().GetNumbertextPath());
osl::FileBase::getSystemPathFromFileURL(aURL, aPhysPath);
#ifdef _WIN32
aPhysPath += "\\";
aPhysPath += "\\";
#else
aPhysPath += "/";
aPhysPath += "/";
#endif
#if ENABLE_LIBNUMBERTEXT
OString path = OUStringToOString(aPhysPath, osl_getThreadTextEncoding());
m_aNumberText.set_prefix(path.getStr());
OString path = OUStringToOString(aPhysPath, osl_getThreadTextEncoding());
m_aNumberText.set_prefix(path.getStr());
#endif
}
}
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() );
if (!m_pPropHelper)
{
sal_Int32 nLen = rArguments.getLength();
if (2 == nLen)
{
Reference< XLinguProperties > xPropSet;
rArguments.getConstArray()[0] >>= xPropSet;
// rArguments.getConstArray()[1] >>= xDicList;
if (m_pPropHelper)
return;
//! Pointer allows for access of the non-UNO functions.
//! 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" );
}
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.
//! 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() );
if (!pPropHelper)
{
sal_Int32 nLen = rArguments.getLength();
if (1 == nLen)
{
Reference< XLinguProperties > xPropSet;
rArguments.getConstArray()[0] >>= xPropSet;
if (pPropHelper)
return;
//! Pointer allows for access of the non-UNO functions.
//! 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 = new PropertyHelper_Thesaurus( static_cast<XThesaurus *>(this), xPropSet );
pPropHelper->AddAsPropListener(); //! after a reference is established
}
else
OSL_FAIL( "wrong number of arguments in sequence" );
sal_Int32 nLen = rArguments.getLength();
if (1 == nLen)
{
Reference< XLinguProperties > xPropSet;
rArguments.getConstArray()[0] >>= xPropSet;
//! Pointer allows for access of the non-UNO functions.
//! 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 = 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)