The SWORD Project  1.9.0.svnversion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
gbfplain.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  *
3  * gbfplain.cpp - SWFilter descendant to strip out all GBF tags or
4  * convert to ASCII rendered symbols
5  *
6  * $Id: gbfplain.cpp 3427 2016-07-03 14:30:33Z scribe $
7  *
8  * Copyright 1997-2013 CrossWire Bible Society (http://www.crosswire.org)
9  * CrossWire Bible Society
10  * P. O. Box 2528
11  * Tempe, AZ 85280-2528
12  *
13  * This program is free software; you can redistribute it and/or modify it
14  * under the terms of the GNU General Public License as published by the
15  * Free Software Foundation version 2.
16  *
17  * This program is distributed in the hope that it will be useful, but
18  * WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20  * General Public License for more details.
21  *
22  */
23 
24 #include <stdlib.h>
25 #include <gbfplain.h>
26 #include <swbuf.h>
27 
28 
30 
31 
33 }
34 
35 
36 char GBFPlain::processText (SWBuf &text, const SWKey *key, const SWModule *module)
37 {
38  char token[2048];
39  int tokpos = 0;
40  bool intoken = false;
41  SWBuf orig = text;
42  const char* from = orig.c_str();
43 
44  for (text = ""; *from; ++from) {
45  if (*from == '<') {
46  intoken = true;
47  tokpos = 0;
48  token[0] = 0;
49  token[1] = 0;
50  token[2] = 0;
51  continue;
52  }
53  if (*from == '>') {
54  intoken = false;
55  // process desired tokens
56  switch (*token) {
57  case 'W': // Strongs
58  switch(token[1]) {
59  case 'G': // Greek
60  case 'H': // Hebrew
61  case 'T': // Tense
62  text.append(" <");
63  //for (char *tok = token + 2; *tok; tok++)
64  // text += *tok;
65  text.append(token+2);
66  text.append("> ");
67  continue;
68  }
69  break;
70  case 'R':
71  switch(token[1]) {
72  case 'F': // footnote begin
73  text.append(" [");
74  continue;
75  case 'f': // footnote end
76  text.append("] ");
77  continue;
78  }
79  break;
80  case 'C':
81  switch(token[1]) {
82  case 'A': // ASCII value
83  text.append((char)atoi(&token[2]));
84  continue;
85  case 'G':
86  text.append('>');
87  continue;
88 /* Bug in WEB
89  case 'L':
90  *to++ = '<';
91  continue;
92 */
93  case 'L': // Bug in WEB. Use above entry when fixed
94  case 'N': // new line
95  text.append('\n');
96  continue;
97  case 'M': // new paragraph
98  text.append("\n\n");
99  continue;
100  }
101  break;
102  }
103  continue;
104  }
105  if (intoken) {
106  if (tokpos < 2045) {
107  token[tokpos++] = *from;
108  // TODO: why is this + 2 ?
109  token[tokpos+2] = 0;
110  }
111  }
112  else text.append(*from);
113  }
114  return 0;
115 }
116 
117 
119 
#define SWORD_NAMESPACE_START
Definition: defs.h:39
Definition: swbuf.h:47
SWText * module
Definition: osis2mod.cpp:105
const char * c_str() const
Definition: swbuf.h:158
SWBuf & append(const char *str, long max=-1)
Definition: swbuf.h:274
GBFPlain()
Definition: gbfplain.cpp:32
virtual char processText(SWBuf &text, const SWKey *key=0, const SWModule *module=0)
Definition: gbfplain.cpp:36
#define SWORD_NAMESPACE_END
Definition: defs.h:40
Definition: swkey.h:77