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