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 nsUTF16ToUnicode_h_ michael@0: #define nsUTF16ToUnicode_h_ michael@0: michael@0: #include "nsISupports.h" michael@0: #include "nsUCSupport.h" michael@0: michael@0: // internal base class michael@0: class nsUTF16ToUnicodeBase : public nsBasicDecoderSupport michael@0: { michael@0: protected: michael@0: // ctor accessible only by child classes michael@0: nsUTF16ToUnicodeBase() { Reset();} michael@0: michael@0: nsresult UTF16ConvertToUnicode(const char * aSrc, michael@0: int32_t * aSrcLength, char16_t * aDest, michael@0: int32_t * aDestLength, bool aSwapBytes); michael@0: michael@0: public: michael@0: //-------------------------------------------------------------------- michael@0: // Subclassing of nsDecoderSupport class [declaration] michael@0: michael@0: NS_IMETHOD GetMaxLength(const char * aSrc, int32_t aSrcLength, michael@0: int32_t * aDestLength); michael@0: NS_IMETHOD Reset(); michael@0: michael@0: protected: michael@0: uint8_t mState; michael@0: // to store an odd byte left over between runs michael@0: uint8_t mOddByte; michael@0: // to store an odd high surrogate left over between runs michael@0: char16_t mOddHighSurrogate; michael@0: // to store an odd low surrogate left over between runs michael@0: char16_t mOddLowSurrogate; michael@0: }; michael@0: michael@0: // UTF-16 big endian michael@0: class nsUTF16BEToUnicode : public nsUTF16ToUnicodeBase michael@0: { michael@0: public: michael@0: michael@0: NS_IMETHOD Convert(const char * aSrc, int32_t * aSrcLength, michael@0: char16_t * aDest, int32_t * aDestLength); michael@0: }; michael@0: michael@0: // UTF-16 little endian michael@0: class nsUTF16LEToUnicode : public nsUTF16ToUnicodeBase michael@0: { michael@0: public: michael@0: michael@0: NS_IMETHOD Convert(const char * aSrc, int32_t * aSrcLength, michael@0: char16_t * aDest, int32_t * aDestLength); michael@0: }; michael@0: michael@0: // UTF-16 with BOM michael@0: class nsUTF16ToUnicode : public nsUTF16ToUnicodeBase michael@0: { michael@0: public: michael@0: michael@0: nsUTF16ToUnicode() { Reset();} michael@0: NS_IMETHOD Convert(const char * aSrc, int32_t * aSrcLength, michael@0: char16_t * aDest, int32_t * aDestLength); michael@0: michael@0: NS_IMETHOD Reset(); michael@0: michael@0: private: michael@0: michael@0: enum Endian {kUnknown, kBigEndian, kLittleEndian}; michael@0: Endian mEndian; michael@0: bool mFoundBOM; michael@0: }; michael@0: michael@0: #endif /* nsUTF16ToUnicode_h_ */