The SWORD Project  1.9.0.svnversion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
osisenum.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  *
3  * osisenum.cpp - SWFilter descendant to hide or show word enumations
4  * in an OSIS module
5  *
6  * $Id: osisenum.cpp 2980 2013-09-14 21:51:47Z scribe $
7  *
8  * Copyright 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 <osisenum.h>
26 #include <utilxml.h>
27 
28 
30 
31 namespace {
32 
33  static const char oName[] = "Enumerations";
34  static const char oTip[] = "Toggles Enumerations 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 OSISEnum::processText(SWBuf &text, const SWKey *key, const SWModule *module) {
53  SWBuf token;
54  bool intoken = false;
55 
56  const SWBuf orig = text;
57  const char * from = orig.c_str();
58 
59  if (!option) {
60  for (text = ""; *from; ++from) {
61  if (*from == '<') {
62  intoken = true;
63  token = "";
64  continue;
65  }
66  if (*from == '>') { // process tokens
67  intoken = false;
68  if (token.startsWith("w ")) { // Word
69  XMLTag wtag(token);
70  const char *l = wtag.getAttribute("n");
71  if (l) {
72  wtag.setAttribute("n", 0);
73  token = wtag;
74  token.trim();
75  // drop <>
76  token << 1;
77  token--;
78  }
79  }
80 
81  // keep token in text
82  text.append('<');
83  text.append(token);
84  text.append('>');
85 
86  continue;
87  }
88  if (intoken) {
89  token += *from;
90  }
91  else {
92  text.append(*from);
93  }
94  }
95  }
96  return 0;
97 }
98 
#define SWORD_NAMESPACE_START
Definition: defs.h:39
Definition: swbuf.h:47
const char * setAttribute(const char *attribName, const char *attribValue, int partNum=-1, char partSplit= '|')
Definition: utilxml.cpp:248
virtual ~OSISEnum()
Definition: osisenum.cpp:48
SWText * module
Definition: osis2mod.cpp:105
Definition: utilxml.h:38
bool startsWith(const SWBuf &prefix) const
Definition: swbuf.h:486
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[]
SWBuf & trim()
Definition: swbuf.h:443
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[]
#define SWORD_NAMESPACE_END
Definition: defs.h:40
Definition: swkey.h:77
OSISEnum()
Definition: osisenum.cpp:44
virtual char processText(SWBuf &text, const SWKey *key=0, const SWModule *module=0)
Definition: osisenum.cpp:52