]> git.tdb.fi Git - libs/core.git/blobdiff - source/utf8.h
Make codecs able to tell their name
[libs/core.git] / source / utf8.h
index 0475523cf52578216e9a63c4a4942ad1c18936e9..0e5e0689cea37fae94670d6747b11a23103f44db 100644 (file)
@@ -1,35 +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:
-               void encode_char(wchar_t);
+               Encoder(ErrorMode em=THROW_ON_ERROR): Codec::Encoder(em) { }
+               virtual void encode_char(UnicodeChar, std::string &);
+       private:
+               virtual void transliterate(UnicodeChar, std::string &);
        };
 
-       class Decoder: public StringCodec::Decoder
+       class Decoder: public Codec::Decoder
        {
        public:
-               Decoder(): 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() const { return new Encoder; }
-       Decoder *create_decoder() const { return new Decoder; }
+       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