bug #70740: r=mjudge, sr=sfraser. Provide case-insensitive comparison for all string classes

This commit is contained in:
scc%mozilla.org 2001-04-18 05:20:06 +00:00
Родитель e389036f8f
Коммит ff2c1cc949
4 изменённых файлов: 164 добавлений и 28 удалений

Просмотреть файл

@ -598,7 +598,27 @@ nsAString::EndWriting( iterator& aResult )
return aResult;
}
NS_COM int Compare( const nsAString& lhs, const nsAString& rhs );
class NS_COM nsStringComparator
{
public:
virtual int operator()( const PRUnichar*, const PRUnichar*, PRUint32 aLength ) const = 0;
};
class NS_COM nsDefaultStringComparator
: public nsStringComparator
{
public:
virtual int operator()( const PRUnichar*, const PRUnichar*, PRUint32 aLength ) const;
};
class NS_COM nsCaseInsensitiveStringComparator
: public nsStringComparator
{
public:
virtual int operator()( const PRUnichar*, const PRUnichar*, PRUint32 aLength ) const;
};
NS_COM int Compare( const nsAString& lhs, const nsAString& rhs, const nsStringComparator& = nsDefaultStringComparator() );
inline
PRBool
@ -706,7 +726,28 @@ nsACString::EndWriting( iterator& aResult )
return aResult;
}
NS_COM int Compare( const nsACString& lhs, const nsACString& rhs );
class NS_COM nsCStringComparator
{
public:
virtual int operator()( const char*, const char*, PRUint32 aLength ) const = 0;
};
class NS_COM nsDefaultCStringComparator
: public nsCStringComparator
{
public:
virtual int operator()( const char*, const char*, PRUint32 aLength ) const;
};
class NS_COM nsCaseInsensitiveCStringComparator
: public nsCStringComparator
{
public:
virtual int operator()( const char*, const char*, PRUint32 aLength ) const;
};
NS_COM int Compare( const nsACString& lhs, const nsACString& rhs, const nsCStringComparator& = nsDefaultCStringComparator() );
inline
PRBool

Просмотреть файл

@ -24,11 +24,24 @@
#include "nsAString.h"
#include "nsPromiseSubstring.h"
#include "nsLocalString.h"
#include "nsCRT.h"
int
nsDefaultStringComparator::operator()( const PRUnichar* lhs, const PRUnichar* rhs, PRUint32 aLength ) const
{
return nsCharTraits<PRUnichar>::compare(lhs, rhs, aLength);
}
int
nsCaseInsensitiveStringComparator::operator()( const PRUnichar* lhs, const PRUnichar* rhs, PRUint32 aLength ) const
{
return nsCRT::strncasecmp(lhs, rhs, aLength);
}
NS_COM
int
Compare( const nsAString& lhs, const nsAString& rhs )
Compare( const nsAString& lhs, const nsAString& rhs, const nsStringComparator& aComparator )
{
typedef nsAString::size_type size_type;
@ -43,8 +56,6 @@ Compare( const nsAString& lhs, const nsAString& rhs )
lhs.BeginReading(leftIter);
rhs.BeginReading(rightIter);
int result;
for (;;)
{
size_type lengthAvailable = size_type( NS_MIN(leftIter.size_forward(), rightIter.size_forward()) );
@ -52,9 +63,12 @@ Compare( const nsAString& lhs, const nsAString& rhs )
if ( lengthAvailable > lengthToCompare )
lengthAvailable = lengthToCompare;
// Note: |result| should be declared in this |if| expression, but some compilers don't like that
if ( (result = nsCharTraits<PRUnichar>::compare(leftIter.get(), rightIter.get(), lengthAvailable)) != 0 )
return result;
{
int result;
// Note: |result| should be declared in this |if| expression, but some compilers don't like that
if ( (result = aComparator(leftIter.get(), rightIter.get(), lengthAvailable)) != 0 )
return result;
}
if ( !(lengthToCompare -= lengthAvailable) )
break;
@ -475,9 +489,21 @@ nsAString::do_ReplaceFromReadable( index_type cutStart, size_type cutLength, con
int
nsDefaultCStringComparator::operator()( const char* lhs, const char* rhs, PRUint32 aLength ) const
{
return nsCharTraits<char>::compare(lhs, rhs, aLength);
}
int
nsCaseInsensitiveCStringComparator::operator()( const char* lhs, const char* rhs, PRUint32 aLength ) const
{
return nsCRT::strncasecmp(lhs, rhs, aLength);
}
NS_COM
int
Compare( const nsACString& lhs, const nsACString& rhs )
Compare( const nsACString& lhs, const nsACString& rhs, const nsCStringComparator& aComparator )
{
typedef nsACString::size_type size_type;
@ -492,8 +518,6 @@ Compare( const nsACString& lhs, const nsACString& rhs )
lhs.BeginReading(leftIter);
rhs.BeginReading(rightIter);
int result;
for (;;)
{
size_type lengthAvailable = size_type( NS_MIN(leftIter.size_forward(), rightIter.size_forward()) );
@ -501,9 +525,12 @@ Compare( const nsACString& lhs, const nsACString& rhs )
if ( lengthAvailable > lengthToCompare )
lengthAvailable = lengthToCompare;
// Note: |result| should be declared in this |if| expression, but some compilers don't like that
if ( (result = nsCharTraits<char>::compare(leftIter.get(), rightIter.get(), lengthAvailable)) != 0 )
return result;
{
int result;
// Note: |result| should be declared in this |if| expression, but some compilers don't like that
if ( (result = aComparator(leftIter.get(), rightIter.get(), lengthAvailable)) != 0 )
return result;
}
if ( !(lengthToCompare -= lengthAvailable) )
break;

Просмотреть файл

@ -598,7 +598,27 @@ nsAString::EndWriting( iterator& aResult )
return aResult;
}
NS_COM int Compare( const nsAString& lhs, const nsAString& rhs );
class NS_COM nsStringComparator
{
public:
virtual int operator()( const PRUnichar*, const PRUnichar*, PRUint32 aLength ) const = 0;
};
class NS_COM nsDefaultStringComparator
: public nsStringComparator
{
public:
virtual int operator()( const PRUnichar*, const PRUnichar*, PRUint32 aLength ) const;
};
class NS_COM nsCaseInsensitiveStringComparator
: public nsStringComparator
{
public:
virtual int operator()( const PRUnichar*, const PRUnichar*, PRUint32 aLength ) const;
};
NS_COM int Compare( const nsAString& lhs, const nsAString& rhs, const nsStringComparator& = nsDefaultStringComparator() );
inline
PRBool
@ -706,7 +726,28 @@ nsACString::EndWriting( iterator& aResult )
return aResult;
}
NS_COM int Compare( const nsACString& lhs, const nsACString& rhs );
class NS_COM nsCStringComparator
{
public:
virtual int operator()( const char*, const char*, PRUint32 aLength ) const = 0;
};
class NS_COM nsDefaultCStringComparator
: public nsCStringComparator
{
public:
virtual int operator()( const char*, const char*, PRUint32 aLength ) const;
};
class NS_COM nsCaseInsensitiveCStringComparator
: public nsCStringComparator
{
public:
virtual int operator()( const char*, const char*, PRUint32 aLength ) const;
};
NS_COM int Compare( const nsACString& lhs, const nsACString& rhs, const nsCStringComparator& = nsDefaultCStringComparator() );
inline
PRBool

Просмотреть файл

@ -24,11 +24,24 @@
#include "nsAString.h"
#include "nsPromiseSubstring.h"
#include "nsLocalString.h"
#include "nsCRT.h"
int
nsDefaultStringComparator::operator()( const PRUnichar* lhs, const PRUnichar* rhs, PRUint32 aLength ) const
{
return nsCharTraits<PRUnichar>::compare(lhs, rhs, aLength);
}
int
nsCaseInsensitiveStringComparator::operator()( const PRUnichar* lhs, const PRUnichar* rhs, PRUint32 aLength ) const
{
return nsCRT::strncasecmp(lhs, rhs, aLength);
}
NS_COM
int
Compare( const nsAString& lhs, const nsAString& rhs )
Compare( const nsAString& lhs, const nsAString& rhs, const nsStringComparator& aComparator )
{
typedef nsAString::size_type size_type;
@ -43,8 +56,6 @@ Compare( const nsAString& lhs, const nsAString& rhs )
lhs.BeginReading(leftIter);
rhs.BeginReading(rightIter);
int result;
for (;;)
{
size_type lengthAvailable = size_type( NS_MIN(leftIter.size_forward(), rightIter.size_forward()) );
@ -52,9 +63,12 @@ Compare( const nsAString& lhs, const nsAString& rhs )
if ( lengthAvailable > lengthToCompare )
lengthAvailable = lengthToCompare;
// Note: |result| should be declared in this |if| expression, but some compilers don't like that
if ( (result = nsCharTraits<PRUnichar>::compare(leftIter.get(), rightIter.get(), lengthAvailable)) != 0 )
return result;
{
int result;
// Note: |result| should be declared in this |if| expression, but some compilers don't like that
if ( (result = aComparator(leftIter.get(), rightIter.get(), lengthAvailable)) != 0 )
return result;
}
if ( !(lengthToCompare -= lengthAvailable) )
break;
@ -475,9 +489,21 @@ nsAString::do_ReplaceFromReadable( index_type cutStart, size_type cutLength, con
int
nsDefaultCStringComparator::operator()( const char* lhs, const char* rhs, PRUint32 aLength ) const
{
return nsCharTraits<char>::compare(lhs, rhs, aLength);
}
int
nsCaseInsensitiveCStringComparator::operator()( const char* lhs, const char* rhs, PRUint32 aLength ) const
{
return nsCRT::strncasecmp(lhs, rhs, aLength);
}
NS_COM
int
Compare( const nsACString& lhs, const nsACString& rhs )
Compare( const nsACString& lhs, const nsACString& rhs, const nsCStringComparator& aComparator )
{
typedef nsACString::size_type size_type;
@ -492,8 +518,6 @@ Compare( const nsACString& lhs, const nsACString& rhs )
lhs.BeginReading(leftIter);
rhs.BeginReading(rightIter);
int result;
for (;;)
{
size_type lengthAvailable = size_type( NS_MIN(leftIter.size_forward(), rightIter.size_forward()) );
@ -501,9 +525,12 @@ Compare( const nsACString& lhs, const nsACString& rhs )
if ( lengthAvailable > lengthToCompare )
lengthAvailable = lengthToCompare;
// Note: |result| should be declared in this |if| expression, but some compilers don't like that
if ( (result = nsCharTraits<char>::compare(leftIter.get(), rightIter.get(), lengthAvailable)) != 0 )
return result;
{
int result;
// Note: |result| should be declared in this |if| expression, but some compilers don't like that
if ( (result = aComparator(leftIter.get(), rightIter.get(), lengthAvailable)) != 0 )
return result;
}
if ( !(lengthToCompare -= lengthAvailable) )
break;