The SWORD Project  1.9.0.svnversion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
teiplain.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  *
3  * teiplain.cpp - TEI to Plaintext filter
4  *
5  * $Id: teiplain.cpp 3696 2020-02-03 19:38:46Z refdoc $
6  *
7  * Copyright 2006-2013 CrossWire Bible Society (http://www.crosswire.org)
8  * CrossWire Bible Society
9  * P. O. Box 2528
10  * Tempe, AZ 85280-2528
11  *
12  * This program is free software; you can redistribute it and/or modify it
13  * under the terms of the GNU General Public License as published by the
14  * Free Software Foundation version 2.
15  *
16  * This program is distributed in the hope that it will be useful, but
17  * WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * General Public License for more details.
20  *
21  */
22 
23 #include <stdlib.h>
24 #include <teiplain.h>
25 #include <ctype.h>
26 
28 
30  setTokenStart("<");
31  setTokenEnd(">");
32 
33  setEscapeStart("&");
34  setEscapeEnd(";");
35 
37 
38  addEscapeStringSubstitute("amp", "&");
39  addEscapeStringSubstitute("apos", "'");
40  addEscapeStringSubstitute("lt", "<");
41  addEscapeStringSubstitute("gt", ">");
42  addEscapeStringSubstitute("quot", "\"");
43 
45 }
46 
47 
48 bool TEIPlain::handleToken(SWBuf &buf, const char *token, BasicFilterUserData *userData) {
49  // manually process if it wasn't a simple substitution
50  if (!substituteToken(buf, token)) {
51  //MyUserData *u = (MyUserData *)userData;
52  XMLTag tag(token);
53 
54  // <p> paragraph tag
55  if (!strcmp(tag.getName(), "p")) {
56  if ((!tag.isEndTag()) && (!tag.isEmpty())) { // non-empty start tag
57  buf += "\n";
58  }
59  else if (tag.isEndTag()) { // end tag
60  buf += "\n";
61  userData->supressAdjacentWhitespace = true;
62  }
63  else { // empty paragraph break marker
64  buf += "\n\n";
65  userData->supressAdjacentWhitespace = true;
66  }
67  }
68 
69  // <entryFree>
70  else if (!strcmp(tag.getName(), "entryFree")) {
71  SWBuf n = tag.getAttribute("n");
72  if ((!tag.isEndTag()) && (!tag.isEmpty())) {
73  if (n != "") {
74  buf += n;
75  buf += ". ";
76  }
77  }
78  }
79 
80  // <sense>
81  else if (!strcmp(tag.getName(), "sense")) {
82  SWBuf n = tag.getAttribute("n");
83  if ((!tag.isEndTag()) && (!tag.isEmpty())) {
84  if (n != "") {
85  buf += n;
86  buf += ". ";
87  }
88  }
89  else if (tag.isEndTag()) {
90  buf += "\n";
91  }
92  }
93 
94  // <div>
95  else if (!strcmp(tag.getName(), "div")) {
96 
97  if ((!tag.isEndTag()) && (!tag.isEmpty())) {
98  buf.append("\n\n\n");
99  }
100  else if (tag.isEndTag()) {
101  }
102  }
103 
104  // <etym>
105  else if (!strcmp(tag.getName(), "etym")) {
106  if ((!tag.isEndTag()) && (!tag.isEmpty())) {
107  buf += "[";
108  }
109  else if (tag.isEndTag()) {
110  buf += "]";
111  }
112  }
113 
114  // <list> <item> This implementation does not distinguish between forms of lists
115  // it would be nice if a numbered list could be added
116 
117  else if (!strcmp(tag.getName(), "list")) {
118  if ((!tag.isEndTag()) && (!tag.isEmpty())) {
119 
120  buf += "\n";
121  }
122  else if (tag.isEndTag()) {
123  buf += "\n";
124  }
125  }
126  else if (!strcmp(tag.getName(), "item")) {
127  if ((!tag.isEndTag()) && (!tag.isEmpty())) {
128  buf += "\t* ";
129  }
130  else if (tag.isEndTag()) {
131  buf += "\n";
132  }
133  }
134  else {
135  return false; // we still didn't handle token
136  }
137  }
138  return true;
139 }
140 
141 
#define SWORD_NAMESPACE_START
Definition: defs.h:39
void setTokenEnd(const char *tokenEnd)
Definition: swbuf.h:47
const char * getName() const
Definition: utilxml.h:58
Definition: utilxml.h:38
void setTokenCaseSensitive(bool val)
void setEscapeStart(const char *escStart)
bool isEmpty() const
Definition: utilxml.h:60
bool substituteToken(SWBuf &buf, const char *token)
void addEscapeStringSubstitute(const char *findString, const char *replaceString)
void setTokenStart(const char *tokenStart)
SWBuf & append(const char *str, long max=-1)
Definition: swbuf.h:274
TEIPlain()
Definition: teiplain.cpp:29
virtual bool handleToken(SWBuf &buf, const char *token, BasicFilterUserData *userData)
Definition: teiplain.cpp:48
const char * getAttribute(const char *attribName, int partNum=-1, char partSplit= '|') const
Definition: utilxml.cpp:230
void setEscapeStringCaseSensitive(bool val)
bool isEndTag(const char *eID=0) const
Definition: utilxml.cpp:323
void setEscapeEnd(const char *escEnd)
#define SWORD_NAMESPACE_END
Definition: defs.h:40