added setDataWithLength to nsISupports[W]String r=jband.

This commit is contained in:
pinkerton%netscape.com 1999-11-30 22:06:05 +00:00
Родитель 701dd6cd4a
Коммит 1a970bd699
2 изменённых файлов: 49 добавлений и 16 удалений

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

@ -41,6 +41,10 @@ interface nsISupportsString : nsISupports
{
attribute string data;
string toString();
// do not include space for null termination in |length|. It is handled
// internally.
void setDataWithLength(in long length, [size_is(length)] in string data);
};
[scriptable, uuid(d79dc970-4a1c-11d3-9890-006008962422)]
@ -48,6 +52,10 @@ interface nsISupportsWString : nsISupports
{
attribute wstring data;
wstring toString();
// do not include space for null termination in |length|. It is handled
// internally. |length| is in characters, not in bytes.
void setDataWithLength(in long length, [size_is(length)] in wstring data);
};
/**

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

@ -138,14 +138,7 @@ NS_IMETHODIMP nsSupportsStringImpl::GetData(char **aData)
NS_IMETHODIMP nsSupportsStringImpl::SetData(const char *aData)
{
if(mData)
nsAllocator::Free(mData);
if(aData)
mData = (char*) nsAllocator::Clone(aData,
(nsCRT::strlen(aData)+1)*sizeof(char));
else
mData = nsnull;
return NS_OK;
return SetDataWithLength(aData ? nsCRT::strlen(aData) : 0, aData);
}
NS_IMETHODIMP nsSupportsStringImpl::ToString(char **_retval)
@ -153,6 +146,24 @@ NS_IMETHODIMP nsSupportsStringImpl::ToString(char **_retval)
return GetData(_retval);
}
NS_IMETHODIMP nsSupportsStringImpl::SetDataWithLength(PRInt32 aLength, const char *aData)
{
if(mData)
nsAllocator::Free(mData);
if(aData) {
mData = NS_STATIC_CAST(char*, nsAllocator::Alloc((aLength+1)*sizeof(char)));
if ( mData ) {
nsCRT::memcpy ( mData, aData, aLength*sizeof(char) );
mData[aLength] = NS_STATIC_CAST(char, 0);
}
else
return NS_ERROR_OUT_OF_MEMORY;
}
else
mData = nsnull;
return NS_OK;
}
/***************************************************************************/
NS_IMPL_ISUPPORTS1(nsSupportsWStringImpl, nsISupportsWString)
@ -191,14 +202,7 @@ NS_IMETHODIMP nsSupportsWStringImpl::GetData(PRUnichar **aData)
NS_IMETHODIMP nsSupportsWStringImpl::SetData(const PRUnichar *aData)
{
if(mData)
nsAllocator::Free(mData);
if(aData)
mData = (PRUnichar*) nsAllocator::Clone(aData,
(nsCRT::strlen(aData)+1)*sizeof(PRUnichar));
else
mData = nsnull;
return NS_OK;
return SetDataWithLength(aData ? nsCRT::strlen(aData) : 0, aData);
}
NS_IMETHODIMP nsSupportsWStringImpl::ToString(PRUnichar **_retval)
@ -206,6 +210,27 @@ NS_IMETHODIMP nsSupportsWStringImpl::ToString(PRUnichar **_retval)
return GetData(_retval);
}
// NOTE: assumes |length| does not include the null and null terminates itself. |length|
// is in characters, not bytes.
NS_IMETHODIMP nsSupportsWStringImpl::SetDataWithLength(PRInt32 aLength, const PRUnichar *aData)
{
if(mData)
nsAllocator::Free(mData);
if(aData) {
mData = NS_STATIC_CAST(PRUnichar*, nsAllocator::Alloc((aLength+1)*sizeof(PRUnichar)));
if ( mData ) {
nsCRT::memcpy ( mData, aData, aLength*sizeof(PRUnichar) );
mData[aLength] = NS_STATIC_CAST(PRUnichar, 0);
}
else
return NS_ERROR_OUT_OF_MEMORY;
}
else
mData = nsnull;
return NS_OK;
}
/***************************************************************************/
NS_IMPL_ISUPPORTS1(nsSupportsPRBoolImpl, nsISupportsPRBool)