| 1 | // |
| 2 | // UTF32Encoding.h |
| 3 | // |
| 4 | // Library: Foundation |
| 5 | // Package: Text |
| 6 | // Module: UTF32Encoding |
| 7 | // |
| 8 | // Definition of the UTF32Encoding 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 | |
| 16 | |
| 17 | #ifndef Foundation_UTF32Encoding_INCLUDED |
| 18 | #define Foundation_UTF32Encoding_INCLUDED |
| 19 | |
| 20 | |
| 21 | #include "Poco/Foundation.h" |
| 22 | #include "Poco/TextEncoding.h" |
| 23 | |
| 24 | |
| 25 | namespace Poco { |
| 26 | |
| 27 | |
| 28 | class Foundation_API UTF32Encoding: public TextEncoding |
| 29 | /// UTF-32 text encoding, as defined in RFC 2781. |
| 30 | /// |
| 31 | /// When converting from UTF-32 to Unicode, surrogates are |
| 32 | /// reported as they are - in other words, surrogate pairs |
| 33 | /// are not combined into one Unicode character. |
| 34 | { |
| 35 | public: |
| 36 | enum ByteOrderType |
| 37 | { |
| 38 | BIG_ENDIAN_BYTE_ORDER, |
| 39 | LITTLE_ENDIAN_BYTE_ORDER, |
| 40 | NATIVE_BYTE_ORDER |
| 41 | }; |
| 42 | |
| 43 | UTF32Encoding(ByteOrderType byteOrder = NATIVE_BYTE_ORDER); |
| 44 | /// Creates and initializes the encoding for the given byte order. |
| 45 | |
| 46 | UTF32Encoding(int byteOrderMark); |
| 47 | /// Creates and initializes the encoding for the byte-order |
| 48 | /// indicated by the given byte-order mark, which is the Unicode |
| 49 | /// character 0xFEFF. |
| 50 | |
| 51 | ~UTF32Encoding(); |
| 52 | |
| 53 | ByteOrderType getByteOrder() const; |
| 54 | /// Returns the byte-order currently in use. |
| 55 | |
| 56 | void setByteOrder(ByteOrderType byteOrder); |
| 57 | /// Sets the byte order. |
| 58 | |
| 59 | void setByteOrder(int byteOrderMark); |
| 60 | /// Sets the byte order according to the given |
| 61 | /// byte order mark, which is the Unicode |
| 62 | /// character 0xFEFF. |
| 63 | |
| 64 | const char* canonicalName() const; |
| 65 | bool isA(const std::string& encodingName) const; |
| 66 | const CharacterMap& characterMap() const; |
| 67 | int convert(const unsigned char* bytes) const; |
| 68 | int convert(int ch, unsigned char* bytes, int length) const; |
| 69 | int queryConvert(const unsigned char* bytes, int length) const; |
| 70 | int sequenceLength(const unsigned char* bytes, int length) const; |
| 71 | |
| 72 | private: |
| 73 | bool _flipBytes; |
| 74 | static const char* _names[]; |
| 75 | static const CharacterMap _charMap; |
| 76 | }; |
| 77 | |
| 78 | |
| 79 | } // namespace Poco |
| 80 | |
| 81 | |
| 82 | #endif // Foundation_UTF32Encoding_INCLUDED |
| 83 | |