The SWORD Project  1.9.0.svnversion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
osisscripref.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  *
3  * osisscripref.cpp - SWFilter descendant to hide or show scripture
4  * references in an OSIS module
5  *
6  * $Id: osisscripref.cpp 3045 2014-03-02 07:53:52Z chrislit $
7  *
8  * Copyright 2003-2014 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 <osisscripref.h>
26 #include <swmodule.h>
27 #include <utilxml.h>
28 
29 
31 
32 namespace {
33 
34  static const char oName[] = "Cross-references";
35  static const char oTip[] = "Toggles Scripture Cross-references On and Off if they exist";
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 OSISScripref::processText(SWBuf &text, const SWKey *key, const SWModule *module) {
54  SWBuf token;
55  bool intoken = false;
56  bool hide = false;
57  SWBuf tagText;
58  XMLTag startTag;
59 
60  SWBuf orig = text;
61  const char *from = orig.c_str();
62 
63  XMLTag tag;
64 
65  for (text = ""; *from; ++from) {
66  if (*from == '<') {
67  intoken = true;
68  token = "";
69  continue;
70  }
71  if (*from == '>') { // process tokens
72  intoken = false;
73 
74  tag = token;
75 
76  if (!strncmp(token.c_str(), "note", 4) || !strncmp(token.c_str(), "/note", 5)) {
77  if (!tag.isEndTag() && !tag.isEmpty()) {
78  startTag = tag;
79  if ((tag.getAttribute("type")) && (!strcmp(tag.getAttribute("type"), "crossReference"))) {
80  hide = true;
81  tagText = "";
82  if (option) { // we want the tag in the text
83  text.append('<');
84  text.append(token);
85  text.append('>');
86  }
87  continue;
88  }
89  }
90  if (hide && tag.isEndTag()) {
91  hide = false;
92  if (option) { // we want the tag in the text
93  text.append(tagText); // end tag gets added further down
94  }
95  else continue; // don't let the end tag get added to the text
96  }
97  }
98 
99  // if not a heading token, keep token in text
100  if (!hide) {
101  text.append('<');
102  text.append(token);
103  text.append('>');
104  }
105  else {
106  tagText.append('<');
107  tagText.append(token);
108  tagText.append('>');
109  }
110  continue;
111  }
112  if (intoken) { //copy token
113  token.append(*from);
114  }
115  else if (!hide) { //copy text which is not inside a token
116  text.append(*from);
117  }
118  else tagText.append(*from);
119  }
120  return 0;
121 }
122 
#define SWORD_NAMESPACE_START
Definition: defs.h:39
Definition: swbuf.h:47
SWText * module
Definition: osis2mod.cpp:105
Definition: utilxml.h:38
virtual char processText(SWBuf &text, const SWKey *key=0, const SWModule *module=0)
bool isEmpty() const
Definition: utilxml.h:60
static const StringList * oValues()
virtual ~OSISScripref()
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[]
static const char * choices[4]
const char * getAttribute(const char *attribName, int partNum=-1, char partSplit= '|') const
Definition: utilxml.cpp:230
static const char oTip[]
bool isEndTag(const char *eID=0) const
Definition: utilxml.cpp:323
#define SWORD_NAMESPACE_END
Definition: defs.h:40
Definition: swkey.h:77