michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nsStringStream_h__ michael@0: #define nsStringStream_h__ michael@0: michael@0: #include "nsIStringStream.h" michael@0: #include "nsStringGlue.h" michael@0: #include "nsMemory.h" michael@0: michael@0: /** michael@0: * Implements: michael@0: * nsIStringInputStream michael@0: * nsIInputStream michael@0: * nsISeekableStream michael@0: * nsISupportsCString michael@0: */ michael@0: #define NS_STRINGINPUTSTREAM_CONTRACTID "@mozilla.org/io/string-input-stream;1" michael@0: #define NS_STRINGINPUTSTREAM_CID \ michael@0: { /* 0abb0835-5000-4790-af28-61b3ba17c295 */ \ michael@0: 0x0abb0835, \ michael@0: 0x5000, \ michael@0: 0x4790, \ michael@0: {0xaf, 0x28, 0x61, 0xb3, 0xba, 0x17, 0xc2, 0x95} \ michael@0: } michael@0: michael@0: /** michael@0: * Factory method to get an nsInputStream from a byte buffer. Result will michael@0: * implement nsIStringInputStream and nsISeekableStream. michael@0: * michael@0: * If aAssignment is NS_ASSIGNMENT_COPY, then the resulting stream holds a copy michael@0: * of the given buffer (aStringToRead), and the caller is free to discard michael@0: * aStringToRead after this function returns. michael@0: * michael@0: * If aAssignment is NS_ASSIGNMENT_DEPEND, then the resulting stream refers michael@0: * directly to the given buffer (aStringToRead), so the caller must ensure that michael@0: * the buffer remains valid for the lifetime of the stream object. Use with michael@0: * care!! michael@0: * michael@0: * If aAssignment is NS_ASSIGNMENT_ADOPT, then the resulting stream refers michael@0: * directly to the given buffer (aStringToRead) and will free aStringToRead michael@0: * once the stream is closed. michael@0: * michael@0: * If aLength is less than zero, then the length of aStringToRead will be michael@0: * determined by scanning the buffer for the first null byte. michael@0: */ michael@0: extern nsresult michael@0: NS_NewByteInputStream(nsIInputStream** aStreamResult, michael@0: const char* aStringToRead, int32_t aLength = -1, michael@0: nsAssignmentType aAssignment = NS_ASSIGNMENT_DEPEND); michael@0: michael@0: /** michael@0: * Factory method to get an nsInputStream from an nsAString. Result will michael@0: * implement nsIStringInputStream and nsISeekableStream. michael@0: * michael@0: * The given string data will be converted to a single-byte data buffer via michael@0: * truncation (i.e., the high-order byte of each character will be discarded). michael@0: * This could result in data-loss, so be careful when using this function. michael@0: */ michael@0: extern nsresult michael@0: NS_NewStringInputStream(nsIInputStream** aStreamResult, michael@0: const nsAString& aStringToRead); michael@0: michael@0: /** michael@0: * Factory method to get an nsInputStream from an nsACString. Result will michael@0: * implement nsIStringInputStream and nsISeekableStream. michael@0: */ michael@0: extern nsresult michael@0: NS_NewCStringInputStream(nsIInputStream** aStreamResult, michael@0: const nsACString& aStringToRead); michael@0: michael@0: #endif // nsStringStream_h__