The SWORD Project  1.9.0.svnversion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
gbfthml.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  *
3  * gbfthml.cpp - GBF to ThML filter
4  *
5  * $Id: gbfthml.cpp 3427 2016-07-03 14:30:33Z scribe $
6  *
7  * Copyright 1999-2013 CrossWire Bible Society (http://www.crosswire.org)
8  * CrossWire Bible Society
9  * P. O. Box 2528
10  * Tempe, AZ 85280-2528
11  *
12  * This program is free software; you can redistribute it and/or modify it
13  * under the terms of the GNU General Public License as published by the
14  * Free Software Foundation version 2.
15  *
16  * This program is distributed in the hope that it will be useful, but
17  * WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * General Public License for more details.
20  *
21  */
22 
23 #include <stdlib.h>
24 #include <gbfthml.h>
25 #include <swbuf.h>
26 
27 
29 
30 
32 {
33 }
34 
35 
36 char GBFThML::processText(SWBuf &text, const SWKey *key, const SWModule *module) {
37  const char *from;
38  char token[2048];
39  int tokpos = 0;
40  bool intoken = false;
41  const char *tok;
42 
43  SWBuf orig = text;
44  from = orig.c_str();
45 
46  for (text = ""; *from; from++) {
47  if (*from == '<') {
48  intoken = true;
49  tokpos = 0;
50  token[0] = 0;
51  token[1] = 0;
52  token[2] = 0;
53  continue;
54  }
55  if (*from == '>') {
56  intoken = false;
57  // process desired tokens
58  switch (*token) {
59  case 'W': // Strongs
60  switch(token[1]) {
61  case 'G':
62  case 'H':
63  text += "<sync type=\"Strongs\" value=\"";
64  for (tok = token + 1; *tok; tok++)
65  text += *tok;
66  text += "\" />";
67  continue;
68 
69  case 'T': // Tense
70  text += "<sync type=\"Morph\" value=\"";
71  for (tok = token + 2; *tok; tok++)
72  text += *tok;
73  text += "\" />";
74  continue;
75  }
76  break;
77  case 'R':
78  switch(token[1])
79  {
80  case 'X':
81  text += "<a href=\"";
82  for (tok = token + 3; *tok; tok++) {
83  if(*tok != '<' && *tok+1 != 'R' && *tok+2 != 'x') {
84  text += *tok;
85  }
86  else {
87  break;
88  }
89  }
90  text += "\">";
91  continue;
92  case 'x':
93  text += "</a>";
94  continue;
95  case 'F': // footnote begin
96  text += "<note>";
97  continue;
98  case 'f': // footnote end
99  text += "</note>";
100  continue;
101  }
102  break;
103  case 'F': // font tags
104  switch(token[1])
105  {
106  case 'N':
107  text += "<font face=\"";
108  for (tok = token + 2; *tok; tok++)
109  text += *tok;
110  text += "\">";
111  continue;
112  case 'n':
113  text += "</font>";
114  continue;
115  case 'I': // italic start
116  text += "<i>";
117  continue;
118  case 'i': // italic end
119  text += "</i>";
120  continue;
121  case 'B': // bold start
122  text += "<b>";
123  continue;
124  case 'b': // bold end
125  text += "</b>";
126  continue;
127 
128  case 'R': // words of Jesus begin
129  text += "<font color=\"#ff0000\">";
130  continue;
131  case 'r': // words of Jesus end
132  text += "</font>";
133  continue;
134  case 'U': // Underline start
135  text += "<u>";
136  continue;
137  case 'u': // Underline end
138  text += "</u>";
139  continue;
140  case 'O': // Old Testament quote begin
141  text += "<cite>";
142  continue;
143  case 'o': // Old Testament quote end
144  text += "</cite>";
145  continue;
146  case 'S': // Superscript begin
147  text += "<sup>";
148  continue;
149  case 's': // Superscript end
150  text += "</sup>";
151  continue;
152  case 'V': // Subscript begin
153  text += "<sub>";
154  continue;
155  case 'v': // Subscript end
156  text += "</sub>";
157  continue;
158  }
159  break;
160  case 'C': // special character tags
161  switch(token[1])
162  {
163  case 'A': // ASCII value
164  text += (char)atoi(&token[2]);
165  continue;
166  case 'G':
167  //*to++ = ' ';
168  continue;
169  case 'L': // line break
170  text += "<br /> ";
171  continue;
172  case 'M': // new paragraph
173  text += "<p />";
174  continue;
175  case 'T':
176  //*to++ = ' ';
177  continue;
178  }
179  break;
180  case 'T': // title formatting
181  switch(token[1])
182  {
183  case 'T': // Book title begin
184  text += "<big>";
185  continue;
186  case 't':
187  text += "</big>";
188  continue;
189  case 'S':
190  text += "<div class=\"sechead\">";
191  continue;
192  case 's':
193  text += "</div>";
194  continue;
195  }
196  break;
197 
198  case 'P': // special formatting
199  switch(token[1]) {
200  case 'P': // Poetry begin
201  text += "<verse>";
202  continue;
203  case 'p':
204  text += "</verse>";
205  continue;
206  }
207  break;
208  }
209  continue;
210  }
211  if (intoken) {
212  if (tokpos < 2045) {
213  token[tokpos++] = *from;
214  //TODO: why is this + 2? Are we trying to keep 2 or 3 nulls after the last valid char?
215  // tokpos has been incremented past the last valid token. it should be pointing to null
216  // +1 should give us 2 nulls, but we're +2 here, which actually keeps 3 nulls after the
217  // last valid char. Why are we doing any of this? These were written before SWBuf and should
218  // probably be switched to SWBuf, but perf tests before and after the switch should be run
219  token[tokpos+2] = 0;
220  }
221  }
222  else text += *from;
223  }
224  return 0;
225 }
226 
227 
#define SWORD_NAMESPACE_START
Definition: defs.h:39
GBFThML()
Definition: gbfthml.cpp:31
Definition: swbuf.h:47
SWText * module
Definition: osis2mod.cpp:105
virtual char processText(SWBuf &text, const SWKey *key=0, const SWModule *module=0)
Definition: gbfthml.cpp:36
const char * c_str() const
Definition: swbuf.h:158
#define SWORD_NAMESPACE_END
Definition: defs.h:40
Definition: swkey.h:77