]> git.tdb.fi Git - libs/core.git/blob - source/iso2022jp.h
82803b67e61446de3950575027d1a8c29232e6d4
[libs/core.git] / source / iso2022jp.h
1 #ifndef MSP_STRINGS_ISO2022JP_H_
2 #define MSP_STRINGS_ISO2022JP_H_
3
4 #include "codec.h"
5
6 namespace Msp {
7
8 class Iso2022Jp: public StringCodec
9 {
10 public:
11         enum Mode
12         {
13                 ASCII,
14                 JISX0201,
15                 JISX0208
16         };
17                 
18         class Encoder: public StringCodec::Encoder
19         {
20         public:
21                 Encoder(ErrorMode em=THROW_ON_ERROR): StringCodec::Encoder(em), mode(ASCII) { }
22                 void encode_char(wchar_t);
23                 void sync();
24         private:
25                 Mode mode;
26
27                 void switch_mode(Mode);
28                 void append_replacement();
29         };
30
31         class Decoder: public StringCodec::Decoder
32         {
33         public:
34                 Decoder(ErrorMode =THROW_ON_ERROR);
35                 void decode_char(const std::string &, std::string::const_iterator &);
36                 void sync();
37         private:
38                 Mode mode;
39                 StringCodec::Decoder *dec;
40                 unsigned escape;
41
42                 void switch_mode(Mode);
43         };
44
45         Encoder *create_encoder(ErrorMode em=THROW_ON_ERROR) const { return new Encoder(em); }
46         Decoder *create_decoder(ErrorMode em=THROW_ON_ERROR) const { return new Decoder(em); }
47 };
48
49 } // namespace Msp
50
51 #endif