summaryrefslogtreecommitdiff
path: root/comphelper
diff options
context:
space:
mode:
authorFrank Schoenheit [fs] <frank.schoenheit@oracle.com>2011-01-18 22:11:21 +0100
committerFrank Schoenheit [fs] <frank.schoenheit@oracle.com>2011-01-18 22:11:21 +0100
commit7ad4e757c3a37889e77ecc60081ef12c27cb8815 (patch)
tree924e0b126648b5323d56cef4f29933ef1aff3734 /comphelper
parent73c1b2ce0dc2f7fe7cb698404f1f15f1534431e1 (diff)
gridsort: getStandardLessPredicate: optional collator instance for string comparison
Diffstat (limited to 'comphelper')
-rwxr-xr-xcomphelper/inc/comphelper/anycompare.hxx57
-rw-r--r--comphelper/source/container/enumerablemap.cxx2
-rwxr-xr-xcomphelper/source/misc/anycompare.cxx8
3 files changed, 56 insertions, 11 deletions
diff --git a/comphelper/inc/comphelper/anycompare.hxx b/comphelper/inc/comphelper/anycompare.hxx
index 94a97e4d78fc..03f41e108ba9 100755
--- a/comphelper/inc/comphelper/anycompare.hxx
+++ b/comphelper/inc/comphelper/anycompare.hxx
@@ -31,6 +31,7 @@
/** === begin UNO includes === **/
#include <com/sun/star/lang/IllegalArgumentException.hpp>
+#include <com/sun/star/i18n/XCollator.hpp>
/** === end UNO includes === **/
#include <comphelper/extract.hxx>
@@ -88,7 +89,7 @@ namespace comphelper
if ( !( _lhs >>= lhs )
|| !( _rhs >>= rhs )
)
- throw ::com::sun::star::lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unsupported key type." ) ), NULL, 1 );
+ throw ::com::sun::star::lang::IllegalArgumentException();
return lhs < rhs;
}
};
@@ -105,12 +106,37 @@ namespace comphelper
if ( !( _lhs >>= lhs )
|| !( _rhs >>= rhs )
)
- throw ::com::sun::star::lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unsupported key type." ) ), NULL, 1 );
+ throw ::com::sun::star::lang::IllegalArgumentException();
return lhs < rhs;
}
};
//==================================================================================================================
+ //= StringCollationPredicateLess
+ //==================================================================================================================
+ class StringCollationPredicateLess : public IKeyPredicateLess
+ {
+ public:
+ StringCollationPredicateLess( ::com::sun::star::uno::Reference< ::com::sun::star::i18n::XCollator > const & i_collator )
+ :m_collator( i_collator )
+ {
+ }
+
+ virtual bool isLess( ::com::sun::star::uno::Any const & _lhs, ::com::sun::star::uno::Any const & _rhs ) const
+ {
+ ::rtl::OUString lhs, rhs;
+ if ( !( _lhs >>= lhs )
+ || !( _rhs >>= rhs )
+ )
+ throw ::com::sun::star::lang::IllegalArgumentException();
+ return m_collator->compareString( lhs, rhs ) < 0;
+ }
+
+ private:
+ ::com::sun::star::uno::Reference< ::com::sun::star::i18n::XCollator > const m_collator;
+ };
+
+ //==================================================================================================================
//= TypePredicateLess
//==================================================================================================================
class TypePredicateLess : public IKeyPredicateLess
@@ -122,7 +148,7 @@ namespace comphelper
if ( !( _lhs >>= lhs )
|| !( _rhs >>= rhs )
)
- throw ::com::sun::star::lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unsupported key type." ) ), NULL, 1 );
+ throw ::com::sun::star::lang::IllegalArgumentException();
return lhs.getTypeName() < rhs.getTypeName();
}
};
@@ -146,7 +172,7 @@ namespace comphelper
|| !_lhs.getValueType().equals( m_enumType )
|| !_rhs.getValueType().equals( m_enumType )
)
- throw ::com::sun::star::lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unsupported key type." ) ), NULL, 1 );
+ throw ::com::sun::star::lang::IllegalArgumentException();
return lhs < rhs;
}
@@ -165,7 +191,7 @@ namespace comphelper
if ( ( _lhs.getValueTypeClass() != ::com::sun::star::uno::TypeClass_INTERFACE )
|| ( _rhs.getValueTypeClass() != ::com::sun::star::uno::TypeClass_INTERFACE )
)
- throw ::com::sun::star::lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unsupported key type." ) ), NULL, 1 );
+ throw ::com::sun::star::lang::IllegalArgumentException();
::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > lhs( _lhs, ::com::sun::star::uno::UNO_QUERY );
::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > rhs( _rhs, ::com::sun::star::uno::UNO_QUERY );
@@ -174,9 +200,24 @@ namespace comphelper
};
//==================================================================================================================
- //= InterfacePredicateLess
- //==================================================================================================================
- ::std::auto_ptr< IKeyPredicateLess > COMPHELPER_DLLPUBLIC getStandardLessPredicate( ::com::sun::star::uno::Type const & i_type );
+ //= getStandardLessPredicate
+ //==================================================================================================================
+ /** creates a default IKeyPredicateLess instance for the given UNO type
+ @param i_type
+ the type for which a predicate instance should be created
+ @param i_collator
+ specifies a collator instance to use, or <NULL/>. If <NULL/>, strings will be compared using the <code>&lt</code>
+ operator, otherwise the collator will be used. The parameter is ignored if <arg>i_type</arg> does not specify
+ the string type.
+ @return
+ a default implementation of IKeyPredicateLess, which is able to compare values of the given type. If no
+ such default implementation is known for the given type, then <NULL/> is returned.
+ */
+ ::std::auto_ptr< IKeyPredicateLess > COMPHELPER_DLLPUBLIC
+ getStandardLessPredicate(
+ ::com::sun::star::uno::Type const & i_type,
+ ::com::sun::star::uno::Reference< ::com::sun::star::i18n::XCollator > const & i_collator
+ );
//......................................................................................................................
} // namespace comphelper
diff --git a/comphelper/source/container/enumerablemap.cxx b/comphelper/source/container/enumerablemap.cxx
index ecc9494056ee..a73983517751 100644
--- a/comphelper/source/container/enumerablemap.cxx
+++ b/comphelper/source/container/enumerablemap.cxx
@@ -405,7 +405,7 @@ namespace comphelper
throw IllegalTypeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unsupported value type." ) ), *this );
// create the comparator for the KeyType, and throw if the type is not supported
- ::std::auto_ptr< IKeyPredicateLess > pComparator( getStandardLessPredicate( aKeyType ) );
+ ::std::auto_ptr< IKeyPredicateLess > pComparator( getStandardLessPredicate( aKeyType, NULL ) );
if ( !pComparator.get() )
throw IllegalTypeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unsupported key type." ) ), *this );
diff --git a/comphelper/source/misc/anycompare.cxx b/comphelper/source/misc/anycompare.cxx
index 2a6b7abda265..a86174daf08e 100755
--- a/comphelper/source/misc/anycompare.cxx
+++ b/comphelper/source/misc/anycompare.cxx
@@ -63,10 +63,11 @@ namespace comphelper
using ::com::sun::star::uno::TypeClass_TYPE;
using ::com::sun::star::uno::TypeClass_ENUM;
using ::com::sun::star::uno::TypeClass_INTERFACE;
+ using ::com::sun::star::i18n::XCollator;
/** === end UNO using === **/
//------------------------------------------------------------------------------------------------------------------
- ::std::auto_ptr< IKeyPredicateLess > getStandardLessPredicate( ::com::sun::star::uno::Type const & i_type )
+ ::std::auto_ptr< IKeyPredicateLess > getStandardLessPredicate( Type const & i_type, Reference< XCollator > const & i_collator )
{
::std::auto_ptr< IKeyPredicateLess > pComparator;
switch ( i_type.getTypeClass() )
@@ -105,7 +106,10 @@ namespace comphelper
pComparator.reset( new ScalarPredicateLess< double >() );
break;
case TypeClass_STRING:
- pComparator.reset( new StringPredicateLess() );
+ if ( i_collator.is() )
+ pComparator.reset( new StringCollationPredicateLess( i_collator ) );
+ else
+ pComparator.reset( new StringPredicateLess() );
break;
case TypeClass_TYPE:
pComparator.reset( new TypePredicateLess() );