X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Futf8.h;h=0e5e0689cea37fae94670d6747b11a23103f44db;hp=40b4fb88ea41eb54cd7ca12ac6c32171027b5a79;hb=271ffa9434c8d9397bb5170cf1ee670c5265ec60;hpb=d2118ac101602cfe2d62fb7deb6ef3fcb0fe137b diff --git a/source/utf8.h b/source/utf8.h index 40b4fb8..0e5e068 100644 --- a/source/utf8.h +++ b/source/utf8.h @@ -1,38 +1,44 @@ +/* $Id$ + +This file is part of libmspstrings +Copyright © 2006-2007 Mikko Rasa +Distributed under the LGPL +*/ + #ifndef MSP_STRINGS_UTF8_H_ #define MSP_STRINGS_UTF8_H_ #include "codec.h" namespace Msp { +namespace Codecs { -class Utf8: public StringCodec +class Utf8: public Codec { public: - class Encoder: public StringCodec::Encoder + class Encoder: public Codec::Encoder { public: - Encoder(ErrorMode em=THROW_ON_ERROR): StringCodec::Encoder(em) { } - void encode_char(wchar_t); + Encoder(ErrorMode em=THROW_ON_ERROR): Codec::Encoder(em) { } + virtual void encode_char(UnicodeChar, std::string &); private: - void append_replacement() { append("\357\277\275"); } + virtual void transliterate(UnicodeChar, std::string &); }; - class Decoder: public StringCodec::Decoder + class Decoder: public Codec::Decoder { public: - Decoder(ErrorMode em=THROW_ON_ERROR): StringCodec::Decoder(em), bytes(0), code(0) { } - void decode_char(const std::string &, std::string::const_iterator &); - void sync(); - void reset(); - private: - unsigned bytes; - unsigned code; + Decoder(ErrorMode em=THROW_ON_ERROR): Codec::Decoder(em) { } + virtual UnicodeChar decode_char(const std::string &, std::string::const_iterator &); }; - Encoder *create_encoder(ErrorMode em=THROW_ON_ERROR) const { return new Encoder(em); } - Decoder *create_decoder(ErrorMode em=THROW_ON_ERROR) const { return new Decoder(em); } + virtual const char *get_name() const { return "UTF-8"; } + + virtual Encoder *create_encoder(ErrorMode em=THROW_ON_ERROR) const { return new Encoder(em); } + virtual Decoder *create_decoder(ErrorMode em=THROW_ON_ERROR) const { return new Decoder(em); } }; +} // namespace Codecs } // namespace Msp #endif