summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-reader/CEncoding.cpp
blob: 18d18d362b8135680c83ab33f412a6146fc58c26 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#include <stdio.h>
#include "CEncoding.h"

tchar CUtf8::getch()
{
    int iret = parent->getch();
    if (iret == EOF) return UEOF;
    tchar ret = iret;
    int count = 0;
    if (ret & (1 << 7))
    {
	unsigned char flags = ret << 1;
	while ((flags & (1 << 7)) != 0)
	{
	    ret <<= 6;
	    ret += parent->getch() & 0x3f;
	    flags <<= 1;
	    count++;
	}
	switch (count)
	{
	    case 0:
		break;
	    case 1:
		ret &= 0x07ff;
		break;
	    case 2:
		break;
	    case 3:
	    case 4:
	    case 5:
	    default:
		printf("Only 16bit unicode supported...");
	}
    }
    return ret;
}


tchar CUcs16be::getch()
{
    int iret = parent->getch();
    if (iret == EOF) return UEOF;
    tchar ret = iret;
    return (ret << 8) + parent->getch();
}

tchar CUcs16le::getch()
{
    int iret = parent->getch();
    if (iret == EOF) return UEOF;
    tchar ret = iret;
    return ret + (parent->getch() << 8);
}

tchar Ccp1252::getch()
{
    int iret = parent->getch();
    switch (iret)
    {
	case EOF:
	    return UEOF;
	case 0x80:
	    return 0x20ac;
	case 0x82:
	    return 0x201a;
	case 0x83:
	    return 0x0192;
	case 0x84:
	    return 0x201e;
	case 0x85:
	    return 0x2026;
	case 0x86:
	    return 0x2020;
	case 0x87:
	    return 0x2021;
	case 0x88:
	    return 0x02c6;
	case 0x89:
	    return 0x2030;
	case 0x8a:
	    return 0x0160;
	case 0x8b:
	    return 0x2039;
	case 0x8c:
	    return 0x0152;
	case 0x8e:
	    return 0x017d;
	case 0x91:
	    return 0x2018;
	case 0x92:
	    return 0x2019;
	case 0x93:
	    return 0x201c;
	case 0x94:
	    return 0x201d;
	case 0x95:
	    return 0x2022;
	case 0x96:
	    return 0x2013;
	case 0x97:
	    return 0x2014;
	case 0x98:
	    return 0x02dc;
	case 0x99:
	    return 0x2122;
	case 0x9a:
	    return 0x0161;
	case 0x9b:
	    return 0x203a;
	case 0x9c:
	    return 0x0153;
	case 0x9e:
	    return 0x017e;
	case 0x9f:
	    return 0x0178;
	default:
	    return iret;
    }
}

tchar CPalm::getch()
{
    tchar iret = Ccp1252::getch();
    switch (iret)
    {
	case 0x18:
	    return 0x2026;
	case 0x19:
	    return 0x2007;
	case 0x8d:
	    return 0x2662;
	case 0x8e:
	    return 0x2663;
	case 0x8f:
	    return 0x2661;
	case 0x90:
	    return 0x2660;
	default:
	    return iret;
    }
}

tchar CAscii::getch()
{
    int iret = parent->getch();
    if (iret == EOF) return UEOF;
    return iret;
}