]> git.tdb.fi Git - libs/core.git/blob - source/stringcodec/jisx0208.h
Add move semantics to Variant
[libs/core.git] / source / stringcodec / jisx0208.h
1 #ifndef MSP_STRINGCODEC_JISX0208_H_
2 #define MSP_STRINGCODEC_JISX0208_H_
3
4 #include <msp/core/mspcore_api.h>
5 #include "codec.h"
6
7 namespace Msp {
8 namespace StringCodec {
9
10 /**
11 Codec for the JIS X 0208 encoding.  This is not particularly useful as a
12 stand-alone codec, due to lack of a linefeed character among other things,
13 but is included as part of some other encodings.
14 */
15 class MSPCORE_API JisX0208: public StandardCodec<JisX0208>
16 {
17 public:
18         class MSPCORE_API Encoder: public Codec::Encoder
19         {
20         public:
21                 Encoder(ErrorMode em = DEFAULT): Codec::Encoder(em) { }
22
23                 void encode_char(unichar, std::string &) override;
24         private:
25                 void transliterate(unichar, std::string &) override;
26         };
27
28         class MSPCORE_API Decoder: public Codec::Decoder
29         {
30         public:
31                 Decoder(ErrorMode em = DEFAULT): Codec::Decoder(em) { }
32
33                 unichar decode_char(const std::string &, std::string::const_iterator &) override;
34         };
35
36         JisX0208(ErrorMode em = DEFAULT): StandardCodec<JisX0208>(em) { }
37
38         const char *get_name() const override { return "JIS X 0208"; }
39 };
40
41
42 struct Kuten
43 {
44         unsigned short ku = 0;
45         unsigned short ten = 0;
46
47         explicit operator bool() { return ku!=0 && ten!=0; }
48 };
49
50 MSPCORE_API unichar jisx0208_to_ucs(Kuten);
51 MSPCORE_API Kuten ucs_to_jisx0208(unichar);
52
53 } // namespace StringCodec
54 } // namespace Msp
55
56 #endif