Line data Source code
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/. */
5 :
6 : #ifndef nsConverterInputStream_h
7 : #define nsConverterInputStream_h
8 :
9 : #include "nsIInputStream.h"
10 : #include "nsIConverterInputStream.h"
11 : #include "nsIUnicharLineInputStream.h"
12 : #include "nsTArray.h"
13 : #include "nsAutoPtr.h"
14 : #include "nsCOMPtr.h"
15 : #include "nsReadLine.h"
16 : #include "mozilla/Encoding.h"
17 :
18 : #define NS_CONVERTERINPUTSTREAM_CONTRACTID "@mozilla.org/intl/converter-input-stream;1"
19 :
20 : // {2BC2AD62-AD5D-4b7b-A9DB-F74AE203C527}
21 : #define NS_CONVERTERINPUTSTREAM_CID \
22 : { 0x2bc2ad62, 0xad5d, 0x4b7b, \
23 : { 0xa9, 0xdb, 0xf7, 0x4a, 0xe2, 0x3, 0xc5, 0x27 } }
24 :
25 :
26 :
27 : class nsConverterInputStream : public nsIConverterInputStream,
28 : public nsIUnicharLineInputStream {
29 :
30 : public:
31 : NS_DECL_ISUPPORTS
32 : NS_DECL_NSIUNICHARINPUTSTREAM
33 : NS_DECL_NSIUNICHARLINEINPUTSTREAM
34 : NS_DECL_NSICONVERTERINPUTSTREAM
35 :
36 3 : nsConverterInputStream()
37 3 : : mLastErrorCode(NS_OK)
38 : , mLeftOverBytes(0)
39 : , mUnicharDataOffset(0)
40 : , mUnicharDataLength(0)
41 : , mErrorsAreFatal(false)
42 3 : , mLineBuffer(nullptr)
43 : {
44 3 : }
45 :
46 : private:
47 0 : virtual ~nsConverterInputStream() { Close(); }
48 :
49 : uint32_t Fill(nsresult *aErrorCode);
50 :
51 : mozilla::UniquePtr<mozilla::Decoder> mConverter;
52 : FallibleTArray<char> mByteData;
53 : FallibleTArray<char16_t> mUnicharData;
54 : nsCOMPtr<nsIInputStream> mInput;
55 :
56 : nsresult mLastErrorCode;
57 : uint32_t mLeftOverBytes;
58 : uint32_t mUnicharDataOffset;
59 : uint32_t mUnicharDataLength;
60 : bool mErrorsAreFatal;
61 :
62 : nsAutoPtr<nsLineBuffer<char16_t> > mLineBuffer;
63 : };
64 :
65 : #endif
66 :
|