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