1 /* -*- Mode: C; tab-width: 4; 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/. */
6 #ifndef nsConverterInputStream_h
7 #define nsConverterInputStream_h
9 #include "nsIInputStream.h"
10 #include "nsIConverterInputStream.h"
11 #include "nsIUnicharLineInputStream.h"
13 #include "nsAutoPtr.h"
15 #include "nsReadLine.h"
16 #include "mozilla/Encoding.h"
18 #define NS_CONVERTERINPUTSTREAM_CONTRACTID \
19 "@mozilla.org/intl/converter-input-stream;1"
21 // {2BC2AD62-AD5D-4b7b-A9DB-F74AE203C527}
22 #define NS_CONVERTERINPUTSTREAM_CID \
24 0x2bc2ad62, 0xad5d, 0x4b7b, { \
25 0xa9, 0xdb, 0xf7, 0x4a, 0xe2, 0x3, 0xc5, 0x27 \
29 class nsConverterInputStream
: public nsIConverterInputStream
,
30 public nsIUnicharLineInputStream
{
33 NS_DECL_NSIUNICHARINPUTSTREAM
34 NS_DECL_NSIUNICHARLINEINPUTSTREAM
35 NS_DECL_NSICONVERTERINPUTSTREAM
37 nsConverterInputStream()
38 : mLastErrorCode(NS_OK
),
40 mUnicharDataOffset(0),
41 mUnicharDataLength(0),
42 mErrorsAreFatal(false),
43 mLineBuffer(nullptr) {}
46 virtual ~nsConverterInputStream() { Close(); }
48 uint32_t Fill(nsresult
* aErrorCode
);
50 mozilla::UniquePtr
<mozilla::Decoder
> mConverter
;
51 FallibleTArray
<char> mByteData
;
52 FallibleTArray
<char16_t
> mUnicharData
;
53 nsCOMPtr
<nsIInputStream
> mInput
;
55 nsresult mLastErrorCode
;
56 uint32_t mLeftOverBytes
;
57 uint32_t mUnicharDataOffset
;
58 uint32_t mUnicharDataLength
;
61 nsAutoPtr
<nsLineBuffer
<char16_t
> > mLineBuffer
;