]> git.tdb.fi Git - libs/core.git/blob - source/iso2022jp.h
Add copyright notices and Id tags
[libs/core.git] / source / iso2022jp.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_ISO2022JP_H_
9 #define MSP_STRINGS_ISO2022JP_H_
10
11 #include "codec.h"
12
13 namespace Msp {
14
15 class Iso2022Jp: public StringCodec
16 {
17 public:
18         enum Mode
19         {
20                 ASCII,
21                 JISX0201,
22                 JISX0208
23         };
24                 
25         class Encoder: public StringCodec::Encoder
26         {
27         public:
28                 Encoder(ErrorMode em=THROW_ON_ERROR): StringCodec::Encoder(em), mode(ASCII) { }
29                 void encode_char(wchar_t);
30                 void sync();
31         private:
32                 Mode mode;
33
34                 void switch_mode(Mode);
35                 void append_replacement();
36         };
37
38         class Decoder: public StringCodec::Decoder
39         {
40         public:
41                 Decoder(ErrorMode =THROW_ON_ERROR);
42                 void decode_char(const std::string &, std::string::const_iterator &);
43                 void sync();
44         private:
45                 Mode mode;
46                 StringCodec::Decoder *dec;
47                 unsigned escape;
48
49                 void switch_mode(Mode);
50         };
51
52         Encoder *create_encoder(ErrorMode em=THROW_ON_ERROR) const { return new Encoder(em); }
53         Decoder *create_decoder(ErrorMode em=THROW_ON_ERROR) const { return new Decoder(em); }
54 };
55
56 } // namespace Msp
57
58 #endif