2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-11-26 17:38:20 -08:00
|
|
|
#ifndef nsUTF16ToUnicode_h_
|
|
|
|
#define nsUTF16ToUnicode_h_
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "nsISupports.h"
|
|
|
|
#include "nsUCSupport.h"
|
|
|
|
|
|
|
|
// internal base class
|
|
|
|
class nsUTF16ToUnicodeBase : public nsBasicDecoderSupport
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
// ctor accessible only by child classes
|
2007-04-23 07:21:53 -07:00
|
|
|
nsUTF16ToUnicodeBase() { Reset();}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-11-26 17:38:20 -08:00
|
|
|
nsresult UTF16ConvertToUnicode(const char * aSrc,
|
|
|
|
int32_t * aSrcLength, PRUnichar * aDest,
|
|
|
|
int32_t * aDestLength, bool aSwapBytes);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
public:
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
// Subclassing of nsDecoderSupport class [declaration]
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
NS_IMETHOD GetMaxLength(const char * aSrc, int32_t aSrcLength,
|
|
|
|
int32_t * aDestLength);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHOD Reset();
|
|
|
|
|
|
|
|
protected:
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t mState;
|
2009-02-22 02:08:27 -08:00
|
|
|
// to store an odd byte left over between runs
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t mOddByte;
|
2009-02-22 02:08:27 -08:00
|
|
|
// to store an odd high surrogate left over between runs
|
|
|
|
PRUnichar mOddHighSurrogate;
|
2010-10-20 09:11:16 -07:00
|
|
|
// to store an odd low surrogate left over between runs
|
|
|
|
PRUnichar mOddLowSurrogate;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
// UTF-16 big endian
|
|
|
|
class nsUTF16BEToUnicode : public nsUTF16ToUnicodeBase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
NS_IMETHOD Convert(const char * aSrc, int32_t * aSrcLength,
|
|
|
|
PRUnichar * aDest, int32_t * aDestLength);
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
// UTF-16 little endian
|
|
|
|
class nsUTF16LEToUnicode : public nsUTF16ToUnicodeBase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
NS_IMETHOD Convert(const char * aSrc, int32_t * aSrcLength,
|
|
|
|
PRUnichar * aDest, int32_t * aDestLength);
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
// UTF-16 with BOM
|
|
|
|
class nsUTF16ToUnicode : public nsUTF16ToUnicodeBase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2009-03-10 14:12:52 -07:00
|
|
|
nsUTF16ToUnicode() { Reset();}
|
2012-08-22 08:56:38 -07:00
|
|
|
NS_IMETHOD Convert(const char * aSrc, int32_t * aSrcLength,
|
|
|
|
PRUnichar * aDest, int32_t * aDestLength);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_IMETHOD Reset();
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
enum Endian {kUnknown, kBigEndian, kLittleEndian};
|
|
|
|
Endian mEndian;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mFoundBOM;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
2012-11-26 17:38:20 -08:00
|
|
|
#endif /* nsUTF16ToUnicode_h_ */
|