1 #ifndef MSP_STRINGCODEC_UTF16_H_
2 #define MSP_STRINGCODEC_UTF16_H_
4 #include <msp/core/mspcore_api.h>
8 namespace StringCodec {
11 The UTF-16 codec, as specified in the Unicode standard. Both little and big
12 endian are supported, as well as autodetection with the BOM. In the absence
13 of a BOM, big endian is assumed.
15 class MSPCORE_API Utf16: public StandardCodec<Utf16>
25 class MSPCORE_API Encoder: public Codec::Encoder
32 Encoder(ErrorMode em = DEFAULT, Endian en = BIG);
34 void encode_char(unichar, std::string &) override;
36 void transliterate(unichar, std::string &) override;
39 class MSPCORE_API Decoder: public Codec::Decoder
45 Decoder(ErrorMode em = DEFAULT, Endian en = AUTO);
47 unichar decode_char(const std::string &, std::string::const_iterator &) override;
49 unichar decode_unit(const std::string &, const std::string::const_iterator &, std::string::const_iterator &);
56 Utf16(ErrorMode em = DEFAULT, Endian en = AUTO):
57 StandardCodec<Utf16>(em),
61 const char *get_name() const override
62 { return endian==BIG ? "UTF-16-BE" : endian==LITTLE ? "UTF-16-LE" : "UTF-16"; }
64 Encoder *create_encoder(ErrorMode em = DEFAULT) const override
65 { return new Encoder(get_error_mode(em), endian); }
67 Decoder *create_decoder(ErrorMode em = DEFAULT) const override
68 { return new Decoder(get_error_mode(em), endian); }
73 A helper template to define the Utf16Be and Utf16Le types.
75 template<Utf16::Endian en>
76 class Utf16E: public Utf16
79 class Encoder: public Utf16::Encoder
82 Encoder(ErrorMode em = DEFAULT): Utf16::Encoder(em, en) { }
85 class Decoder: public Utf16::Decoder
88 Decoder(ErrorMode em = DEFAULT): Utf16::Decoder(em, en) { }
91 Utf16E(ErrorMode em = DEFAULT): Utf16(em, en) { }
94 typedef Utf16E<Utf16::BIG> Utf16Be;
95 typedef Utf16E<Utf16::LITTLE> Utf16Le;
97 } // namespace StringCodec