Bumping manifests a=b2g-bump
[gecko.git] / xpcom / io / nsStringStream.h
blob2af1124e2e07b0f0f22a7d5bcddbc180e077bcc4
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef nsStringStream_h__
8 #define nsStringStream_h__
10 #include "nsIStringStream.h"
11 #include "nsStringGlue.h"
12 #include "nsMemory.h"
14 /**
15 * Implements:
16 * nsIStringInputStream
17 * nsIInputStream
18 * nsISeekableStream
19 * nsISupportsCString
21 #define NS_STRINGINPUTSTREAM_CONTRACTID "@mozilla.org/io/string-input-stream;1"
22 #define NS_STRINGINPUTSTREAM_CID \
23 { /* 0abb0835-5000-4790-af28-61b3ba17c295 */ \
24 0x0abb0835, \
25 0x5000, \
26 0x4790, \
27 {0xaf, 0x28, 0x61, 0xb3, 0xba, 0x17, 0xc2, 0x95} \
30 /**
31 * Factory method to get an nsInputStream from a byte buffer. Result will
32 * implement nsIStringInputStream and nsISeekableStream.
34 * If aAssignment is NS_ASSIGNMENT_COPY, then the resulting stream holds a copy
35 * of the given buffer (aStringToRead), and the caller is free to discard
36 * aStringToRead after this function returns.
38 * If aAssignment is NS_ASSIGNMENT_DEPEND, then the resulting stream refers
39 * directly to the given buffer (aStringToRead), so the caller must ensure that
40 * the buffer remains valid for the lifetime of the stream object. Use with
41 * care!!
43 * If aAssignment is NS_ASSIGNMENT_ADOPT, then the resulting stream refers
44 * directly to the given buffer (aStringToRead) and will free aStringToRead
45 * once the stream is closed.
47 * If aLength is less than zero, then the length of aStringToRead will be
48 * determined by scanning the buffer for the first null byte.
50 extern nsresult
51 NS_NewByteInputStream(nsIInputStream** aStreamResult,
52 const char* aStringToRead, int32_t aLength = -1,
53 nsAssignmentType aAssignment = NS_ASSIGNMENT_DEPEND);
55 /**
56 * Factory method to get an nsInputStream from an nsAString. Result will
57 * implement nsIStringInputStream and nsISeekableStream.
59 * The given string data will be converted to a single-byte data buffer via
60 * truncation (i.e., the high-order byte of each character will be discarded).
61 * This could result in data-loss, so be careful when using this function.
63 extern nsresult
64 NS_NewStringInputStream(nsIInputStream** aStreamResult,
65 const nsAString& aStringToRead);
67 /**
68 * Factory method to get an nsInputStream from an nsACString. Result will
69 * implement nsIStringInputStream and nsISeekableStream.
71 extern nsresult
72 NS_NewCStringInputStream(nsIInputStream** aStreamResult,
73 const nsACString& aStringToRead);
75 #endif // nsStringStream_h__