major upgrade to string class implementation

This commit is contained in:
rickg%netscape.com 1998-08-03 20:46:38 +00:00
Родитель 2a744becdb
Коммит 42fbaf0a68
10 изменённых файлов: 3220 добавлений и 2840 удалений

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

@ -15,6 +15,23 @@
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/**
* MODULE NOTES:
* @update gess7/30/98
*
* Much as I hate to do it, we were using string compares wrong.
* Often, programmers call functions like strcmp(s1,s2), and pass
* one or more null strings. Rather than blow up on these, I've
* added quick checks to ensure that cases like this don't cause
* us to fail.
*
* In general, if you pass a null into any of these string compare
* routines, we simply return 0.
*/
#include "nsCRT.h"
// XXX Bug: These tables don't lowercase the upper 128 characters properly
@ -123,137 +140,228 @@ PRUnichar nsCRT::ToLower(PRUnichar aChar)
PRInt32 nsCRT::strlen(const PRUnichar* s)
{
PRInt32 len = 0;
while (*s++ != 0) {
len++;
if(s) {
while (*s++ != 0) {
len++;
}
}
return len;
}
/**
* Compare unichar string ptrs, stopping at the 1st null
* NOTE: If both are null, we return 0.
* @update gess7/30/98
* @param s1 and s2 both point to unichar strings
* @return 1 if they match, 0 if not
*/
PRInt32 nsCRT::strcmp(const PRUnichar* s1, const PRUnichar* s2)
{
for (;;) {
PRUnichar c1 = *s1++;
PRUnichar c2 = *s2++;
if (c1 != c2) {
if (c1 < c2) return -1;
return 1;
if(s1 && s2) {
for (;;) {
PRUnichar c1 = *s1++;
PRUnichar c2 = *s2++;
if (c1 != c2) {
if (c1 < c2) return -1;
return 1;
}
if ((0==c1) || (0==c2)) break;
}
if (c1 == 0) break;
}
return 0;
}
// characters following a null character are not compared
/**
* Compare unichar string ptrs, stopping at the 1st null or nth char.
* NOTE: If either is null, we return 0.
* @update gess7/30/98
* @param s1 and s2 both point to unichar strings
* @return 1 if they match, 0 if not
*/
PRInt32 nsCRT::strncmp(const PRUnichar* s1, const PRUnichar* s2, PRInt32 n)
{
while (--n >= 0) {
PRUnichar c1 = *s1++;
PRUnichar c2 = *s2++;
if (c1 != c2) {
if (c1 < c2) return -1;
return 1;
if(s1 && s2) {
if(0<n) {
while (--n >= 0) {
PRUnichar c1 = *s1++;
PRUnichar c2 = *s2++;
if (c1 != c2) {
if (c1 < c2) return -1;
return 1;
}
if ((0==c1) || (0==c2)) break;
}
}
if (c1 == 0) break;
else return 1;
}
return 0;
}
/**
* Compare unichar string ptrs without regard to case
* NOTE: If both are null, we return 0.
* @update gess7/30/98
* @param s1 and s2 both point to unichar strings
* @return 1 if they match, 0 if not
*/
PRInt32 nsCRT::strcasecmp(const PRUnichar* s1, const PRUnichar* s2)
{
for (;;) {
PRUnichar c1 = *s1++;
PRUnichar c2 = *s2++;
if (c1 != c2) {
c1 = TOLOWER(c1);
c2 = TOLOWER(c2);
if(s1 && s2) {
for (;;) {
PRUnichar c1 = *s1++;
PRUnichar c2 = *s2++;
if (c1 != c2) {
if (c1 < c2) return -1;
return 1;
c1 = TOLOWER(c1);
c2 = TOLOWER(c2);
if (c1 != c2) {
if (c1 < c2) return -1;
return 1;
}
}
if ((0==c1) || (0==c2)) break;
}
if (c1 == 0) break;
}
return 0;
}
/**
* Compare unichar string ptrs, stopping at the 1st null or nth char;
* also ignoring the case of characters.
* NOTE: If both are null, we return 0.
* @update gess7/30/98
* @param s1 and s2 both point to unichar strings
* @return 1 if they match, 0 if not
*/
PRInt32 nsCRT::strncasecmp(const PRUnichar* s1, const PRUnichar* s2, PRInt32 n)
{
while (--n >= 0) {
PRUnichar c1 = *s1++;
PRUnichar c2 = *s2++;
if (c1 != c2) {
c1 = TOLOWER(c1);
c2 = TOLOWER(c2);
if (c1 != c2) {
if (c1 < c2) return -1;
return 1;
if(s1 && s2) {
if(0<n){
while (--n >= 0) {
PRUnichar c1 = *s1++;
PRUnichar c2 = *s2++;
if (c1 != c2) {
c1 = TOLOWER(c1);
c2 = TOLOWER(c2);
if (c1 != c2) {
if (c1 < c2) return -1;
return 1;
}
}
if ((0==c1) || (0==c2)) break;
}
}
if (c1 == 0) break;
} else return 1;
}
return 0;
}
/**
* Compare a unichar string ptr to cstring.
* NOTE: If both are null, we return 0.
* @update gess7/30/98
* @param s1 points to unichar string
* @param s2 points to cstring
* @return 1 if they match, 0 if not
*/
PRInt32 nsCRT::strcmp(const PRUnichar* s1, const char* s2)
{
for (;;) {
PRUnichar c1 = *s1++;
PRUnichar c2 = kIsoLatin1ToUCS2[*(const unsigned char*)s2++];
if (c1 != c2) {
if (c1 < c2) return -1;
return 1;
if(s1 && s2) {
for (;;) {
PRUnichar c1 = *s1++;
PRUnichar c2 = kIsoLatin1ToUCS2[*(const unsigned char*)s2++];
if (c1 != c2) {
if (c1 < c2) return -1;
return 1;
}
if ((0==c1) || (0==c2)) break;
}
if (c1 == 0) break;
}
return 0;
}
/**
* Compare a unichar string ptr to cstring, up to N chars.
* NOTE: If both are null, we return 0.
* @update gess7/30/98
* @param s1 points to unichar string
* @param s2 points to cstring
* @return 1 if they match, 0 if not
*/
PRInt32 nsCRT::strncmp(const PRUnichar* s1, const char* s2, PRInt32 n)
{
while (--n >= 0) {
PRUnichar c1 = *s1++;
PRUnichar c2 = kIsoLatin1ToUCS2[*(const unsigned char*)s2++];
if (c1 != c2) {
if (c1 < c2) return -1;
return 1;
}
if (c1 == 0) break;
if(s1 && s2) {
if(0<n){
while (--n >= 0) {
PRUnichar c1 = *s1++;
PRUnichar c2 = kIsoLatin1ToUCS2[*(const unsigned char*)s2++];
if (c1 != c2) {
if (c1 < c2) return -1;
return 1;
}
if ((0==c1) || (0==c2)) break;
}
} else return 1;
}
return 0;
}
/**
* Compare a unichar string ptr to cstring without regard to case
* NOTE: If both are null, we return 0.
* @update gess7/30/98
* @param s1 points to unichar string
* @param s2 points to cstring
* @return 1 if they match, 0 if not
*/
PRInt32 nsCRT::strcasecmp(const PRUnichar* s1, const char* s2)
{
for (;;) {
PRUnichar c1 = *s1++;
PRUnichar c2 = kIsoLatin1ToUCS2[*(const unsigned char*)s2++];
if (c1 != c2) {
c1 = TOLOWER(c1);
c2 = TOLOWER(c2);
if(s1 && s2) {
for (;;) {
PRUnichar c1 = *s1++;
PRUnichar c2 = kIsoLatin1ToUCS2[*(const unsigned char*)s2++];
if (c1 != c2) {
if (c1 < c2) return -1;
return 1;
c1 = TOLOWER(c1);
c2 = TOLOWER(c2);
if (c1 != c2) {
if (c1 < c2) return -1;
return 1;
}
}
if ((0==c1) || (0==c2)) break;
}
if (c1 == 0) break;
}
return 0;
}
/**
* Caseless compare up to N chars between unichar string ptr to cstring.
* NOTE: If both are null, we return 0.
* @update gess7/30/98
* @param s1 points to unichar string
* @param s2 points to cstring
* @return 1 if they match, 0 if not
*/
PRInt32 nsCRT::strncasecmp(const PRUnichar* s1, const char* s2, PRInt32 n)
{
while (--n >= 0) {
PRUnichar c1 = *s1++;
PRUnichar c2 = kIsoLatin1ToUCS2[*(const unsigned char*)s2++];
if (c1 != c2) {
c1 = TOLOWER(c1);
c2 = TOLOWER(c2);
if (c1 != c2) {
if (c1 < c2) return -1;
return 1;
if(s1 && s2){
if(0<n){
while (--n >= 0) {
PRUnichar c1 = *s1++;
PRUnichar c2 = kIsoLatin1ToUCS2[*(const unsigned char*)s2++];
if (c1 != c2) {
c1 = TOLOWER(c1);
c2 = TOLOWER(c2);
if (c1 != c2) {
if (c1 < c2) return -1;
return 1;
}
}
if (c1 == 0) break;
}
}
if (c1 == 0) break;
} else return 1;
}
return 0;
}
@ -261,10 +369,12 @@ PRInt32 nsCRT::strncasecmp(const PRUnichar* s1, const char* s2, PRInt32 n)
PRInt32 nsCRT::HashCode(const PRUnichar* us)
{
PRInt32 rv = 0;
PRUnichar ch;
while ((ch = *us++) != 0) {
// FYI: rv = rv*37 + ch
rv = ((rv << 5) + (rv << 2) + rv) + ch;
if(us) {
PRUnichar ch;
while ((ch = *us++) != 0) {
// FYI: rv = rv*37 + ch
rv = ((rv << 5) + (rv << 2) + rv) + ch;
}
}
return rv;
}

Разница между файлами не показана из-за своего большого размера Загрузить разницу

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

@ -58,10 +58,9 @@ class NS_BASE nsString {
///accessor methods
//@{
PRUnichar* GetUnicode(void) const;
const PRUnichar* GetUnicode(void) const;
operator PRUnichar*() const;
PRUnichar* operator()() const;
PRUnichar operator()(PRInt32 i) const;
PRUnichar& operator[](PRInt32 i) const;
PRUnichar& CharAt(PRInt32 anIndex) const;
@ -84,7 +83,7 @@ class NS_BASE nsString {
char* ToNewCString() const;
char* ToCString(char* aBuf,PRInt32 aBufLength) const;
void ToString(nsString& aString) const;
void Copy(nsString& aString) const;
PRUnichar* ToNewUnicode() const;
float ToFloat(PRInt32* aErrorCode) const;
@ -93,18 +92,20 @@ class NS_BASE nsString {
///string manipulation methods...
//@{
nsString& SetString(const PRUnichar* aStr,PRInt32 aLength=-1);
nsString& SetString(const char* anISOLatin1,PRInt32 aLength=-1);
nsString& operator=(const nsString& aString);
nsString& operator=(const char* anISOLatin1);
nsString& operator=(char aChar);
nsString& operator=(const PRUnichar* aBuffer);
nsString& operator=(PRUnichar aChar);
nsString& SetString(const PRUnichar* aStr,PRInt32 aLength=-1);
nsString& SetString(const char* anISOLatin1,PRInt32 aLength=-1);
nsString& operator+=(const nsString& aString);
nsString& operator+=(const char* anISOLatin1);
nsString& operator+=(const PRUnichar* aBuffer);
nsString& operator+=(PRUnichar aChar);
nsString& Append(const nsString& aString,PRInt32 aLength=-1);
nsString& Append(const char* anISOLatin1,PRInt32 aLength=-1);
nsString& Append(char aChar);
@ -152,35 +153,35 @@ class NS_BASE nsString {
///comparision methods...
//@{
virtual PRInt32 Compare(const nsString &S,PRBool aIgnoreCase=PR_FALSE) const;
virtual PRInt32 Compare(const char *anISOLatin1,PRBool aIgnoreCase=PR_FALSE) const;
virtual PRInt32 Compare(const PRUnichar *aString,PRBool aIgnoreCase=PR_FALSE) const;
virtual PRInt32 Compare(const char *anISOLatin1,PRInt32 aLength=-1,PRBool aIgnoreCase=PR_FALSE) const;
virtual PRInt32 Compare(const PRUnichar *aString,PRInt32 aLength=-1,PRBool aIgnoreCase=PR_FALSE) const;
PRInt32 operator==(const nsString &S) const;
PRInt32 operator==(const char *anISOLatin1) const;
PRInt32 operator==(const PRUnichar* aString) const;
PRInt32 operator!=(const nsString &S) const;
PRInt32 operator!=(const char *anISOLatin1) const;
PRInt32 operator!=(const PRUnichar* aString) const;
PRInt32 operator<(const nsString &S) const;
PRInt32 operator<(const char *anISOLatin1) const;
PRInt32 operator<(const PRUnichar* aString) const;
PRInt32 operator>(const nsString &S) const;
PRInt32 operator>(const char *anISOLatin1) const;
PRInt32 operator>(const PRUnichar* aString) const;
PRInt32 operator<=(const nsString &S) const;
PRInt32 operator<=(const char *anISOLatin1) const;
PRInt32 operator<=(const PRUnichar* aString) const;
PRInt32 operator>=(const nsString &S) const;
PRInt32 operator>=(const char *anISOLatin1) const;
PRInt32 operator>=(const PRUnichar* aString) const;
PRBool operator==(const nsString &S) const;
PRBool operator==(const char *anISOLatin1) const;
PRBool operator==(const PRUnichar* aString) const;
PRBool operator!=(const nsString &S) const;
PRBool operator!=(const char *anISOLatin1) const;
PRBool operator!=(const PRUnichar* aString) const;
PRBool operator<(const nsString &S) const;
PRBool operator<(const char *anISOLatin1) const;
PRBool operator<(const PRUnichar* aString) const;
PRBool operator>(const nsString &S) const;
PRBool operator>(const char *anISOLatin1) const;
PRBool operator>(const PRUnichar* aString) const;
PRBool operator<=(const nsString &S) const;
PRBool operator<=(const char *anISOLatin1) const;
PRBool operator<=(const PRUnichar* aString) const;
PRBool operator>=(const nsString &S) const;
PRBool operator>=(const char *anISOLatin1) const;
PRBool operator>=(const PRUnichar* aString) const;
PRBool Equals(const nsString& aString) const;
PRBool Equals(const char* anISOLatin1) const;
PRBool Equals(const char* anISOLatin1,PRInt32 aLength=-1) const;
PRBool Equals(const nsIAtom *aAtom) const;
PRBool Equals(const PRUnichar* s1, const PRUnichar* s2) const;
PRBool EqualsIgnoreCase(const nsString& aString) const;
PRBool EqualsIgnoreCase(const char* anISOLatin1) const;
PRBool EqualsIgnoreCase(const char* anISOLatin1,PRInt32 aLength=-1) const;
PRBool EqualsIgnoreCase(const nsIAtom *aAtom) const;
PRBool EqualsIgnoreCase(const PRUnichar* s1, const PRUnichar* s2) const;
//@}
@ -195,6 +196,7 @@ typedef PRUnichar chartype;
chartype* mStr;
PRInt32 mLength;
PRInt32 mCapacity;
static PRBool mSelfTested;
};
extern NS_BASE int fputs(const nsString& aString, FILE* out);

Разница между файлами не показана из-за своего большого размера Загрузить разницу

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

@ -58,10 +58,9 @@ class NS_BASE nsString {
///accessor methods
//@{
PRUnichar* GetUnicode(void) const;
const PRUnichar* GetUnicode(void) const;
operator PRUnichar*() const;
PRUnichar* operator()() const;
PRUnichar operator()(PRInt32 i) const;
PRUnichar& operator[](PRInt32 i) const;
PRUnichar& CharAt(PRInt32 anIndex) const;
@ -84,7 +83,7 @@ class NS_BASE nsString {
char* ToNewCString() const;
char* ToCString(char* aBuf,PRInt32 aBufLength) const;
void ToString(nsString& aString) const;
void Copy(nsString& aString) const;
PRUnichar* ToNewUnicode() const;
float ToFloat(PRInt32* aErrorCode) const;
@ -93,18 +92,20 @@ class NS_BASE nsString {
///string manipulation methods...
//@{
nsString& SetString(const PRUnichar* aStr,PRInt32 aLength=-1);
nsString& SetString(const char* anISOLatin1,PRInt32 aLength=-1);
nsString& operator=(const nsString& aString);
nsString& operator=(const char* anISOLatin1);
nsString& operator=(char aChar);
nsString& operator=(const PRUnichar* aBuffer);
nsString& operator=(PRUnichar aChar);
nsString& SetString(const PRUnichar* aStr,PRInt32 aLength=-1);
nsString& SetString(const char* anISOLatin1,PRInt32 aLength=-1);
nsString& operator+=(const nsString& aString);
nsString& operator+=(const char* anISOLatin1);
nsString& operator+=(const PRUnichar* aBuffer);
nsString& operator+=(PRUnichar aChar);
nsString& Append(const nsString& aString,PRInt32 aLength=-1);
nsString& Append(const char* anISOLatin1,PRInt32 aLength=-1);
nsString& Append(char aChar);
@ -152,35 +153,35 @@ class NS_BASE nsString {
///comparision methods...
//@{
virtual PRInt32 Compare(const nsString &S,PRBool aIgnoreCase=PR_FALSE) const;
virtual PRInt32 Compare(const char *anISOLatin1,PRBool aIgnoreCase=PR_FALSE) const;
virtual PRInt32 Compare(const PRUnichar *aString,PRBool aIgnoreCase=PR_FALSE) const;
virtual PRInt32 Compare(const char *anISOLatin1,PRInt32 aLength=-1,PRBool aIgnoreCase=PR_FALSE) const;
virtual PRInt32 Compare(const PRUnichar *aString,PRInt32 aLength=-1,PRBool aIgnoreCase=PR_FALSE) const;
PRInt32 operator==(const nsString &S) const;
PRInt32 operator==(const char *anISOLatin1) const;
PRInt32 operator==(const PRUnichar* aString) const;
PRInt32 operator!=(const nsString &S) const;
PRInt32 operator!=(const char *anISOLatin1) const;
PRInt32 operator!=(const PRUnichar* aString) const;
PRInt32 operator<(const nsString &S) const;
PRInt32 operator<(const char *anISOLatin1) const;
PRInt32 operator<(const PRUnichar* aString) const;
PRInt32 operator>(const nsString &S) const;
PRInt32 operator>(const char *anISOLatin1) const;
PRInt32 operator>(const PRUnichar* aString) const;
PRInt32 operator<=(const nsString &S) const;
PRInt32 operator<=(const char *anISOLatin1) const;
PRInt32 operator<=(const PRUnichar* aString) const;
PRInt32 operator>=(const nsString &S) const;
PRInt32 operator>=(const char *anISOLatin1) const;
PRInt32 operator>=(const PRUnichar* aString) const;
PRBool operator==(const nsString &S) const;
PRBool operator==(const char *anISOLatin1) const;
PRBool operator==(const PRUnichar* aString) const;
PRBool operator!=(const nsString &S) const;
PRBool operator!=(const char *anISOLatin1) const;
PRBool operator!=(const PRUnichar* aString) const;
PRBool operator<(const nsString &S) const;
PRBool operator<(const char *anISOLatin1) const;
PRBool operator<(const PRUnichar* aString) const;
PRBool operator>(const nsString &S) const;
PRBool operator>(const char *anISOLatin1) const;
PRBool operator>(const PRUnichar* aString) const;
PRBool operator<=(const nsString &S) const;
PRBool operator<=(const char *anISOLatin1) const;
PRBool operator<=(const PRUnichar* aString) const;
PRBool operator>=(const nsString &S) const;
PRBool operator>=(const char *anISOLatin1) const;
PRBool operator>=(const PRUnichar* aString) const;
PRBool Equals(const nsString& aString) const;
PRBool Equals(const char* anISOLatin1) const;
PRBool Equals(const char* anISOLatin1,PRInt32 aLength=-1) const;
PRBool Equals(const nsIAtom *aAtom) const;
PRBool Equals(const PRUnichar* s1, const PRUnichar* s2) const;
PRBool EqualsIgnoreCase(const nsString& aString) const;
PRBool EqualsIgnoreCase(const char* anISOLatin1) const;
PRBool EqualsIgnoreCase(const char* anISOLatin1,PRInt32 aLength=-1) const;
PRBool EqualsIgnoreCase(const nsIAtom *aAtom) const;
PRBool EqualsIgnoreCase(const PRUnichar* s1, const PRUnichar* s2) const;
//@}
@ -195,6 +196,7 @@ typedef PRUnichar chartype;
chartype* mStr;
PRInt32 mLength;
PRInt32 mCapacity;
static PRBool mSelfTested;
};
extern NS_BASE int fputs(const nsString& aString, FILE* out);

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

@ -15,6 +15,23 @@
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/**
* MODULE NOTES:
* @update gess7/30/98
*
* Much as I hate to do it, we were using string compares wrong.
* Often, programmers call functions like strcmp(s1,s2), and pass
* one or more null strings. Rather than blow up on these, I've
* added quick checks to ensure that cases like this don't cause
* us to fail.
*
* In general, if you pass a null into any of these string compare
* routines, we simply return 0.
*/
#include "nsCRT.h"
// XXX Bug: These tables don't lowercase the upper 128 characters properly
@ -123,137 +140,228 @@ PRUnichar nsCRT::ToLower(PRUnichar aChar)
PRInt32 nsCRT::strlen(const PRUnichar* s)
{
PRInt32 len = 0;
while (*s++ != 0) {
len++;
if(s) {
while (*s++ != 0) {
len++;
}
}
return len;
}
/**
* Compare unichar string ptrs, stopping at the 1st null
* NOTE: If both are null, we return 0.
* @update gess7/30/98
* @param s1 and s2 both point to unichar strings
* @return 1 if they match, 0 if not
*/
PRInt32 nsCRT::strcmp(const PRUnichar* s1, const PRUnichar* s2)
{
for (;;) {
PRUnichar c1 = *s1++;
PRUnichar c2 = *s2++;
if (c1 != c2) {
if (c1 < c2) return -1;
return 1;
if(s1 && s2) {
for (;;) {
PRUnichar c1 = *s1++;
PRUnichar c2 = *s2++;
if (c1 != c2) {
if (c1 < c2) return -1;
return 1;
}
if ((0==c1) || (0==c2)) break;
}
if (c1 == 0) break;
}
return 0;
}
// characters following a null character are not compared
/**
* Compare unichar string ptrs, stopping at the 1st null or nth char.
* NOTE: If either is null, we return 0.
* @update gess7/30/98
* @param s1 and s2 both point to unichar strings
* @return 1 if they match, 0 if not
*/
PRInt32 nsCRT::strncmp(const PRUnichar* s1, const PRUnichar* s2, PRInt32 n)
{
while (--n >= 0) {
PRUnichar c1 = *s1++;
PRUnichar c2 = *s2++;
if (c1 != c2) {
if (c1 < c2) return -1;
return 1;
if(s1 && s2) {
if(0<n) {
while (--n >= 0) {
PRUnichar c1 = *s1++;
PRUnichar c2 = *s2++;
if (c1 != c2) {
if (c1 < c2) return -1;
return 1;
}
if ((0==c1) || (0==c2)) break;
}
}
if (c1 == 0) break;
else return 1;
}
return 0;
}
/**
* Compare unichar string ptrs without regard to case
* NOTE: If both are null, we return 0.
* @update gess7/30/98
* @param s1 and s2 both point to unichar strings
* @return 1 if they match, 0 if not
*/
PRInt32 nsCRT::strcasecmp(const PRUnichar* s1, const PRUnichar* s2)
{
for (;;) {
PRUnichar c1 = *s1++;
PRUnichar c2 = *s2++;
if (c1 != c2) {
c1 = TOLOWER(c1);
c2 = TOLOWER(c2);
if(s1 && s2) {
for (;;) {
PRUnichar c1 = *s1++;
PRUnichar c2 = *s2++;
if (c1 != c2) {
if (c1 < c2) return -1;
return 1;
c1 = TOLOWER(c1);
c2 = TOLOWER(c2);
if (c1 != c2) {
if (c1 < c2) return -1;
return 1;
}
}
if ((0==c1) || (0==c2)) break;
}
if (c1 == 0) break;
}
return 0;
}
/**
* Compare unichar string ptrs, stopping at the 1st null or nth char;
* also ignoring the case of characters.
* NOTE: If both are null, we return 0.
* @update gess7/30/98
* @param s1 and s2 both point to unichar strings
* @return 1 if they match, 0 if not
*/
PRInt32 nsCRT::strncasecmp(const PRUnichar* s1, const PRUnichar* s2, PRInt32 n)
{
while (--n >= 0) {
PRUnichar c1 = *s1++;
PRUnichar c2 = *s2++;
if (c1 != c2) {
c1 = TOLOWER(c1);
c2 = TOLOWER(c2);
if (c1 != c2) {
if (c1 < c2) return -1;
return 1;
if(s1 && s2) {
if(0<n){
while (--n >= 0) {
PRUnichar c1 = *s1++;
PRUnichar c2 = *s2++;
if (c1 != c2) {
c1 = TOLOWER(c1);
c2 = TOLOWER(c2);
if (c1 != c2) {
if (c1 < c2) return -1;
return 1;
}
}
if ((0==c1) || (0==c2)) break;
}
}
if (c1 == 0) break;
} else return 1;
}
return 0;
}
/**
* Compare a unichar string ptr to cstring.
* NOTE: If both are null, we return 0.
* @update gess7/30/98
* @param s1 points to unichar string
* @param s2 points to cstring
* @return 1 if they match, 0 if not
*/
PRInt32 nsCRT::strcmp(const PRUnichar* s1, const char* s2)
{
for (;;) {
PRUnichar c1 = *s1++;
PRUnichar c2 = kIsoLatin1ToUCS2[*(const unsigned char*)s2++];
if (c1 != c2) {
if (c1 < c2) return -1;
return 1;
if(s1 && s2) {
for (;;) {
PRUnichar c1 = *s1++;
PRUnichar c2 = kIsoLatin1ToUCS2[*(const unsigned char*)s2++];
if (c1 != c2) {
if (c1 < c2) return -1;
return 1;
}
if ((0==c1) || (0==c2)) break;
}
if (c1 == 0) break;
}
return 0;
}
/**
* Compare a unichar string ptr to cstring, up to N chars.
* NOTE: If both are null, we return 0.
* @update gess7/30/98
* @param s1 points to unichar string
* @param s2 points to cstring
* @return 1 if they match, 0 if not
*/
PRInt32 nsCRT::strncmp(const PRUnichar* s1, const char* s2, PRInt32 n)
{
while (--n >= 0) {
PRUnichar c1 = *s1++;
PRUnichar c2 = kIsoLatin1ToUCS2[*(const unsigned char*)s2++];
if (c1 != c2) {
if (c1 < c2) return -1;
return 1;
}
if (c1 == 0) break;
if(s1 && s2) {
if(0<n){
while (--n >= 0) {
PRUnichar c1 = *s1++;
PRUnichar c2 = kIsoLatin1ToUCS2[*(const unsigned char*)s2++];
if (c1 != c2) {
if (c1 < c2) return -1;
return 1;
}
if ((0==c1) || (0==c2)) break;
}
} else return 1;
}
return 0;
}
/**
* Compare a unichar string ptr to cstring without regard to case
* NOTE: If both are null, we return 0.
* @update gess7/30/98
* @param s1 points to unichar string
* @param s2 points to cstring
* @return 1 if they match, 0 if not
*/
PRInt32 nsCRT::strcasecmp(const PRUnichar* s1, const char* s2)
{
for (;;) {
PRUnichar c1 = *s1++;
PRUnichar c2 = kIsoLatin1ToUCS2[*(const unsigned char*)s2++];
if (c1 != c2) {
c1 = TOLOWER(c1);
c2 = TOLOWER(c2);
if(s1 && s2) {
for (;;) {
PRUnichar c1 = *s1++;
PRUnichar c2 = kIsoLatin1ToUCS2[*(const unsigned char*)s2++];
if (c1 != c2) {
if (c1 < c2) return -1;
return 1;
c1 = TOLOWER(c1);
c2 = TOLOWER(c2);
if (c1 != c2) {
if (c1 < c2) return -1;
return 1;
}
}
if ((0==c1) || (0==c2)) break;
}
if (c1 == 0) break;
}
return 0;
}
/**
* Caseless compare up to N chars between unichar string ptr to cstring.
* NOTE: If both are null, we return 0.
* @update gess7/30/98
* @param s1 points to unichar string
* @param s2 points to cstring
* @return 1 if they match, 0 if not
*/
PRInt32 nsCRT::strncasecmp(const PRUnichar* s1, const char* s2, PRInt32 n)
{
while (--n >= 0) {
PRUnichar c1 = *s1++;
PRUnichar c2 = kIsoLatin1ToUCS2[*(const unsigned char*)s2++];
if (c1 != c2) {
c1 = TOLOWER(c1);
c2 = TOLOWER(c2);
if (c1 != c2) {
if (c1 < c2) return -1;
return 1;
if(s1 && s2){
if(0<n){
while (--n >= 0) {
PRUnichar c1 = *s1++;
PRUnichar c2 = kIsoLatin1ToUCS2[*(const unsigned char*)s2++];
if (c1 != c2) {
c1 = TOLOWER(c1);
c2 = TOLOWER(c2);
if (c1 != c2) {
if (c1 < c2) return -1;
return 1;
}
}
if (c1 == 0) break;
}
}
if (c1 == 0) break;
} else return 1;
}
return 0;
}
@ -261,10 +369,12 @@ PRInt32 nsCRT::strncasecmp(const PRUnichar* s1, const char* s2, PRInt32 n)
PRInt32 nsCRT::HashCode(const PRUnichar* us)
{
PRInt32 rv = 0;
PRUnichar ch;
while ((ch = *us++) != 0) {
// FYI: rv = rv*37 + ch
rv = ((rv << 5) + (rv << 2) + rv) + ch;
if(us) {
PRUnichar ch;
while ((ch = *us++) != 0) {
// FYI: rv = rv*37 + ch
rv = ((rv << 5) + (rv << 2) + rv) + ch;
}
}
return rv;
}

Разница между файлами не показана из-за своего большого размера Загрузить разницу

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

@ -58,10 +58,9 @@ class NS_BASE nsString {
///accessor methods
//@{
PRUnichar* GetUnicode(void) const;
const PRUnichar* GetUnicode(void) const;
operator PRUnichar*() const;
PRUnichar* operator()() const;
PRUnichar operator()(PRInt32 i) const;
PRUnichar& operator[](PRInt32 i) const;
PRUnichar& CharAt(PRInt32 anIndex) const;
@ -84,7 +83,7 @@ class NS_BASE nsString {
char* ToNewCString() const;
char* ToCString(char* aBuf,PRInt32 aBufLength) const;
void ToString(nsString& aString) const;
void Copy(nsString& aString) const;
PRUnichar* ToNewUnicode() const;
float ToFloat(PRInt32* aErrorCode) const;
@ -93,18 +92,20 @@ class NS_BASE nsString {
///string manipulation methods...
//@{
nsString& SetString(const PRUnichar* aStr,PRInt32 aLength=-1);
nsString& SetString(const char* anISOLatin1,PRInt32 aLength=-1);
nsString& operator=(const nsString& aString);
nsString& operator=(const char* anISOLatin1);
nsString& operator=(char aChar);
nsString& operator=(const PRUnichar* aBuffer);
nsString& operator=(PRUnichar aChar);
nsString& SetString(const PRUnichar* aStr,PRInt32 aLength=-1);
nsString& SetString(const char* anISOLatin1,PRInt32 aLength=-1);
nsString& operator+=(const nsString& aString);
nsString& operator+=(const char* anISOLatin1);
nsString& operator+=(const PRUnichar* aBuffer);
nsString& operator+=(PRUnichar aChar);
nsString& Append(const nsString& aString,PRInt32 aLength=-1);
nsString& Append(const char* anISOLatin1,PRInt32 aLength=-1);
nsString& Append(char aChar);
@ -152,35 +153,35 @@ class NS_BASE nsString {
///comparision methods...
//@{
virtual PRInt32 Compare(const nsString &S,PRBool aIgnoreCase=PR_FALSE) const;
virtual PRInt32 Compare(const char *anISOLatin1,PRBool aIgnoreCase=PR_FALSE) const;
virtual PRInt32 Compare(const PRUnichar *aString,PRBool aIgnoreCase=PR_FALSE) const;
virtual PRInt32 Compare(const char *anISOLatin1,PRInt32 aLength=-1,PRBool aIgnoreCase=PR_FALSE) const;
virtual PRInt32 Compare(const PRUnichar *aString,PRInt32 aLength=-1,PRBool aIgnoreCase=PR_FALSE) const;
PRInt32 operator==(const nsString &S) const;
PRInt32 operator==(const char *anISOLatin1) const;
PRInt32 operator==(const PRUnichar* aString) const;
PRInt32 operator!=(const nsString &S) const;
PRInt32 operator!=(const char *anISOLatin1) const;
PRInt32 operator!=(const PRUnichar* aString) const;
PRInt32 operator<(const nsString &S) const;
PRInt32 operator<(const char *anISOLatin1) const;
PRInt32 operator<(const PRUnichar* aString) const;
PRInt32 operator>(const nsString &S) const;
PRInt32 operator>(const char *anISOLatin1) const;
PRInt32 operator>(const PRUnichar* aString) const;
PRInt32 operator<=(const nsString &S) const;
PRInt32 operator<=(const char *anISOLatin1) const;
PRInt32 operator<=(const PRUnichar* aString) const;
PRInt32 operator>=(const nsString &S) const;
PRInt32 operator>=(const char *anISOLatin1) const;
PRInt32 operator>=(const PRUnichar* aString) const;
PRBool operator==(const nsString &S) const;
PRBool operator==(const char *anISOLatin1) const;
PRBool operator==(const PRUnichar* aString) const;
PRBool operator!=(const nsString &S) const;
PRBool operator!=(const char *anISOLatin1) const;
PRBool operator!=(const PRUnichar* aString) const;
PRBool operator<(const nsString &S) const;
PRBool operator<(const char *anISOLatin1) const;
PRBool operator<(const PRUnichar* aString) const;
PRBool operator>(const nsString &S) const;
PRBool operator>(const char *anISOLatin1) const;
PRBool operator>(const PRUnichar* aString) const;
PRBool operator<=(const nsString &S) const;
PRBool operator<=(const char *anISOLatin1) const;
PRBool operator<=(const PRUnichar* aString) const;
PRBool operator>=(const nsString &S) const;
PRBool operator>=(const char *anISOLatin1) const;
PRBool operator>=(const PRUnichar* aString) const;
PRBool Equals(const nsString& aString) const;
PRBool Equals(const char* anISOLatin1) const;
PRBool Equals(const char* anISOLatin1,PRInt32 aLength=-1) const;
PRBool Equals(const nsIAtom *aAtom) const;
PRBool Equals(const PRUnichar* s1, const PRUnichar* s2) const;
PRBool EqualsIgnoreCase(const nsString& aString) const;
PRBool EqualsIgnoreCase(const char* anISOLatin1) const;
PRBool EqualsIgnoreCase(const char* anISOLatin1,PRInt32 aLength=-1) const;
PRBool EqualsIgnoreCase(const nsIAtom *aAtom) const;
PRBool EqualsIgnoreCase(const PRUnichar* s1, const PRUnichar* s2) const;
//@}
@ -195,6 +196,7 @@ typedef PRUnichar chartype;
chartype* mStr;
PRInt32 mLength;
PRInt32 mCapacity;
static PRBool mSelfTested;
};
extern NS_BASE int fputs(const nsString& aString, FILE* out);

Разница между файлами не показана из-за своего большого размера Загрузить разницу

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

@ -58,10 +58,9 @@ class NS_BASE nsString {
///accessor methods
//@{
PRUnichar* GetUnicode(void) const;
const PRUnichar* GetUnicode(void) const;
operator PRUnichar*() const;
PRUnichar* operator()() const;
PRUnichar operator()(PRInt32 i) const;
PRUnichar& operator[](PRInt32 i) const;
PRUnichar& CharAt(PRInt32 anIndex) const;
@ -84,7 +83,7 @@ class NS_BASE nsString {
char* ToNewCString() const;
char* ToCString(char* aBuf,PRInt32 aBufLength) const;
void ToString(nsString& aString) const;
void Copy(nsString& aString) const;
PRUnichar* ToNewUnicode() const;
float ToFloat(PRInt32* aErrorCode) const;
@ -93,18 +92,20 @@ class NS_BASE nsString {
///string manipulation methods...
//@{
nsString& SetString(const PRUnichar* aStr,PRInt32 aLength=-1);
nsString& SetString(const char* anISOLatin1,PRInt32 aLength=-1);
nsString& operator=(const nsString& aString);
nsString& operator=(const char* anISOLatin1);
nsString& operator=(char aChar);
nsString& operator=(const PRUnichar* aBuffer);
nsString& operator=(PRUnichar aChar);
nsString& SetString(const PRUnichar* aStr,PRInt32 aLength=-1);
nsString& SetString(const char* anISOLatin1,PRInt32 aLength=-1);
nsString& operator+=(const nsString& aString);
nsString& operator+=(const char* anISOLatin1);
nsString& operator+=(const PRUnichar* aBuffer);
nsString& operator+=(PRUnichar aChar);
nsString& Append(const nsString& aString,PRInt32 aLength=-1);
nsString& Append(const char* anISOLatin1,PRInt32 aLength=-1);
nsString& Append(char aChar);
@ -152,35 +153,35 @@ class NS_BASE nsString {
///comparision methods...
//@{
virtual PRInt32 Compare(const nsString &S,PRBool aIgnoreCase=PR_FALSE) const;
virtual PRInt32 Compare(const char *anISOLatin1,PRBool aIgnoreCase=PR_FALSE) const;
virtual PRInt32 Compare(const PRUnichar *aString,PRBool aIgnoreCase=PR_FALSE) const;
virtual PRInt32 Compare(const char *anISOLatin1,PRInt32 aLength=-1,PRBool aIgnoreCase=PR_FALSE) const;
virtual PRInt32 Compare(const PRUnichar *aString,PRInt32 aLength=-1,PRBool aIgnoreCase=PR_FALSE) const;
PRInt32 operator==(const nsString &S) const;
PRInt32 operator==(const char *anISOLatin1) const;
PRInt32 operator==(const PRUnichar* aString) const;
PRInt32 operator!=(const nsString &S) const;
PRInt32 operator!=(const char *anISOLatin1) const;
PRInt32 operator!=(const PRUnichar* aString) const;
PRInt32 operator<(const nsString &S) const;
PRInt32 operator<(const char *anISOLatin1) const;
PRInt32 operator<(const PRUnichar* aString) const;
PRInt32 operator>(const nsString &S) const;
PRInt32 operator>(const char *anISOLatin1) const;
PRInt32 operator>(const PRUnichar* aString) const;
PRInt32 operator<=(const nsString &S) const;
PRInt32 operator<=(const char *anISOLatin1) const;
PRInt32 operator<=(const PRUnichar* aString) const;
PRInt32 operator>=(const nsString &S) const;
PRInt32 operator>=(const char *anISOLatin1) const;
PRInt32 operator>=(const PRUnichar* aString) const;
PRBool operator==(const nsString &S) const;
PRBool operator==(const char *anISOLatin1) const;
PRBool operator==(const PRUnichar* aString) const;
PRBool operator!=(const nsString &S) const;
PRBool operator!=(const char *anISOLatin1) const;
PRBool operator!=(const PRUnichar* aString) const;
PRBool operator<(const nsString &S) const;
PRBool operator<(const char *anISOLatin1) const;
PRBool operator<(const PRUnichar* aString) const;
PRBool operator>(const nsString &S) const;
PRBool operator>(const char *anISOLatin1) const;
PRBool operator>(const PRUnichar* aString) const;
PRBool operator<=(const nsString &S) const;
PRBool operator<=(const char *anISOLatin1) const;
PRBool operator<=(const PRUnichar* aString) const;
PRBool operator>=(const nsString &S) const;
PRBool operator>=(const char *anISOLatin1) const;
PRBool operator>=(const PRUnichar* aString) const;
PRBool Equals(const nsString& aString) const;
PRBool Equals(const char* anISOLatin1) const;
PRBool Equals(const char* anISOLatin1,PRInt32 aLength=-1) const;
PRBool Equals(const nsIAtom *aAtom) const;
PRBool Equals(const PRUnichar* s1, const PRUnichar* s2) const;
PRBool EqualsIgnoreCase(const nsString& aString) const;
PRBool EqualsIgnoreCase(const char* anISOLatin1) const;
PRBool EqualsIgnoreCase(const char* anISOLatin1,PRInt32 aLength=-1) const;
PRBool EqualsIgnoreCase(const nsIAtom *aAtom) const;
PRBool EqualsIgnoreCase(const PRUnichar* s1, const PRUnichar* s2) const;
//@}
@ -195,6 +196,7 @@ typedef PRUnichar chartype;
chartype* mStr;
PRInt32 mLength;
PRInt32 mCapacity;
static PRBool mSelfTested;
};
extern NS_BASE int fputs(const nsString& aString, FILE* out);