]> git.tdb.fi Git - libs/core.git/blob - source/stringcodec/jisx0208.h
Move files around to prepare for assimilation into core
[libs/core.git] / source / stringcodec / 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
29                 virtual void encode_char(UnicodeChar, std::string &);
30         private:
31                 virtual void transliterate(UnicodeChar, std::string &);
32         };
33
34         class Decoder: public Codec::Decoder
35         {
36         public:
37                 Decoder(ErrorMode em = THROW_ON_ERROR): Codec::Decoder(em) { }
38
39                 virtual UnicodeChar decode_char(const std::string &, std::string::const_iterator &);
40         };
41
42         virtual const char *get_name() const { return "JIS X 0208"; }
43
44         virtual Encoder *create_encoder(ErrorMode em = THROW_ON_ERROR) const { return new Encoder(em); }
45         virtual Decoder *create_decoder(ErrorMode em = THROW_ON_ERROR) const { return new Decoder(em); }
46 };
47
48
49 struct Kuten
50 {
51         unsigned short ku;
52         unsigned short ten;
53
54         Kuten(): ku(0), ten(0) { }
55
56         operator bool() { return ku!=0 && ten!=0; }
57 };
58
59 extern UnicodeChar jisx0208_to_ucs(Kuten);
60 extern Kuten ucs_to_jisx0208(UnicodeChar);
61
62 } // namespace Codecs
63 } // namespace Msp
64
65 #endif