The SWORD Project  1.9.0.svnversion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
gbfredletterwords.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  *
3  * gbfredletterwords.cpp - SWFilter descendant to toggle red coloring of
4  * words of Christ in a GBF module
5  *
6  * $Id: gbfredletterwords.cpp 3427 2016-07-03 14:30:33Z scribe $
7  *
8  * Copyright 2003-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 <gbfredletterwords.h>
26 #include <swmodule.h>
27 #include <ctype.h>
28 
29 
31 
32 namespace {
33 
34  static const char oName[] = "Words of Christ in Red";
35  static const char oTip[] = "Toggles Red Coloring for Words of Christ On and Off if they are marked";
36 
37  static const StringList *oValues() {
38  static const SWBuf choices[3] = {"Off", "On", ""};
39  static const StringList oVals(&choices[0], &choices[2]);
40  return &oVals;
41  }
42 }
43 
44 
46 }
47 
48 
50 }
51 
52 
53 char GBFRedLetterWords::processText(SWBuf &text, const SWKey *key, const SWModule *module) {
57  if (!option) { // if we don't want footnotes
58  char token[4096]; // cheese. Fix.
59  int tokpos = 0;
60  bool intoken = false;
61  bool hide = false;
62 
63  const char *from;
64  SWBuf orig = text;
65  from = orig.c_str();
66  for (text = ""; *from; from++) {
67  if (*from == '<') {
68  intoken = true;
69  tokpos = 0;
70 // memset(token, 0, 4096);
71  token[0] = 0;
72  token[1] = 0;
73  token[2] = 0;
74  continue;
75  }
76  if (*from == '>') { // process tokens
77  intoken = false;
78  /*switch (*token) {
79  case 'F': // Font attribute
80  switch(token[1]) {
81  case 'R': // Begin red letter words
82  hide = true;
83  break;
84  case 'r': // end red letter words
85  hide = false;
86  break;
87  }
88  continue; // skip token
89  }*/
90 
91  //hide the token if either FR or Fr was detected
92  hide = (token[0] == 'F' && ( (token[1] == 'R') || (token[1] == 'r') ));
93 
94  // if not a red letter word token, keep token in text
95  if (!hide) {
96  text += '<';
97  for (char *tok = token; *tok; tok++)
98  text += *tok;
99  text += '>';
100  }
101  continue;
102  }
103  if (intoken) {
104  if (tokpos < 4090) {
105  token[tokpos++] = *from;
106  // TODO: why is this + 2 ? The below comment still doesn't help me understand. The switch statment
107  // is commented out in this filter
108  token[tokpos+2] = 0; // +2 cuz we init token with 2 extra '0' because of switch statement
109  }
110  }
111  else {
112  text += *from;
113  }
114  }
115  }
116  return 0;
117 }
118 
#define SWORD_NAMESPACE_START
Definition: defs.h:39
Definition: swbuf.h:47
SWText * module
Definition: osis2mod.cpp:105
virtual char processText(SWBuf &text, const SWKey *key=0, const SWModule *module=0)
static const StringList * oValues()
const char * c_str() const
Definition: swbuf.h:158
std::list< SWBuf > StringList
Definition: swmodule.cpp:91
static const char oName[]
static const char * choices[4]
static const char oTip[]
#define SWORD_NAMESPACE_END
Definition: defs.h:40
Definition: swkey.h:77