summaryrefslogtreecommitdiff
path: root/src/modules/filters/utf8greekaccents.cpp
blob: b0e5dc8f2fd0655b7d7fe118da18557119a4d9ff (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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
/******************************************************************************
 *
 * UTF8GreekAccents - SWFilter decendant to remove UTF-8 Greek accents
 *
 */


#include <stdlib.h>
#include <stdio.h>
#include <utf8greekaccents.h>


const char UTF8GreekAccents::on[] = "On";
const char UTF8GreekAccents::off[] = "Off";
const char UTF8GreekAccents::optName[] = "Greek Accents";
const char UTF8GreekAccents::optTip[] = "Toggles Greek Accents";

UTF8GreekAccents::UTF8GreekAccents() {
	option = true;
	options.push_back(on);
	options.push_back(off);
}

UTF8GreekAccents::~UTF8GreekAccents(){};

void UTF8GreekAccents::setOptionValue(const char *ival)
{
	option = (!stricmp(ival, on));
}

const char *UTF8GreekAccents::getOptionValue()
{
	return (option) ? on:off;
}

char UTF8GreekAccents::ProcessText(char *text, int maxlen, const SWKey *key, const SWModule *module)
{
	if (!option) {
    unsigned char *to, *from;

	to = (unsigned char*)text;
	for (from = (unsigned char*)text; *from; from++) {
	  //first just remove combining characters
	  if (*from == 0xE2 && *(from + 1) == 0x80 && *(from + 2) == 0x99)
	    from += 2;
	  else if (*from == 0xCC && *(from + 1)) {
	    if (*(from + 1) == 0x80 || *(from + 1) == 0x81 || *(from + 1) == 0x82 || *(from + 1) == 0x88 || *(from + 1) == 0x93 || *(from + 1) == 0x94)
	      from++;
	  }
	  else if (*from == 0xCD && *(from + 1) == 0xBA)
	    from++;
	  //now converted pre-composed characters to their alphabetic bases, discarding the accents

	  //Greek
	  //capital alpha
	  else if ((*from == 0xCE && *(from + 1) == 0x86)) {
	    *to++ = 0xCE;
	    *to++ = 0x91;
	    from++;
	  }
	  //capital epsilon
	  else if ((*from == 0xCE && *(from + 1) == 0x88)) {
	    *to++ = 0xCE;
	    *to++ = 0x95;
	    from++;
	  }
	  //capital eta
	  else if ((*from == 0xCE && *(from + 1) == 0x89)) {
	    *to++ = 0xCE;
	    *to++ = 0x97;
	    from++;
	  }
	  //capital iota
	  else if ((*from == 0xCE && (*(from + 1) == 0x8A || *(from + 1) == 0xAA))) {
	    *to++ = 0xCE;
	    *to++ = 0x99;
	    from++;
	  }
	  //capital omicron
	  else if ((*from == 0xCE && *(from + 1) == 0x8C)) {
	    *to++ = 0xCE;
	    *to++ = 0x9F;
	    from++;
	  }
	  //capital upsilon
	  else if ((*from == 0xCE && (*(from + 1) == 0x8E || *(from + 1) == 0xAB))) {
	    *to++ = 0xCE;
	    *to++ = 0xA5;
	    from++;
	  }
	  //capital omega
	  else if ((*from == 0xCE && *(from + 1) == 0x8F)) {
	    *to++ = 0xCE;
	    *to++ = 0xA9;
	    from++;
	  }

	  //alpha
	  else if ((*from == 0xCE && *(from + 1) == 0xAC)) {
	    *to++ = 0xCE;
	    *to++ = 0xB1;
	    from++;
	  }
	  //epsilon
	  else if ((*from == 0xCE && *(from + 1) == 0xAD)) {
	    *to++ = 0xCE;
	    *to++ = 0xB5;
	    from++;
	  }
	  //eta
	  else if ((*from == 0xCE && *(from + 1) == 0xAE)) {
	    *to++ = 0xCE;
	    *to++ = 0xB7;
	    from++;
	  }
	  //iota
	  else if ((*from == 0xCE && *(from + 1) == 0xAF) || (*from == 0xCF && *(from + 1) == 0x8A)) {
	    *to++ = 0xCE;
	    *to++ = 0xB9;
	    from++;
	  }
	  //omicron
	  else if ((*from == 0xCF && *(from + 1) == 0x8C)) {
	    *to++ = 0xCE;
	    *to++ = 0xBF;
	    from++;
	  }
	  //upsilon
	  else if ((*from == 0xCE && *(from + 1) == 0x88) || (*from == 0xCF && (*(from + 1) == 0x8B || *(from + 1) == 0x8D))) {
	    *to++ = 0xCF;
	    *to++ = 0x85;
	    from++;
	  }
	  //omega
	  else if ((*from == 0xCF && *(from + 1) == 0x8E)) {
	    *to++ = 0xCF;
	    *to++ = 0x89;
	    from++;
	  }

	  //Extended Greek
	  //capital alpha
	  else if (*from == 0xE1 && ((*(from + 1) == 0xBC || *(from + 1) == 0xBE) && *(from + 2) >= 0x88 && *(from + 2) <= 0x8F) || (*(from + 1) == 0xBE && *(from + 2) >= 0xB8 && *(from + 2) <= 0xBC)) {
	    *to++ = 0xCE;
	    *to++ = 0x91;
	    from+=2;
	  }
	  //capital epsilon
	  else if (*from == 0xE1 && ((*(from + 1) == 0xBC && *(from + 2) >= 0x98 && *(from + 2) <= 0x9D) || (*(from + 1) == 0xBF && (*(from + 2) == 0x88 || *(from + 2) == 0x89)))) {
	    *to++ = 0xCE;
	    *to++ = 0x95;
	    from+=2;
	  }
	  //capital eta
	  else if (*from == 0xE1 && ((*(from + 1) == 0xBC && *(from + 2) >= 0xA8 && *(from + 2) <= 0xAF) || (*(from + 1) == 0xBE && *(from + 2) >= 0x98 && *(from + 2) <= 0x9F) || (*(from + 1) == 0xBF && *(from + 2) >= 0x8A && *(from + 2) <= 0x8C))) {
	    *to++ = 0xCE;
	    *to++ = 0x97;
	    from+=2;
	  }
	  //capital iota
	  else if (*from == 0xE1 && ((*(from + 1) == 0xBC && *(from + 2) >= 0xB8 && *(from + 2) <= 0xBF) || (*(from + 1) == 0xBF && *(from + 2) >= 0x98 && *(from + 2) <= 0x9B))) {
	    *to++ = 0xCE;
	    *to++ = 0x99;
	    from+=2;
	  }
	  //capital omicron
	  else if (*from == 0xE1 && ((*(from + 1) == 0xBD && *(from + 2) >= 0x88 && *(from + 2) <= 0x8D) || (*(from + 1) == 0xBF && *(from + 2) == 0xB8 || *(from + 2) == 0xB9))) {
	    *to++ = 0xCE;
	    *to++ = 0x9F;
	    from+=2;
	  }
	  //capital upsilon
	  else if (*from == 0xE1 && ((*(from + 1) == 0xBD && *(from + 2) >= 0x99 && *(from + 2) <= 0x9F) || (*(from + 1) == 0xBF && *(from + 2) >= 0xA8 && *(from + 2) <= 0xAB))) {
	    *to++ = 0xCE;
	    *to++ = 0xA5;
	    from+=2;
	  }
	  //capital omega
	  else if (*from == 0xE1 && (((*(from + 1) == 0xBD || *(from + 1) == 0xBE) && *(from + 2) >= 0xA8 && *(from + 2) <= 0xAF) || (*(from + 1) == 0xBF && *(from + 2) >= 0xBA && *(from + 2) <= 0xBC))) {
	    *to++ = 0xCE;
	    *to++ = 0xA9;
	    from+=2;
	  }
	  //capital rho
	  else if (*from == 0xE1 && *(from + 1) == 0xBF && *(from + 2) == 0xAC) {
	    *to++ = 0xCE;
	    *to++ = 0xA1;
	    from+=2;
	  }

	  //alpha
	  else if (*from == 0xE1 && ((*(from + 1) == 0xBC || *(from + 1) == 0xBE) && *(from + 2) >= 0x80 && *(from + 2) <= 0x87) || (*(from + 1) == 0xBD && (*(from + 2) == 0xB0 || *(from + 2) == 0xB1)) || (*(from + 1) == 0xBE && *(from + 2) >= 0xB0 && *(from + 2) <= 0xB7)) {
	    *to++ = 0xCE;
	    *to++ = 0xB1;
	    from+=2;
	  }
	  //epsilon
	  else if (*from == 0xE1 && ((*(from + 1) == 0xBC && *(from + 2) >= 0x90 && *(from + 2) <= 0x95) || (*(from + 1) == 0xBD && (*(from + 2) == 0xB2 || *(from + 2) == 0xB3)))) {
	    *to++ = 0xCE;
	    *to++ = 0xB5;
	    from+=2;
	  }
	  //eta
	  else if (*from == 0xE1 && ((*(from + 1) == 0xBE && *(from + 2) >= 0x90 && *(from + 2) <= 0x97) || (*(from + 1) == 0xBC && *(from + 2) >= 0xA0 && *(from + 2) <= 0xA7) || (*(from + 1) == 0xBF && *(from + 2) >= 0x82 && *(from + 2) <= 0x87) || (*(from + 1) == 0xBD && (*(from + 2) == 0xB4 || *(from + 2) == 0xB5)))) {
	    *to++ = 0xCE;
	    *to++ = 0xB7;
	    from+=2;
	  }
	  //iota
	  else if (*from == 0xE1 && ((*(from + 1) == 0xBC && *(from + 2) >= 0xB0 && *(from + 2) <= 0xB7) || (*(from + 1) == 0xBD && (*(from + 2) == 0xB6 || *(from + 2) == 0xB7)) || (*(from + 1) == 0xBF && *(from + 2) >= 0x90 && *(from + 2) <= 0x97))) {
	    *to++ = 0xCE;
	    *to++ = 0xB9;
	    from+=2;
	  }
	  //omicron
	  else if (*from == 0xE1 && (*(from + 1) == 0xBD && ((*(from + 2) >= 0x80 && *(from + 2) <= 0x85) || (*(from + 2) == 0xB8 || *(from + 2) == 0xB9)))) {
	    *to++ = 0xCE;
	    *to++ = 0xBF;
	    from+=2;
	  }
	  //upsilon
	  else if (*from == 0xE1 && ((*(from + 1) == 0xBD && ((*(from + 2) >= 0x90 && *(from + 2) <= 0x97) || *(from + 2) == 0xBA || *(from + 2) == 0xBB)) || (*(from + 1) == 0xBF && ((*(from + 2) >= 0xA0 && *(from + 2) <= 0xA3) || *(from + 2) == 0xA6 || *(from + 2) == 0xA7)))) {
	    *to++ = 0xCF;
	    *to++ = 0x85;
	    from+=2;
	  }
	  //omega
	  else if (*from == 0xE1 && ((*(from + 1) == 0xBD && ((*(from + 2) >= 0xA0 && *(from + 2) <= 0xA7) || (*(from + 2) == 0xBC || *(from + 2) == 0xBD))) || (*(from + 1) == 0xBE && (*(from + 2) >= 0xA0 && *(from + 2) <= 0xA7)) || (*(from + 1) == 0xBF && *(from + 2) >= 0xB2 && *(from + 2) <= 0xB7))) {
	    *to++ = 0xCF;
	    *to++ = 0x89;
	    from+=2;
	  }
	  //rho
	  else if (*from == 0xE1 && *(from + 1) == 0xBF && (*(from + 2) == 0xA4 && *(from + 2) == 0xA5)) {
	    *to++ = 0xCF;
	    *to++ = 0x81;
	    from+=2;
	  }
	  else
	    *to++ = *from;
	}
	*to++ = 0;
	*to = 0;
     }
	return 0;
}