Tag: cws_src680_hsqldb3 User: fs Date: 05/03/21 01:44:50 Modified: /dba/connectivity/source/drivers/hsqldb/ HDriver.cxx
Log: #i44127# fallback to system locale, if necessary fallback to comparing the language parts of locales only, if necessary File Changes: Directory: /dba/connectivity/source/drivers/hsqldb/ =================================================== File [changed]: HDriver.cxx Url: http://dba.openoffice.org/source/browse/dba/connectivity/source/drivers/hsqldb/HDriver.cxx?r1=1.7.10.1&r2=1.7.10.2 Delta lines: +44 -4 -------------------- --- HDriver.cxx 18 Mar 2005 16:42:39 -0000 1.7.10.1 +++ HDriver.cxx 21 Mar 2005 09:44:47 -0000 1.7.10.2 @@ -2,9 +2,9 @@ * * $RCSfile: HDriver.cxx,v $ * - * $Revision: 1.7.10.1 $ + * $Revision: 1.7.10.2 $ * - * last change: $Author: fs $ $Date: 2005/03/18 16:42:39 $ + * last change: $Author: fs $ $Date: 2005/03/21 09:44:47 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -109,6 +109,9 @@ #ifndef _OSL_FILE_H_ #include <osl/file.h> #endif +#ifndef _OSL_PROCESS_H_ +#include <osl/process.h> +#endif //........................................................................ namespace connectivity { @@ -561,7 +564,7 @@ namespace { //.............................................................. - const sal_Char* lcl_getCollationForLocale( const ::rtl::OUString& _rLocaleString ) + const sal_Char* lcl_getCollationForLocale( const ::rtl::OUString& _rLocaleString, bool _bAcceptCountryMismatch = false ) { static const sal_Char* pTranslations[] = { @@ -661,13 +664,36 @@ NULL, NULL }; + ::rtl::OUString sLocaleString( _rLocaleString ); + sal_Char nCompareTermination = 0; + + if ( _bAcceptCountryMismatch ) + { + // strip the country part from the compare string + sal_Int32 nCountrySep = sLocaleString.indexOf( '-' ); + if ( nCountrySep > -1 ) + sLocaleString = sLocaleString.copy( 0, nCountrySep ); + + // the entries in the translation table are compared until the + // - character only, not until the terminating 0 + nCompareTermination = '-'; + } + const sal_Char** pLookup = pTranslations; for ( ; *pLookup; ++pLookup ) { - if ( _rLocaleString.equalsAscii( *pLookup ) ) + sal_Int32 nCompareUntil = 0; + while ( (*pLookup)[ nCompareUntil ] != nCompareTermination ) + ++nCompareUntil; + + if ( sLocaleString.equalsAsciiL( *pLookup, nCompareUntil ) ) return *( pLookup + 1 ); } + if ( !_bAcceptCountryMismatch ) + // second round, this time without matching the country + return lcl_getCollationForLocale( _rLocaleString, true ); + OSL_ENSURE( false, "lcl_getCollationForLocale: unknown locale string, falling back to Latin1_General!" ); return "Latin1_General"; } @@ -719,6 +745,20 @@ catch( const Exception& ) { OSL_ENSURE( sal_False, "lcl_getSystemLocale: caught an exception!" ); + } + if ( !sLocaleString.getLength() ) + { + rtl_Locale* pProcessLocale = NULL; + osl_getProcessLocale( &pProcessLocale ); + + ::rtl::OUStringBuffer aProcLocale; + aProcLocale.append( pProcessLocale->Language->buffer, pProcessLocale->Language->length ); + if ( pProcessLocale->Country->length ) + { + aProcLocale.appendAscii( "-" ); + aProcLocale.append( pProcessLocale->Country->buffer, pProcessLocale->Country->length ); + } + sLocaleString = aProcLocale.makeStringAndClear(); } return sLocaleString; } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
