[sword-svn] r1973 - in trunk: include src/modules/filters

scribe at www.crosswire.org scribe at www.crosswire.org
Tue Sep 19 21:10:15 MST 2006


Author: scribe
Date: 2006-09-19 21:09:16 -0700 (Tue, 19 Sep 2006)
New Revision: 1973

Modified:
   trunk/include/osisrtf.h
   trunk/src/modules/filters/osisrtf.cpp
   trunk/src/modules/filters/plainhtml.cpp
   trunk/src/modules/filters/thmlrtf.cpp
Log:
Added handling of control codes for some filters.


Modified: trunk/include/osisrtf.h
===================================================================
--- trunk/include/osisrtf.h	2006-09-20 02:40:14 UTC (rev 1972)
+++ trunk/include/osisrtf.h	2006-09-20 04:09:16 UTC (rev 1973)
@@ -33,6 +33,7 @@
 protected:
 	virtual BasicFilterUserData *createUserData(const SWModule *module, const SWKey *key);
 	virtual bool handleToken(SWBuf &buf, const char *token, BasicFilterUserData *userData);
+	virtual char processText(SWBuf &text, const SWKey *key = 0, const SWModule *module = 0);
 public:
 	OSISRTF();
 };

Modified: trunk/src/modules/filters/osisrtf.cpp
===================================================================
--- trunk/src/modules/filters/osisrtf.cpp	2006-09-20 02:40:14 UTC (rev 1972)
+++ trunk/src/modules/filters/osisrtf.cpp	2006-09-20 04:09:16 UTC (rev 1973)
@@ -61,6 +61,7 @@
 
 };
 
+
 OSISRTF::OSISRTF() {
 	setTokenStart("<");
 	setTokenEnd(">");
@@ -87,6 +88,46 @@
 }
 
 
+char OSISRTF::processText(SWBuf &text, const SWKey *key, const SWModule *module) {
+
+	// preprocess text buffer to escape RTF control codes
+	const char *from;
+	SWBuf orig = text;
+	from = orig.c_str();
+	for (text = ""; *from; from++) {  //loop to remove extra spaces
+		switch (*from) {
+		case '{':
+		case '}':
+		case '\\':
+			text += "\\";
+			text += *from;
+			break;
+		default:
+			text += *from;
+		}
+	}
+	text += (char)0;
+
+	SWBasicFilter::processText(text, key, module);  //handle tokens as usual
+
+	orig = text;
+	from = orig.c_str();
+	for (text = ""; *from; from++) {  //loop to remove extra spaces
+		if ((strchr(" \t\n\r", *from))) {
+			while (*(from+1) && (strchr(" \t\n\r", *(from+1)))) {
+				from++;
+			}
+			text += " ";
+		}
+		else {
+			text += *from;
+		}
+	}
+	text += (char)0;	// probably not needed, but don't want to remove without investigating (same as above)
+	return 0;
+}
+
+
 bool OSISRTF::handleToken(SWBuf &buf, const char *token, BasicFilterUserData *userData) {
   // manually process if it wasn't a simple substitution
 	if (!substituteToken(buf, token)) {

Modified: trunk/src/modules/filters/plainhtml.cpp
===================================================================
--- trunk/src/modules/filters/plainhtml.cpp	2006-09-20 02:40:14 UTC (rev 1972)
+++ trunk/src/modules/filters/plainhtml.cpp	2006-09-20 04:09:16 UTC (rev 1973)
@@ -1,5 +1,5 @@
 /***************************************************************************
-                          rwphtml.cpp  -  description
+                          plainhtml.cpp  -  description
                              -------------------
     begin                : Thu Jun 24 1999
     copyright            : (C) 1999 by Torsten Uhlmann
@@ -55,6 +55,18 @@
 			text += ") </SMALL></FONT>";
 			continue;
 		}
+		else if (*from == '<') {
+			text += "&lt;";
+			continue;
+		}
+		else if (*from == '>') {
+			text += "&gt;";
+			continue;
+		}
+		else if (*from == '&') {
+			text += "&amp;";
+			continue;
+		}
 		else if ((*from == ' ') && (count > 5000))
 		{
 			text += "<WBR>";

Modified: trunk/src/modules/filters/thmlrtf.cpp
===================================================================
--- trunk/src/modules/filters/thmlrtf.cpp	2006-09-20 02:40:14 UTC (rev 1972)
+++ trunk/src/modules/filters/thmlrtf.cpp	2006-09-20 04:09:16 UTC (rev 1973)
@@ -155,23 +155,42 @@
 
 
 char ThMLRTF::processText(SWBuf &text, const SWKey *key, const SWModule *module) {
-	SWBasicFilter::processText(text, key, module);  //handle tokens as usual
+
+	// preprocess text buffer to escape RTF control codes
 	const char *from;
 	SWBuf orig = text;
 	from = orig.c_str();
 	for (text = ""; *from; from++) {  //loop to remove extra spaces
-                if ((strchr(" \t\n\r", *from))) {
-                        while (*(from+1) && (strchr(" \t\n\r", *(from+1)))) {
-                                from++;
-                        }
-                        text += " ";
-                }
-			 else {
-                        text += *from;
-                }
-        }
-        text += (char)0;
-        return 0;
+		switch (*from) {
+		case '{':
+		case '}':
+		case '\\':
+			text += "\\";
+			text += *from;
+			break;
+		default:
+			text += *from;
+		}
+	}
+	text += (char)0;
+
+	SWBasicFilter::processText(text, key, module);  //handle tokens as usual
+
+	orig = text;
+	from = orig.c_str();
+	for (text = ""; *from; from++) {  //loop to remove extra spaces
+		if ((strchr(" \t\n\r", *from))) {
+			while (*(from+1) && (strchr(" \t\n\r", *(from+1)))) {
+				from++;
+			}
+			text += " ";
+		}
+		else {
+			text += *from;
+		}
+	}
+	text += (char)0;	// probably not needed, but don't want to remove without investigating (same as above)
+	return 0;
 }
 
 




More information about the sword-cvs mailing list