nsUnicodeToUTF8.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. #ifndef nsUnicodeToUTF8_h___
  6. #define nsUnicodeToUTF8_h___
  7. #include "mozilla/Attributes.h"
  8. #include "nsIUnicodeEncoder.h"
  9. // Class ID for our UnicodeToUTF8 charset converter
  10. // {7C657D18-EC5E-11d2-8AAC-00600811A836}
  11. #define NS_UNICODETOUTF8_CID \
  12. { 0x7c657d18, 0xec5e, 0x11d2, {0x8a, 0xac, 0x0, 0x60, 0x8, 0x11, 0xa8, 0x36}}
  13. #define NS_UNICODETOUTF8_CONTRACTID "@mozilla.org/intl/unicode/encoder;1?charset=UTF-8"
  14. //#define NS_ERROR_UCONV_NOUNICODETOUTF8
  15. // NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_UCONV, 0x31)
  16. //----------------------------------------------------------------------
  17. // Class nsUnicodeToUTF8 [declaration]
  18. /**
  19. * A character set converter from Unicode to UTF8.
  20. *
  21. * @created 05/Apr/1999
  22. * @author Catalin Rotaru [CATA]
  23. */
  24. class nsUnicodeToUTF8 final : public nsIUnicodeEncoder
  25. {
  26. ~nsUnicodeToUTF8() {}
  27. NS_DECL_ISUPPORTS
  28. public:
  29. /**
  30. * Class constructor.
  31. */
  32. nsUnicodeToUTF8() {mHighSurrogate = 0;}
  33. NS_IMETHOD Convert(const char16_t*aSrc,
  34. int32_t* aSrcLength,
  35. char* aDest,
  36. int32_t* aDestLength) override;
  37. NS_IMETHOD Finish(char* aDest, int32_t* aDestLength) override;
  38. MOZ_MUST_USE NS_IMETHOD GetMaxLength(const char16_t* aSrc,
  39. int32_t aSrcLength,
  40. int32_t* aDestLength) override;
  41. NS_IMETHOD Reset() override {mHighSurrogate = 0; return NS_OK;}
  42. NS_IMETHOD SetOutputErrorBehavior(int32_t aBehavior,
  43. nsIUnicharEncoder* aEncoder, char16_t aChar) override {return NS_OK;}
  44. protected:
  45. char16_t mHighSurrogate;
  46. };
  47. #endif /* nsUnicodeToUTF8_h___ */