Bug 116957: Put Adopt on ns{C}String, and use it in nsStandardURL. r=dbaron, rs=scc

This commit is contained in:
jaggernaut%netscape.com 2001-12-26 23:14:12 +00:00
parent c8db620184
commit 75b1455d5d
9 changed files with 43 additions and 4 deletions

View File

@ -413,8 +413,7 @@ nsStandardURL::BuildNormalizedSpec(const char *spec)
if (mDirectory.mLen > 1)
CoalescePath(buf + mDirectory.mPos);
mSpec = buf; // XXX too bad there isn't some way of avoiding this strdup!
free(buf);
mSpec.Adopt(buf);
return NS_OK;
}

View File

@ -864,7 +864,14 @@ void nsCString::InsertWithConversion(PRUnichar aChar,PRUint32 anOffset){
}
void nsCString::Adopt(char* aPtr, PRInt32 aLength) {
nsStr::Destroy(*this);
if (aLength == -1)
aLength = nsCharTraits<char>::length(aPtr);
// We don't know the capacity, so we'll just have to assume
// capacity = length.
nsStr::Initialize(*this, aPtr, aLength, aLength, eOneByte, PR_TRUE);
}
/**********************************************************************
Searching methods...

View File

@ -301,6 +301,9 @@ public:
#endif
// Takes ownership of aPtr, sets the current length to aLength if specified.
void Adopt( char* aPtr, PRInt32 aLength = -1 );
/**********************************************************************
Searching methods...
*********************************************************************/

View File

@ -866,6 +866,14 @@ void nsString::InsertWithConversion(const char* aCString,PRUint32 anOffset,PRInt
}
}
void nsString::Adopt(PRUnichar* aPtr, PRInt32 aLength) {
nsStr::Destroy(*this);
if (aLength == -1)
aLength = nsCharTraits<PRUnichar>::length(aPtr);
// We don't know the capacity, so we'll just have to assume
// capacity = length.
nsStr::Initialize(*this, (char*)aPtr, aLength, aLength, eTwoByte, PR_TRUE);
}
/**********************************************************************

View File

@ -322,6 +322,8 @@ public:
//void InsertWithConversion(char);
void InsertWithConversion(const char*, PRUint32, PRInt32=-1);
// Takes ownership of aPtr, sets the current length to aLength if specified.
void Adopt( PRUnichar* aPtr, PRInt32 aLength = -1 );
/**********************************************************************
Searching methods...

View File

@ -864,7 +864,14 @@ void nsCString::InsertWithConversion(PRUnichar aChar,PRUint32 anOffset){
}
void nsCString::Adopt(char* aPtr, PRInt32 aLength) {
nsStr::Destroy(*this);
if (aLength == -1)
aLength = nsCharTraits<char>::length(aPtr);
// We don't know the capacity, so we'll just have to assume
// capacity = length.
nsStr::Initialize(*this, aPtr, aLength, aLength, eOneByte, PR_TRUE);
}
/**********************************************************************
Searching methods...

View File

@ -301,6 +301,9 @@ public:
#endif
// Takes ownership of aPtr, sets the current length to aLength if specified.
void Adopt( char* aPtr, PRInt32 aLength = -1 );
/**********************************************************************
Searching methods...
*********************************************************************/

View File

@ -866,6 +866,14 @@ void nsString::InsertWithConversion(const char* aCString,PRUint32 anOffset,PRInt
}
}
void nsString::Adopt(PRUnichar* aPtr, PRInt32 aLength) {
nsStr::Destroy(*this);
if (aLength == -1)
aLength = nsCharTraits<PRUnichar>::length(aPtr);
// We don't know the capacity, so we'll just have to assume
// capacity = length.
nsStr::Initialize(*this, (char*)aPtr, aLength, aLength, eTwoByte, PR_TRUE);
}
/**********************************************************************

View File

@ -322,6 +322,8 @@ public:
//void InsertWithConversion(char);
void InsertWithConversion(const char*, PRUint32, PRInt32=-1);
// Takes ownership of aPtr, sets the current length to aLength if specified.
void Adopt( PRUnichar* aPtr, PRInt32 aLength = -1 );
/**********************************************************************
Searching methods...