summaryrefslogtreecommitdiff
path: root/i18nlangtag
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2013-09-03 14:17:54 +0200
committerEike Rathke <erack@redhat.com>2013-09-03 14:30:14 +0200
commit7c032aa60eaccde88a9064a80bb69fe8076a040b (patch)
tree3067766fcd68db6739d4b77ab7697f093ec5e54c /i18nlangtag
parentc318f19c492f76e3b7d557257b3706f05b6fed62 (diff)
resolve all known fallbacks
Needed for rsc during build time to not pull in liblangtag and its data. Change-Id: I1d4dd32b04ed93ec75720132a30b66ef63fec179
Diffstat (limited to 'i18nlangtag')
-rw-r--r--i18nlangtag/Library_i18nlangtag.mk1
-rw-r--r--i18nlangtag/source/languagetag/languagetag.cxx42
2 files changed, 41 insertions, 2 deletions
diff --git a/i18nlangtag/Library_i18nlangtag.mk b/i18nlangtag/Library_i18nlangtag.mk
index fd1548b0d882..30b6e012ab12 100644
--- a/i18nlangtag/Library_i18nlangtag.mk
+++ b/i18nlangtag/Library_i18nlangtag.mk
@@ -21,6 +21,7 @@ $(eval $(call gb_Library_use_libraries,i18nlangtag,\
))
$(eval $(call gb_Library_use_externals,i18nlangtag,\
+ boost_headers \
icu_headers \
icuuc \
))
diff --git a/i18nlangtag/source/languagetag/languagetag.cxx b/i18nlangtag/source/languagetag/languagetag.cxx
index 65236ce4cc84..de48d068ca88 100644
--- a/i18nlangtag/source/languagetag/languagetag.cxx
+++ b/i18nlangtag/source/languagetag/languagetag.cxx
@@ -16,6 +16,7 @@
#include <osl/file.hxx>
#include <rtl/instance.hxx>
#include <rtl/locale.h>
+#include <boost/unordered_set.hpp>
//#define erDEBUG
@@ -46,13 +47,44 @@ struct myLtError
~myLtError() { if (p) lt_error_unref( p); }
};
-
// "statics" to be returned as const reference to an empty locale and string.
namespace {
struct theEmptyLocale : public rtl::Static< lang::Locale, theEmptyLocale > {};
struct theEmptyBcp47 : public rtl::Static< OUString, theEmptyBcp47 > {};
}
+typedef ::boost::unordered_set< OUString, OUStringHash > KnownTagSet;
+namespace {
+struct theKnowns : public rtl::Static< KnownTagSet, theKnowns > {};
+struct theMutex : public rtl::Static< osl::Mutex, theMutex > {};
+}
+
+static const KnownTagSet & getKnowns()
+{
+ KnownTagSet & rKnowns = theKnowns::get();
+ if (rKnowns.empty())
+ {
+ osl::MutexGuard aGuard( theMutex::get());
+ if (rKnowns.empty())
+ {
+ ::std::vector< MsLangId::LanguagetagMapping > aDefined( MsLangId::getDefinedLanguagetags());
+ for (::std::vector< MsLangId::LanguagetagMapping >::const_iterator it( aDefined.begin());
+ it != aDefined.end(); ++it)
+ {
+ // Do not use the BCP47 string here to initialize the
+ // LanguageTag because then canonicalize() would call this
+ // getKnowns() again..
+ ::std::vector< OUString > aFallbacks( LanguageTag( (*it).mnLang).getFallbackStrings());
+ for (::std::vector< OUString >::const_iterator fb( aFallbacks.begin()); fb != aFallbacks.end(); ++fb)
+ {
+ rKnowns.insert( *fb);
+ }
+ }
+ }
+ }
+ return rKnowns;
+}
+
/** A reference holder for liblangtag data de/initialization, one static
instance. Currently implemented such that the first "ref" inits and dtor
@@ -448,7 +480,7 @@ bool LanguageTag::canonicalize()
// Now this is getting funny.. we only have some BCP47 string
// and want to determine if parsing it would be possible
// without using liblangtag just to see if it is a simple known
- // locale.
+ // locale or could fall back to one.
OUString aLanguage, aScript, aCountry, aVariants;
Extraction eExt = simpleExtract( maBcp47, aLanguage, aScript, aCountry, aVariants);
if (eExt != EXTRACTED_NONE)
@@ -512,6 +544,12 @@ bool LanguageTag::canonicalize()
}
if (mnLangID != LANGUAGE_DONTKNOW && mnLangID != LANGUAGE_SYSTEM)
meIsLiblangtagNeeded = DECISION_NO; // known locale
+ else
+ {
+ const KnownTagSet& rKnowns = getKnowns();
+ if (rKnowns.find( maBcp47) != rKnowns.end())
+ meIsLiblangtagNeeded = DECISION_NO; // known fallback
+ }
}
}
if (bTemporaryLocale)