loplugin:constantparam in i18nlangtag

Change-Id: I148a47a9b63b78651ec18cd947f45b8f4dbb9345
Reviewed-on: https://gerrit.libreoffice.org/44094
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
This commit is contained in:
Noel Grandin
2017-10-31 09:07:27 +02:00
parent 33a3de2f0c
commit eb5d232342
6 changed files with 41 additions and 63 deletions

View File

@@ -144,26 +144,20 @@ LanguageType MsLangId::resolveSystemLanguageByScriptType( LanguageType nLang, sa
// static // static
css::lang::Locale MsLangId::Conversion::convertLanguageToLocale( css::lang::Locale MsLangId::Conversion::convertLanguageToLocale(
LanguageType nLang, bool bResolveSystem ) LanguageType nLang )
{ {
css::lang::Locale aLocale; css::lang::Locale aLocale;
if (!bResolveSystem && simplifySystemLanguages( nLang) == LANGUAGE_SYSTEM) // Still resolve LANGUAGE_DONTKNOW if resolving is not requested,
; // nothing => empty locale // but not LANGUAGE_SYSTEM or others.
else LanguageType nOrigLang = nLang;
nLang = MsLangId::getRealLanguage(nLang);
convertLanguageToLocaleImpl( nLang, aLocale, true );
if (aLocale.Language.isEmpty() && simplifySystemLanguages(nOrigLang) == LANGUAGE_SYSTEM)
{ {
// Still resolve LANGUAGE_DONTKNOW if resolving is not requested, // None found but resolve requested, last resort is "en-US".
// but not LANGUAGE_SYSTEM or others. aLocale.Language = "en";
LanguageType nOrigLang = nLang; aLocale.Country = "US";
if (bResolveSystem || nLang == LANGUAGE_DONTKNOW) aLocale.Variant.clear();
nLang = MsLangId::getRealLanguage( nLang);
convertLanguageToLocaleImpl( nLang, aLocale, true);
if (bResolveSystem && aLocale.Language.isEmpty() && simplifySystemLanguages( nOrigLang) == LANGUAGE_SYSTEM)
{
// None found but resolve requested, last resort is "en-US".
aLocale.Language = "en";
aLocale.Country = "US";
aLocale.Variant.clear();
}
} }
return aLocale; return aLocale;
} }
@@ -187,7 +181,7 @@ css::lang::Locale MsLangId::getFallbackLocale(
{ {
// empty language => LANGUAGE_SYSTEM // empty language => LANGUAGE_SYSTEM
if (rLocale.Language.isEmpty()) if (rLocale.Language.isEmpty())
return Conversion::lookupFallbackLocale( Conversion::convertLanguageToLocale( LANGUAGE_SYSTEM, true)); return Conversion::lookupFallbackLocale( Conversion::convertLanguageToLocale( LANGUAGE_SYSTEM ));
else else
return Conversion::lookupFallbackLocale( rLocale); return Conversion::lookupFallbackLocale( rLocale);
} }

View File

@@ -961,7 +961,7 @@ LanguageTag::ImplPtr LanguageTag::registerImpl() const
// May have involved canonicalize(), so compare with // May have involved canonicalize(), so compare with
// pImpl->maBcp47 instead of maBcp47! // pImpl->maBcp47 instead of maBcp47!
aBcp47 = LanguageTagImpl::convertToBcp47( aBcp47 = LanguageTagImpl::convertToBcp47(
MsLangId::Conversion::convertLanguageToLocale( pImpl->mnLangID, true)); MsLangId::Conversion::convertLanguageToLocale( pImpl->mnLangID ));
bInsert = (aBcp47 == pImpl->maBcp47); bInsert = (aBcp47 == pImpl->maBcp47);
} }
} }
@@ -1344,7 +1344,7 @@ void LanguageTagImpl::convertLocaleToBcp47()
// locale via LanguageTag::convertToBcp47(LanguageType) and // locale via LanguageTag::convertToBcp47(LanguageType) and
// LanguageTag::convertToLocale(LanguageType) would instantiate another // LanguageTag::convertToLocale(LanguageType) would instantiate another
// LanguageTag. // LanguageTag.
maLocale = MsLangId::Conversion::convertLanguageToLocale( LANGUAGE_SYSTEM, true); maLocale = MsLangId::Conversion::convertLanguageToLocale( LANGUAGE_SYSTEM );
} }
if (maLocale.Language.isEmpty()) if (maLocale.Language.isEmpty())
{ {
@@ -1488,7 +1488,7 @@ void LanguageTagImpl::convertLangToLocale()
mbInitializedLangID = true; mbInitializedLangID = true;
} }
// Resolve system here! The original is remembered as mbSystemLocale. // Resolve system here! The original is remembered as mbSystemLocale.
maLocale = MsLangId::Conversion::convertLanguageToLocale( mnLangID, true); maLocale = MsLangId::Conversion::convertLanguageToLocale( mnLangID );
mbInitializedLocale = true; mbInitializedLocale = true;
} }

View File

@@ -267,15 +267,9 @@ public:
const Bcp47CountryEntry * pEntry ); const Bcp47CountryEntry * pEntry );
/** Convert a LanguageType to a Locale. /** Convert a LanguageType to a Locale. */
@param bResolveSystem
If bResolveSystem==true, a LANGUAGE_SYSTEM is resolved.
If bResolveSystem==false, a LANGUAGE_SYSTEM results in an
empty Locale.
*/
I18NLANGTAG_DLLPRIVATE static css::lang::Locale convertLanguageToLocale( I18NLANGTAG_DLLPRIVATE static css::lang::Locale convertLanguageToLocale(
LanguageType nLang, bool bResolveSystem ); LanguageType nLang );
/** Used by convertLanguageToLocale(LanguageType,bool) and /** Used by convertLanguageToLocale(LanguageType,bool) and
getLocale(IsoLanguageCountryEntry*) and getLocale(IsoLanguageCountryEntry*) and

View File

@@ -41,8 +41,7 @@ namespace linguistic
std::vector< OUString > std::vector< OUString >
MergeProposalSeqs( MergeProposalSeqs(
std::vector< OUString > &rAlt1, std::vector< OUString > &rAlt1,
std::vector< OUString > &rAlt2, std::vector< OUString > &rAlt2 );
bool bAllowDuplicates );
void SeqRemoveNegEntries( void SeqRemoveNegEntries(
std::vector< OUString > &rSeq, std::vector< OUString > &rSeq,

View File

@@ -48,7 +48,7 @@ namespace jfw
{ {
OString getElement(OString const & docPath, OString getElement(OString const & docPath,
xmlChar const * pathExpression, bool bThrowIfEmpty) xmlChar const * pathExpression)
{ {
//Prepare the xml document and context //Prepare the xml document and context
OSL_ASSERT(!docPath.isEmpty()); OSL_ASSERT(!docPath.isEmpty());
@@ -70,10 +70,9 @@ OString getElement(OString const & docPath,
OString sValue; OString sValue;
if (xmlXPathNodeSetIsEmpty(pathObj->nodesetval)) if (xmlXPathNodeSetIsEmpty(pathObj->nodesetval))
{ {
if (bThrowIfEmpty) throw FrameworkException(
throw FrameworkException( JFW_E_ERROR,
JFW_E_ERROR, "[Java framework] Error in function getElement (elements.cxx)");
"[Java framework] Error in function getElement (elements.cxx)");
} }
else else
{ {
@@ -85,7 +84,7 @@ OString getElement(OString const & docPath,
OString getElementUpdated() OString getElementUpdated()
{ {
return getElement(jfw::getVendorSettingsPath(), return getElement(jfw::getVendorSettingsPath(),
reinterpret_cast<xmlChar const *>("/jf:javaSelection/jf:updated/text()"), true); reinterpret_cast<xmlChar const *>("/jf:javaSelection/jf:updated/text()"));
} }
void createSettingsStructure(xmlDoc * document, bool * bNeedsSave) void createSettingsStructure(xmlDoc * document, bool * bNeedsSave)

View File

@@ -125,7 +125,7 @@ void SeqRemoveNegEntries( std::vector< OUString > &rSeq,
{ {
std::vector< OUString > aNew; std::vector< OUString > aNew;
// merge sequence without duplicates and empty strings in new empty sequence // merge sequence without duplicates and empty strings in new empty sequence
aNew = MergeProposalSeqs( aNew, rSeq, false ); aNew = MergeProposalSeqs( aNew, rSeq );
rSeq = aNew; rSeq = aNew;
} }
} }
@@ -133,38 +133,30 @@ void SeqRemoveNegEntries( std::vector< OUString > &rSeq,
std::vector< OUString > MergeProposalSeqs( std::vector< OUString > MergeProposalSeqs(
std::vector< OUString > &rAlt1, std::vector< OUString > &rAlt1,
std::vector< OUString > &rAlt2, std::vector< OUString > &rAlt2 )
bool bAllowDuplicates )
{ {
std::vector< OUString > aMerged; std::vector< OUString > aMerged;
if (rAlt1.empty() && bAllowDuplicates) size_t nAltCount1 = rAlt1.size();
aMerged = rAlt2; size_t nAltCount2 = rAlt2.size();
else if (rAlt2.empty() && bAllowDuplicates)
aMerged = rAlt1; sal_Int32 nCountNew = std::min<sal_Int32>( nAltCount1 + nAltCount2, (sal_Int32) MAX_PROPOSALS );
else aMerged.resize( nCountNew );
sal_Int32 nIndex = 0;
sal_Int32 i = 0;
for (int j = 0; j < 2; j++)
{ {
size_t nAltCount1 = rAlt1.size(); sal_Int32 nCount = j == 0 ? nAltCount1 : nAltCount2;
size_t nAltCount2 = rAlt2.size(); std::vector< OUString >& rAlt = j == 0 ? rAlt1 : rAlt2;
for (i = 0; i < nCount && nIndex < MAX_PROPOSALS; i++)
sal_Int32 nCountNew = std::min<sal_Int32>( nAltCount1 + nAltCount2, (sal_Int32) MAX_PROPOSALS );
aMerged.resize( nCountNew );
sal_Int32 nIndex = 0;
sal_Int32 i = 0;
for (int j = 0; j < 2; j++)
{ {
sal_Int32 nCount = j == 0 ? nAltCount1 : nAltCount2; if (!rAlt[i].isEmpty() &&
std::vector< OUString >& rAlt = j == 0 ? rAlt1 : rAlt2; !SeqHasEntry(aMerged, rAlt[i] ))
for (i = 0; i < nCount && nIndex < MAX_PROPOSALS; i++) aMerged[ nIndex++ ] = rAlt[ i ];
{
if (!rAlt[i].isEmpty() &&
(bAllowDuplicates || !SeqHasEntry(aMerged, rAlt[i] )))
aMerged[ nIndex++ ] = rAlt[ i ];
}
} }
aMerged.resize( nIndex );
} }
aMerged.resize( nIndex );
return aMerged; return aMerged;
} }