]> git.tdb.fi Git - libs/core.git/blob - source/iso2022jp.h
Initial upload
[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(): mode(ASCII) { }
22                 void encode_char(wchar_t);
23                 void sync() { switch_mode(ASCII); }
24         private:
25                 Mode mode;
26
27                 void switch_mode(Mode);
28         };
29
30         class Decoder: public StringCodec::Decoder
31         {
32         public:
33                 Decoder();
34                 void decode_char(const std::string &, std::string::const_iterator &);
35                 void sync();
36         private:
37                 Mode mode;
38                 StringCodec::Decoder *dec;
39                 unsigned escape;
40
41                 void switch_mode(Mode);
42         };
43
44         Encoder *create_encoder() const { return new Encoder; }
45         Decoder *create_decoder() const { return new Decoder; }
46 };
47
48 } // namespace Msp
49
50 #endif