The SWORD Project  1.9.0.svnversion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
thmllemma.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  *
3  * thmllemma.cpp - SWFilter descendant to hide or show lemmas
4  * in a ThML module
5  *
6  * $Id: thmllemma.cpp 2980 2013-09-14 21:51:47Z 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 #include <stdlib.h>
25 #include <thmllemma.h>
26 
27 
29 
30 namespace {
31 
32  static const char oName[] = "Lemmas";
33  static const char oTip[] = "Toggles Lemmas On and Off if they exist";
34 
35  static const StringList *oValues() {
36  static const SWBuf choices[3] = {"Off", "On", ""};
37  static const StringList oVals(&choices[0], &choices[2]);
38  return &oVals;
39  }
40 }
41 
42 
44 }
45 
46 
48 }
49 
50 
51 char ThMLLemma::processText(SWBuf &text, const SWKey *key, const SWModule *module) {
52  if (!option) { // if we don't want lemmas
53  bool intoken = false;
54 
55  SWBuf token;
56  SWBuf orig = text;
57  const char *from = orig.c_str();
58  for (text = ""; *from; from++) {
59  if (*from == '<') {
60  intoken = true;
61  token = "";
62  continue;
63  }
64  if (*from == '>') { // process tokens
65  intoken = false;
66  if (!strncmp(token.c_str(), "sync ", 5) && strstr(token.c_str(), "type=\"lemma\"")) { // Lemma
67  continue;
68  }
69 
70  // if not a lemma token, keep token in text
71  text += '<';
72  text += token;
73  text += '>';
74  continue;
75  }
76 
77  if (intoken) {
78  token += *from;
79  }
80  else {
81  text += *from;
82  }
83  }
84  }
85  return 0;
86 }
87 
#define SWORD_NAMESPACE_START
Definition: defs.h:39
Definition: swbuf.h:47
virtual ~ThMLLemma()
Definition: thmllemma.cpp: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 char processText(SWBuf &text, const SWKey *key=0, const SWModule *module=0)
Definition: thmllemma.cpp:51
#define SWORD_NAMESPACE_END
Definition: defs.h:40
Definition: swkey.h:77