]> git.tdb.fi Git - libs/core.git/blob - source/jisx0208.h
9e9ff9bc97a6544061bc6b4b47ca0f0b1600ecdd
[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 namespace Codecs {
15
16 /**
17 Codec for the JIS X 0208 encoding.  This is not particularly useful as a
18 stand-alone codec, due to lack of a linefeed character among other things,
19 but is included as part of some other encodings.
20 */
21 class JisX0208: public Codec
22 {
23 public:
24         class Encoder: public Codec::Encoder
25         {
26         public:
27                 Encoder(ErrorMode em=THROW_ON_ERROR): Codec::Encoder(em) { }
28                 virtual void encode_char(UnicodeChar, std::string &);
29         private:
30                 virtual void transliterate(UnicodeChar, std::string &);
31         };
32
33         class Decoder: public Codec::Decoder
34         {
35         public:
36                 Decoder(ErrorMode em=THROW_ON_ERROR): Codec::Decoder(em) { }
37                 virtual UnicodeChar decode_char(const std::string &, std::string::const_iterator &);
38         };
39
40         Encoder *create_encoder(ErrorMode em=THROW_ON_ERROR) const { return new Encoder(em); }
41         Decoder *create_decoder(ErrorMode em=THROW_ON_ERROR) const { return new Decoder(em); }
42 };
43
44 struct Kuten
45 {
46         unsigned short ku;
47         unsigned short ten;
48
49         Kuten(): ku(0), ten(0) { }
50         operator bool() { return ku!=0 && ten!=0; }
51 };
52
53 extern UnicodeChar jisx0208_to_ucs(Kuten);
54 extern Kuten ucs_to_jisx0208(UnicodeChar);
55
56 } // namespace Codecs
57 } // namespace Msp
58
59 #endif