]> git.tdb.fi Git - libs/core.git/blobdiff - source/utf8.h
Rework the codec API completely to remove the internal buffering
[libs/core.git] / source / utf8.h
index 94569eef9542f551ff8f821c5b6d079aa3f36325..70d44b00840b3d29f39d651e652388c1466b4bfc 100644 (file)
@@ -11,35 +11,32 @@ Distributed under the LGPL
 #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); }
 };
 
+} // namespace Codecs
 } // namespace Msp
 
 #endif