The SWORD Project  1.9.0.svnversion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
gbfmorph.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  *
3  * gbfmorph.cpp - SWFilter descendant to hide or show morph tags
4  * in a GBF module
5  *
6  * $Id: gbfmorph.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 #include <stdlib.h>
25 #include <gbfmorph.h>
26 
27 
29 
30 namespace {
31 
32  static const char oName[] = "Morphological Tags";
33  static const char oTip[] = "Toggles Morphological Tags 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 GBFMorph::processText(SWBuf &text, const SWKey *key, const SWModule *module) {
52  if (!option) { // if we don't want morph tags
53  const char *from;
54  char token[2048]; // cheese. Fix.
55  int tokpos = 0;
56  bool intoken = false;
57  bool lastspace = false;
58 
59  SWBuf orig = text;
60  from = orig.c_str();
61 
62  for (text = ""; *from; from++) {
63  if (*from == '<') {
64  intoken = true;
65  tokpos = 0;
66  token[0] = 0;
67  token[1] = 0;
68  token[2] = 0;
69  continue;
70  }
71  if (*from == '>') { // process tokens
72  intoken = false;
73  if (*token == 'W' && token[1] == 'T') { // Morph
74  if ((from[1] == ' ') || (from[1] == ',') || (from[1] == ';') || (from[1] == '.') || (from[1] == '?') || (from[1] == '!') || (from[1] == ')') || (from[1] == '\'') || (from[1] == '\"')) {
75  if (lastspace)
76  text--;
77  }
78  continue;
79  }
80  // if not a morph tag token, keep token in text
81  text += '<';
82  text += token;
83  text += '>';
84  continue;
85  }
86  if (intoken) {
87  if (tokpos < 2045) {
88  token[tokpos++] = *from;
89  // TODO: why is this + 2 ?
90  token[tokpos+2] = 0;
91  }
92  }
93  else {
94  text += *from;
95  lastspace = (*from == ' ');
96  }
97  }
98  }
99  return 0;
100 }
101 
GBFMorph()
Definition: gbfmorph.cpp:43
#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[]
#define SWORD_NAMESPACE_END
Definition: defs.h:40
Definition: swkey.h:77
virtual char processText(SWBuf &text, const SWKey *key=0, const SWModule *module=0)
Definition: gbfmorph.cpp:51
virtual ~GBFMorph()
Definition: gbfmorph.cpp:47