]> git.tdb.fi Git - libs/core.git/blob - source/iso885915.cpp
Add a function to perform simple character mapping
[libs/core.git] / source / iso885915.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 "iso885915.h"
10
11 using namespace std;
12
13 namespace {
14
15 const unsigned map_size=8;
16
17 const int mapping[map_size*2]=
18 {
19         0x0152, 0xBC,
20         0x0153, 0xBD,
21         0x0160, 0xA6,
22         0x0161, 0xA8,
23         0x0178, 0xBE,
24         0x017D, 0xB4,
25         0x017E, 0xB8,
26         0x20AC, 0xA4
27 };
28
29 }
30
31 namespace Msp {
32 namespace Codecs {
33
34 void Iso885915::Encoder::encode_char(UnicodeChar ch, string &buf)
35 {
36         int tch=transform_mapping_or_direct(mapping, map_size, ch, false);
37         if(tch<0 || tch>0xFF)
38                 error(ch, buf, "Can't express character in ISO-8859-15");
39         else
40                 buf+=tch;
41
42 }
43
44 void Iso885915::Encoder::transliterate(UnicodeChar, string &buf)
45 {
46         buf+='?';
47 }
48
49
50 UnicodeChar Iso885915::Decoder::decode_char(const string &str, string::const_iterator &i)
51 {
52         if(i==str.end())
53                 return error("No input");
54
55         unsigned char ch=*i;
56         int tch=transform_mapping_or_direct(mapping, map_size, ch, true);
57
58         UnicodeChar result;
59         if(tch==-1)
60                 result=error("Undefined ISO-8859-15 character");
61         else
62                 result=tch;
63
64         ++i;
65         return result;
66 }
67
68 } // namespace Codecs
69 } // namespace Msp