]> git.tdb.fi Git - libs/core.git/blob - source/stringcodec/iso646fi.cpp
Additional adjustments for Poller
[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 StringCodec {
28
29 void Iso646Fi::Encoder::encode_char(unichar 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, invalid_character(ch, "ISO-646-FI"));
34         else
35                 buf += tch;
36 }
37
38 void Iso646Fi::Encoder::transliterate(unichar, string &buf)
39 {
40         buf += '?';
41 }
42
43
44 unichar Iso646Fi::Decoder::decode_char(const string &str, string::const_iterator &i)
45 {
46         if(i==str.end())
47                 return -1;
48
49         unsigned char ch = *i;
50         unichar result;
51         if(ch>=0x80)
52                 result = error(invalid_sequence(i, i+1, "undefined ISO-646-FI character"));
53         else
54                 result = transform_mapping_or_direct(mapping, map_size, ch, true);
55
56         ++i;
57         return result;
58 }
59
60 } // namespace StringCodec
61 } // namespace Msp