From 0facb993457bf1c7b06b22c5d2f794fbfd4295e6 Mon Sep 17 00:00:00 2001 From: "rickg%netscape.com" Date: Fri, 7 May 1999 00:47:24 +0000 Subject: [PATCH] fixed an error subsuming autostrings, and removed an AIX warning git-svn-id: svn://10.0.0.236/trunk@30641 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/base/src/nsStr.cpp | 4 +-- mozilla/base/src/nsString2.cpp | 36 ++++++++++++++++----- mozilla/base/src/nsString2.h | 30 +++++++++++------ mozilla/string/obsolete/nsStr.cpp | 4 +-- mozilla/string/obsolete/nsString2.cpp | 36 ++++++++++++++++----- mozilla/string/obsolete/nsString2.h | 30 +++++++++++------ mozilla/xpcom/ds/nsStr.cpp | 4 +-- mozilla/xpcom/ds/nsString2.cpp | 36 ++++++++++++++++----- mozilla/xpcom/ds/nsString2.h | 30 +++++++++++------ mozilla/xpcom/string/obsolete/nsStr.cpp | 4 +-- mozilla/xpcom/string/obsolete/nsString2.cpp | 36 ++++++++++++++++----- mozilla/xpcom/string/obsolete/nsString2.h | 30 +++++++++++------ 12 files changed, 200 insertions(+), 80 deletions(-) diff --git a/mozilla/base/src/nsStr.cpp b/mozilla/base/src/nsStr.cpp index 4d3fc6ab211..153e0240e69 100644 --- a/mozilla/base/src/nsStr.cpp +++ b/mozilla/base/src/nsStr.cpp @@ -478,7 +478,7 @@ PRInt32 nsStr::FindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool aIgnor * @param * @return */ -PRInt32 nsStr::FindChar(const nsStr& aDest,const PRUnichar aChar, PRBool aIgnoreCase,PRUint32 anOffset) { +PRInt32 nsStr::FindChar(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,PRUint32 anOffset) { PRInt32 result=gFindChars[aDest.mCharSize](aDest.mStr,aDest.mLength,anOffset,aChar,aIgnoreCase); return result; } @@ -553,7 +553,7 @@ PRInt32 nsStr::RFindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool aIgno * @param * @return */ -PRInt32 nsStr::RFindChar(const nsStr& aDest,const PRUnichar aChar, PRBool aIgnoreCase,PRUint32 anOffset) { +PRInt32 nsStr::RFindChar(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,PRUint32 anOffset) { PRInt32 result=gRFindChars[aDest.mCharSize](aDest.mStr,aDest.mLength,anOffset,aChar,aIgnoreCase); return result; } diff --git a/mozilla/base/src/nsString2.cpp b/mozilla/base/src/nsString2.cpp index d1224ddc94f..fb0c7926dfa 100644 --- a/mozilla/base/src/nsString2.cpp +++ b/mozilla/base/src/nsString2.cpp @@ -1,3 +1,4 @@ +#define RICKG_DEBUG 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- * @@ -101,15 +102,33 @@ public: ***********************************************************************/ void Subsume(nsStr& aDest,nsStr& aSource){ - aDest.mStr=aSource.mStr; - aDest.mLength=aSource.mLength; - aDest.mCharSize=aSource.mCharSize; - aDest.mCapacity=aSource.mCapacity; - aDest.mOwnsBuffer=aSource.mOwnsBuffer; - aSource.mOwnsBuffer=PR_FALSE; - aSource.mStr=0; + if(aSource.mStr && aSource.mLength) { + if(aSource.mOwnsBuffer){ + aDest.mStr=aSource.mStr; + aDest.mLength=aSource.mLength; + aDest.mCharSize=aSource.mCharSize; + aDest.mCapacity=aSource.mCapacity; + aDest.mOwnsBuffer=aSource.mOwnsBuffer; + aSource.mOwnsBuffer=false; + aSource.mStr=0; + } + else{ + nsStr::Assign(aDest,aSource,0,aSource.mLength,0); + } + } + else nsStr::Truncate(aDest,0,0); } +#ifdef RICKG_DEBUG +/******************************************************** + This class's only purpose in life is to test nsString2. + ********************************************************/ +class CStringTester { +public: + CStringTester(); +}; +#endif + /** * Default constructor. Note that we actually allocate a small buffer * to begin with. This is because the "philosophy" of the string class @@ -1917,7 +1936,8 @@ CStringTester::CStringTester() { nsSubsumeStr temp3=theString+'?'; nsString2 temp4(temp3); temp1=temp3; - nsSubsumeStr temp5("hello"); + nsAutoString2 temp5("hello"); + nsSubsumeStr temp6(temp5); } nsString2 theString1(theSize); diff --git a/mozilla/base/src/nsString2.h b/mozilla/base/src/nsString2.h index ec7b2be85fe..4e4fef5a80d 100644 --- a/mozilla/base/src/nsString2.h +++ b/mozilla/base/src/nsString2.h @@ -149,6 +149,26 @@ void Truncate(PRInt32 anIndex=0); */ PRBool IsOrdered(void) const; +/** + * Determine whether or not the characters in this + * string are in store as 1 or 2 byte (unicode) strings. + * + * @return TRUE if ordered. + */ +PRBool IsUnicode(void) const { + PRBool result=PRBool(mCharSize==eTwoByte); + return result; +} + +/** + * Determine whether or not this string has a length of 0 + * + * @return TRUE if empty. + */ +PRBool IsEmpty(void) const { + return PRBool(0==mLength); +} + /********************************************************************** Accessor methods... *********************************************************************/ @@ -774,16 +794,6 @@ public: nsSubsumeStr(const char* aString); }; -#ifdef RICKG_DEBUG -/******************************************************** - This class's only purpose in life is to test nsString2. - ********************************************************/ -class CStringTester { -public: - CStringTester(); -}; -#endif - #endif diff --git a/mozilla/string/obsolete/nsStr.cpp b/mozilla/string/obsolete/nsStr.cpp index 4d3fc6ab211..153e0240e69 100644 --- a/mozilla/string/obsolete/nsStr.cpp +++ b/mozilla/string/obsolete/nsStr.cpp @@ -478,7 +478,7 @@ PRInt32 nsStr::FindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool aIgnor * @param * @return */ -PRInt32 nsStr::FindChar(const nsStr& aDest,const PRUnichar aChar, PRBool aIgnoreCase,PRUint32 anOffset) { +PRInt32 nsStr::FindChar(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,PRUint32 anOffset) { PRInt32 result=gFindChars[aDest.mCharSize](aDest.mStr,aDest.mLength,anOffset,aChar,aIgnoreCase); return result; } @@ -553,7 +553,7 @@ PRInt32 nsStr::RFindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool aIgno * @param * @return */ -PRInt32 nsStr::RFindChar(const nsStr& aDest,const PRUnichar aChar, PRBool aIgnoreCase,PRUint32 anOffset) { +PRInt32 nsStr::RFindChar(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,PRUint32 anOffset) { PRInt32 result=gRFindChars[aDest.mCharSize](aDest.mStr,aDest.mLength,anOffset,aChar,aIgnoreCase); return result; } diff --git a/mozilla/string/obsolete/nsString2.cpp b/mozilla/string/obsolete/nsString2.cpp index d1224ddc94f..fb0c7926dfa 100644 --- a/mozilla/string/obsolete/nsString2.cpp +++ b/mozilla/string/obsolete/nsString2.cpp @@ -1,3 +1,4 @@ +#define RICKG_DEBUG 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- * @@ -101,15 +102,33 @@ public: ***********************************************************************/ void Subsume(nsStr& aDest,nsStr& aSource){ - aDest.mStr=aSource.mStr; - aDest.mLength=aSource.mLength; - aDest.mCharSize=aSource.mCharSize; - aDest.mCapacity=aSource.mCapacity; - aDest.mOwnsBuffer=aSource.mOwnsBuffer; - aSource.mOwnsBuffer=PR_FALSE; - aSource.mStr=0; + if(aSource.mStr && aSource.mLength) { + if(aSource.mOwnsBuffer){ + aDest.mStr=aSource.mStr; + aDest.mLength=aSource.mLength; + aDest.mCharSize=aSource.mCharSize; + aDest.mCapacity=aSource.mCapacity; + aDest.mOwnsBuffer=aSource.mOwnsBuffer; + aSource.mOwnsBuffer=false; + aSource.mStr=0; + } + else{ + nsStr::Assign(aDest,aSource,0,aSource.mLength,0); + } + } + else nsStr::Truncate(aDest,0,0); } +#ifdef RICKG_DEBUG +/******************************************************** + This class's only purpose in life is to test nsString2. + ********************************************************/ +class CStringTester { +public: + CStringTester(); +}; +#endif + /** * Default constructor. Note that we actually allocate a small buffer * to begin with. This is because the "philosophy" of the string class @@ -1917,7 +1936,8 @@ CStringTester::CStringTester() { nsSubsumeStr temp3=theString+'?'; nsString2 temp4(temp3); temp1=temp3; - nsSubsumeStr temp5("hello"); + nsAutoString2 temp5("hello"); + nsSubsumeStr temp6(temp5); } nsString2 theString1(theSize); diff --git a/mozilla/string/obsolete/nsString2.h b/mozilla/string/obsolete/nsString2.h index ec7b2be85fe..4e4fef5a80d 100644 --- a/mozilla/string/obsolete/nsString2.h +++ b/mozilla/string/obsolete/nsString2.h @@ -149,6 +149,26 @@ void Truncate(PRInt32 anIndex=0); */ PRBool IsOrdered(void) const; +/** + * Determine whether or not the characters in this + * string are in store as 1 or 2 byte (unicode) strings. + * + * @return TRUE if ordered. + */ +PRBool IsUnicode(void) const { + PRBool result=PRBool(mCharSize==eTwoByte); + return result; +} + +/** + * Determine whether or not this string has a length of 0 + * + * @return TRUE if empty. + */ +PRBool IsEmpty(void) const { + return PRBool(0==mLength); +} + /********************************************************************** Accessor methods... *********************************************************************/ @@ -774,16 +794,6 @@ public: nsSubsumeStr(const char* aString); }; -#ifdef RICKG_DEBUG -/******************************************************** - This class's only purpose in life is to test nsString2. - ********************************************************/ -class CStringTester { -public: - CStringTester(); -}; -#endif - #endif diff --git a/mozilla/xpcom/ds/nsStr.cpp b/mozilla/xpcom/ds/nsStr.cpp index 4d3fc6ab211..153e0240e69 100644 --- a/mozilla/xpcom/ds/nsStr.cpp +++ b/mozilla/xpcom/ds/nsStr.cpp @@ -478,7 +478,7 @@ PRInt32 nsStr::FindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool aIgnor * @param * @return */ -PRInt32 nsStr::FindChar(const nsStr& aDest,const PRUnichar aChar, PRBool aIgnoreCase,PRUint32 anOffset) { +PRInt32 nsStr::FindChar(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,PRUint32 anOffset) { PRInt32 result=gFindChars[aDest.mCharSize](aDest.mStr,aDest.mLength,anOffset,aChar,aIgnoreCase); return result; } @@ -553,7 +553,7 @@ PRInt32 nsStr::RFindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool aIgno * @param * @return */ -PRInt32 nsStr::RFindChar(const nsStr& aDest,const PRUnichar aChar, PRBool aIgnoreCase,PRUint32 anOffset) { +PRInt32 nsStr::RFindChar(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,PRUint32 anOffset) { PRInt32 result=gRFindChars[aDest.mCharSize](aDest.mStr,aDest.mLength,anOffset,aChar,aIgnoreCase); return result; } diff --git a/mozilla/xpcom/ds/nsString2.cpp b/mozilla/xpcom/ds/nsString2.cpp index d1224ddc94f..fb0c7926dfa 100644 --- a/mozilla/xpcom/ds/nsString2.cpp +++ b/mozilla/xpcom/ds/nsString2.cpp @@ -1,3 +1,4 @@ +#define RICKG_DEBUG 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- * @@ -101,15 +102,33 @@ public: ***********************************************************************/ void Subsume(nsStr& aDest,nsStr& aSource){ - aDest.mStr=aSource.mStr; - aDest.mLength=aSource.mLength; - aDest.mCharSize=aSource.mCharSize; - aDest.mCapacity=aSource.mCapacity; - aDest.mOwnsBuffer=aSource.mOwnsBuffer; - aSource.mOwnsBuffer=PR_FALSE; - aSource.mStr=0; + if(aSource.mStr && aSource.mLength) { + if(aSource.mOwnsBuffer){ + aDest.mStr=aSource.mStr; + aDest.mLength=aSource.mLength; + aDest.mCharSize=aSource.mCharSize; + aDest.mCapacity=aSource.mCapacity; + aDest.mOwnsBuffer=aSource.mOwnsBuffer; + aSource.mOwnsBuffer=false; + aSource.mStr=0; + } + else{ + nsStr::Assign(aDest,aSource,0,aSource.mLength,0); + } + } + else nsStr::Truncate(aDest,0,0); } +#ifdef RICKG_DEBUG +/******************************************************** + This class's only purpose in life is to test nsString2. + ********************************************************/ +class CStringTester { +public: + CStringTester(); +}; +#endif + /** * Default constructor. Note that we actually allocate a small buffer * to begin with. This is because the "philosophy" of the string class @@ -1917,7 +1936,8 @@ CStringTester::CStringTester() { nsSubsumeStr temp3=theString+'?'; nsString2 temp4(temp3); temp1=temp3; - nsSubsumeStr temp5("hello"); + nsAutoString2 temp5("hello"); + nsSubsumeStr temp6(temp5); } nsString2 theString1(theSize); diff --git a/mozilla/xpcom/ds/nsString2.h b/mozilla/xpcom/ds/nsString2.h index ec7b2be85fe..4e4fef5a80d 100644 --- a/mozilla/xpcom/ds/nsString2.h +++ b/mozilla/xpcom/ds/nsString2.h @@ -149,6 +149,26 @@ void Truncate(PRInt32 anIndex=0); */ PRBool IsOrdered(void) const; +/** + * Determine whether or not the characters in this + * string are in store as 1 or 2 byte (unicode) strings. + * + * @return TRUE if ordered. + */ +PRBool IsUnicode(void) const { + PRBool result=PRBool(mCharSize==eTwoByte); + return result; +} + +/** + * Determine whether or not this string has a length of 0 + * + * @return TRUE if empty. + */ +PRBool IsEmpty(void) const { + return PRBool(0==mLength); +} + /********************************************************************** Accessor methods... *********************************************************************/ @@ -774,16 +794,6 @@ public: nsSubsumeStr(const char* aString); }; -#ifdef RICKG_DEBUG -/******************************************************** - This class's only purpose in life is to test nsString2. - ********************************************************/ -class CStringTester { -public: - CStringTester(); -}; -#endif - #endif diff --git a/mozilla/xpcom/string/obsolete/nsStr.cpp b/mozilla/xpcom/string/obsolete/nsStr.cpp index 4d3fc6ab211..153e0240e69 100644 --- a/mozilla/xpcom/string/obsolete/nsStr.cpp +++ b/mozilla/xpcom/string/obsolete/nsStr.cpp @@ -478,7 +478,7 @@ PRInt32 nsStr::FindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool aIgnor * @param * @return */ -PRInt32 nsStr::FindChar(const nsStr& aDest,const PRUnichar aChar, PRBool aIgnoreCase,PRUint32 anOffset) { +PRInt32 nsStr::FindChar(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,PRUint32 anOffset) { PRInt32 result=gFindChars[aDest.mCharSize](aDest.mStr,aDest.mLength,anOffset,aChar,aIgnoreCase); return result; } @@ -553,7 +553,7 @@ PRInt32 nsStr::RFindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool aIgno * @param * @return */ -PRInt32 nsStr::RFindChar(const nsStr& aDest,const PRUnichar aChar, PRBool aIgnoreCase,PRUint32 anOffset) { +PRInt32 nsStr::RFindChar(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,PRUint32 anOffset) { PRInt32 result=gRFindChars[aDest.mCharSize](aDest.mStr,aDest.mLength,anOffset,aChar,aIgnoreCase); return result; } diff --git a/mozilla/xpcom/string/obsolete/nsString2.cpp b/mozilla/xpcom/string/obsolete/nsString2.cpp index d1224ddc94f..fb0c7926dfa 100644 --- a/mozilla/xpcom/string/obsolete/nsString2.cpp +++ b/mozilla/xpcom/string/obsolete/nsString2.cpp @@ -1,3 +1,4 @@ +#define RICKG_DEBUG 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- * @@ -101,15 +102,33 @@ public: ***********************************************************************/ void Subsume(nsStr& aDest,nsStr& aSource){ - aDest.mStr=aSource.mStr; - aDest.mLength=aSource.mLength; - aDest.mCharSize=aSource.mCharSize; - aDest.mCapacity=aSource.mCapacity; - aDest.mOwnsBuffer=aSource.mOwnsBuffer; - aSource.mOwnsBuffer=PR_FALSE; - aSource.mStr=0; + if(aSource.mStr && aSource.mLength) { + if(aSource.mOwnsBuffer){ + aDest.mStr=aSource.mStr; + aDest.mLength=aSource.mLength; + aDest.mCharSize=aSource.mCharSize; + aDest.mCapacity=aSource.mCapacity; + aDest.mOwnsBuffer=aSource.mOwnsBuffer; + aSource.mOwnsBuffer=false; + aSource.mStr=0; + } + else{ + nsStr::Assign(aDest,aSource,0,aSource.mLength,0); + } + } + else nsStr::Truncate(aDest,0,0); } +#ifdef RICKG_DEBUG +/******************************************************** + This class's only purpose in life is to test nsString2. + ********************************************************/ +class CStringTester { +public: + CStringTester(); +}; +#endif + /** * Default constructor. Note that we actually allocate a small buffer * to begin with. This is because the "philosophy" of the string class @@ -1917,7 +1936,8 @@ CStringTester::CStringTester() { nsSubsumeStr temp3=theString+'?'; nsString2 temp4(temp3); temp1=temp3; - nsSubsumeStr temp5("hello"); + nsAutoString2 temp5("hello"); + nsSubsumeStr temp6(temp5); } nsString2 theString1(theSize); diff --git a/mozilla/xpcom/string/obsolete/nsString2.h b/mozilla/xpcom/string/obsolete/nsString2.h index ec7b2be85fe..4e4fef5a80d 100644 --- a/mozilla/xpcom/string/obsolete/nsString2.h +++ b/mozilla/xpcom/string/obsolete/nsString2.h @@ -149,6 +149,26 @@ void Truncate(PRInt32 anIndex=0); */ PRBool IsOrdered(void) const; +/** + * Determine whether or not the characters in this + * string are in store as 1 or 2 byte (unicode) strings. + * + * @return TRUE if ordered. + */ +PRBool IsUnicode(void) const { + PRBool result=PRBool(mCharSize==eTwoByte); + return result; +} + +/** + * Determine whether or not this string has a length of 0 + * + * @return TRUE if empty. + */ +PRBool IsEmpty(void) const { + return PRBool(0==mLength); +} + /********************************************************************** Accessor methods... *********************************************************************/ @@ -774,16 +794,6 @@ public: nsSubsumeStr(const char* aString); }; -#ifdef RICKG_DEBUG -/******************************************************** - This class's only purpose in life is to test nsString2. - ********************************************************/ -class CStringTester { -public: - CStringTester(); -}; -#endif - #endif