xpcom/io/nsStringStream.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/xpcom/io/nsStringStream.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,74 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef nsStringStream_h__
    1.10 +#define nsStringStream_h__
    1.11 +
    1.12 +#include "nsIStringStream.h"
    1.13 +#include "nsStringGlue.h"
    1.14 +#include "nsMemory.h"
    1.15 +
    1.16 +/**
    1.17 + * Implements:
    1.18 + *   nsIStringInputStream
    1.19 + *   nsIInputStream
    1.20 + *   nsISeekableStream
    1.21 + *   nsISupportsCString
    1.22 + */
    1.23 +#define NS_STRINGINPUTSTREAM_CONTRACTID "@mozilla.org/io/string-input-stream;1"
    1.24 +#define NS_STRINGINPUTSTREAM_CID                     \
    1.25 +{ /* 0abb0835-5000-4790-af28-61b3ba17c295 */         \
    1.26 +    0x0abb0835,                                      \
    1.27 +    0x5000,                                          \
    1.28 +    0x4790,                                          \
    1.29 +    {0xaf, 0x28, 0x61, 0xb3, 0xba, 0x17, 0xc2, 0x95} \
    1.30 +}
    1.31 +
    1.32 +/**
    1.33 + * Factory method to get an nsInputStream from a byte buffer.  Result will
    1.34 + * implement nsIStringInputStream and nsISeekableStream.
    1.35 + *
    1.36 + * If aAssignment is NS_ASSIGNMENT_COPY, then the resulting stream holds a copy
    1.37 + * of the given buffer (aStringToRead), and the caller is free to discard
    1.38 + * aStringToRead after this function returns.
    1.39 + *
    1.40 + * If aAssignment is NS_ASSIGNMENT_DEPEND, then the resulting stream refers
    1.41 + * directly to the given buffer (aStringToRead), so the caller must ensure that
    1.42 + * the buffer remains valid for the lifetime of the stream object.  Use with
    1.43 + * care!!
    1.44 + *
    1.45 + * If aAssignment is NS_ASSIGNMENT_ADOPT, then the resulting stream refers
    1.46 + * directly to the given buffer (aStringToRead) and will free aStringToRead
    1.47 + * once the stream is closed.
    1.48 + *
    1.49 + * If aLength is less than zero, then the length of aStringToRead will be
    1.50 + * determined by scanning the buffer for the first null byte.
    1.51 + */
    1.52 +extern nsresult
    1.53 +NS_NewByteInputStream(nsIInputStream** aStreamResult,
    1.54 +                      const char* aStringToRead, int32_t aLength = -1,
    1.55 +                      nsAssignmentType aAssignment = NS_ASSIGNMENT_DEPEND);
    1.56 +
    1.57 +/**
    1.58 + * Factory method to get an nsInputStream from an nsAString.  Result will
    1.59 + * implement nsIStringInputStream and nsISeekableStream.
    1.60 + *
    1.61 + * The given string data will be converted to a single-byte data buffer via
    1.62 + * truncation (i.e., the high-order byte of each character will be discarded).
    1.63 + * This could result in data-loss, so be careful when using this function.
    1.64 + */
    1.65 +extern nsresult
    1.66 +NS_NewStringInputStream(nsIInputStream** aStreamResult,
    1.67 +                        const nsAString& aStringToRead);
    1.68 +
    1.69 +/**
    1.70 + * Factory method to get an nsInputStream from an nsACString.  Result will
    1.71 + * implement nsIStringInputStream and nsISeekableStream.
    1.72 + */
    1.73 +extern nsresult
    1.74 +NS_NewCStringInputStream(nsIInputStream** aStreamResult,
    1.75 +                         const nsACString& aStringToRead);
    1.76 +
    1.77 +#endif // nsStringStream_h__

mercurial