nsUnicodeToGBK.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /* -*- Mode: C++; tab-width: 2; 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. * A character set converter from Unicode to GBK.
  7. *
  8. *
  9. * @created 08/Sept/1999
  10. * @author Yueheng Xu, Yueheng.Xu@intel.com
  11. */
  12. #ifndef nsUnicodeToGBK_h___
  13. #define nsUnicodeToGBK_h___
  14. #include "nsUCSupport.h"
  15. #include "nsCOMPtr.h"
  16. #include "nsIUnicodeEncoder.h"
  17. #include "nsGBKConvUtil.h"
  18. //----------------------------------------------------------------------
  19. // Class nsUnicodeToGBK [declaration]
  20. class nsUnicodeToGBK: public nsEncoderSupport
  21. {
  22. public:
  23. /**
  24. * Class constructor.
  25. */
  26. explicit nsUnicodeToGBK(uint32_t aMaxLengthFactor = 2);
  27. virtual ~nsUnicodeToGBK() {}
  28. protected:
  29. //--------------------------------------------------------------------
  30. // Subclassing of nsEncoderSupport class [declaration]
  31. NS_IMETHOD ConvertNoBuffNoErr(const char16_t * aSrc,
  32. int32_t * aSrcLength,
  33. char * aDest,
  34. int32_t * aDestLength);
  35. protected:
  36. char16_t mSurrogateHigh;
  37. nsGBKConvUtil mUtil;
  38. virtual nsresult TryExtensionEncoder(char16_t aChar, char* aDest,
  39. int32_t* aOutLen);
  40. virtual nsresult Try4BytesEncoder(char16_t aChar, char* aDest,
  41. int32_t* aOutLen);
  42. virtual nsresult EncodeSurrogate(char16_t aSurrogateHigh,
  43. char16_t aSurrogateLow, char* aDest,
  44. int32_t aDestLength, int32_t aBufferLength);
  45. };
  46. class nsUnicodeToGB18030: public nsUnicodeToGBK
  47. {
  48. public:
  49. nsUnicodeToGB18030() : nsUnicodeToGBK(4) {}
  50. virtual ~nsUnicodeToGB18030() {}
  51. protected:
  52. virtual nsresult TryExtensionEncoder(char16_t aChar, char* aDest,
  53. int32_t* aOutLen) override;
  54. virtual nsresult Try4BytesEncoder(char16_t aChar, char* aDest,
  55. int32_t* aOutLen) override;
  56. virtual nsresult EncodeSurrogate(char16_t aSurrogateHigh,
  57. char16_t aSurrogateLow, char* aDest,
  58. int32_t aDestLength,
  59. int32_t aBufferLength) override;
  60. };
  61. #endif /* nsUnicodeToGBK_h___ */