]> git.tdb.fi Git - libs/core.git/blob - source/stringcodec/iso646fi.cpp
Drop copyright and license notices from source files
[libs/core.git] / source / stringcodec / iso646fi.cpp
1 #include "codecutils.h"
2 #include "iso646fi.h"
3
4 using namespace std;
5
6 namespace {
7
8 const unsigned map_size = 9;
9
10 const int mapping[map_size*2]=
11 {
12         0xC4, 0x5B,
13         0xC5, 0x5D,
14         0xD6, 0x5C,
15         0xDC, 0x5E,
16         0xE4, 0x7B,
17         0xE5, 0x7D,
18         0xE9, 0x60,
19         0xF6, 0x7C,
20         0xFC, 0x7E
21 };
22
23 }
24
25
26 namespace Msp {
27 namespace Codecs {
28
29 void Iso646Fi::Encoder::encode_char(UnicodeChar ch, string &buf)
30 {
31         int tch = transform_mapping_or_direct(mapping, map_size, ch, false);
32         if(tch<0 || tch>0x7F)
33                 error(ch, buf, "Can't express character in ISO-646-FI");
34         else
35                 buf += tch;
36 }
37
38 void Iso646Fi::Encoder::transliterate(UnicodeChar, string &buf)
39 {
40         buf += '?';
41 }
42
43
44 UnicodeChar Iso646Fi::Decoder::decode_char(const string &str, string::const_iterator &i)
45 {
46         if(i==str.end())
47                 return error("No input");
48
49         unsigned char ch = *i;
50         int tch = (ch<=0x7F ? transform_mapping_or_direct(mapping, map_size, ch, true) : -1);
51
52         UnicodeChar result;
53         if(tch==-1)
54                 result = error("Undefined ISO-646-FI character");
55         else
56                 result = tch;
57
58         ++i;
59         return result;
60 }
61
62 } // namespace Codecs
63 } // namespace Msp