]> git.tdb.fi Git - libs/core.git/blob - jisx0201.cpp
4d9d6bdf5eaea9c257a13325643c574b1672761d
[libs/core.git] / jisx0201.cpp
1 #include "jisx0201.h"
2
3 using namespace std;
4
5 namespace Msp {
6 namespace StringCodec {
7
8 void JisX0201::Encoder::encode_char(unichar ch, string &buf)
9 {
10         if(ch>=0 && ch<=0x7F && ch!=0x5C && ch!=0x7E)
11                 buf += ch;
12         else if(ch==0xA5)
13                 buf += 0x5C;
14         else if(ch==0x203E)
15                 buf += 0x7E;
16         else if(ch>=0xFF61 && ch<=0xFF9F)
17                 buf += ch-0xFEC0;
18         else
19                 error(ch, buf, "Can't express character in JIS X 0201");
20 }
21
22 void JisX0201::Encoder::transliterate(unichar, string &buf)
23 {
24         buf += '?';
25 }
26
27
28 unichar JisX0201::Decoder::decode_char(const string &str, string::const_iterator &i)
29 {
30         if(i==str.end())
31                 return -1;
32
33         unsigned char ch = *i;
34         unichar result;
35         if(ch==0x5C)
36                 result = 0xA5;
37         else if(ch==0x7E)
38                 result = 0x203E;
39         else if(ch<=0x7F)
40                 result = ch;
41         else if(ch>=0xA1 && ch<=0xDF)
42                 result = ch+0xFEC0;
43         else
44                 result = error("Undefined JIS X 0201 character");
45
46         ++i;
47         return result;
48 }
49
50 } // namespace StringCodec
51 } // namespace Msp