]> git.tdb.fi Git - libs/core.git/blobdiff - source/jisx0208.h
Make codecs able to tell their name
[libs/core.git] / source / jisx0208.h
index a81f578108c9f933f3fdbf3ac91b16cd7e6b6baf..27609e619ddc1dcd3e0669e98f0cd26090b18548 100644 (file)
@@ -1,35 +1,61 @@
+/* $Id$
+
+This file is part of libmspstrings
+Copyright © 2006-2007 Mikko Rasa
+Distributed under the LGPL
+*/
+
 #ifndef MSP_STRINGS_JISX0208_H_
 #define MSP_STRINGS_JISX0208_H_
 
 #include "codec.h"
 
 namespace Msp {
-
-class JisX0208: public StringCodec
+namespace Codecs {
+
+/**
+Codec for the JIS X 0208 encoding.  This is not particularly useful as a
+stand-alone codec, due to lack of a linefeed character among other things,
+but is included as part of some other encodings.
+*/
+class JisX0208: 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:
-               void decode_char(const std::string &, std::string::const_iterator &);
-               void sync();
-       private:
-               char high;
+               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 "JIS X 0208"; }
+
+       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); }
+};
+
+struct Kuten
+{
+       unsigned short ku;
+       unsigned short ten;
+
+       Kuten(): ku(0), ten(0) { }
+       operator bool() { return ku!=0 && ten!=0; }
 };
 
-extern wchar_t jisx0208_to_ucs(unsigned short);
-extern unsigned short ucs_to_jisx0208(wchar_t);
+extern UnicodeChar jisx0208_to_ucs(Kuten);
+extern Kuten ucs_to_jisx0208(UnicodeChar);
 
+} // namespace Codecs
 } // namespace Msp
 
 #endif