UTF16Encoding.h 2.1 KB

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