summaryrefslogtreecommitdiffstats
path: root/lingucomponent
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2020-04-07 10:55:00 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2020-04-07 13:10:29 +0200
commit35f9dec3645f7a4a8d1f7f9dfb62e28d73bc5244 (patch)
tree36be6e2e018ff56f0e2b757202bfbe6912bd5729 /lingucomponent
parenttdf#119038 DOCX: fix FollowTextFlow handling (diff)
downloadcore-35f9dec3645f7a4a8d1f7f9dfb62e28d73bc5244.tar.gz
core-35f9dec3645f7a4a8d1f7f9dfb62e28d73bc5244.zip
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>
Diffstat (limited to 'lingucomponent')
-rw-r--r--lingucomponent/source/hyphenator/hyphen/hyphenimp.cxx36
-rw-r--r--lingucomponent/source/languageguessing/guess.cxx73
-rw-r--r--lingucomponent/source/languageguessing/guesslang.cxx80
-rw-r--r--lingucomponent/source/lingutil/lingutil.cxx110
-rw-r--r--lingucomponent/source/numbertext/numbertext.cxx30
-rw-r--r--lingucomponent/source/spellcheck/spell/sspellimp.cxx36
-rw-r--r--lingucomponent/source/thesaurus/libnth/nthesimp.cxx32
7 files changed, 198 insertions, 199 deletions
diff --git a/lingucomponent/source/hyphenator/hyphen/hyphenimp.cxx b/lingucomponent/source/hyphenator/hyphen/hyphenimp.cxx
index e6692a1d0b50..d03aaf1df0ea 100644
--- a/lingucomponent/source/hyphenator/hyphen/hyphenimp.cxx
+++ b/lingucomponent/source/hyphenator/hyphen/hyphenimp.cxx
@@ -736,25 +736,25 @@ void SAL_CALL Hyphenator::initialize( const Sequence< Any >& rArguments )
{
MutexGuard aGuard( GetLinguMutex() );
- if (!pPropHelper)
+ if (pPropHelper)
+ return;
+
+ sal_Int32 nLen = rArguments.getLength();
+ if (2 == nLen)
{
- 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" );
- }
+ 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" );
}
}
diff --git a/lingucomponent/source/languageguessing/guess.cxx b/lingucomponent/source/languageguessing/guess.cxx
index a2f3be35382b..45700ff7d1ff 100644
--- a/lingucomponent/source/languageguessing/guess.cxx
+++ b/lingucomponent/source/languageguessing/guess.cxx
@@ -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: */
diff --git a/lingucomponent/source/languageguessing/guesslang.cxx b/lingucomponent/source/languageguessing/guesslang.cxx
index 3e285b6909cc..7e9d1999b919 100644
--- a/lingucomponent/source/languageguessing/guesslang.cxx
+++ b/lingucomponent/source/languageguessing/guesslang.cxx
@@ -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;
-
- // set default fingerprint path to where those get installed
- OUString aPhysPath;
- OUString aURL( SvtPathOptions().GetFingerprintPath() );
- osl::FileBase::getSystemPathFromFileURL( aURL, aPhysPath );
+ 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
+ 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(
diff --git a/lingucomponent/source/lingutil/lingutil.cxx b/lingucomponent/source/lingutil/lingutil.cxx
index a05145e4e26b..1c9f449ce499 100644
--- a/lingucomponent/source/lingutil/lingutil.cxx
+++ b/lingucomponent/source/lingutil/lingutil.cxx
@@ -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 );
}
}
}
diff --git a/lingucomponent/source/numbertext/numbertext.cxx b/lingucomponent/source/numbertext/numbertext.cxx
index 44149fa39d68..006e99d30aed 100644
--- a/lingucomponent/source/numbertext/numbertext.cxx
+++ b/lingucomponent/source/numbertext/numbertext.cxx
@@ -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;
-
- // set default numbertext path to where those get installed
- OUString aPhysPath;
- OUString aURL(SvtPathOptions().GetNumbertextPath());
- osl::FileBase::getSystemPathFromFileURL(aURL, aPhysPath);
+ 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
+ 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&
diff --git a/lingucomponent/source/spellcheck/spell/sspellimp.cxx b/lingucomponent/source/spellcheck/spell/sspellimp.cxx
index 60dcc350f07a..04fc7d8e2b0d 100644
--- a/lingucomponent/source/spellcheck/spell/sspellimp.cxx
+++ b/lingucomponent/source/spellcheck/spell/sspellimp.cxx
@@ -569,25 +569,25 @@ void SAL_CALL SpellChecker::initialize( const Sequence< Any >& rArguments )
{
MutexGuard aGuard( GetLinguMutex() );
- if (!m_pPropHelper)
+ if (m_pPropHelper)
+ return;
+
+ sal_Int32 nLen = rArguments.getLength();
+ if (2 == nLen)
{
- 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" );
- }
+ 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" );
}
}
diff --git a/lingucomponent/source/thesaurus/libnth/nthesimp.cxx b/lingucomponent/source/thesaurus/libnth/nthesimp.cxx
index 7cab6c0770eb..e165d0962918 100644
--- a/lingucomponent/source/thesaurus/libnth/nthesimp.cxx
+++ b/lingucomponent/source/thesaurus/libnth/nthesimp.cxx
@@ -470,24 +470,24 @@ void SAL_CALL Thesaurus::initialize( const Sequence< Any >& rArguments )
{
MutexGuard aGuard( GetLinguMutex() );
- if (!pPropHelper)
+ if (pPropHelper)
+ return;
+
+ sal_Int32 nLen = rArguments.getLength();
+ if (1 == nLen)
{
- 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" );
+ 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)