]> git.tdb.fi Git - libs/core.git/blob - source/iso646fi.cpp
Rework the codec API completely to remove the internal buffering
[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 "iso646fi.h"
9
10 using namespace std;
11
12 namespace Msp {
13 namespace Codecs {
14
15 void Iso646Fi::Encoder::encode_char(UnicodeChar ch, string &buf)
16 {
17         if((ch>=0 && ch<=0x5A) || ch==0x5F || (ch>=0x61 && ch<=0x7A))
18                 buf+=ch;
19         else if(ch==0xC4)
20                 buf+=0x5B;
21         else if(ch==0xC5)
22                 buf+=0x5D;
23         else if(ch==0xD6)
24                 buf+=0x5C;
25         else if(ch==0xDC)
26                 buf+=0x5E;
27         else if(ch==0xE4)
28                 buf+=0x7B;
29         else if(ch==0xE5)
30                 buf+=0x7D;
31         else if(ch==0xE9)
32                 buf+=0x60;
33         else if(ch==0xF6)
34                 buf+=0x7C;
35         else if(ch==0xFC)
36                 buf+=0x7E;
37         else
38                 error(ch, buf, "Can't express character in ISO-646-FI");
39 }
40
41 void Iso646Fi::Encoder::transliterate(UnicodeChar, string &buf)
42 {
43         buf+='?';
44 }
45
46
47 UnicodeChar Iso646Fi::Decoder::decode_char(const string &str, string::const_iterator &i)
48 {
49         if(i==str.end())
50                 return error("No input");
51
52         unsigned char ch=*i;
53         UnicodeChar result=-1;
54         if(ch==0x5B)
55                 result=0xC4;
56         else if(ch==0x5C)
57                 result=0xD6;
58         else if(ch==0x5D)
59                 result=0xC5;
60         else if(ch==0x5E)
61                 result=0xDC;
62         else if(ch==0x60)
63                 result=0xE9;
64         else if(ch==0x7B)
65                 result=0xE4;
66         else if(ch==0x7C)
67                 result=0xF6;
68         else if(ch==0x7D)
69                 result=0xE5;
70         else if(ch==0x7E)
71                 result=0xFC;
72         else if(ch<=0x7F)
73                 result=ch;
74         else
75                 result=error("Undefined ISO-646-FI character");
76
77         ++i;
78         return result;
79 }
80
81 } // namespace Codecs
82 } // namespace Msp