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

scribe at crosswire.org scribe at crosswire.org
Mon May 4 16:18:51 MST 2009


Author: scribe
Date: 2009-05-04 16:18:51 -0700 (Mon, 04 May 2009)
New Revision: 2378

Modified:
   trunk/include/swbuf.h
   trunk/include/utilxml.h
   trunk/src/modules/filters/osisheadings.cpp
   trunk/src/utilfuns/utilxml.cpp
Log:
added ability for (SWBuf("xyz") == (const char *)0) to return false without crash
added optional isEndTag(const char *eID = 0) parameter which, if passed, will check for attribute("eID") == eID
added working filter logic for new osis2mod logic <div type="x-milestone" subType="x-preverse" sID="xxxx"/>


Modified: trunk/include/swbuf.h
===================================================================
--- trunk/include/swbuf.h	2009-05-04 08:04:55 UTC (rev 2377)
+++ trunk/include/swbuf.h	2009-05-04 23:18:51 UTC (rev 2378)
@@ -420,13 +420,14 @@
 	 */
 	inline bool endsWith(const char *postfix) const { unsigned int psize = strlen(postfix); return (size() >= psize)?!strncmp(end-psize, postfix, psize):false; }
 
-	inline int compare(const char *other) const { return strcmp(c_str(), other); }
+	// be sure we've been given a valid pointer to compare.  If not, we return !=; specifically less-than, for lack of better options
+	inline int compare(const char *other) const { return (other?strcmp(c_str(), other):-1); }
 	inline bool operator ==(const char *other) const { return compare(other) == 0; }
 	inline bool operator !=(const char *other) const { return compare(other) != 0; }
-	inline bool operator > (const char *other) const { return compare(other) > 0; }
-	inline bool operator < (const char *other) const { return compare(other) < 0; }
-	inline bool operator <=(const char *other) const { return compare(other) <= 0; }
-	inline bool operator >=(const char *other) const { return compare(other) >= 0; }
+	inline bool operator > (const char *other) const { return other && compare(other) > 0; }
+	inline bool operator < (const char *other) const { return other && compare(other) < 0; }
+	inline bool operator <=(const char *other) const { return other && compare(other) <= 0; }
+	inline bool operator >=(const char *other) const { return other && compare(other) >= 0; }
 };
 
 

Modified: trunk/include/utilxml.h
===================================================================
--- trunk/include/utilxml.h	2009-05-04 08:04:55 UTC (rev 2377)
+++ trunk/include/utilxml.h	2009-05-04 23:18:51 UTC (rev 2378)
@@ -70,7 +70,11 @@
 			endTag = false;
 	}
 
-	inline bool isEndTag() const { return endTag; }
+	/***
+	 * if an eID is provided, then we check to be sure we have an attribute <tag eID="xxx"/> value xxx equiv to what is given us
+	 * otherwise, we return if we're a simple XML end </tag>.
+	 */
+	bool isEndTag(const char *eID = 0) const;
 
 	const StringList getAttributeNames() const;
 	int getAttributePartCount(const char *attribName, char partSplit = '|') const;

Modified: trunk/src/modules/filters/osisheadings.cpp
===================================================================
--- trunk/src/modules/filters/osisheadings.cpp	2009-05-04 08:04:55 UTC (rev 2377)
+++ trunk/src/modules/filters/osisheadings.cpp	2009-05-04 23:18:51 UTC (rev 2378)
@@ -51,6 +51,8 @@
 	bool preverse   = false;
 	bool withinTitle = false;
 	bool withinPreverseDiv = false;
+	SWBuf preverseDivID = "";
+	const char *pvDID = 0;
 	bool canonical  = false;
 	SWBuf header;
 	int headerNum   = 0;
@@ -77,32 +79,36 @@
 			// <title> </title> <div subType="x-preverse"> (</div> ## when in previous)
 			if ( (!withinPreverseDiv && !strcmp(tag.getName(), "title")) || 
 				(!strcmp(tag.getName(), "div") &&
-					((tag.isEndTag() && withinPreverseDiv) ||
+					((withinPreverseDiv && (tag.isEndTag(pvDID))) ||
 					 (tag.getAttribute("subType") && !strcmp(tag.getAttribute("subType"), "x-preverse")))
 				)) {
 
-				withinTitle = !tag.isEndTag();
+				withinTitle = (!tag.isEndTag(pvDID));
 				if (!strcmp(tag.getName(), "div")) {
-					withinPreverseDiv = !tag.isEndTag();
+					withinPreverseDiv = (!tag.isEndTag(pvDID));
+					if (!pvDID) {
+						preverseDivID = tag.getAttribute("sID");
+						pvDID = (preverseDivID.length())? preverseDivID.c_str() : 0;
+					}
 				}
 				
-				if (!tag.isEndTag()) { //start tag
-					if (!tag.isEmpty()) {
+				if (!tag.isEndTag(pvDID)) { //start tag
+					if (!tag.isEmpty() || pvDID) {
 						startTag = tag;
 					}
 				}
 				
-				if ( withinPreverseDiv
+				if ( !tag.isEndTag(pvDID) && (withinPreverseDiv 
 					|| (tag.getAttribute("subType") && !stricmp(tag.getAttribute("subType"), "x-preverse"))
 					|| (tag.getAttribute("subtype") && !stricmp(tag.getAttribute("subtype"), "x-preverse"))	// deprecated
-						) {
+						)) {
 					hide = true;
 					preverse = true;
 					header = "";
 					canonical = (tag.getAttribute("canonical") && (!stricmp(tag.getAttribute("canonical"), "true")));
 					continue;
 				}
-				if (!tag.isEndTag()) { //start tag
+				if (!tag.isEndTag(pvDID)) { //start tag
 					hide = true;
 					header = "";
 					if (option || canonical) {	// we want the tag in the text
@@ -112,7 +118,7 @@
 					}
 					continue;
 				}
-				if (hide && tag.isEndTag()) {
+				if (hide && tag.isEndTag(pvDID)) {
 					if (module->isProcessEntryAttributes() && ((option || canonical) || (!preverse))) {
 						if (preverse) {
 							sprintf(buf, "%i", pvHeaderNum++);
@@ -138,6 +144,7 @@
 						continue;
 					}
 					preverse = false;
+					pvDID = 0;
 				}
 			}
 

Modified: trunk/src/utilfuns/utilxml.cpp
===================================================================
--- trunk/src/utilfuns/utilxml.cpp	2009-05-04 08:04:55 UTC (rev 2377)
+++ trunk/src/utilfuns/utilxml.cpp	2009-05-04 23:18:51 UTC (rev 2378)
@@ -309,4 +309,13 @@
 }
 
 
+// if an eID is provided, then we check to be sure we have an attribute <tag eID="xxx"/> value xxx equiv to what is given us
+// otherwise, we return if we're a simple XML end </tag>.
+bool XMLTag::isEndTag(const char *eID) const {
+	if (eID) {
+		return (SWBuf(eID) == getAttribute("eID"));
+	}
+	return endTag;
+}
+
 SWORD_NAMESPACE_END




More information about the sword-cvs mailing list