]> git.tdb.fi Git - libs/core.git/blob - source/jisx0208.h
4e3175066ac4fa097d71f8c572435c3f805b89bb
[libs/core.git] / source / jisx0208.h
1 /* $Id$
2
3 This file is part of libmspstrings
4 Copyright © 2006-2007 Mikko Rasa
5 Distributed under the LGPL
6 */
7
8 #ifndef MSP_STRINGS_JISX0208_H_
9 #define MSP_STRINGS_JISX0208_H_
10
11 #include "codec.h"
12
13 namespace Msp {
14
15 class JisX0208: public StringCodec
16 {
17 public:
18         class Encoder: public StringCodec::Encoder
19         {
20         public:
21                 Encoder(ErrorMode em=THROW_ON_ERROR): StringCodec::Encoder(em) { }
22                 void encode_char(wchar_t);
23         private:
24                 void append_replacement() { append("!)"); }
25         };
26
27         class Decoder: public StringCodec::Decoder
28         {
29         public:
30                 Decoder(ErrorMode em=THROW_ON_ERROR): StringCodec::Decoder(em), high(0) { }
31                 void decode_char(const std::string &, std::string::const_iterator &);
32                 void sync();
33                 void reset();
34         private:
35                 char high;
36         };
37
38         Encoder *create_encoder(ErrorMode em=THROW_ON_ERROR) const { return new Encoder(em); }
39         Decoder *create_decoder(ErrorMode em=THROW_ON_ERROR) const { return new Decoder(em); }
40 };
41
42 extern wchar_t jisx0208_to_ucs(unsigned short);
43 extern unsigned short ucs_to_jisx0208(wchar_t);
44
45 } // namespace Msp
46
47 #endif