summaryrefslogtreecommitdiff
path: root/i18nlangtag
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2013-07-11 16:46:20 +0200
committerEike Rathke <erack@redhat.com>2013-07-11 17:48:14 +0200
commit00de85cc75e3501a5597c2f293407b1b76fef429 (patch)
treee8110972db71d069f7d8b88b3793d4938a1c8050 /i18nlangtag
parent547affaf66ea063970438e321e98b0f788a3027c (diff)
added getMatchingFallback()
Change-Id: I5805ab98049bd7dfd8ca1b58632f6c0115197bdd
Diffstat (limited to 'i18nlangtag')
-rw-r--r--i18nlangtag/source/languagetag/languagetag.cxx45
1 files changed, 45 insertions, 0 deletions
diff --git a/i18nlangtag/source/languagetag/languagetag.cxx b/i18nlangtag/source/languagetag/languagetag.cxx
index 13e25f8b8197..4aefa79e6c8d 100644
--- a/i18nlangtag/source/languagetag/languagetag.cxx
+++ b/i18nlangtag/source/languagetag/languagetag.cxx
@@ -1312,4 +1312,49 @@ LanguageTag::Extraction LanguageTag::simpleExtract( const OUString& rBcp47,
}
+// static
+::std::vector< com::sun::star::lang::Locale >::const_iterator LanguageTag::getMatchingFallback(
+ const ::std::vector< com::sun::star::lang::Locale > & rList,
+ const com::sun::star::lang::Locale & rReference )
+{
+ if (rList.empty())
+ return rList.end();
+
+ ::std::vector< lang::Locale >::const_iterator it;
+
+ // Try the simple case first without constructing fallbacks.
+ for (it = rList.begin(); it != rList.end(); ++it)
+ {
+ if ( (*it).Language == rReference.Language &&
+ (*it).Country == rReference.Country &&
+ (*it).Variant == rReference.Variant)
+ return it; // exact match
+ }
+
+ // Now for each reference fallback test the fallbacks of the list in order.
+ ::std::vector< OUString > aFallbacks( LanguageTag( rReference).getFallbackStrings());
+ aFallbacks.erase( aFallbacks.begin()); // first is full BCP47, we already checked that
+ ::std::vector< ::std::vector< OUString > > aListFallbacks( rList.size());
+ for (it = rList.begin(); it != rList.end(); ++it)
+ {
+ ::std::vector< OUString > aTmp( LanguageTag( *it).getFallbackStrings());
+ aListFallbacks.push_back( aTmp);
+ }
+ for (::std::vector< OUString >::const_iterator rfb( aFallbacks.begin()); rfb != aFallbacks.end(); ++rfb)
+ {
+ for (::std::vector< ::std::vector< OUString > >::const_iterator lfb( aListFallbacks.begin());
+ lfb != aListFallbacks.end(); ++lfb)
+ {
+ for (::std::vector< OUString >::const_iterator fb( (*lfb).begin()); fb != (*lfb).end(); ++fb)
+ {
+ if (*rfb == *fb)
+ return rList.begin() + (lfb - aListFallbacks.begin());
+ }
+ }
+ }
+
+ // No match found.
+ return rList.end();
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */