]> git.tdb.fi Git - libs/core.git/blob - source/iso646fi.cpp
45c29ffb5dab08d1edc80075152af9b12c1b826f
[libs/core.git] / source / iso646fi.cpp
1 #include "iso646fi.h"
2
3 using namespace std;
4
5 namespace Msp {
6
7 void Iso646Fi::Encoder::encode_char(wchar_t c)
8 {
9         if((c>=0 && c<=0x5A) || c==0x5F || (c>=0x61 && c<=0x7A))
10                 append(c);
11         else if(c==0xC4)
12                 append(0x5B);
13         else if(c==0xC5)
14                 append(0x5D);
15         else if(c==0xD6)
16                 append(0x5C);
17         else if(c==0xDC)
18                 append(0x5E);
19         else if(c==0xE4)
20                 append(0x7B);
21         else if(c==0xE5)
22                 append(0x7D);
23         else if(c==0xE9)
24                 append(0x60);
25         else if(c==0xF6)
26                 append(0x7C);
27         else if(c==0xFC)
28                 append(0x7E);
29         else
30                 throw CodecError("Can't express character in ISO-646-FI");
31 }
32
33 void Iso646Fi::Decoder::decode_char(const string &str, string::const_iterator &i)
34 {
35         if(i==str.end())
36                 return;
37
38         unsigned char c=*i++;
39         if(c==0x5B)
40                 append(0xC4);
41         else if(c==0x5C)
42                 append(0xD6);
43         else if(c==0x5D)
44                 append(0xC5);
45         else if(c==0x5E)
46                 append(0xDC);
47         else if(c==0x60)
48                 append(0xE9);
49         else if(c==0x7B)
50                 append(0xE4);
51         else if(c==0x7C)
52                 append(0xF6);
53         else if(c==0x7D)
54                 append(0xE5);
55         else if(c==0x7E)
56                 append(0xFC);
57         else if(c<=0x7F)
58                 append(c);
59         else
60                 throw CodecError("Invalid ISO-646-FI string (undefined character)");
61 }
62
63 }