UTF16Encoding.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. //
  2. // UTF16Encoding.h
  3. //
  4. // $Id: //poco/1.4/Foundation/include/Poco/UTF16Encoding.h#1 $
  5. //
  6. // Library: Foundation
  7. // Package: Text
  8. // Module: UTF16Encoding
  9. //
  10. // Definition of the UTF16Encoding class.
  11. //
  12. // Copyright (c) 2004-2007, Applied Informatics Software Engineering GmbH.
  13. // and Contributors.
  14. //
  15. // SPDX-License-Identifier: BSL-1.0
  16. //
  17. #ifndef Foundation_UTF16Encoding_INCLUDED
  18. #define Foundation_UTF16Encoding_INCLUDED
  19. #include "Poco/Foundation.h"
  20. #include "Poco/TextEncoding.h"
  21. namespace Poco {
  22. class Foundation_API UTF16Encoding: public TextEncoding
  23. /// UTF-16 text encoding, as defined in RFC 2781.
  24. ///
  25. /// When converting from UTF-16 to Unicode, surrogates are
  26. /// reported as they are - in other words, surrogate pairs
  27. /// are not combined into one Unicode character.
  28. /// When converting from Unicode to UTF-16, however, characters
  29. /// outside the 16-bit range are converted into a low and
  30. /// high surrogate.
  31. {
  32. public:
  33. enum ByteOrderType
  34. {
  35. BIG_ENDIAN_BYTE_ORDER,
  36. LITTLE_ENDIAN_BYTE_ORDER,
  37. NATIVE_BYTE_ORDER
  38. };
  39. UTF16Encoding(ByteOrderType byteOrder = NATIVE_BYTE_ORDER);
  40. /// Creates and initializes the encoding for the given byte order.
  41. UTF16Encoding(int byteOrderMark);
  42. /// Creates and initializes the encoding for the byte-order
  43. /// indicated by the given byte-order mark, which is the Unicode
  44. /// character 0xFEFF.
  45. ~UTF16Encoding();
  46. ByteOrderType getByteOrder() const;
  47. /// Returns the byte-order currently in use.
  48. void setByteOrder(ByteOrderType byteOrder);
  49. /// Sets the byte order.
  50. void setByteOrder(int byteOrderMark);
  51. /// Sets the byte order according to the given
  52. /// byte order mark, which is the Unicode
  53. /// character 0xFEFF.
  54. const char* canonicalName() const;
  55. bool isA(const std::string& encodingName) const;
  56. const CharacterMap& characterMap() const;
  57. int convert(const unsigned char* bytes) const;
  58. int convert(int ch, unsigned char* bytes, int length) const;
  59. int queryConvert(const unsigned char* bytes, int length) const;
  60. int sequenceLength(const unsigned char* bytes, int length) const;
  61. private:
  62. bool _flipBytes;
  63. static const char* _names[];
  64. static const CharacterMap _charMap;
  65. };
  66. } // namespace Poco
  67. #endif // Foundation_UTF16Encoding_INCLUDED