From f5dbd849388cb32e76c76846232c782ce3d9b0ad Mon Sep 17 00:00:00 2001 From: "scc%netscape.com" Date: Sat, 1 Apr 2000 22:27:03 +0000 Subject: [PATCH] not sure if this is the _best_ way to solve the problem, but I added a c-string version of |NS_NewStringInputStream|, which can't use overloading since it's |extern "C"|, so I named it |NS_NewCStringInputStream|. --- xpcom/io/nsIStringStream.cpp | 27 +++++++++++++++++++++++++++ xpcom/io/nsIStringStream.h | 7 +++++++ 2 files changed, 34 insertions(+) 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,