The SWORD Project  1.9.0.svnversion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
osisredletterwords.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  *
3  * osisredletterwords.cpp - SWFilter descendant to toggle red coloring for
4  * words of Christ in an OSIS module
5  *
6  * $Id: osisredletterwords.cpp 2980 2013-09-14 21:51:47Z 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 <osisredletterwords.h>
26 #include <swmodule.h>
27 
28 
30 
31 namespace {
32 
33  static const char oName[] = "Words of Christ in Red";
34  static const char oTip[] = "Toggles Red Coloring for Words of Christ On and Off if they are marked";
35 
36  static const StringList *oValues() {
37  static const SWBuf choices[3] = {"On", "Off", ""};
38  static const StringList oVals(&choices[0], &choices[2]);
39  return &oVals;
40  }
41 }
42 
43 
45 }
46 
47 
49 }
50 
51 
52 char OSISRedLetterWords::processText(SWBuf &text, const SWKey *key, const SWModule *module) {
53  if (option) //leave in the red lettered words
54  return 0;
55 
56  SWBuf token;
57  bool intoken = false;
58 
59  SWBuf orig = text;
60  const char *from = orig.c_str();
61 
62  //taken out of the loop
63  const char* start = 0;
64  const char* end = 0;
65 
66  for (text = ""; *from; from++) {
67  if (*from == '<') {
68  intoken = true;
69  token = "";
70  continue;
71  }
72  else if (*from == '>') { // process tokens
73  intoken = false;
74 
75  if ((token[0] == 'q') && (token[1] == ' ')) { //q tag
76  start = strstr(token.c_str(), " who=\"Jesus\"");
77  if (start && (strlen(start) >= 12)) { //we found a quote of Jesus Christ
78  end = start+12; //marks the end of the who attribute value
79 
80  text.append('<');
81  text.append(token, start - (token.c_str())); //the text before the who attr
82  text.append(end, token.c_str() + token.length() - end); //text after the who attr
83  text.append('>');
84 
85  continue;
86  }
87  }
88 
89  //token not processed, append it. We don't want to alter the text
90  text.append('<');
91  text.append(token);
92  text.append('>');
93  continue;
94  }
95 
96  if (intoken) { //copy token
97  token.append(*from);
98  }
99  else { //copy text which is not inside a token
100  text.append(*from);
101  }
102  }
103  return 0;
104 }
105 
107 
#define SWORD_NAMESPACE_START
Definition: defs.h:39
Definition: swbuf.h:47
unsigned long length() const
Definition: swbuf.h:197
SWText * module
Definition: osis2mod.cpp:105
static const StringList * oValues()
const char * c_str() const
Definition: swbuf.h:158
std::list< SWBuf > StringList
Definition: swmodule.cpp:91
SWBuf & append(const char *str, long max=-1)
Definition: swbuf.h:274
static const char oName[]
virtual char processText(SWBuf &text, const SWKey *key=0, const SWModule *module=0)
static const char * choices[4]
static const char oTip[]
#define SWORD_NAMESPACE_END
Definition: defs.h:40
Definition: swkey.h:77