1 #ifndef MSP_STRINGCODEC_UTF16_H_
2 #define MSP_STRINGCODEC_UTF16_H_
7 namespace StringCodec {
10 The UTF-16 codec, as specified in the Unicode standard. Both little and big
11 endian are supported, as well as autodetection with the BOM. In the absence
12 of a BOM, big endian is assumed.
14 class Utf16: public StandardCodec<Utf16>
24 class Encoder: public Codec::Encoder
31 Encoder(ErrorMode em = DEFAULT, Endian en = BIG);
33 void encode_char(unichar, std::string &) override;
35 void transliterate(unichar, std::string &) override;
38 class Decoder: public Codec::Decoder
44 Decoder(ErrorMode em = DEFAULT, Endian en = AUTO);
46 unichar decode_char(const std::string &, std::string::const_iterator &) override;
48 unichar decode_unit(const std::string &, const std::string::const_iterator &, std::string::const_iterator &);
55 Utf16(ErrorMode em = DEFAULT, Endian en = AUTO):
56 StandardCodec<Utf16>(em),
60 const char *get_name() const override
61 { return endian==BIG ? "UTF-16-BE" : endian==LITTLE ? "UTF-16-LE" : "UTF-16"; }
63 Encoder *create_encoder(ErrorMode em = DEFAULT) const override
64 { return new Encoder(get_error_mode(em), endian); }
66 Decoder *create_decoder(ErrorMode em = DEFAULT) const override
67 { return new Decoder(get_error_mode(em), endian); }
72 A helper template to define the Utf16Be and Utf16Le types.
74 template<Utf16::Endian en>
75 class Utf16E: public Utf16
78 class Encoder: public Utf16::Encoder
81 Encoder(ErrorMode em = DEFAULT): Utf16::Encoder(em, en) { }
84 class Decoder: public Utf16::Decoder
87 Decoder(ErrorMode em = DEFAULT): Utf16::Decoder(em, en) { }
90 Utf16E(ErrorMode em = DEFAULT): Utf16(em, en) { }
93 typedef Utf16E<Utf16::BIG> Utf16Be;
94 typedef Utf16E<Utf16::LITTLE> Utf16Le;
96 } // namespace StringCodec