1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/intl/uconv/ucvlatin/nsUTF16ToUnicode.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,77 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef nsUTF16ToUnicode_h_ 1.10 +#define nsUTF16ToUnicode_h_ 1.11 + 1.12 +#include "nsISupports.h" 1.13 +#include "nsUCSupport.h" 1.14 + 1.15 +// internal base class 1.16 +class nsUTF16ToUnicodeBase : public nsBasicDecoderSupport 1.17 +{ 1.18 +protected: 1.19 + // ctor accessible only by child classes 1.20 + nsUTF16ToUnicodeBase() { Reset();} 1.21 + 1.22 + nsresult UTF16ConvertToUnicode(const char * aSrc, 1.23 + int32_t * aSrcLength, char16_t * aDest, 1.24 + int32_t * aDestLength, bool aSwapBytes); 1.25 + 1.26 +public: 1.27 + //-------------------------------------------------------------------- 1.28 + // Subclassing of nsDecoderSupport class [declaration] 1.29 + 1.30 + NS_IMETHOD GetMaxLength(const char * aSrc, int32_t aSrcLength, 1.31 + int32_t * aDestLength); 1.32 + NS_IMETHOD Reset(); 1.33 + 1.34 +protected: 1.35 + uint8_t mState; 1.36 + // to store an odd byte left over between runs 1.37 + uint8_t mOddByte; 1.38 + // to store an odd high surrogate left over between runs 1.39 + char16_t mOddHighSurrogate; 1.40 + // to store an odd low surrogate left over between runs 1.41 + char16_t mOddLowSurrogate; 1.42 +}; 1.43 + 1.44 +// UTF-16 big endian 1.45 +class nsUTF16BEToUnicode : public nsUTF16ToUnicodeBase 1.46 +{ 1.47 +public: 1.48 + 1.49 + NS_IMETHOD Convert(const char * aSrc, int32_t * aSrcLength, 1.50 + char16_t * aDest, int32_t * aDestLength); 1.51 +}; 1.52 + 1.53 +// UTF-16 little endian 1.54 +class nsUTF16LEToUnicode : public nsUTF16ToUnicodeBase 1.55 +{ 1.56 +public: 1.57 + 1.58 + NS_IMETHOD Convert(const char * aSrc, int32_t * aSrcLength, 1.59 + char16_t * aDest, int32_t * aDestLength); 1.60 +}; 1.61 + 1.62 +// UTF-16 with BOM 1.63 +class nsUTF16ToUnicode : public nsUTF16ToUnicodeBase 1.64 +{ 1.65 +public: 1.66 + 1.67 + nsUTF16ToUnicode() { Reset();} 1.68 + NS_IMETHOD Convert(const char * aSrc, int32_t * aSrcLength, 1.69 + char16_t * aDest, int32_t * aDestLength); 1.70 + 1.71 + NS_IMETHOD Reset(); 1.72 + 1.73 +private: 1.74 + 1.75 + enum Endian {kUnknown, kBigEndian, kLittleEndian}; 1.76 + Endian mEndian; 1.77 + bool mFoundBOM; 1.78 +}; 1.79 + 1.80 +#endif /* nsUTF16ToUnicode_h_ */