X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Fjisx0208.h;h=9e9ff9bc97a6544061bc6b4b47ca0f0b1600ecdd;hp=4e3175066ac4fa097d71f8c572435c3f805b89bb;hb=f47bc86e6ce900c5323e593db003c93110538268;hpb=79d472ad3fde75de2eba2487579b047d35e56978;ds=sidebyside diff --git a/source/jisx0208.h b/source/jisx0208.h index 4e31750..9e9ff9b 100644 --- a/source/jisx0208.h +++ b/source/jisx0208.h @@ -11,37 +11,49 @@ Distributed under the LGPL #include "codec.h" namespace Msp { +namespace Codecs { -class JisX0208: public StringCodec +/** +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: - 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("!)"); } + 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), high(0) { } - void decode_char(const std::string &, std::string::const_iterator &); - void sync(); - void reset(); - 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(ErrorMode em=THROW_ON_ERROR) const { return new Encoder(em); } Decoder *create_decoder(ErrorMode em=THROW_ON_ERROR) const { return new Decoder(em); } }; -extern wchar_t jisx0208_to_ucs(unsigned short); -extern unsigned short ucs_to_jisx0208(wchar_t); +struct Kuten +{ + unsigned short ku; + unsigned short ten; + + Kuten(): ku(0), ten(0) { } + operator bool() { return ku!=0 && ten!=0; } +}; + +extern UnicodeChar jisx0208_to_ucs(Kuten); +extern Kuten ucs_to_jisx0208(UnicodeChar); +} // namespace Codecs } // namespace Msp #endif