From 61451beb943685998feaad3e9de7c610506ec0db Mon Sep 17 00:00:00 2001 From: "rickg%netscape.com" Date: Fri, 24 Mar 2000 07:21:56 +0000 Subject: [PATCH] WIP for new string library, and defensive coding improvement in SetCapcity; r=buster git-svn-id: svn://10.0.0.236/trunk@64014 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/string/obsolete/nsString.cpp | 10 ++++++---- mozilla/string/obsolete/nsString.h | 14 +++++++------- mozilla/string/obsolete/nsString2.cpp | 8 +++++--- mozilla/string/obsolete/nsString2.h | 16 ++++++++-------- mozilla/xpcom/ds/nsString.cpp | 10 ++++++---- mozilla/xpcom/ds/nsString.h | 14 +++++++------- mozilla/xpcom/ds/nsString2.cpp | 8 +++++--- mozilla/xpcom/ds/nsString2.h | 16 ++++++++-------- mozilla/xpcom/string/obsolete/nsString.cpp | 10 ++++++---- mozilla/xpcom/string/obsolete/nsString.h | 14 +++++++------- mozilla/xpcom/string/obsolete/nsString2.cpp | 8 +++++--- mozilla/xpcom/string/obsolete/nsString2.h | 16 ++++++++-------- 12 files changed, 78 insertions(+), 66 deletions(-) diff --git a/mozilla/string/obsolete/nsString.cpp b/mozilla/string/obsolete/nsString.cpp index 98354eddee4..cab23e7acd5 100644 --- a/mozilla/string/obsolete/nsString.cpp +++ b/mozilla/string/obsolete/nsString.cpp @@ -175,7 +175,7 @@ void nsCString::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const { /** * This method truncates this string to given length. * - * @update gess 01/04/99 + * @update rickg 03.23.2000 * @param anIndex -- new length of string * @return nada */ @@ -192,10 +192,12 @@ void nsCString::SetLength(PRUint32 anIndex) { * @param aLength -- contains new length for mStr */ void nsCString::SetCapacity(PRUint32 aLength) { - if(aLength>mCapacity) { - GrowCapacity(*this,aLength); + if(aLength) { + if(aLength>mCapacity) { + GrowCapacity(*this,aLength); + } + AddNullTerminator(*this); } - AddNullTerminator(*this); } /********************************************************************** diff --git a/mozilla/string/obsolete/nsString.h b/mozilla/string/obsolete/nsString.h index 52ef4d7d0b2..d2b8b3bae17 100644 --- a/mozilla/string/obsolete/nsString.h +++ b/mozilla/string/obsolete/nsString.h @@ -584,9 +584,9 @@ public: * @param aCount tells us how many iterations to make starting at the given offset * @return offset in string, or -1 (kNotFound) */ - PRInt32 Find(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const; - PRInt32 Find(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const; - PRInt32 Find(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const; + PRInt32 Find(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=0,PRInt32 aCount=-1) const; + PRInt32 Find(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=0,PRInt32 aCount=-1) const; + PRInt32 Find(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=0,PRInt32 aCount=-1) const; /** * Search for given char within this string @@ -597,7 +597,7 @@ public: * @param aCount tells us how many iterations to make starting at the given offset * @return find pos in string, or -1 (kNotFound) */ - PRInt32 FindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const; + PRInt32 FindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=0,PRInt32 aCount=-1) const; /** * This method searches this string for the first character @@ -606,9 +606,9 @@ public: * @param anOffset tells us where to start searching in this * @return -1 if not found, else the offset in this */ - PRInt32 FindCharInSet(const char* aString,PRInt32 anOffset=-1) const; - PRInt32 FindCharInSet(const PRUnichar* aString,PRInt32 anOffset=-1) const; - PRInt32 FindCharInSet(const nsStr& aString,PRInt32 anOffset=-1) const; + PRInt32 FindCharInSet(const char* aString,PRInt32 anOffset=0) const; + PRInt32 FindCharInSet(const PRUnichar* aString,PRInt32 anOffset=0) const; + PRInt32 FindCharInSet(const nsStr& aString,PRInt32 anOffset=0) const; /** diff --git a/mozilla/string/obsolete/nsString2.cpp b/mozilla/string/obsolete/nsString2.cpp index a310463c2a7..e41fc3330a2 100644 --- a/mozilla/string/obsolete/nsString2.cpp +++ b/mozilla/string/obsolete/nsString2.cpp @@ -204,10 +204,12 @@ void nsString::SetLength(PRUint32 anIndex) { * @return */ void nsString::SetCapacity(PRUint32 aLength) { - if(aLength>mCapacity) { - GrowCapacity(*this,aLength); + if(aLength) { + if(aLength>mCapacity) { + GrowCapacity(*this,aLength); + } + AddNullTerminator(*this); } - AddNullTerminator(*this); } /********************************************************************** diff --git a/mozilla/string/obsolete/nsString2.h b/mozilla/string/obsolete/nsString2.h index be2d6c2e4f8..76e3a14f35f 100644 --- a/mozilla/string/obsolete/nsString2.h +++ b/mozilla/string/obsolete/nsString2.h @@ -643,10 +643,10 @@ public: * @param aCount tells us how many iterations to make starting at the given offset * @return offset in string, or -1 (kNotFound) */ - PRInt32 Find(const nsString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const; - PRInt32 Find(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const; - PRInt32 Find(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const; - PRInt32 Find(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const; + PRInt32 Find(const nsString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=0,PRInt32 aCount=-1) const; + PRInt32 Find(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=0,PRInt32 aCount=-1) const; + PRInt32 Find(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=0,PRInt32 aCount=-1) const; + PRInt32 Find(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=0,PRInt32 aCount=-1) const; /** @@ -659,7 +659,7 @@ public: * @return find pos in string, or -1 (kNotFound) */ //PRInt32 Find(PRUnichar aChar,PRInt32 offset=-1,PRBool aIgnoreCase=PR_FALSE) const; - PRInt32 FindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const; + PRInt32 FindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=0,PRInt32 aCount=-1) const; /** * This method searches this string for the first character @@ -668,9 +668,9 @@ public: * @param anOffset tells us where to start searching in this * @return -1 if not found, else the offset in this */ - PRInt32 FindCharInSet(const char* aString,PRInt32 anOffset=-1) const; - PRInt32 FindCharInSet(const PRUnichar* aString,PRInt32 anOffset=-1) const; - PRInt32 FindCharInSet(const nsStr& aString,PRInt32 anOffset=-1) const; + PRInt32 FindCharInSet(const char* aString,PRInt32 anOffset=0) const; + PRInt32 FindCharInSet(const PRUnichar* aString,PRInt32 anOffset=0) const; + PRInt32 FindCharInSet(const nsStr& aString,PRInt32 anOffset=0) const; /** diff --git a/mozilla/xpcom/ds/nsString.cpp b/mozilla/xpcom/ds/nsString.cpp index 98354eddee4..cab23e7acd5 100644 --- a/mozilla/xpcom/ds/nsString.cpp +++ b/mozilla/xpcom/ds/nsString.cpp @@ -175,7 +175,7 @@ void nsCString::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const { /** * This method truncates this string to given length. * - * @update gess 01/04/99 + * @update rickg 03.23.2000 * @param anIndex -- new length of string * @return nada */ @@ -192,10 +192,12 @@ void nsCString::SetLength(PRUint32 anIndex) { * @param aLength -- contains new length for mStr */ void nsCString::SetCapacity(PRUint32 aLength) { - if(aLength>mCapacity) { - GrowCapacity(*this,aLength); + if(aLength) { + if(aLength>mCapacity) { + GrowCapacity(*this,aLength); + } + AddNullTerminator(*this); } - AddNullTerminator(*this); } /********************************************************************** diff --git a/mozilla/xpcom/ds/nsString.h b/mozilla/xpcom/ds/nsString.h index 52ef4d7d0b2..d2b8b3bae17 100644 --- a/mozilla/xpcom/ds/nsString.h +++ b/mozilla/xpcom/ds/nsString.h @@ -584,9 +584,9 @@ public: * @param aCount tells us how many iterations to make starting at the given offset * @return offset in string, or -1 (kNotFound) */ - PRInt32 Find(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const; - PRInt32 Find(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const; - PRInt32 Find(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const; + PRInt32 Find(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=0,PRInt32 aCount=-1) const; + PRInt32 Find(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=0,PRInt32 aCount=-1) const; + PRInt32 Find(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=0,PRInt32 aCount=-1) const; /** * Search for given char within this string @@ -597,7 +597,7 @@ public: * @param aCount tells us how many iterations to make starting at the given offset * @return find pos in string, or -1 (kNotFound) */ - PRInt32 FindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const; + PRInt32 FindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=0,PRInt32 aCount=-1) const; /** * This method searches this string for the first character @@ -606,9 +606,9 @@ public: * @param anOffset tells us where to start searching in this * @return -1 if not found, else the offset in this */ - PRInt32 FindCharInSet(const char* aString,PRInt32 anOffset=-1) const; - PRInt32 FindCharInSet(const PRUnichar* aString,PRInt32 anOffset=-1) const; - PRInt32 FindCharInSet(const nsStr& aString,PRInt32 anOffset=-1) const; + PRInt32 FindCharInSet(const char* aString,PRInt32 anOffset=0) const; + PRInt32 FindCharInSet(const PRUnichar* aString,PRInt32 anOffset=0) const; + PRInt32 FindCharInSet(const nsStr& aString,PRInt32 anOffset=0) const; /** diff --git a/mozilla/xpcom/ds/nsString2.cpp b/mozilla/xpcom/ds/nsString2.cpp index a310463c2a7..e41fc3330a2 100644 --- a/mozilla/xpcom/ds/nsString2.cpp +++ b/mozilla/xpcom/ds/nsString2.cpp @@ -204,10 +204,12 @@ void nsString::SetLength(PRUint32 anIndex) { * @return */ void nsString::SetCapacity(PRUint32 aLength) { - if(aLength>mCapacity) { - GrowCapacity(*this,aLength); + if(aLength) { + if(aLength>mCapacity) { + GrowCapacity(*this,aLength); + } + AddNullTerminator(*this); } - AddNullTerminator(*this); } /********************************************************************** diff --git a/mozilla/xpcom/ds/nsString2.h b/mozilla/xpcom/ds/nsString2.h index be2d6c2e4f8..76e3a14f35f 100644 --- a/mozilla/xpcom/ds/nsString2.h +++ b/mozilla/xpcom/ds/nsString2.h @@ -643,10 +643,10 @@ public: * @param aCount tells us how many iterations to make starting at the given offset * @return offset in string, or -1 (kNotFound) */ - PRInt32 Find(const nsString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const; - PRInt32 Find(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const; - PRInt32 Find(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const; - PRInt32 Find(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const; + PRInt32 Find(const nsString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=0,PRInt32 aCount=-1) const; + PRInt32 Find(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=0,PRInt32 aCount=-1) const; + PRInt32 Find(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=0,PRInt32 aCount=-1) const; + PRInt32 Find(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=0,PRInt32 aCount=-1) const; /** @@ -659,7 +659,7 @@ public: * @return find pos in string, or -1 (kNotFound) */ //PRInt32 Find(PRUnichar aChar,PRInt32 offset=-1,PRBool aIgnoreCase=PR_FALSE) const; - PRInt32 FindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const; + PRInt32 FindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=0,PRInt32 aCount=-1) const; /** * This method searches this string for the first character @@ -668,9 +668,9 @@ public: * @param anOffset tells us where to start searching in this * @return -1 if not found, else the offset in this */ - PRInt32 FindCharInSet(const char* aString,PRInt32 anOffset=-1) const; - PRInt32 FindCharInSet(const PRUnichar* aString,PRInt32 anOffset=-1) const; - PRInt32 FindCharInSet(const nsStr& aString,PRInt32 anOffset=-1) const; + PRInt32 FindCharInSet(const char* aString,PRInt32 anOffset=0) const; + PRInt32 FindCharInSet(const PRUnichar* aString,PRInt32 anOffset=0) const; + PRInt32 FindCharInSet(const nsStr& aString,PRInt32 anOffset=0) const; /** diff --git a/mozilla/xpcom/string/obsolete/nsString.cpp b/mozilla/xpcom/string/obsolete/nsString.cpp index 98354eddee4..cab23e7acd5 100644 --- a/mozilla/xpcom/string/obsolete/nsString.cpp +++ b/mozilla/xpcom/string/obsolete/nsString.cpp @@ -175,7 +175,7 @@ void nsCString::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const { /** * This method truncates this string to given length. * - * @update gess 01/04/99 + * @update rickg 03.23.2000 * @param anIndex -- new length of string * @return nada */ @@ -192,10 +192,12 @@ void nsCString::SetLength(PRUint32 anIndex) { * @param aLength -- contains new length for mStr */ void nsCString::SetCapacity(PRUint32 aLength) { - if(aLength>mCapacity) { - GrowCapacity(*this,aLength); + if(aLength) { + if(aLength>mCapacity) { + GrowCapacity(*this,aLength); + } + AddNullTerminator(*this); } - AddNullTerminator(*this); } /********************************************************************** diff --git a/mozilla/xpcom/string/obsolete/nsString.h b/mozilla/xpcom/string/obsolete/nsString.h index 52ef4d7d0b2..d2b8b3bae17 100644 --- a/mozilla/xpcom/string/obsolete/nsString.h +++ b/mozilla/xpcom/string/obsolete/nsString.h @@ -584,9 +584,9 @@ public: * @param aCount tells us how many iterations to make starting at the given offset * @return offset in string, or -1 (kNotFound) */ - PRInt32 Find(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const; - PRInt32 Find(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const; - PRInt32 Find(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const; + PRInt32 Find(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=0,PRInt32 aCount=-1) const; + PRInt32 Find(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=0,PRInt32 aCount=-1) const; + PRInt32 Find(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=0,PRInt32 aCount=-1) const; /** * Search for given char within this string @@ -597,7 +597,7 @@ public: * @param aCount tells us how many iterations to make starting at the given offset * @return find pos in string, or -1 (kNotFound) */ - PRInt32 FindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const; + PRInt32 FindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=0,PRInt32 aCount=-1) const; /** * This method searches this string for the first character @@ -606,9 +606,9 @@ public: * @param anOffset tells us where to start searching in this * @return -1 if not found, else the offset in this */ - PRInt32 FindCharInSet(const char* aString,PRInt32 anOffset=-1) const; - PRInt32 FindCharInSet(const PRUnichar* aString,PRInt32 anOffset=-1) const; - PRInt32 FindCharInSet(const nsStr& aString,PRInt32 anOffset=-1) const; + PRInt32 FindCharInSet(const char* aString,PRInt32 anOffset=0) const; + PRInt32 FindCharInSet(const PRUnichar* aString,PRInt32 anOffset=0) const; + PRInt32 FindCharInSet(const nsStr& aString,PRInt32 anOffset=0) const; /** diff --git a/mozilla/xpcom/string/obsolete/nsString2.cpp b/mozilla/xpcom/string/obsolete/nsString2.cpp index a310463c2a7..e41fc3330a2 100644 --- a/mozilla/xpcom/string/obsolete/nsString2.cpp +++ b/mozilla/xpcom/string/obsolete/nsString2.cpp @@ -204,10 +204,12 @@ void nsString::SetLength(PRUint32 anIndex) { * @return */ void nsString::SetCapacity(PRUint32 aLength) { - if(aLength>mCapacity) { - GrowCapacity(*this,aLength); + if(aLength) { + if(aLength>mCapacity) { + GrowCapacity(*this,aLength); + } + AddNullTerminator(*this); } - AddNullTerminator(*this); } /********************************************************************** diff --git a/mozilla/xpcom/string/obsolete/nsString2.h b/mozilla/xpcom/string/obsolete/nsString2.h index be2d6c2e4f8..76e3a14f35f 100644 --- a/mozilla/xpcom/string/obsolete/nsString2.h +++ b/mozilla/xpcom/string/obsolete/nsString2.h @@ -643,10 +643,10 @@ public: * @param aCount tells us how many iterations to make starting at the given offset * @return offset in string, or -1 (kNotFound) */ - PRInt32 Find(const nsString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const; - PRInt32 Find(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const; - PRInt32 Find(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const; - PRInt32 Find(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const; + PRInt32 Find(const nsString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=0,PRInt32 aCount=-1) const; + PRInt32 Find(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=0,PRInt32 aCount=-1) const; + PRInt32 Find(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=0,PRInt32 aCount=-1) const; + PRInt32 Find(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=0,PRInt32 aCount=-1) const; /** @@ -659,7 +659,7 @@ public: * @return find pos in string, or -1 (kNotFound) */ //PRInt32 Find(PRUnichar aChar,PRInt32 offset=-1,PRBool aIgnoreCase=PR_FALSE) const; - PRInt32 FindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const; + PRInt32 FindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=0,PRInt32 aCount=-1) const; /** * This method searches this string for the first character @@ -668,9 +668,9 @@ public: * @param anOffset tells us where to start searching in this * @return -1 if not found, else the offset in this */ - PRInt32 FindCharInSet(const char* aString,PRInt32 anOffset=-1) const; - PRInt32 FindCharInSet(const PRUnichar* aString,PRInt32 anOffset=-1) const; - PRInt32 FindCharInSet(const nsStr& aString,PRInt32 anOffset=-1) const; + PRInt32 FindCharInSet(const char* aString,PRInt32 anOffset=0) const; + PRInt32 FindCharInSet(const PRUnichar* aString,PRInt32 anOffset=0) const; + PRInt32 FindCharInSet(const nsStr& aString,PRInt32 anOffset=0) const; /**