]> git.tdb.fi Git - libs/core.git/blob - source/stringcodec/ascii.cpp
Move files around to prepare for assimilation into core
[libs/core.git] / source / stringcodec / ascii.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 "ascii.h"
9
10 using namespace std;
11
12 /*namespace {
13
14 char translit_latin1[0x60]=
15 {
16 };
17
18 const char *translit_katakana[0x60]=
19 {
20         "--", "a", "a", "i", "i", "u", "u", "e", "e", "o", "o",
21         "ka", "ga", "ki", "gi", "ku", "gu", "ke", "ge", "ko", "go",
22         "sa", "za", "si", "zi", "su", "zu", "se", "ze", "so", "zo",
23         "ta", "da", "ti", "di", "tu", "tu", "du", "te", "de", "to", "do",
24 };
25
26 }*/
27
28 namespace Msp {
29 namespace Codecs {
30
31 void Ascii::Encoder::encode_char(UnicodeChar ch, string &buf)
32 {
33         if(ch<0 || ch>0x7F)
34                 return error(ch, buf, "Can't express character in ASCII");
35
36         buf += ch;
37 }
38
39 void Ascii::Encoder::transliterate(UnicodeChar ch, string &buf)
40 {
41         if(ch>=0xC0 && ch<=0xC5)
42                 buf += 'A';
43         else if(ch==0xC6)
44                 buf += "AE";
45         else if(ch==0xC7)
46                 buf += 'C';
47         else if(ch>=0xC8 && ch<=0xCB)
48                 buf += 'E';
49         else if(ch>=0xCC && ch<=0xCF)
50                 buf += 'I';
51         else if(ch==0xD0)
52                 buf += 'D';
53         else if(ch==0xD1)
54                 buf += 'N';
55         else if((ch>=0xD2 && ch<=0xD7) || ch==0xD9)
56                 buf += 'O';
57         else if(ch==0xD8)
58                 buf += 'x';
59         else if(ch>=0xDA && ch<=0xDC)
60                 buf += 'U';
61         else if(ch==0xDD)
62                 buf += 'Y';
63         else if(ch==0xDE)
64                 buf += 'T';
65         else if(ch==0xDF)
66                 buf += "ss";
67         else if(ch>=0xE0 && ch<=0xE5)
68                 buf += 'a';
69         else if(ch==0xE6)
70                 buf += "ae";
71         else if(ch==0xE7)
72                 buf += 'c';
73         else if(ch>=0xE8 && ch<=0xEB)
74                 buf += 'e';
75         else if(ch>=0xEC && ch<=0xEF)
76                 buf += 'i';
77         else if(ch==0xF0)
78                 buf += 'd';
79         else if(ch==0xF1)
80                 buf += 'n';
81         else if((ch>=0xF2 && ch<=0xF7) || ch==0xF9)
82                 buf += 'o';
83         else if(ch==0xF8)
84                 buf += '/';
85         else if(ch>=0xFA && ch<=0xFC)
86                 buf += 'u';
87         else if(ch==0xFD)
88                 buf += 'y';
89         else if(ch==0xFE)
90                 buf += 't';
91         else if(ch==0xFF)
92                 buf += 'y';
93         else
94                 buf += '?';
95 }
96
97
98 UnicodeChar Ascii::Decoder::decode_char(const string &str, string::const_iterator &i)
99 {
100         if(i==str.end())
101                 return error("No input");
102         else if(*i&0x80)
103         {
104                 UnicodeChar result = error("Undefined ASCII character");
105                 ++i;
106                 return result;
107         }
108         else
109                 return *i++;
110 }
111
112 } // namespace Codecs
113 } // namespace Msp