]> git.tdb.fi Git - libs/core.git/blob - source/stringcodec/iso885915.cpp
Move files around to prepare for assimilation into core
[libs/core.git] / source / stringcodec / 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
32 namespace Msp {
33 namespace Codecs {
34
35 void Iso885915::Encoder::encode_char(UnicodeChar ch, string &buf)
36 {
37         int tch = transform_mapping_or_direct(mapping, map_size, ch, false);
38         if(tch<0 || tch>0xFF)
39                 error(ch, buf, "Can't express character in ISO-8859-15");
40         else
41                 buf += tch;
42
43 }
44
45 void Iso885915::Encoder::transliterate(UnicodeChar, string &buf)
46 {
47         buf += '?';
48 }
49
50
51 UnicodeChar Iso885915::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 = transform_mapping_or_direct(mapping, map_size, ch, true);
58
59         UnicodeChar result;
60         if(tch==-1)
61                 result = error("Undefined ISO-8859-15 character");
62         else
63                 result = tch;
64
65         ++i;
66         return result;
67 }
68
69 } // namespace Codecs
70 } // namespace Msp