]> git.tdb.fi Git - libs/core.git/blob - source/stringcodec/jisx0201.cpp
Drop copyright and license notices from source files
[libs/core.git] / source / stringcodec / jisx0201.cpp
1 #include "jisx0201.h"
2
3 using namespace std;
4
5 namespace Msp {
6 namespace Codecs {
7
8 void JisX0201::Encoder::encode_char(UnicodeChar 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(UnicodeChar, string &buf)
23 {
24         buf += '?';
25 }
26
27
28 UnicodeChar JisX0201::Decoder::decode_char(const string &str, string::const_iterator &i)
29 {
30         if(i==str.end())
31                 return error("No input");
32
33         unsigned char ch = *i;
34         UnicodeChar 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 Codecs
51 } // namespace Msp