[sword-cvs] sword/src/modules/filters osisplain.cpp,1.4,1.5

sword@www.crosswire.org sword@www.crosswire.org
Fri, 18 Jul 2003 03:36:04 -0700


Update of /usr/local/cvsroot/sword/src/modules/filters
In directory www:/tmp/cvs-serv7851/src/modules/filters

Modified Files:
	osisplain.cpp 
Log Message:
Some small optimizations to OSISPlain


Index: osisplain.cpp
===================================================================
RCS file: /usr/local/cvsroot/sword/src/modules/filters/osisplain.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- osisplain.cpp	27 Jun 2003 02:21:05 -0000	1.4
+++ osisplain.cpp	18 Jul 2003 10:36:02 -0000	1.5
@@ -42,151 +42,96 @@
 bool OSISPlain::handleToken(SWBuf &buf, const char *token, DualStringMap &userData) {
   // manually process if it wasn't a simple substitution
 	if (!substituteToken(buf, token)) {
-		XMLTag tag(token);
-		
-		// <w> tag
-		if (!strcmp(tag.getName(), "w")) {
-
-			// start <w> tag
-			if ((!tag.isEmpty()) && (!tag.isEndTag())) {
-				userData["w"] = token;
+		if (((*token == 'w') && (token[1] == ' ')) ||
+		((*token == '/') && (token[1] == 'w') && (!token[2]))) {
+			bool start = false;
+			if (*token == 'w') {
+				if (token[strlen(token)-1] != '/') {
+					userData["w"] = token;
+					return true;
+				}
+				start = true;
 			}
+			XMLTag tag = (start) ? token : userData["w"].c_str();
+			bool show = true;	// to handle unplaced article in kjv2003-- temporary till combined
 
-			// end or empty <w> tag
-			else {
-				bool endTag = tag.isEndTag();
-				SWBuf lastText;
-				bool show = true;	// to handle unplaced article in kjv2003-- temporary till combined
-
-				if (endTag) {
-					tag = userData["w"].c_str();
-					lastText = userData["lastTextNode"].c_str();
-				}
-				else lastText = "stuff";
+			SWBuf lastText = (start) ? "stuff" : userData["lastTextNode"].c_str();
 					
-				const char *attrib;
-				const char *val;
-				if (attrib = tag.getAttribute("xlit")) {
-					val = strchr(attrib, ':');
-					val = (val) ? (val + 1) : attrib;
-					buf.appendFormatted(" <%s>", val);
-				}
-				if (attrib = tag.getAttribute("gloss")) {
+			const char *attrib;
+			const char *val;
+			if (attrib = tag.getAttribute("xlit")) {
+				val = strchr(attrib, ':');
+				val = (val) ? (val + 1) : attrib;
+				buf.appendFormatted(" <%s>", val);
+			}
+			if (attrib = tag.getAttribute("gloss")) {
+				val = strchr(attrib, ':');
+				val = (val) ? (val + 1) : attrib;
+				buf.appendFormatted(" <%s>", val);
+			}
+			if (attrib = tag.getAttribute("lemma")) {
+				int count = tag.getAttributePartCount("lemma");
+				int i = (count > 1) ? 0 : -1;		// -1 for whole value cuz it's faster, but does the same thing as 0
+				do {
+					attrib = tag.getAttribute("lemma", i);
+					if (i < 0) i = 0;	// to handle our -1 condition
 					val = strchr(attrib, ':');
 					val = (val) ? (val + 1) : attrib;
-					buf.appendFormatted(" <%s>", val);
-				}
-				if (attrib = tag.getAttribute("lemma")) {
-					int count = tag.getAttributePartCount("lemma");
-					int i = (count > 1) ? 0 : -1;		// -1 for whole value cuz it's faster, but does the same thing as 0
-					do {
-						attrib = tag.getAttribute("lemma", i);
-						if (i < 0) i = 0;	// to handle our -1 condition
-						val = strchr(attrib, ':');
-						val = (val) ? (val + 1) : attrib;
-						if ((strchr("GH", *val)) && (isdigit(val[1])))
-							val++;
-						if ((!strcmp(val, "3588")) && (lastText.length() < 1))
-							show = false;
-						else	buf.appendFormatted(" <%s>}", val);
-					} while (++i < count);
-				}
-				if ((attrib = tag.getAttribute("morph")) && (show)) {
-					int count = tag.getAttributePartCount("morph");
-					int i = (count > 1) ? 0 : -1;		// -1 for whole value cuz it's faster, but does the same thing as 0
-					do {
-						attrib = tag.getAttribute("morph", i);
-						if (i < 0) i = 0;	// to handle our -1 condition
-						val = strchr(attrib, ':');
-						val = (val) ? (val + 1) : attrib;
-						if ((*val == 'T') && (strchr("GH", val[1])) && (isdigit(val[2])))
-							val+=2;
-						buf.appendFormatted(" (%s)", val);
-					} while (++i < count);
-				}
-				if (attrib = tag.getAttribute("POS")) {
+					if ((strchr("GH", *val)) && (isdigit(val[1])))
+						val++;
+					if ((!strcmp(val, "3588")) && (lastText.length() < 1))
+						show = false;
+					else	buf.appendFormatted(" <%s>}", val);
+				} while (++i < count);
+			}
+			if ((attrib = tag.getAttribute("morph")) && (show)) {
+				int count = tag.getAttributePartCount("morph");
+				int i = (count > 1) ? 0 : -1;		// -1 for whole value cuz it's faster, but does the same thing as 0
+				do {
+					attrib = tag.getAttribute("morph", i);
+					if (i < 0) i = 0;	// to handle our -1 condition
 					val = strchr(attrib, ':');
 					val = (val) ? (val + 1) : attrib;
-					buf.appendFormatted(" <%s>", val);
-				}
+					if ((*val == 'T') && (strchr("GH", val[1])) && (isdigit(val[2])))
+						val+=2;
+					buf.appendFormatted(" (%s)", val);
+				} while (++i < count);
+			}
+			if (attrib = tag.getAttribute("POS")) {
+				val = strchr(attrib, ':');
+				val = (val) ? (val + 1) : attrib;
+				buf.appendFormatted(" <%s>", val);
 			}
 		}
 
 		// <note> tag
-		else if (!strcmp(tag.getName(), "note")) {
-			if (!tag.isEmpty() && !tag.isEndTag()) {
-				SWBuf type = tag.getAttribute("type");
-
-				if (type != "strongsMarkup") {	// leave strong's markup notes out, in the future we'll probably have different option filters to turn different note types on or off
+		else if (!strncmp(token, "note", 4)) {
+				if (!strstr(token, "strongsMarkup")) {	// leave strong's markup notes out, in the future we'll probably have different option filters to turn different note types on or off
 					buf += " (";
 				}
 				else	userData["suspendTextPassThru"] = "true";
 			}
-			if (tag.isEndTag()) {
-				if (userData["suspendTextPassThru"] == "false")
-					buf += ")";
-				else	userData["suspendTextPassThru"] = "false";
-			}
+		else if (!strncmp(token, "/note", 5)) {
+			if (userData["suspendTextPassThru"] == "false")
+				buf += ")";
+			else	userData["suspendTextPassThru"] = "false";
 		}
 
 		// <p> paragraph tag
-		else if (!strcmp(tag.getName(), "p")) {
-			if ((!tag.isEndTag()) && (!tag.isEmpty())) {	// non-empty start tag
-				buf += "\n";
-			}
-			else if (tag.isEndTag()) {	// end tag
+		else if (((*token == 'p') && ((token[1] == ' ') || (!token[1]))) ||
+			((*token == '/') && (token[1] == 'p') && (!token[2]))) {
 				buf += "\n";
-			}
-			else {					// empty paragraph break marker
-				buf += "\n\n";
-			}
 		}
 
 		// <line> poetry, etc
-		else if (!strcmp(tag.getName(), "line")) {
-			if ((!tag.isEndTag()) && (!tag.isEmpty())) {
-			}
-			else if (tag.isEndTag()) {
-				buf += "\n";
-			}
-			else {	// empty line marker
+		else if ((!strncmp(token, "line", 4)) ||
+			(!strncmp(token, "/line", 5))) {
 				buf += "\n";
-			}
 		}
 
 		// <title>
-		else if (!strcmp(tag.getName(), "title")) {
-			if ((!tag.isEndTag()) && (!tag.isEmpty())) {
-			}
-			else if (tag.isEndTag()) {
-				buf += "\n";
-			}
-			else {	// empty title marker
-				// what to do?  is this even valid?
-				buf += "\n";
-			}
-		}
-
-		// <q> quote
-		else if (!strcmp(tag.getName(), "q")) {
-			SWBuf type = tag.getAttribute("type");
-			SWBuf who = tag.getAttribute("who");
-			const char *lev = tag.getAttribute("level");
-			int level = (lev) ? atoi(lev) : 1;
-			
-			if ((!tag.isEndTag()) && (!tag.isEmpty())) {
-
-				//alternate " and '
-				buf += (level % 2) ? '\'' : '\"';
-			}
-			else if (tag.isEndTag()) {
-				//alternate " and '
-				buf += (level % 2) ? '\'' : '\"';
-			}
-			else {	// empty quote marker
-				//alternate " and '
-				buf += (level % 2) ? '\'' : '\"';
-			}
+		else if (!strncmp(token, "/title", 6)) {
+			buf += "\n";
 		}
 
 		else {