]> git.tdb.fi Git - libs/core.git/blob - source/iso2022jp.h
Added reset function for StringCodec::Decoder
[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();
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                 void reset();
37         private:
38                 Mode mode;
39                 StringCodec::Decoder *dec;
40                 unsigned escape;
41
42                 void switch_mode(Mode);
43         };
44
45         Encoder *create_encoder() const { return new Encoder; }
46         Decoder *create_decoder() const { return new Decoder; }
47 };
48
49 } // namespace Msp
50
51 #endif