The SWORD Project  1.9.0.svnversion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
papyriplain.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  *
3  * papyriplain.cpp - SWFilter descendant to strip out all Papyri tags
4  *
5  * $Id: papyriplain.cpp 2980 2013-09-14 21:51:47Z scribe $
6  *
7  * Copyright 2005-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 <papyriplain.h>
25 
27 
28 
30 }
31 
32 
33 char PapyriPlain::processText (SWBuf &text, const SWKey *key, const SWModule *module)
34 {
35  SWBuf orig = text;
36  const char *from = orig.c_str();
37 
38  for (text = ""; *from; ++from) {
39 
40  // remove hyphen and whitespace if that is all that separates words
41  // also be sure we're not a double hyphen '--'
42  if ((*from == '-') && (text.length() > 0) && (text[text.length()-1] != '-')) {
43  char remove = 0;
44  const char *c;
45  for (c = from+1; *c; c++) {
46  if ((*c == 10) || (*c == 13)) {
47  remove = 1;
48  }
49  if (!strchr(" \t\n", *c)) {
50  if (remove) remove++;
51  break;
52  }
53  }
54  if (remove > 1) {
55  from = c-1;
56  continue;
57  }
58  }
59 
60  // remove all newlines
61  if ((*from == 10) || (*from == 13)) {
62  if ((text.length()>1) && (text[text.length()-2] != ' ') && (*(from+1) != ' '))
63  text.append(' ');
64  continue;
65  }
66 
67 
68  // strip odd characters
69  switch (*from) {
70  case '(':
71  case ')':
72  case '[':
73  case ']':
74  case '{':
75  case '}':
76  case '<':
77  case '>':
78  continue;
79  }
80 
81  // if we've made it this far
82  text.append(*from);
83 
84  }
85  return 0;
86 }
87 
#define SWORD_NAMESPACE_START
Definition: defs.h:39
Definition: swbuf.h:47
unsigned long length() const
Definition: swbuf.h:197
SWText * module
Definition: osis2mod.cpp:105
virtual char processText(SWBuf &text, const SWKey *key=0, const SWModule *module=0)
Definition: papyriplain.cpp:33
const char * c_str() const
Definition: swbuf.h:158
SWBuf & append(const char *str, long max=-1)
Definition: swbuf.h:274
#define SWORD_NAMESPACE_END
Definition: defs.h:40
Definition: swkey.h:77