The SWORD Project  1.9.0.svnversion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
swbasicfilter.h
Go to the documentation of this file.
1 /******************************************************************************
2  *
3  * swbasicfilter.h - class SWBasicFilter: a starting point SWFilter which
4  * provides a SAX-like processing features for more
5  * easily writing other filters.
6  * provides some basic methods that make filter writing
7  * easier
8  *
9  * $Id: swbasicfilter.h 3786 2020-08-30 11:35:14Z scribe $
10  *
11  * Copyright 2001-2013 CrossWire Bible Society (http://www.crosswire.org)
12  * CrossWire Bible Society
13  * P. O. Box 2528
14  * Tempe, AZ 85280-2528
15  *
16  * This program is free software; you can redistribute it and/or modify it
17  * under the terms of the GNU General Public License as published by the
18  * Free Software Foundation version 2.
19  *
20  * This program is distributed in the hope that it will be useful, but
21  * WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23  * General Public License for more details.
24  *
25  */
26 
27 #ifndef SWBASICFILTER_H
28 #define SWBASICFILTER_H
29 
30 #include <swfilter.h>
31 #include <swbuf.h>
32 
34 
35 class VerseKey;
36 
37 // not a protected inner class because MSVC++ sucks and can't handle it
39 public:
40  BasicFilterUserData(const SWModule *module, const SWKey *key);
41  virtual ~BasicFilterUserData() {}
42  const SWModule *module;
43  const SWKey *key;
44  const VerseKey *vkey;
49 };
50 
62 class SWDLLEXPORT SWBasicFilter : public virtual SWFilter {
63 
64 class Private;
65 
66  char *tokenStart;
67  char *tokenEnd;
68  char *escStart;
69  char *escEnd;
71  char escEndLen;
80 
81 
83 public:
84 
85  SWBasicFilter();
86  virtual char processText(SWBuf &text, const SWKey *key = 0, const SWModule *module = 0);
87  virtual ~SWBasicFilter();
88 
89 protected:
90 
91  virtual BasicFilterUserData *createUserData(const SWModule *module, const SWKey *key) {
92  return new BasicFilterUserData(module, key);
93  }
94 
95  // STAGEs
96  static const char INITIALIZE; // flag for indicating processing before char loop
97  static const char PRECHAR; // flag for indicating processing at top in char loop
98  static const char POSTCHAR; // flag for indicating processing at bottom in char loop
99  static const char FINALIZE; // flag for indicating processing after char loop
100 
101 
103  void setEscapeStart(const char *escStart);
104 
106  void setEscapeEnd(const char *escEnd);
107 
109  void setTokenStart(const char *tokenStart);
110 
112  void setTokenEnd(const char *tokenEnd);
113 
117  void setPassThruUnknownToken(bool val);
118 
123  void setPassThruUnknownEscapeString(bool val);
124 
128  void setPassThruNumericEscapeString(bool val);
129 
133  void setEscapeStringCaseSensitive(bool val);
134 
137  void addAllowedEscapeString(const char *findString);
138 
141  void removeAllowedEscapeString(const char *findString);
142 
145  void addEscapeStringSubstitute(const char *findString, const char *replaceString);
146 
149  void removeEscapeStringSubstitute(const char *findString);
150 
152  bool substituteEscapeString(SWBuf &buf, const char *escString);
153 
155  bool passAllowedEscapeString(SWBuf &buf, const char *escString);
156 
158  void appendEscapeString(SWBuf &buf, const char *escString);
159 
163  void setTokenCaseSensitive(bool val);
164 
168  void addTokenSubstitute(const char *findString, const char *replaceString);
169 
172  void removeTokenSubstitute(const char *findString);
173 
175  bool substituteToken(SWBuf &buf, const char *token);
176 
183  virtual bool handleToken(SWBuf &buf, const char *token, BasicFilterUserData *userData);
184 
185  virtual bool processStage(char /*stage*/, SWBuf &/*text*/, char *&/*from*/, BasicFilterUserData * /*userData*/) { return false; }
186  virtual void setStageProcessing(char stages) { processStages = stages; } // see STATICs up above
187 
195  virtual bool handleEscapeString(SWBuf &buf, const char *escString, BasicFilterUserData *userData);
196 
202  virtual bool handleNumericEscapeString(SWBuf &buf, const char *escString);
203 
204 
205 };
206 
208 #endif
#define SWORD_NAMESPACE_START
Definition: defs.h:39
static const char PRECHAR
Definition: swbasicfilter.h:97
Definition: swbuf.h:47
static const char POSTCHAR
Definition: swbasicfilter.h:98
char * tokenStart
Definition: swbasicfilter.h:64
#define SWDLLEXPORT
Definition: defs.h:171
const SWModule * module
Definition: swbasicfilter.h:42
bool passThruUnknownEsc
Definition: swbasicfilter.h:77
SWText * module
Definition: osis2mod.cpp:105
bool handleToken(SWBuf &text, XMLTag token)
Definition: osis2mod.cpp:617
bool passThruNumericEsc
Definition: swbasicfilter.h:78
bool passThruUnknownToken
Definition: swbasicfilter.h:76
const VerseKey * vkey
Definition: swbasicfilter.h:44
static const char FINALIZE
Definition: swbasicfilter.h:99
virtual ~BasicFilterUserData()
Definition: swbasicfilter.h:41
bool tokenCaseSensitive
Definition: swbasicfilter.h:75
virtual bool processStage(char, SWBuf &, char *&, BasicFilterUserData *)
virtual BasicFilterUserData * createUserData(const SWModule *module, const SWKey *key)
Definition: swbasicfilter.h:91
static const char INITIALIZE
Definition: swbasicfilter.h:96
const SWKey * key
Definition: swbasicfilter.h:43
virtual char processText(SWBuf &text, const SWKey *key=0, const SWModule *module=0)=0
bool escStringCaseSensitive
Definition: swbasicfilter.h:74
virtual void setStageProcessing(char stages)
#define SWORD_NAMESPACE_END
Definition: defs.h:40
Definition: swkey.h:77
Private * p
Definition: swbasicfilter.h:82