summaryrefslogtreecommitdiff
path: root/scripting
diff options
context:
space:
mode:
authorVladimir Glazounov <vg@openoffice.org>2008-01-28 12:58:20 +0000
committerVladimir Glazounov <vg@openoffice.org>2008-01-28 12:58:20 +0000
commitb3bbdd5d59e72f350830aea7f31d6fb5d6e36172 (patch)
tree6a450c8dfce3c48e81ee8cd47ba27b525d3693ba /scripting
parent1142acabd6f323109cdc764093138a788bb55d71 (diff)
INTEGRATION: CWS ab42 (1.4.38); FILE MERGED
2008/01/07 13:17:23 ab 1.4.38.1: #i82278# Fixed closest match algorithm
Diffstat (limited to 'scripting')
-rw-r--r--scripting/source/stringresource/stringresource.cxx56
1 files changed, 38 insertions, 18 deletions
diff --git a/scripting/source/stringresource/stringresource.cxx b/scripting/source/stringresource/stringresource.cxx
index a11f5b3305d9..f96445466166 100644
--- a/scripting/source/stringresource/stringresource.cxx
+++ b/scripting/source/stringresource/stringresource.cxx
@@ -4,9 +4,9 @@
*
* $RCSfile: stringresource.cxx,v $
*
- * $Revision: 1.4 $
+ * $Revision: 1.5 $
*
- * last change: $Author: rt $ $Date: 2007-01-29 16:26:23 $
+ * last change: $Author: vg $ $Date: 2008-01-28 13:58:20 $
*
* The Contents of this file are made available subject to
* the terms of GNU Lesser General Public License Version 2.1.
@@ -394,23 +394,12 @@ void StringResourceImpl::setCurrentLocale( const Locale& locale, sal_Bool FindCl
{
::osl::MutexGuard aGuard( getMutex() );
- (void)locale;
- (void)FindClosestMatch;
+ LocaleItem* pLocaleItem = NULL;
+ if( FindClosestMatch )
+ pLocaleItem = getClosestMatchItemForLocale( locale );
+ else
+ pLocaleItem = getItemForLocale( locale, true );
- LocaleItem* pLocaleItem = getItemForLocale( locale, !FindClosestMatch );
- if( pLocaleItem == NULL && FindClosestMatch )
- {
- Locale aTestLocale( locale );
- aTestLocale.Variant = ::rtl::OUString();
- pLocaleItem = getItemForLocale( locale, false );
- if( pLocaleItem == NULL )
- {
- aTestLocale.Country = ::rtl::OUString();
- pLocaleItem = getItemForLocale( locale, false );
- if( pLocaleItem == NULL && m_pDefaultLocaleItem != NULL )
- pLocaleItem = m_pDefaultLocaleItem;
- }
- }
if( pLocaleItem != NULL )
{
loadLocale( pLocaleItem );
@@ -724,6 +713,37 @@ LocaleItem* StringResourceImpl::getItemForLocale
return pRetItem;
}
+// Returns the LocalItem for a given locale, if it exists, otherwise NULL
+// This method performes a closest match search, at least the language must match
+LocaleItem* StringResourceImpl::getClosestMatchItemForLocale( const Locale& locale )
+{
+ LocaleItem* pRetItem = NULL;
+
+ // Search for locale
+ for( sal_Int32 iPass = 0 ; iPass <= 2 ; ++iPass )
+ {
+ for( LocaleItemVectorConstIt it = m_aLocaleItemVector.begin(); it != m_aLocaleItemVector.end(); it++ )
+ {
+ LocaleItem* pLocaleItem = *it;
+ if( pLocaleItem )
+ {
+ Locale& cmp_locale = pLocaleItem->m_locale;
+ if( cmp_locale.Language == locale.Language &&
+ (iPass > 1 || cmp_locale.Country == locale.Country) &&
+ (iPass > 0 || cmp_locale.Variant == locale.Variant) )
+ {
+ pRetItem = pLocaleItem;
+ break;
+ }
+ }
+ }
+ if( pRetItem )
+ break;
+ }
+
+ return pRetItem;
+}
+
void StringResourceImpl::implModified( void )
{
m_bModified = true;