~ubuntu-branches/ubuntu/jaunty/bibletime/jaunty

« back to all changes in this revision

Viewing changes to bibletime/backend/bt_thmlplain.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Ralph Janke
  • Date: 2008-05-10 15:18:16 UTC
  • mfrom: (1.1.6 upstream) (3.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080510151816-bqp8y1to705zd0fm
Tags: 1.6.5.1-1
* New upstream version (Closes: #441161, #271502)
* fixes for new autotools and gcc 4.3 (Closes: #407291)
* added poxml to Build-Depends
* No DFSG necessary anymore since biblestudy howto has 
  now Commons Licence 
* Added libclucene-dev to dev-depends (Closes: #436677)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/******************************************************************************
 
2
 *
 
3
 * thmlplain -  SWFilter descendant to strip out all ThML tags or convert to
 
4
 *              ASCII rendered symbols.
 
5
 */
 
6
 
 
7
#include "bt_thmlplain.h"
 
8
 
 
9
#include <stdlib.h>
 
10
#include <swbuf.h>
 
11
 
 
12
using namespace sword;
 
13
 
 
14
namespace Filters {
 
15
 
 
16
BT_ThMLPlain::BT_ThMLPlain() {
 
17
}
 
18
 
 
19
char BT_ThMLPlain::processText(SWBuf &text, const SWKey *key, const SWModule *module)
 
20
{
 
21
        char token[2048];
 
22
        int tokpos = 0;
 
23
        bool intoken = false;
 
24
        bool ampersand = false;
 
25
 
 
26
        const char *from;
 
27
        SWBuf orig = text;
 
28
        from = orig.c_str();
 
29
        for (text = ""; *from; from++)
 
30
        {
 
31
                if (*from == 10 || *from == 13)
 
32
                        from++;
 
33
                if (*from == '<') {
 
34
                        intoken = true;
 
35
                        tokpos = 0;
 
36
                        token[0] = 0;
 
37
                        token[1] = 0;
 
38
                        token[2] = 0;
 
39
                        ampersand = false;
 
40
                        continue;
 
41
                }
 
42
                else if (*from == '&') {
 
43
                        intoken = true;
 
44
                        tokpos = 0;
 
45
                        token[0] = 0;
 
46
                        token[1] = 0;
 
47
                        token[2] = 0;
 
48
                        ampersand = true;
 
49
                        continue;
 
50
                }
 
51
                if (*from == ';' && ampersand) {
 
52
                        intoken = false;
 
53
                        ampersand = false;
 
54
 
 
55
                        if (!strncmp("nbsp", token, 4)) text += " ";
 
56
                        else if (!strncmp("quot", token, 4)) text += "\"";
 
57
                        else if (!strncmp("amp", token, 3)) text += "&";
 
58
                        else if (!strncmp("lt", token, 2)) text += "<";
 
59
                        else if (!strncmp("gt", token, 2)) text += ">";
 
60
                        else if (!strncmp("brvbar", token, 6)) text += "¦";
 
61
                        else if (!strncmp("sect", token, 4)) text += "§";
 
62
                        else if (!strncmp("copy", token, 4)) text += "©";
 
63
                        else if (!strncmp("laquo", token, 5)) text += "«";
 
64
                        else if (!strncmp("reg", token, 3)) text += "®";
 
65
                        else if (!strncmp("acute", token, 5)) text += "´";
 
66
                        else if (!strncmp("para", token, 4)) text += "¶";
 
67
                        else if (!strncmp("raquo", token, 5)) text += "»";
 
68
 
 
69
                        else if (!strncmp("Aacute", token, 6)) text += "Á";
 
70
                        else if (!strncmp("Agrave", token, 6)) text += "À";
 
71
                        else if (!strncmp("Acirc", token, 5)) text += "Â";
 
72
                        else if (!strncmp("Auml", token, 4)) text += "Ä";
 
73
                        else if (!strncmp("Atilde", token, 6)) text += "Ã";
 
74
                        else if (!strncmp("Aring", token, 5)) text += "Å";
 
75
                        else if (!strncmp("aacute", token, 6)) text += "á";
 
76
                        else if (!strncmp("agrave", token, 6)) text += "à";
 
77
                        else if (!strncmp("acirc", token, 5)) text += "â";
 
78
                        else if (!strncmp("auml", token, 4)) text += "ä";
 
79
                        else if (!strncmp("atilde", token, 6)) text += "ã";
 
80
                        else if (!strncmp("aring", token, 5)) text += "å";
 
81
                        else if (!strncmp("Eacute", token, 6)) text += "É";
 
82
                        else if (!strncmp("Egrave", token, 6)) text += "È";
 
83
                        else if (!strncmp("Ecirc", token, 5)) text += "Ê";
 
84
                        else if (!strncmp("Euml", token, 4)) text += "Ë";
 
85
                        else if (!strncmp("eacute", token, 6)) text += "é";
 
86
                        else if (!strncmp("egrave", token, 6)) text += "è";
 
87
                        else if (!strncmp("ecirc", token, 5)) text += "ê";
 
88
                        else if (!strncmp("euml", token, 4)) text += "ë";
 
89
                        else if (!strncmp("Iacute", token, 6)) text += "Í";
 
90
                        else if (!strncmp("Igrave", token, 6)) text += "Ì";
 
91
                        else if (!strncmp("Icirc", token, 5)) text += "Î";
 
92
                        else if (!strncmp("Iuml", token, 4)) text += "Ï";
 
93
                        else if (!strncmp("iacute", token, 6)) text += "í";
 
94
                        else if (!strncmp("igrave", token, 6)) text += "ì";
 
95
                        else if (!strncmp("icirc", token, 5)) text += "î";
 
96
                        else if (!strncmp("iuml", token, 4)) text += "ï";
 
97
                        else if (!strncmp("Oacute", token, 6)) text += "Ó";
 
98
                        else if (!strncmp("Ograve", token, 6)) text += "Ò";
 
99
                        else if (!strncmp("Ocirc", token, 5)) text += "Ô";
 
100
                        else if (!strncmp("Ouml", token, 4)) text += "Ö";
 
101
                        else if (!strncmp("Otilde", token, 6)) text += "Õ";
 
102
                        else if (!strncmp("oacute", token, 6)) text += "ó";
 
103
                        else if (!strncmp("ograve", token, 6)) text += "ò";
 
104
                        else if (!strncmp("ocirc", token, 5)) text += "ô";
 
105
                        else if (!strncmp("ouml", token, 4)) text += "ö";
 
106
                        else if (!strncmp("otilde", token, 6)) text += "õ";
 
107
                        else if (!strncmp("Uacute", token, 6)) text += "Ú";
 
108
                        else if (!strncmp("Ugrave", token, 6)) text += "Ù";
 
109
                        else if (!strncmp("Ucirc", token, 5)) text += "Û";
 
110
                        else if (!strncmp("Uuml", token, 4)) text += "Ü";
 
111
                        else if (!strncmp("uacute", token, 6)) text += "ú";
 
112
                        else if (!strncmp("ugrave", token, 6)) text += "ù";
 
113
                        else if (!strncmp("ucirc", token, 5)) text += "û";
 
114
                        else if (!strncmp("uuml", token, 4)) text += "ü";
 
115
                        else if (!strncmp("Yacute", token, 6)) text += "Ý";
 
116
                        else if (!strncmp("yacute", token, 6)) text += "ý";
 
117
                        else if (!strncmp("yuml", token, 4)) text += "ÿ";
 
118
 
 
119
                        else if (!strncmp("deg", token, 3)) text += "°";
 
120
                        else if (!strncmp("plusmn", token, 6)) text += "±";
 
121
                        else if (!strncmp("sup2", token, 4)) text += "²";
 
122
                        else if (!strncmp("sup3", token, 4)) text += "³";
 
123
                        else if (!strncmp("sup1", token, 4)) text += "¹";
 
124
                        else if (!strncmp("nbsp", token, 4)) text += "º";
 
125
                        else if (!strncmp("pound", token, 5)) text += "£";
 
126
                        else if (!strncmp("cent", token, 4)) text += "¢";
 
127
                        else if (!strncmp("frac14", token, 6)) text += "¼";
 
128
                        else if (!strncmp("frac12", token, 6)) text += "½";
 
129
                        else if (!strncmp("frac34", token, 6)) text += "¾";
 
130
                        else if (!strncmp("iquest", token, 6)) text += "¿";
 
131
                        else if (!strncmp("iexcl", token, 5)) text += "¡";
 
132
                        else if (!strncmp("ETH", token, 3)) text += "Ð";
 
133
                        else if (!strncmp("eth", token, 3)) text += "ð";
 
134
                        else if (!strncmp("THORN", token, 5)) text += "Þ";
 
135
                        else if (!strncmp("thorn", token, 5)) text += "þ";
 
136
                        else if (!strncmp("AElig", token, 5)) text += "Æ";
 
137
                        else if (!strncmp("aelig", token, 5)) text += "æ";
 
138
                        else if (!strncmp("Oslash", token, 6)) text += "Ø";
 
139
                        else if (!strncmp("curren", token, 6)) text += "¤";
 
140
                        else if (!strncmp("Ccedil", token, 6)) text += "Ç";
 
141
                        else if (!strncmp("ccedil", token, 6)) text += "ç";
 
142
                        else if (!strncmp("szlig", token, 5)) text += "ß";
 
143
                        else if (!strncmp("Ntilde", token, 6)) text += "Ñ";
 
144
                        else if (!strncmp("ntilde", token, 6)) text += "ñ";
 
145
                        else if (!strncmp("yen", token, 3)) text += "¥";
 
146
                        else if (!strncmp("not", token, 3)) text += "¬";
 
147
                        else if (!strncmp("ordf", token, 4)) text += "ª";
 
148
                        else if (!strncmp("uml", token, 3)) text += "¨";
 
149
                        else if (!strncmp("shy", token, 3)) text += "­";
 
150
                        else if (!strncmp("macr", token, 4)) text += "¯";
 
151
                        else if (!strncmp("micro", token, 5)) text += "µ";
 
152
                        else if (!strncmp("middot", token, 6)) text +="·";
 
153
                        else if (!strncmp("cedil", token, 5)) text += "¸";
 
154
                        else if (!strncmp("ordm", token, 4)) text +=  "º";
 
155
                        else if (!strncmp("times", token, 5)) text += "×";
 
156
                        else if (!strncmp("divide", token, 6)) text +="÷";
 
157
                        else if (!strncmp("oslash", token, 6)) text +="ø";
 
158
                        continue;
 
159
 
 
160
                }
 
161
                else if (*from == '>' && !ampersand) {
 
162
                        intoken = false;
 
163
                        // process desired tokens
 
164
                        if (!strncmp(token, "sync type=\"Strongs\" value=\"", 27)) {
 
165
                                text += ' ';
 
166
                                text += '<';
 
167
                                for (unsigned int i = 27; token[i] != '\"'; i++)
 
168
                                        text += token[i];
 
169
                                text += '>';
 
170
                                continue;
 
171
                        }
 
172
                        if (!strncmp(token, "sync type=\"morph\" value=\"", 25)) {
 
173
                                text += ' ';
 
174
                                text += '(';
 
175
                                for (unsigned int i = 25; token[i] != '\"'; i++)
 
176
                                        text += token[i];
 
177
                                text += ')';
 
178
                                continue;
 
179
                        }
 
180
                        if (!strncmp("note", token, 4)) {
 
181
                                text += ' ';
 
182
                                text += '(';
 
183
                        }
 
184
                        else if (!strncmp("br", token, 2))
 
185
                                text += '\n';
 
186
                        else if (!strncmp("/p", token, 2))
 
187
                                text += '\n';
 
188
                        else if (!strncmp("/note", token, 5)) {
 
189
                                text += ')';
 
190
                                text += ' ';
 
191
                        }
 
192
                        continue;
 
193
                }
 
194
                if (intoken) {
 
195
                        if (tokpos < 2045)
 
196
                                token[tokpos++] = *from;
 
197
                                token[tokpos+2] = 0;
 
198
                }
 
199
                else    text += *from;
 
200
        }
 
201
 
 
202
        orig = text;
 
203
        from = orig.c_str();
 
204
        for (text = ""; *from; from++) {  //loop to remove extra spaces
 
205
                if ((strchr(" \t\n\r", *from))) {
 
206
                        while (*(from+1) && (strchr(" \t\n\r", *(from+1)))) {
 
207
                                from++;
 
208
                        }
 
209
                        text += " ";
 
210
                }
 
211
                else {
 
212
                        text += *from;
 
213
                }
 
214
        }
 
215
        text += (char)0;
 
216
 
 
217
        return 0;
 
218
}
 
219
 
 
220
 
 
221
}