Simplify a bit
Change-Id: I71ec9be6b2003971cdf3c4c1a2a7c21092a316ca Reviewed-on: https://gerrit.libreoffice.org/c/core/+/148184 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
This commit is contained in:
@@ -684,7 +684,6 @@ IsoLanguageCountryEntry const aImplIsoLangEntries[] =
|
||||
{ LANGUAGE_MULTIPLE, "mul", "" , k0 }, // multiple languages, many languages are used
|
||||
{ LANGUAGE_UNDETERMINED, "und", "" , k0 }, // undetermined language, language cannot be identified
|
||||
{ LANGUAGE_NONE, "zxx", "" , k0 }, // added to ISO 639-2 on 2006-01-11: Used to declare the absence of linguistic information
|
||||
{ LANGUAGE_DONTKNOW, "", "" , k0 } // marks end of table
|
||||
};
|
||||
|
||||
IsoLanguageScriptCountryEntry const aImplIsoLangScriptEntries[] =
|
||||
@@ -779,7 +778,6 @@ IsoLanguageScriptCountryEntry const aImplIsoLangScriptEntries[] =
|
||||
{ LANGUAGE_KAZAKH_CYRILLIC_LSO, "kk-Cyrl", "" , k0 }, // MS reserved
|
||||
{ LANGUAGE_KANURI_NIGERIA, "kr-Latn", "NG", k0 }, // macrolanguage code; MS since rev.15
|
||||
{ LANGUAGE_TAMAZIGHT_ARABIC_MOROCCO, "tzm-Arab", "MA", k0 }, // MS since rev.15, was reserved
|
||||
{ LANGUAGE_DONTKNOW, "", "" , k0 } // marks end of table
|
||||
};
|
||||
|
||||
Bcp47CountryEntry const aImplBcp47CountryEntries[] =
|
||||
@@ -800,7 +798,6 @@ Bcp47CountryEntry const aImplBcp47CountryEntries[] =
|
||||
{ LANGUAGE_OBSOLETE_USER_SPANISH_LATIN_AMERICA, "es-419", "", "", LANGUAGE_SPANISH_LATIN_AMERICA },
|
||||
{ LANGUAGE_USER_INTERSLAVIC_LATIN, "art-Latn-x-interslv", "", "", k0 }, // see discussion in tdf#145853
|
||||
{ LANGUAGE_USER_INTERSLAVIC_CYRILLIC, "art-Cyrl-x-interslv", "", "", k0 },
|
||||
{ LANGUAGE_DONTKNOW, "", "", "", k0 } // marks end of table
|
||||
};
|
||||
|
||||
const IsoLanguageCountryEntry aLastResortFallbackEntry =
|
||||
@@ -985,66 +982,63 @@ void MsLangId::Conversion::convertLanguageToLocaleImpl( LanguageType nLang,
|
||||
Label_Override_Lang_Locale:
|
||||
|
||||
// Search for LangID in BCP47
|
||||
for (const Bcp47CountryEntry* pBcp47Entry = aImplBcp47CountryEntries;
|
||||
pBcp47Entry->mnLang != LANGUAGE_DONTKNOW; ++pBcp47Entry)
|
||||
for (const auto& rBcp47Entry : aImplBcp47CountryEntries)
|
||||
{
|
||||
if (pBcp47Entry->mnLang == nLang)
|
||||
if (rBcp47Entry.mnLang == nLang)
|
||||
{
|
||||
if (bIgnoreOverride || !pBcp47Entry->mnOverride)
|
||||
if (bIgnoreOverride || !rBcp47Entry.mnOverride)
|
||||
{
|
||||
rLocale.Language = I18NLANGTAG_QLT;
|
||||
rLocale.Country = OUString::createFromAscii( pBcp47Entry->maCountry);
|
||||
rLocale.Variant = pBcp47Entry->getTagString();
|
||||
rLocale.Country = OUString::createFromAscii(rBcp47Entry.maCountry);
|
||||
rLocale.Variant = rBcp47Entry.getTagString();
|
||||
return;
|
||||
}
|
||||
else if (pBcp47Entry->mnOverride && pBcp47EntryOverride != pBcp47Entry)
|
||||
else if (rBcp47Entry.mnOverride && pBcp47EntryOverride != &rBcp47Entry)
|
||||
{
|
||||
pBcp47EntryOverride = pBcp47Entry;
|
||||
nLang = getOverrideLang( pBcp47Entry->mnLang, pBcp47Entry->mnOverride);
|
||||
pBcp47EntryOverride = &rBcp47Entry;
|
||||
nLang = getOverrideLang(rBcp47Entry.mnLang, rBcp47Entry.mnOverride);
|
||||
goto Label_Override_Lang_Locale;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Search for LangID in ISO lll-Ssss-CC
|
||||
for (const IsoLanguageScriptCountryEntry* pScriptEntry = aImplIsoLangScriptEntries;
|
||||
pScriptEntry->mnLang != LANGUAGE_DONTKNOW; ++pScriptEntry)
|
||||
for (const auto& rScriptEntry : aImplIsoLangScriptEntries)
|
||||
{
|
||||
if (pScriptEntry->mnLang == nLang)
|
||||
if (rScriptEntry.mnLang == nLang)
|
||||
{
|
||||
if (bIgnoreOverride || !pScriptEntry->mnOverride)
|
||||
if (bIgnoreOverride || !rScriptEntry.mnOverride)
|
||||
{
|
||||
rLocale.Language = I18NLANGTAG_QLT;
|
||||
rLocale.Country = OUString::createFromAscii( pScriptEntry->maCountry);
|
||||
rLocale.Variant = pScriptEntry->getTagString();
|
||||
rLocale.Country = OUString::createFromAscii(rScriptEntry.maCountry);
|
||||
rLocale.Variant = rScriptEntry.getTagString();
|
||||
return;
|
||||
}
|
||||
else if (pScriptEntry->mnOverride && pScriptEntryOverride != pScriptEntry)
|
||||
else if (rScriptEntry.mnOverride && pScriptEntryOverride != &rScriptEntry)
|
||||
{
|
||||
pScriptEntryOverride = pScriptEntry;
|
||||
nLang = getOverrideLang( pScriptEntry->mnLang, pScriptEntry->mnOverride);
|
||||
pScriptEntryOverride = &rScriptEntry;
|
||||
nLang = getOverrideLang(rScriptEntry.mnLang, rScriptEntry.mnOverride);
|
||||
goto Label_Override_Lang_Locale;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Search for LangID in ISO lll-CC
|
||||
for (const IsoLanguageCountryEntry* pEntry = aImplIsoLangEntries;
|
||||
pEntry->mnLang != LANGUAGE_DONTKNOW; ++pEntry)
|
||||
for (const auto& rEntry : aImplIsoLangEntries)
|
||||
{
|
||||
if (pEntry->mnLang == nLang)
|
||||
if (rEntry.mnLang == nLang)
|
||||
{
|
||||
if (bIgnoreOverride || !pEntry->mnOverride)
|
||||
if (bIgnoreOverride || !rEntry.mnOverride)
|
||||
{
|
||||
rLocale.Language = OUString::createFromAscii( pEntry->maLanguage );
|
||||
rLocale.Country = OUString::createFromAscii( pEntry->maCountry );
|
||||
rLocale.Language = OUString::createFromAscii(rEntry.maLanguage);
|
||||
rLocale.Country = OUString::createFromAscii(rEntry.maCountry);
|
||||
rLocale.Variant.clear();
|
||||
return;
|
||||
}
|
||||
else if (pEntry->mnOverride && pEntryOverride != pEntry)
|
||||
else if (rEntry.mnOverride && pEntryOverride != &rEntry)
|
||||
{
|
||||
pEntryOverride = pEntry;
|
||||
nLang = getOverrideLang( pEntry->mnLang, pEntry->mnOverride);
|
||||
pEntryOverride = &rEntry;
|
||||
nLang = getOverrideLang(rEntry.mnLang, rEntry.mnOverride);
|
||||
goto Label_Override_Lang_Locale;
|
||||
}
|
||||
}
|
||||
@@ -1120,25 +1114,23 @@ css::lang::Locale MsLangId::Conversion::lookupFallbackLocale(
|
||||
{
|
||||
// Search in BCP47, only full match and one fallback, for other
|
||||
// fallbacks only LanguageTag can decide.
|
||||
for (const Bcp47CountryEntry* pBcp47Entry = aImplBcp47CountryEntries;
|
||||
pBcp47Entry->mnLang != LANGUAGE_DONTKNOW; ++pBcp47Entry)
|
||||
for (const auto& rBcp47Entry : aImplBcp47CountryEntries)
|
||||
{
|
||||
if ( rLocale.Variant.equalsIgnoreAsciiCase( pBcp47Entry->getTagString()) ||
|
||||
rLocale.Variant.equalsIgnoreAsciiCaseAscii( pBcp47Entry->mpFallback))
|
||||
return getLocale( pBcp47Entry); // may override
|
||||
if ( rLocale.Variant.equalsIgnoreAsciiCase(rBcp47Entry.getTagString()) ||
|
||||
rLocale.Variant.equalsIgnoreAsciiCaseAscii(rBcp47Entry.mpFallback))
|
||||
return getLocale(&rBcp47Entry); // may override
|
||||
}
|
||||
|
||||
// Search in ISO lll-Ssss-CC
|
||||
const IsoLanguageScriptCountryEntry* pFirstScript = nullptr;
|
||||
for (const IsoLanguageScriptCountryEntry* pScriptEntry = aImplIsoLangScriptEntries;
|
||||
pScriptEntry->mnLang != LANGUAGE_DONTKNOW; ++pScriptEntry)
|
||||
for (const auto& rScriptEntry : aImplIsoLangScriptEntries)
|
||||
{
|
||||
if (pScriptEntry->startsInIgnoreAsciiCase( rLocale.Variant))
|
||||
if (rScriptEntry.startsInIgnoreAsciiCase(rLocale.Variant))
|
||||
{
|
||||
if (rLocale.Variant.equalsIgnoreAsciiCase( pScriptEntry->getTagString()))
|
||||
return getLocale( pScriptEntry); // may override
|
||||
if (rLocale.Variant.equalsIgnoreAsciiCase(rScriptEntry.getTagString()))
|
||||
return getLocale(&rScriptEntry); // may override
|
||||
if (!pFirstScript)
|
||||
pFirstScript = pScriptEntry;
|
||||
pFirstScript = &rScriptEntry;
|
||||
}
|
||||
}
|
||||
// If at least a lll-Ssss matched, try that with country or use it as
|
||||
@@ -1150,7 +1142,7 @@ css::lang::Locale MsLangId::Conversion::lookupFallbackLocale(
|
||||
if (!aUpperCountry.isEmpty() && rLocale.Variant.getLength() > 11)
|
||||
{
|
||||
for (const IsoLanguageScriptCountryEntry* pScriptEntry = pFirstScript;
|
||||
pScriptEntry->mnLang != LANGUAGE_DONTKNOW; ++pScriptEntry)
|
||||
pScriptEntry != std::end(aImplIsoLangScriptEntries); ++pScriptEntry)
|
||||
{
|
||||
if (aUpperCountry.equalsAscii( pScriptEntry->maCountry) &&
|
||||
pScriptEntry->startsInIgnoreAsciiCase( rLocale.Variant))
|
||||
@@ -1173,19 +1165,18 @@ css::lang::Locale MsLangId::Conversion::lookupFallbackLocale(
|
||||
|
||||
// Search for locale and remember first lang-only.
|
||||
const IsoLanguageCountryEntry* pFirstLang = nullptr;
|
||||
const IsoLanguageCountryEntry* pEntry = aImplIsoLangEntries;
|
||||
for ( ; pEntry->mnLang != LANGUAGE_DONTKNOW; ++pEntry)
|
||||
for (const auto& rEntry : aImplIsoLangEntries)
|
||||
{
|
||||
if (aLowerLang.equalsAscii( pEntry->maLanguage))
|
||||
if (aLowerLang.equalsAscii(rEntry.maLanguage))
|
||||
{
|
||||
if (*pEntry->maCountry)
|
||||
if (*rEntry.maCountry)
|
||||
{
|
||||
if (nCountryLen && aUpperCountry.equalsAscii( pEntry->maCountry))
|
||||
return getLocale( pEntry); // may override
|
||||
if (nCountryLen && aUpperCountry.equalsAscii(rEntry.maCountry))
|
||||
return getLocale(&rEntry); // may override
|
||||
}
|
||||
else
|
||||
{
|
||||
if (pEntry->mnLang.anyOf(
|
||||
if (rEntry.mnLang.anyOf(
|
||||
// These are known to have no country assigned.
|
||||
LANGUAGE_USER_ESPERANTO,
|
||||
LANGUAGE_USER_INTERLINGUA,
|
||||
@@ -1199,28 +1190,17 @@ css::lang::Locale MsLangId::Conversion::lookupFallbackLocale(
|
||||
LANGUAGE_UNDETERMINED,
|
||||
LANGUAGE_NONE))
|
||||
{
|
||||
return getLocale( pEntry); // may override
|
||||
return getLocale(&rEntry); // may override
|
||||
}
|
||||
}
|
||||
if (!pFirstLang)
|
||||
pFirstLang = pEntry;
|
||||
// Search for first entry of language with any country.
|
||||
if (!pFirstLang && *rEntry.maCountry)
|
||||
pFirstLang = &rEntry;
|
||||
}
|
||||
}
|
||||
|
||||
// Language not found at all => use default.
|
||||
if (!pFirstLang)
|
||||
return aLastResortFallbackEntry.getLocale();
|
||||
|
||||
// Search for first entry of language with any country.
|
||||
pEntry = pFirstLang;
|
||||
for ( ; pEntry->mnLang != LANGUAGE_DONTKNOW; ++pEntry)
|
||||
{
|
||||
if (aLowerLang.equalsAscii( pEntry->maLanguage))
|
||||
{
|
||||
if (*pEntry->maCountry)
|
||||
return getLocale( pEntry); // may override
|
||||
}
|
||||
}
|
||||
if (pFirstLang)
|
||||
return getLocale(pFirstLang); // may override
|
||||
|
||||
return aLastResortFallbackEntry.getLocale();
|
||||
}
|
||||
@@ -1250,21 +1230,19 @@ LanguageType MsLangId::Conversion::convertLocaleToLanguageImpl(
|
||||
return convertPrivateUseToLanguage( rLocale.Variant);
|
||||
|
||||
// Search in BCP47
|
||||
for (const Bcp47CountryEntry* pBcp47Entry = aImplBcp47CountryEntries;
|
||||
pBcp47Entry->mnLang != LANGUAGE_DONTKNOW; ++pBcp47Entry)
|
||||
for (const auto& rBcp47Entry : aImplBcp47CountryEntries)
|
||||
{
|
||||
if (rLocale.Variant.equalsIgnoreAsciiCase( pBcp47Entry->getTagString()))
|
||||
return getOverrideLang( pBcp47Entry->mnLang, pBcp47Entry->mnOverride);
|
||||
if (rLocale.Variant.equalsIgnoreAsciiCase(rBcp47Entry.getTagString()))
|
||||
return getOverrideLang(rBcp47Entry.mnLang, rBcp47Entry.mnOverride);
|
||||
}
|
||||
|
||||
// Search in ISO lll-Ssss-CC
|
||||
for (const IsoLanguageScriptCountryEntry* pScriptEntry = aImplIsoLangScriptEntries;
|
||||
pScriptEntry->mnLang != LANGUAGE_DONTKNOW; ++pScriptEntry)
|
||||
for (const auto& rScriptEntry : aImplIsoLangScriptEntries)
|
||||
{
|
||||
if (pScriptEntry->startsInIgnoreAsciiCase( rLocale.Variant))
|
||||
if (rScriptEntry.startsInIgnoreAsciiCase(rLocale.Variant))
|
||||
{
|
||||
if (rLocale.Variant.equalsIgnoreAsciiCase( pScriptEntry->getTagString()))
|
||||
return getOverrideLang( pScriptEntry->mnLang, pScriptEntry->mnOverride);
|
||||
if (rLocale.Variant.equalsIgnoreAsciiCase(rScriptEntry.getTagString()))
|
||||
return getOverrideLang(rScriptEntry.mnLang, rScriptEntry.mnOverride);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1276,11 +1254,10 @@ LanguageType MsLangId::Conversion::convertLocaleToLanguageImpl(
|
||||
OUString aUpperCountry = rLocale.Country.toAsciiUpperCase();
|
||||
|
||||
// Search in ISO lll-CC
|
||||
for (const IsoLanguageCountryEntry* pEntry = aImplIsoLangEntries;
|
||||
pEntry->mnLang != LANGUAGE_DONTKNOW; ++pEntry)
|
||||
for (const auto& rEntry : aImplIsoLangEntries)
|
||||
{
|
||||
if (aLowerLang.equalsAscii( pEntry->maLanguage) && aUpperCountry.equalsAscii( pEntry->maCountry))
|
||||
return getOverrideLang( pEntry->mnLang, pEntry->mnOverride);
|
||||
if (aLowerLang.equalsAscii(rEntry.maLanguage) && aUpperCountry.equalsAscii(rEntry.maCountry))
|
||||
return getOverrideLang(rEntry.mnLang, rEntry.mnOverride);
|
||||
}
|
||||
}
|
||||
return LANGUAGE_DONTKNOW;
|
||||
@@ -1297,21 +1274,19 @@ css::lang::Locale MsLangId::Conversion::getOverride( const css::lang::Locale& rL
|
||||
return rLocale; // no overrides
|
||||
|
||||
// Search in BCP47
|
||||
for (const Bcp47CountryEntry* pBcp47Entry = aImplBcp47CountryEntries;
|
||||
pBcp47Entry->mnLang != LANGUAGE_DONTKNOW; ++pBcp47Entry)
|
||||
for (const auto& rBcp47Entry : aImplBcp47CountryEntries)
|
||||
{
|
||||
if (rLocale.Variant.equalsIgnoreAsciiCase( pBcp47Entry->getTagString()))
|
||||
return getLocale( pBcp47Entry); // may override
|
||||
if (rLocale.Variant.equalsIgnoreAsciiCase(rBcp47Entry.getTagString()))
|
||||
return getLocale(&rBcp47Entry); // may override
|
||||
}
|
||||
|
||||
// Search in ISO lll-Ssss-CC
|
||||
for (const IsoLanguageScriptCountryEntry* pScriptEntry = aImplIsoLangScriptEntries;
|
||||
pScriptEntry->mnLang != LANGUAGE_DONTKNOW; ++pScriptEntry)
|
||||
for (const auto& rScriptEntry : aImplIsoLangScriptEntries)
|
||||
{
|
||||
if (pScriptEntry->startsInIgnoreAsciiCase( rLocale.Variant))
|
||||
if (rScriptEntry.startsInIgnoreAsciiCase(rLocale.Variant))
|
||||
{
|
||||
if (rLocale.Variant.equalsIgnoreAsciiCase( pScriptEntry->getTagString()))
|
||||
return getLocale( pScriptEntry); // may override
|
||||
if (rLocale.Variant.equalsIgnoreAsciiCase(rScriptEntry.getTagString()))
|
||||
return getLocale(&rScriptEntry); // may override
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1323,11 +1298,10 @@ css::lang::Locale MsLangId::Conversion::getOverride( const css::lang::Locale& rL
|
||||
OUString aUpperCountry = rLocale.Country.toAsciiUpperCase();
|
||||
|
||||
// Search in ISO lll-CC
|
||||
for (const IsoLanguageCountryEntry* pEntry = aImplIsoLangEntries;
|
||||
pEntry->mnLang != LANGUAGE_DONTKNOW; ++pEntry)
|
||||
for (const auto& rEntry : aImplIsoLangEntries)
|
||||
{
|
||||
if (aLowerLang.equalsAscii( pEntry->maLanguage) && aUpperCountry.equalsAscii( pEntry->maCountry))
|
||||
return getLocale( pEntry); // may override
|
||||
if (aLowerLang.equalsAscii(rEntry.maLanguage) && aUpperCountry.equalsAscii(rEntry.maCountry))
|
||||
return getLocale(&rEntry); // may override
|
||||
}
|
||||
}
|
||||
return lang::Locale();
|
||||
@@ -1346,14 +1320,13 @@ LanguageType MsLangId::Conversion::convertIsoNamesToLanguage( const OUString& rL
|
||||
if (!bSkipIsoTable)
|
||||
{
|
||||
// first look for exact match
|
||||
for (const IsoLanguageCountryEntry* pEntry = aImplIsoLangEntries;
|
||||
pEntry->mnLang != LANGUAGE_DONTKNOW; ++pEntry)
|
||||
for (const auto& rEntry : aImplIsoLangEntries)
|
||||
{
|
||||
if ( aLowerLang.equalsAscii( pEntry->maLanguage ) )
|
||||
if ( aLowerLang.equalsAscii(rEntry.maLanguage) )
|
||||
{
|
||||
if ( aUpperCountry.isEmpty() ||
|
||||
aUpperCountry.equalsAscii( pEntry->maCountry ) )
|
||||
return pEntry->mnLang;
|
||||
aUpperCountry.equalsAscii(rEntry.maCountry) )
|
||||
return rEntry.mnLang;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1397,11 +1370,10 @@ LanguageType MsLangId::Conversion::convertIsoNamesToLanguage( const OUString& rL
|
||||
// (to allow reading country and language in separate steps, in any order)
|
||||
if ( !rCountry.isEmpty() && rLang.isEmpty() )
|
||||
{
|
||||
for (const IsoLanguageCountryEntry* pEntry2 = aImplIsoLangEntries;
|
||||
pEntry2->mnLang != LANGUAGE_DONTKNOW; ++pEntry2)
|
||||
for (const auto& rEntry2 : aImplIsoLangEntries)
|
||||
{
|
||||
if ( aUpperCountry.equalsAscii( pEntry2->maCountry ) )
|
||||
return pEntry2->mnLang;
|
||||
if ( aUpperCountry.equalsAscii(rEntry2.maCountry) )
|
||||
return rEntry2.mnLang;
|
||||
}
|
||||
|
||||
aLowerLang = aUpperCountry.toAsciiLowerCase();
|
||||
@@ -1541,21 +1513,18 @@ LanguageType MsLangId::convertUnxByteStringToLanguage(
|
||||
::std::vector< MsLangId::LanguagetagMapping > MsLangId::getDefinedLanguagetags()
|
||||
{
|
||||
::std::vector< LanguagetagMapping > aVec;
|
||||
for (const Bcp47CountryEntry* pEntry = aImplBcp47CountryEntries;
|
||||
pEntry->mnLang != LANGUAGE_DONTKNOW; ++pEntry)
|
||||
{
|
||||
aVec.emplace_back( pEntry->getTagString(), pEntry->mnLang);
|
||||
}
|
||||
for (const IsoLanguageScriptCountryEntry* pEntry = aImplIsoLangScriptEntries;
|
||||
pEntry->mnLang != LANGUAGE_DONTKNOW; ++pEntry)
|
||||
{
|
||||
aVec.emplace_back( pEntry->getTagString(), pEntry->mnLang);
|
||||
}
|
||||
for (const IsoLanguageCountryEntry* pEntry = aImplIsoLangEntries;
|
||||
pEntry->mnLang != LANGUAGE_DONTKNOW; ++pEntry)
|
||||
{
|
||||
aVec.emplace_back( pEntry->getTagString(), pEntry->mnLang);
|
||||
}
|
||||
aVec.reserve(std::size(aImplBcp47CountryEntries) + std::size(aImplIsoLangScriptEntries)
|
||||
+ std::size(aImplIsoLangEntries));
|
||||
|
||||
for (const auto& rEntry : aImplBcp47CountryEntries)
|
||||
aVec.emplace_back(rEntry.getTagString(), rEntry.mnLang);
|
||||
|
||||
for (const auto& rEntry : aImplIsoLangScriptEntries)
|
||||
aVec.emplace_back(rEntry.getTagString(), rEntry.mnLang);
|
||||
|
||||
for (const auto& rEntry : aImplIsoLangEntries)
|
||||
aVec.emplace_back(rEntry.getTagString(), rEntry.mnLang);
|
||||
|
||||
return aVec;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user