summaryrefslogtreecommitdiff
path: root/include/swbasicfilter.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/swbasicfilter.h')
-rw-r--r--include/swbasicfilter.h99
1 files changed, 86 insertions, 13 deletions
diff --git a/include/swbasicfilter.h b/include/swbasicfilter.h
index d225d85..2985220 100644
--- a/include/swbasicfilter.h
+++ b/include/swbasicfilter.h
@@ -4,7 +4,7 @@
* many filter will need and can use as a starting
* point.
*
- * $Id: swbasicfilter.h,v 1.7 2002/03/04 01:56:44 scribe Exp $
+ * $Id: swbasicfilter.h,v 1.22 2003/08/12 05:36:30 scribe Exp $
*
* Copyright 1998 CrossWire Bible Society (http://www.crosswire.org)
* CrossWire Bible Society
@@ -26,50 +26,123 @@
#define SWBASICFILTER_H
#include <swfilter.h>
-
-#include <defs.h>
#include <map>
-using namespace std;
+SWORD_NAMESPACE_START
+
+
+// not a protected inner class because MSVC++ sucks and can't handle it
+class BasicFilterUserData {
+public:
+ BasicFilterUserData(const SWModule *module, const SWKey *key) { this->module = module; this->key = key; suspendTextPassThru = false; supressAdjacentWhitespace = false; }
+ virtual ~BasicFilterUserData() {}
+ const SWModule *module;
+ const SWKey *key;
+ SWBuf lastTextNode;
+ bool suspendTextPassThru;
+ bool supressAdjacentWhitespace;
+};
+/** A filter providing commonly used functionality.
+ * This filter has facilities for handling SGML/HTML/XML like tokens and
+ * escape strings (like SGML entities). It has the facility for just
+ * substituting the given tokens and escape strings to other strings and for
+ * "manual" custom token handling.
+ *
+ * In this class the functions with arguments looking as <code>char
+ * **buf</code> write a character sequnce at address specified by
+ * <code>*buf</code> address and change <code>*buf</code> to point past
+ * the last char of the written sequence.
+ */
class SWDLLEXPORT SWBasicFilter : public SWFilter {
char *tokenStart;
char *tokenEnd;
char *escStart;
char *escEnd;
+ char escStartLen;
+ char escEndLen;
+ char tokenStartLen;
+ char tokenEndLen;
bool escStringCaseSensitive;
bool tokenCaseSensitive;
bool passThruUnknownToken;
bool passThruUnknownEsc;
+ char processStages;
public:
+
SWBasicFilter();
- virtual char ProcessText(char *text, int maxlen, const SWKey *, const SWModule * = 0);
+ virtual char processText(SWBuf &text, const SWKey *key = 0, const SWModule *module = 0);
virtual ~SWBasicFilter();
protected:
- const SWModule *module;
- const SWKey *key;
- typedef map<string, string> DualStringMap;
+
+ virtual BasicFilterUserData *createUserData(const SWModule *module, const SWKey *key) {
+ return new BasicFilterUserData(module, key);
+ }
+
+ // STAGEs
+ static const char INITIALIZE; // flag for indicating processing before char loop
+ static const char PRECHAR; // flag for indicating processing at top in char loop
+ static const char POSTCHAR; // flag for indicating processing at bottom in char loop
+ static const char FINALIZE; // flag for indicating processing after char loop
+
+
+ typedef std::map<SWBuf, SWBuf> DualStringMap;
DualStringMap tokenSubMap;
DualStringMap escSubMap;
+
+ /** Sets the beginning of escape sequence (by default "&").*/
void setEscapeStart(const char *escStart);
+
+ /** Sets the end of escape sequence (by default ";").*/
void setEscapeEnd(const char *escEnd);
+
+ /** Sets the beginning of token start sequence (by default "<").*/
void setTokenStart(const char *tokenStart);
+
+ /** Sets the end of token start sequence (by default ">").*/
void setTokenEnd(const char *tokenEnd);
+
+ /** Sets whether pass thru unknown tokens unchanged or just ignore (remove) them.
+ * Default is false.*/
void setPassThruUnknownToken(bool val);
+
+ /** Sets whether pass thru unknown escape sequences unchanged or just ignore (remove) them.
+ * Default is false.*/
void setPassThruUnknownEscapeString(bool val);
+
void setTokenCaseSensitive(bool val);
void setEscapeStringCaseSensitive(bool val);
+
void addTokenSubstitute(const char *findString, const char *replaceString);
void addEscapeStringSubstitute(const char *findString, const char *replaceString);
- bool substituteToken(char **buf, const char *token);
- bool substituteEscapeString(char **buf, const char *escString);
- void pushString(char **buf, const char *format, ...);
+
+ void replaceTokenSubstitute(const char *findString, const char *replaceString);
+ void replaceEscapeStringSubstitute(const char *findString, const char *replaceString);
+
+ bool substituteToken(SWBuf &buf, const char *token);
+ bool substituteEscapeString(SWBuf &buf, const char *escString);
+
+ /** This function is called for every token encountered in the input text.
+ * @param buf the output buffer (FIXME: what is its size?)
+ * @param token the token (e.g. <code>"p align='left'"</code>
+ * @param userData FIXME: document this
+ * @return <code>false</code> if was not handled and should be handled in
+ * the default way (by just substituting).*/
+ virtual bool handleToken(SWBuf &buf, const char *token, BasicFilterUserData *userData);
+ virtual bool processStage(char stage, SWBuf &text, char *&from, BasicFilterUserData *userData) { return false; }
+ virtual void setStageProcessing(char stages) { processStages = stages; } // see STATICs up above
- virtual bool handleToken(char **buf, const char *token, DualStringMap &userData);
- virtual bool handleEscapeString(char **buf, const char *escString, DualStringMap &userData);
+ /** This function is called for every escape sequence encountered in the input text.
+ * @param buf the output buffer (FIXME: what is its size?)
+ * @param escString the escape sequence (e.g. <code>"amp"</code> for &amp;amp;)
+ * @param userData FIXME: document this
+ * @return <code>false</code> if was not handled and should be handled in
+ * the default way (by just substituting).*/
+ virtual bool handleEscapeString(SWBuf &buf, const char *escString, BasicFilterUserData *userData);
};
+SWORD_NAMESPACE_END
#endif