2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "nsUnicharInputStream.h"
|
|
|
|
#include "nsIInputStream.h"
|
|
|
|
#include "nsIByteBuffer.h"
|
|
|
|
#include "nsIUnicharBuffer.h"
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "nsCRT.h"
|
|
|
|
#include "nsUTF8Utils.h"
|
2012-06-05 16:51:58 -07:00
|
|
|
#include "mozilla/Attributes.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include <fcntl.h>
|
2011-12-20 21:09:17 -08:00
|
|
|
#if defined(XP_WIN)
|
2007-03-22 10:30:00 -07:00
|
|
|
#include <io.h>
|
|
|
|
#else
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define STRING_BUFFER_SIZE 8192
|
|
|
|
|
2012-06-05 16:51:58 -07:00
|
|
|
class StringUnicharInputStream MOZ_FINAL : public nsIUnicharInputStream {
|
2007-03-22 10:30:00 -07:00
|
|
|
public:
|
|
|
|
StringUnicharInputStream(const nsAString& aString) :
|
|
|
|
mString(aString), mPos(0), mLen(aString.Length()) { }
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIUNICHARINPUTSTREAM
|
|
|
|
|
|
|
|
nsString mString;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mPos;
|
|
|
|
uint32_t mLen;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
private:
|
|
|
|
~StringUnicharInputStream() { }
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
StringUnicharInputStream::Read(PRUnichar* aBuf,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aCount,
|
|
|
|
uint32_t *aReadCount)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (mPos >= mLen) {
|
|
|
|
*aReadCount = 0;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
nsAString::const_iterator iter;
|
|
|
|
mString.BeginReading(iter);
|
|
|
|
const PRUnichar* us = iter.get();
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t amount = mLen - mPos;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (amount > aCount) {
|
|
|
|
amount = aCount;
|
|
|
|
}
|
|
|
|
memcpy(aBuf, us + mPos, sizeof(PRUnichar) * amount);
|
|
|
|
mPos += amount;
|
|
|
|
*aReadCount = amount;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
StringUnicharInputStream::ReadSegments(nsWriteUnicharSegmentFun aWriter,
|
|
|
|
void* aClosure,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aCount, uint32_t *aReadCount)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t bytesWritten;
|
|
|
|
uint32_t totalBytesWritten = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsresult rv;
|
2013-01-15 04:22:03 -08:00
|
|
|
aCount = XPCOM_MIN(mString.Length() - mPos, aCount);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsAString::const_iterator iter;
|
|
|
|
mString.BeginReading(iter);
|
|
|
|
|
|
|
|
while (aCount) {
|
|
|
|
rv = aWriter(this, aClosure, iter.get() + mPos,
|
|
|
|
totalBytesWritten, aCount, &bytesWritten);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
// don't propagate errors to the caller
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
aCount -= bytesWritten;
|
|
|
|
totalBytesWritten += bytesWritten;
|
|
|
|
mPos += bytesWritten;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aReadCount = totalBytesWritten;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
StringUnicharInputStream::ReadString(uint32_t aCount, nsAString& aString,
|
|
|
|
uint32_t* aReadCount)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (mPos >= mLen) {
|
|
|
|
*aReadCount = 0;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t amount = mLen - mPos;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (amount > aCount) {
|
|
|
|
amount = aCount;
|
|
|
|
}
|
|
|
|
aString = Substring(mString, mPos, amount);
|
|
|
|
mPos += amount;
|
|
|
|
*aReadCount = amount;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult StringUnicharInputStream::Close()
|
|
|
|
{
|
|
|
|
mPos = mLen;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS1(StringUnicharInputStream, nsIUnicharInputStream)
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2012-06-05 16:51:58 -07:00
|
|
|
class UTF8InputStream MOZ_FINAL : public nsIUnicharInputStream {
|
2007-03-22 10:30:00 -07:00
|
|
|
public:
|
|
|
|
UTF8InputStream();
|
|
|
|
nsresult Init(nsIInputStream* aStream);
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIUNICHARINPUTSTREAM
|
|
|
|
|
|
|
|
private:
|
|
|
|
~UTF8InputStream();
|
|
|
|
|
|
|
|
protected:
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t Fill(nsresult * aErrorCode);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
static void CountValidUTF8Bytes(const char *aBuf, uint32_t aMaxBytes, uint32_t& aValidUTF8bytes, uint32_t& aValidUTF16CodeUnits);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsIInputStream> mInput;
|
|
|
|
nsCOMPtr<nsIByteBuffer> mByteData;
|
|
|
|
nsCOMPtr<nsIUnicharBuffer> mUnicharData;
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mByteDataOffset;
|
|
|
|
uint32_t mUnicharDataOffset;
|
|
|
|
uint32_t mUnicharDataLength;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
UTF8InputStream::UTF8InputStream() :
|
|
|
|
mByteDataOffset(0),
|
|
|
|
mUnicharDataOffset(0),
|
|
|
|
mUnicharDataLength(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
UTF8InputStream::Init(nsIInputStream* aStream)
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
nsresult rv = NS_NewByteBuffer(getter_AddRefs(mByteData), nullptr,
|
2007-03-22 10:30:00 -07:00
|
|
|
STRING_BUFFER_SIZE);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2012-07-30 07:20:58 -07:00
|
|
|
rv = NS_NewUnicharBuffer(getter_AddRefs(mUnicharData), nullptr,
|
2007-03-22 10:30:00 -07:00
|
|
|
STRING_BUFFER_SIZE);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
mInput = aStream;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS1(UTF8InputStream,nsIUnicharInputStream)
|
|
|
|
|
|
|
|
UTF8InputStream::~UTF8InputStream()
|
|
|
|
{
|
|
|
|
Close();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult UTF8InputStream::Close()
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
mInput = nullptr;
|
|
|
|
mByteData = nullptr;
|
|
|
|
mUnicharData = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult UTF8InputStream::Read(PRUnichar* aBuf,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aCount,
|
|
|
|
uint32_t *aReadCount)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(mUnicharDataLength >= mUnicharDataOffset, "unsigned madness");
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t readCount = mUnicharDataLength - mUnicharDataOffset;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult errorCode;
|
|
|
|
if (0 == readCount) {
|
|
|
|
// Fill the unichar buffer
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t bytesRead = Fill(&errorCode);
|
2008-03-13 12:01:53 -07:00
|
|
|
if (bytesRead <= 0) {
|
2007-03-22 10:30:00 -07:00
|
|
|
*aReadCount = 0;
|
|
|
|
return errorCode;
|
|
|
|
}
|
2008-03-13 12:01:53 -07:00
|
|
|
readCount = bytesRead;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
if (readCount > aCount) {
|
|
|
|
readCount = aCount;
|
|
|
|
}
|
|
|
|
memcpy(aBuf, mUnicharData->GetBuffer() + mUnicharDataOffset,
|
|
|
|
readCount * sizeof(PRUnichar));
|
|
|
|
mUnicharDataOffset += readCount;
|
|
|
|
*aReadCount = readCount;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
UTF8InputStream::ReadSegments(nsWriteUnicharSegmentFun aWriter,
|
|
|
|
void* aClosure,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aCount, uint32_t *aReadCount)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(mUnicharDataLength >= mUnicharDataOffset, "unsigned madness");
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t bytesToWrite = mUnicharDataLength - mUnicharDataOffset;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
if (0 == bytesToWrite) {
|
|
|
|
// Fill the unichar buffer
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t bytesRead = Fill(&rv);
|
2008-03-13 12:01:53 -07:00
|
|
|
if (bytesRead <= 0) {
|
2007-03-22 10:30:00 -07:00
|
|
|
*aReadCount = 0;
|
|
|
|
return rv;
|
|
|
|
}
|
2008-03-13 12:01:53 -07:00
|
|
|
bytesToWrite = bytesRead;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (bytesToWrite > aCount)
|
|
|
|
bytesToWrite = aCount;
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t bytesWritten;
|
|
|
|
uint32_t totalBytesWritten = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
while (bytesToWrite) {
|
|
|
|
rv = aWriter(this, aClosure,
|
|
|
|
mUnicharData->GetBuffer() + mUnicharDataOffset,
|
|
|
|
totalBytesWritten, bytesToWrite, &bytesWritten);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
// don't propagate errors to the caller
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
bytesToWrite -= bytesWritten;
|
|
|
|
totalBytesWritten += bytesWritten;
|
|
|
|
mUnicharDataOffset += bytesWritten;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aReadCount = totalBytesWritten;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
UTF8InputStream::ReadString(uint32_t aCount, nsAString& aString,
|
|
|
|
uint32_t* aReadCount)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(mUnicharDataLength >= mUnicharDataOffset, "unsigned madness");
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t readCount = mUnicharDataLength - mUnicharDataOffset;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult errorCode;
|
|
|
|
if (0 == readCount) {
|
|
|
|
// Fill the unichar buffer
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t bytesRead = Fill(&errorCode);
|
2008-03-13 12:01:53 -07:00
|
|
|
if (bytesRead <= 0) {
|
2007-03-22 10:30:00 -07:00
|
|
|
*aReadCount = 0;
|
|
|
|
return errorCode;
|
|
|
|
}
|
2008-03-13 12:01:53 -07:00
|
|
|
readCount = bytesRead;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
if (readCount > aCount) {
|
|
|
|
readCount = aCount;
|
|
|
|
}
|
2007-07-08 00:08:04 -07:00
|
|
|
const PRUnichar* buf = reinterpret_cast<const PRUnichar*>(mUnicharData->GetBuffer() +
|
2007-03-22 10:30:00 -07:00
|
|
|
mUnicharDataOffset);
|
|
|
|
aString.Assign(buf, readCount);
|
|
|
|
|
|
|
|
mUnicharDataOffset += readCount;
|
|
|
|
*aReadCount = readCount;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t UTF8InputStream::Fill(nsresult * aErrorCode)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
if (nullptr == mInput) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// We already closed the stream!
|
|
|
|
*aErrorCode = NS_BASE_STREAM_CLOSED;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(mByteData->GetLength() >= mByteDataOffset, "unsigned madness");
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t remainder = mByteData->GetLength() - mByteDataOffset;
|
2007-03-22 10:30:00 -07:00
|
|
|
mByteDataOffset = remainder;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t nb = mByteData->Fill(aErrorCode, mInput, remainder);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (nb <= 0) {
|
|
|
|
// Because we assume a many to one conversion, the lingering data
|
|
|
|
// in the byte buffer must be a partial conversion
|
|
|
|
// fragment. Because we know that we have received no more new
|
|
|
|
// data to add to it, we can't convert it. Therefore, we discard
|
|
|
|
// it.
|
|
|
|
return nb;
|
|
|
|
}
|
|
|
|
NS_ASSERTION(remainder + nb == mByteData->GetLength(), "bad nb");
|
|
|
|
|
|
|
|
// Now convert as much of the byte buffer to unicode as possible
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t srcLen, dstLen;
|
2007-03-22 10:30:00 -07:00
|
|
|
CountValidUTF8Bytes(mByteData->GetBuffer(),remainder + nb, srcLen, dstLen);
|
|
|
|
|
|
|
|
// the number of UCS2 characters should always be <= the number of
|
|
|
|
// UTF8 chars
|
|
|
|
NS_ASSERTION( (remainder+nb >= srcLen), "cannot be longer than out buffer");
|
2012-08-22 08:56:38 -07:00
|
|
|
NS_ASSERTION(int32_t(dstLen) <= mUnicharData->GetBufferSize(),
|
2007-03-22 10:30:00 -07:00
|
|
|
"Ouch. I would overflow my buffer if I wasn't so careful.");
|
2012-08-22 08:56:38 -07:00
|
|
|
if (int32_t(dstLen) > mUnicharData->GetBufferSize()) return 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
ConvertUTF8toUTF16 converter(mUnicharData->GetBuffer());
|
|
|
|
|
|
|
|
nsASingleFragmentCString::const_char_iterator start = mByteData->GetBuffer();
|
|
|
|
nsASingleFragmentCString::const_char_iterator end = mByteData->GetBuffer() + srcLen;
|
|
|
|
|
|
|
|
copy_string(start, end, converter);
|
2008-03-13 12:01:53 -07:00
|
|
|
if (converter.Length() != dstLen) {
|
|
|
|
*aErrorCode = NS_BASE_STREAM_BAD_CONVERSION;
|
|
|
|
return -1;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
mUnicharDataOffset = 0;
|
|
|
|
mUnicharDataLength = dstLen;
|
|
|
|
mByteDataOffset = srcLen;
|
|
|
|
|
|
|
|
return dstLen;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-22 08:56:38 -07:00
|
|
|
UTF8InputStream::CountValidUTF8Bytes(const char* aBuffer, uint32_t aMaxBytes, uint32_t& aValidUTF8bytes, uint32_t& aValidUTF16CodeUnits)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
const char *c = aBuffer;
|
|
|
|
const char *end = aBuffer + aMaxBytes;
|
|
|
|
const char *lastchar = c; // pre-initialize in case of 0-length buffer
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t utf16length = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
while (c < end && *c) {
|
|
|
|
lastchar = c;
|
|
|
|
utf16length++;
|
|
|
|
|
|
|
|
if (UTF8traits::isASCII(*c))
|
|
|
|
c++;
|
|
|
|
else if (UTF8traits::is2byte(*c))
|
|
|
|
c += 2;
|
|
|
|
else if (UTF8traits::is3byte(*c))
|
|
|
|
c += 3;
|
|
|
|
else if (UTF8traits::is4byte(*c)) {
|
|
|
|
c += 4;
|
|
|
|
utf16length++; // add 1 more because this will be converted to a
|
|
|
|
// surrogate pair.
|
|
|
|
}
|
|
|
|
else if (UTF8traits::is5byte(*c))
|
|
|
|
c += 5;
|
|
|
|
else if (UTF8traits::is6byte(*c))
|
|
|
|
c += 6;
|
|
|
|
else {
|
|
|
|
NS_WARNING("Unrecognized UTF8 string in UTF8InputStream::CountValidUTF8Bytes()");
|
|
|
|
break; // Otherwise we go into an infinite loop. But what happens now?
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (c > end) {
|
|
|
|
c = lastchar;
|
|
|
|
utf16length--;
|
|
|
|
}
|
|
|
|
|
|
|
|
aValidUTF8bytes = c - aBuffer;
|
|
|
|
aValidUTF16CodeUnits = utf16length;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_QUERY_INTERFACE2(nsSimpleUnicharStreamFactory,
|
|
|
|
nsIFactory,
|
|
|
|
nsISimpleUnicharStreamFactory)
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(nsrefcnt) nsSimpleUnicharStreamFactory::AddRef() { return 2; }
|
|
|
|
NS_IMETHODIMP_(nsrefcnt) nsSimpleUnicharStreamFactory::Release() { return 1; }
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSimpleUnicharStreamFactory::CreateInstance(nsISupports* aOuter, REFNSIID aIID,
|
|
|
|
void **aResult)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsSimpleUnicharStreamFactory::LockFactory(bool aLock)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSimpleUnicharStreamFactory::CreateInstanceFromString(const nsAString& aString,
|
|
|
|
nsIUnicharInputStream* *aResult)
|
|
|
|
{
|
|
|
|
StringUnicharInputStream* it = new StringUnicharInputStream(aString);
|
|
|
|
if (!it) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ADDREF(*aResult = it);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSimpleUnicharStreamFactory::CreateInstanceFromUTF8Stream(nsIInputStream* aStreamToWrap,
|
|
|
|
nsIUnicharInputStream* *aResult)
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
*aResult = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Create converter input stream
|
|
|
|
nsRefPtr<UTF8InputStream> it = new UTF8InputStream();
|
|
|
|
if (!it)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
nsresult rv = it->Init(aStreamToWrap);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
NS_ADDREF(*aResult = it);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSimpleUnicharStreamFactory*
|
|
|
|
nsSimpleUnicharStreamFactory::GetInstance()
|
|
|
|
{
|
2007-07-08 00:08:04 -07:00
|
|
|
return const_cast<nsSimpleUnicharStreamFactory*>(&kInstance);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
const nsSimpleUnicharStreamFactory
|
|
|
|
nsSimpleUnicharStreamFactory::kInstance;
|