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