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