The SWORD Project  1.9.0.svnversion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
gbfheadings.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  *
3  * gbfheadings.cpp - SWFilter descendant to hide or show headings
4  * in a GBF module
5  *
6  * $Id: gbfheadings.cpp 3427 2016-07-03 14:30:33Z scribe $
7  *
8  * Copyright 2001-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 
25 #include <stdlib.h>
26 #include <gbfheadings.h>
27 
28 
30 
31 namespace {
32 
33  static const char oName[] = "Headings";
34  static const char oTip[] = "Toggles Headings On and Off if they exist";
35 
36  static const StringList *oValues() {
37  static const SWBuf choices[3] = {"Off", "On", ""};
38  static const StringList oVals(&choices[0], &choices[2]);
39  return &oVals;
40  }
41 }
42 
43 
45 }
46 
47 
49 }
50 
51 
52 char GBFHeadings::processText(SWBuf &text, const SWKey *key, const SWModule *module) {
53  if (!option) { // if we don't want headings
54  char token[2048]; // cheese. Fix.
55  int tokpos = 0;
56  bool intoken = false;
57  bool hide = false;
58 
59  const char *from;
60  SWBuf orig = text;
61  from = orig.c_str();
62  for (text = ""; *from; from++) {
63  if (*from == '<') {
64  intoken = true;
65  tokpos = 0;
66 // memset(token, 0, 2048);
67  token[0] = 0;
68  token[1] = 0;
69  token[2] = 0;
70  continue;
71  }
72  if (*from == '>') { // process tokens
73  intoken = false;
74  switch (*token) {
75  case 'T': // Reference
76  switch(token[1]) {
77  case 'S': // Begin heading
78  hide = true;
79  break;
80  case 's': // end heading
81  hide = false;
82  break;
83  }
84  continue; // skip token
85  }
86  // if not a heading token, keep token in text
87  if (!hide) {
88  text += '<';
89  for (char *tok = token; *tok; tok++)
90  text += *tok;
91  text += '>';
92  }
93  continue;
94  }
95  if (intoken) {
96  if (tokpos < 2045) {
97  token[tokpos++] = *from;
98  // TODO: why is this + 2 ?
99  token[tokpos+2] = 0;
100  }
101  }
102  else {
103  if (!hide) {
104  text += *from;
105  }
106  }
107  }
108  }
109  return 0;
110 }
111 
#define SWORD_NAMESPACE_START
Definition: defs.h:39
Definition: swbuf.h:47
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
static const char oName[]
static const char * choices[4]
static const char oTip[]
virtual ~GBFHeadings()
Definition: gbfheadings.cpp:48
virtual char processText(SWBuf &text, const SWKey *key=0, const SWModule *module=0)
Definition: gbfheadings.cpp:52
#define SWORD_NAMESPACE_END
Definition: defs.h:40
Definition: swkey.h:77