The SWORD Project  1.9.0.svnversion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
osismorph.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  *
3  * osismorph.cpp - SWFilter descendant to hide or show morph tags
4  * in a OSIS module
5  *
6  * $Id: osismorph.cpp 3427 2016-07-03 14:30:33Z scribe $
7  *
8  * Copyright 2003-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 <osismorph.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 OSISMorph::processText(SWBuf &text, const SWKey *key, const SWModule *module) {
51  if (!option) { // if we don't want morph tags
52  char token[2048]; // cheese. Fix.
53  int tokpos = 0;
54  bool intoken = false;
55  SWBuf orig = text;
56  const char *from = orig.c_str();
57 
58  //taken out of the loop for speed
59  const char* start = 0;
60  const char* end = 0;
61 
62  for (text = ""; *from; ++from) {
63  if (*from == '<') {
64  intoken = true;
65  tokpos = 0;
66  token[0] = 0;
67  continue;
68  }
69  if (*from == '>') { // process tokens
70  intoken = false;
71 
72  if ((*token == 'w') && (token[1] == ' ')) {
73  start = strstr(token+2, "morph=\""); //we leave out "w " at the start
74  end = start ? strchr(start+7, '"') : 0; //search the end of the morph value
75 
76  if (start && end) { //start and end of the morph tag found
77  text.append('<');
78  text.append(token, start-token); //the text before the morph attr
79  text.append(end+1); //text after the morph attr
80  text.append('>');
81 
82  continue; //next loop
83  }
84  }
85 
86  text.append('<');
87  text.append(token);
88  text.append('>');
89 
90  continue;
91  }
92  if (intoken) {
93  if (tokpos < 2045) {
94  token[tokpos++] = *from;
95  token[tokpos] = 0;
96  }
97  }
98  else {
99  text.append(*from);
100  }
101  }
102  }
103  return 0;
104 }
105 
#define SWORD_NAMESPACE_START
Definition: defs.h:39
Definition: swbuf.h:47
SWText * module
Definition: osis2mod.cpp:105
static const StringList * oValues()
virtual char processText(SWBuf &text, const SWKey *key=0, const SWModule *module=0)
Definition: osismorph.cpp:50
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]
static const char oTip[]
virtual ~OSISMorph()
Definition: osismorph.cpp:46
#define SWORD_NAMESPACE_END
Definition: defs.h:40
Definition: swkey.h:77