]> git.tdb.fi Git - libs/core.git/blob - source/iso646fi.cpp
Add copyright notices and Id tags
[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
14 void Iso646Fi::Encoder::encode_char(wchar_t c_)
15 {
16         // Win32 has typedef unsigned short wchar_t
17         int c=c_;
18
19         if((c>=0 && c<=0x5A) || c==0x5F || (c>=0x61 && c<=0x7A))
20                 append(c);
21         else if(c==0xC4)
22                 append(0x5B);
23         else if(c==0xC5)
24                 append(0x5D);
25         else if(c==0xD6)
26                 append(0x5C);
27         else if(c==0xDC)
28                 append(0x5E);
29         else if(c==0xE4)
30                 append(0x7B);
31         else if(c==0xE5)
32                 append(0x7D);
33         else if(c==0xE9)
34                 append(0x60);
35         else if(c==0xF6)
36                 append(0x7C);
37         else if(c==0xFC)
38                 append(0x7E);
39         else
40                 error("Can't express character in ISO-646-FI");
41 }
42
43 void Iso646Fi::Decoder::decode_char(const string &str, string::const_iterator &i)
44 {
45         if(i==str.end())
46                 return;
47
48         unsigned char c=*i++;
49         if(c==0x5B)
50                 append(0xC4);
51         else if(c==0x5C)
52                 append(0xD6);
53         else if(c==0x5D)
54                 append(0xC5);
55         else if(c==0x5E)
56                 append(0xDC);
57         else if(c==0x60)
58                 append(0xE9);
59         else if(c==0x7B)
60                 append(0xE4);
61         else if(c==0x7C)
62                 append(0xF6);
63         else if(c==0x7D)
64                 append(0xE5);
65         else if(c==0x7E)
66                 append(0xFC);
67         else if(c<=0x7F)
68                 append(c);
69         else
70                 error("Invalid ISO-646-FI string (undefined character)");
71 }
72
73 }