1 | // |
---|
2 | // UTF16Encoding.h |
---|
3 | // |
---|
4 | // $Id: //poco/1.3/Foundation/include/Poco/UTF16Encoding.h#4 $ |
---|
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 | // Permission is hereby granted, free of charge, to any person or organization |
---|
16 | // obtaining a copy of the software and accompanying documentation covered by |
---|
17 | // this license (the "Software") to use, reproduce, display, distribute, |
---|
18 | // execute, and transmit the Software, and to prepare derivative works of the |
---|
19 | // Software, and to permit third-parties to whom the Software is furnished to |
---|
20 | // do so, all subject to the following: |
---|
21 | // |
---|
22 | // The copyright notices in the Software and this entire statement, including |
---|
23 | // the above license grant, this restriction and the following disclaimer, |
---|
24 | // must be included in all copies of the Software, in whole or in part, and |
---|
25 | // all derivative works of the Software, unless such copies or derivative |
---|
26 | // works are solely in the form of machine-executable object code generated by |
---|
27 | // a source language processor. |
---|
28 | // |
---|
29 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
---|
30 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
---|
31 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT |
---|
32 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE |
---|
33 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, |
---|
34 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
---|
35 | // DEALINGS IN THE SOFTWARE. |
---|
36 | // |
---|
37 | |
---|
38 | |
---|
39 | #ifndef Foundation_UTF16Encoding_INCLUDED |
---|
40 | #define Foundation_UTF16Encoding_INCLUDED |
---|
41 | |
---|
42 | |
---|
43 | #include "Poco/Foundation.h" |
---|
44 | #include "Poco/TextEncoding.h" |
---|
45 | |
---|
46 | |
---|
47 | namespace Poco { |
---|
48 | |
---|
49 | |
---|
50 | class Foundation_API UTF16Encoding: public TextEncoding |
---|
51 | /// UTF-16 text encoding, as defined in RFC 2781. |
---|
52 | /// |
---|
53 | /// When converting from UTF-16 to Unicode, surrogates are |
---|
54 | /// reported as they are - in other words, surrogate pairs |
---|
55 | /// are not combined into one Unicode character. |
---|
56 | /// When converting from Unicode to UTF-16, however, characters |
---|
57 | /// outside the 16-bit range are converted into a low and |
---|
58 | /// high surrogate. |
---|
59 | { |
---|
60 | public: |
---|
61 | enum ByteOrderType |
---|
62 | { |
---|
63 | BIG_ENDIAN_BYTE_ORDER, |
---|
64 | LITTLE_ENDIAN_BYTE_ORDER, |
---|
65 | NATIVE_BYTE_ORDER |
---|
66 | }; |
---|
67 | |
---|
68 | UTF16Encoding(ByteOrderType byteOrder = NATIVE_BYTE_ORDER); |
---|
69 | /// Creates and initializes the encoding for the given byte order. |
---|
70 | |
---|
71 | UTF16Encoding(int byteOrderMark); |
---|
72 | /// Creates and initializes the encoding for the byte-order |
---|
73 | /// indicated by the given byte-order mark, which is the Unicode |
---|
74 | /// character 0xFEFF. |
---|
75 | |
---|
76 | ~UTF16Encoding(); |
---|
77 | |
---|
78 | ByteOrderType getByteOrder() const; |
---|
79 | /// Returns the byte-order currently in use. |
---|
80 | |
---|
81 | void setByteOrder(ByteOrderType byteOrder); |
---|
82 | /// Sets the byte order. |
---|
83 | |
---|
84 | void setByteOrder(int byteOrderMark); |
---|
85 | /// Sets the byte order according to the given |
---|
86 | /// byte order mark, which is the Unicode |
---|
87 | /// character 0xFEFF. |
---|
88 | |
---|
89 | const char* canonicalName() const; |
---|
90 | bool isA(const std::string& encodingName) const; |
---|
91 | const CharacterMap& characterMap() const; |
---|
92 | int convert(const unsigned char* bytes) const; |
---|
93 | int convert(int ch, unsigned char* bytes, int length) const; |
---|
94 | int queryConvert(const unsigned char* bytes, int length) const; |
---|
95 | int sequenceLength(const unsigned char* bytes, int length) const; |
---|
96 | |
---|
97 | private: |
---|
98 | bool _flipBytes; |
---|
99 | static const char* _names[]; |
---|
100 | static const CharacterMap _charMap; |
---|
101 | }; |
---|
102 | |
---|
103 | |
---|
104 | } // namespace Poco |
---|
105 | |
---|
106 | |
---|
107 | #endif // Foundation_UTF16Encoding_INCLUDED |
---|