diff --git a/xpcom/io/nsIStringStream.cpp b/xpcom/io/nsIStringStream.cpp index 6cdd00d0d9ce..a31b621ef415 100644 --- a/xpcom/io/nsIStringStream.cpp +++ b/xpcom/io/nsIStringStream.cpp @@ -265,6 +265,12 @@ class ConstStringImpl { } + ConstStringImpl(const nsCString& inString) + : ConstCharImpl(inString.ToNewCString(), + inString.Length()) + { + } + ~ConstStringImpl() { Recycle((char*)mConstString); @@ -381,6 +387,27 @@ extern "C" NS_COM nsresult NS_NewStringInputStream( return NS_OK; } +//---------------------------------------------------------------------------------------- +extern "C" NS_COM nsresult NS_NewCStringInputStream( + nsISupports** aStreamResult, + const nsCString& aStringToRead) + // Factory method to get an nsInputStream from a cstring. Result will implement all the + // file stream interfaces in nsIFileStream.h +//---------------------------------------------------------------------------------------- +{ + NS_PRECONDITION(aStreamResult != nsnull, "null ptr"); + if (! aStreamResult) + return NS_ERROR_NULL_POINTER; + + ConstStringImpl* stream = new ConstStringImpl(aStringToRead); + if (! stream) + return NS_ERROR_OUT_OF_MEMORY; + + NS_ADDREF(stream); + *aStreamResult = (nsISupports*)(void*)stream; + return NS_OK; +} + //---------------------------------------------------------------------------------------- extern "C" NS_COM nsresult NS_NewStringOutputStream( nsISupports** aStreamResult, diff --git a/xpcom/io/nsIStringStream.h b/xpcom/io/nsIStringStream.h index d4c774cb4699..8a64eb91f684 100644 --- a/xpcom/io/nsIStringStream.h +++ b/xpcom/io/nsIStringStream.h @@ -33,6 +33,13 @@ extern "C" NS_COM nsresult NS_NewStringInputStream( // Factory method to get an nsInputStream from a string. Result will implement all the // file stream interfaces in nsIFileStream.h +//---------------------------------------------------------------------------------------- +extern "C" NS_COM nsresult NS_NewCStringInputStream( + nsISupports** aStreamResult, + const nsCString& aStringToRead); + // Factory method to get an nsInputStream from a cstring. Result will implement all the + // file stream interfaces in nsIFileStream.h + //---------------------------------------------------------------------------------------- extern "C" NS_COM nsresult NS_NewStringOutputStream( nsISupports** aStreamResult,