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