Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Functions
nsStringStream.cpp File Reference
#include "nsStringStream.h"
#include "prerror.h"
#include "plstr.h"
#include "nsReadableUtils.h"
#include "nsCRT.h"
#include "nsISeekableStream.h"
#include "nsInt64.h"

Go to the source code of this file.

Classes

class  nsStringInputStream

Defines

#define NS_FILE_RESULT(x)   ns_file_convert_result((PRInt32)x)
 Based on original code from nsIStringStream.cpp.
#define NS_FILE_FAILURE   NS_FILE_RESULT(-1)

Functions

static nsresult ns_file_convert_result (PRInt32 nativeErr)
 NS_IMPL_THREADSAFE_ISUPPORTS3 (nsStringInputStream, nsIStringInputStream, nsIInputStream, nsISeekableStream) NS_IMETHODIMP nsStringInputStream
NS_COM nsresult NS_NewStringInputStream (nsIInputStream **aStreamResult, const nsAString &aStringToRead)
NS_COM nsresult NS_NewCStringInputStream (nsIInputStream **aStreamResult, const nsACString &aStringToRead)
NS_COM nsresult NS_NewCharInputStream (nsIInputStream **aStreamResult, const char *aStringToRead)
NS_COM nsresult NS_NewByteInputStream (nsIInputStream **aStreamResult, const char *aStringToRead, PRInt32 aLength)
NS_METHOD nsStringInputStreamConstructor (nsISupports *outer, REFNSIID iid, void **result)

Define Documentation

Definition at line 64 of file nsStringStream.cpp.

Based on original code from nsIStringStream.cpp.

Definition at line 63 of file nsStringStream.cpp.


Function Documentation

static nsresult ns_file_convert_result ( PRInt32  nativeErr) [static]

Definition at line 66 of file nsStringStream.cpp.

{
    return nativeErr ?
        NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES,((nativeErr)&0xFFFF))
        : NS_OK;
}

Definition at line 132 of file nsStringStream.cpp.

{
    NS_ENSURE_ARG_POINTER(data);

    if (dataLen < 0)
        dataLen = strlen(data);

    return AdoptData(nsCRT::strndup(data, dataLen), dataLen);
}

Here is the call graph for this function:

NS_COM nsresult NS_NewByteInputStream ( nsIInputStream **  aStreamResult,
const char *  aStringToRead,
PRInt32  aLength 
)

Definition at line 396 of file nsStringStream.cpp.

{
    NS_PRECONDITION(aStreamResult, "null out ptr");

    nsStringInputStream* stream = new nsStringInputStream();
    if (! stream)
        return NS_ERROR_OUT_OF_MEMORY;

    NS_ADDREF(stream);

    nsresult rv = stream->ShareData(aStringToRead, aLength);
    
    if (NS_FAILED(rv)) {
        NS_RELEASE(stream);
        return rv;
    }
    
    *aStreamResult = stream;
    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

NS_COM nsresult NS_NewCharInputStream ( nsIInputStream **  aStreamResult,
const char *  aStringToRead 
)

Definition at line 371 of file nsStringStream.cpp.

{
    NS_PRECONDITION(aStreamResult, "null out ptr");

    nsStringInputStream* stream = new nsStringInputStream();
    if (! stream)
        return NS_ERROR_OUT_OF_MEMORY;

    NS_ADDREF(stream);

    nsresult rv = stream->ShareData(aStringToRead, -1);
    
    if (NS_FAILED(rv)) {
        NS_RELEASE(stream);
        return rv;
    }
    
    *aStreamResult = stream;
    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

NS_COM nsresult NS_NewCStringInputStream ( nsIInputStream **  aStreamResult,
const nsACString &  aStringToRead 
)

Definition at line 340 of file nsStringStream.cpp.

{
    NS_PRECONDITION(aStreamResult, "null out ptr");

    char* data = ToNewCString(aStringToRead);
    if (!data)
        return NS_ERROR_OUT_OF_MEMORY;

    nsStringInputStream* stream = new nsStringInputStream();
    if (! stream) {
        nsMemory::Free(data);
        return NS_ERROR_OUT_OF_MEMORY;
    }

    NS_ADDREF(stream);

    nsresult rv = stream->AdoptData(data, aStringToRead.Length());
    if (NS_FAILED(rv)) {
        nsMemory::Free(data);
        NS_RELEASE(stream);
        return rv;
    }
    
    *aStreamResult = stream;
    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

NS_COM nsresult NS_NewStringInputStream ( nsIInputStream **  aStreamResult,
const nsAString &  aStringToRead 
)

Definition at line 309 of file nsStringStream.cpp.

{
    NS_PRECONDITION(aStreamResult, "null out ptr");

    char* data = ToNewCString(aStringToRead);
    if (!data)
        return NS_ERROR_OUT_OF_MEMORY;

    nsStringInputStream* stream = new nsStringInputStream();
    if (! stream) {
        nsMemory::Free(data);
        return NS_ERROR_OUT_OF_MEMORY;
    }

    NS_ADDREF(stream);

    nsresult rv = stream->AdoptData(data, aStringToRead.Length());
    if (NS_FAILED(rv)) {
        nsMemory::Free(data);
        NS_RELEASE(stream);
        return rv;
    }
    
    *aStreamResult = stream;
    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

NS_METHOD nsStringInputStreamConstructor ( nsISupports *  outer,
REFNSIID  iid,
void **  result 
)

Definition at line 421 of file nsStringStream.cpp.

{
    *result = nsnull;

    if (outer)
        return NS_ERROR_NO_AGGREGATION;

    nsStringInputStream *inst;
    NS_NEWXPCOM(inst, nsStringInputStream);
    if (!inst)
        return NS_ERROR_OUT_OF_MEMORY;

    NS_ADDREF(inst);
    nsresult rv = inst->QueryInterface(iid, result);
    NS_RELEASE(inst);

    return rv;
}

Here is the call graph for this function: