[sword-svn] r278 - trunk/modules/nasb/cutil

scribe at crosswire.org scribe at crosswire.org
Wed Jun 2 04:17:47 MST 2010


Author: scribe
Date: 2010-06-02 04:17:47 -0700 (Wed, 02 Jun 2010)
New Revision: 278

Modified:
   trunk/modules/nasb/cutil/nasbosis.cpp
Log:
latest fixed for first cut.  Mostly valid XML and OSIS...


Modified: trunk/modules/nasb/cutil/nasbosis.cpp
===================================================================
--- trunk/modules/nasb/cutil/nasbosis.cpp	2010-06-02 05:51:10 UTC (rev 277)
+++ trunk/modules/nasb/cutil/nasbosis.cpp	2010-06-02 11:17:47 UTC (rev 278)
@@ -111,10 +111,10 @@
 void unicodeTicks(string &outstring);
 void prepLine(string &outstring, int currentTestament, bool note);
 string getNoteBody(int nfd, string &noteLine, string osisID, int currentBookNo, int currentChapter, int currentVerse, string nStr, const char *nx);
-#ifdef HAVESWORD
-const char *convertToOSIS(const char *inRef, const SWKey *key);
-#endif
 
+
+
+
 int main(int argc, char **argv) {
 
 	// Let's test our command line arguments
@@ -190,8 +190,8 @@
 
 
 		// BOOK NAMES  <BN>
-		if (!strncmp(buffer, "<BN>", 4)) {
-			string book = buffer+4;
+		if (!strncmp(outstring.c_str(), "<BN>", 4)) {
+			string book = outstring.c_str()+4;
 			book = book.substr(0, book.find_first_of("<"));
 			outstring = "";
 			if (inVerse) {
@@ -230,8 +230,8 @@
 
 		// CHAPTERS
 		//<SN>PSALM
-		if ((!strncmp(buffer, "<CN>CHAPTER", 11)) || (!strncmp(buffer, "<SN>PSALM", 9))) {
-			string chapterTitle = buffer+4;
+		if ((!strncmp(outstring.c_str(), "<CN>CHAPTER", 11)) || (!strncmp(outstring.c_str(), "<SN>PSALM", 9))) {
+			string chapterTitle = outstring.c_str()+4;
 			chapterTitle = chapterTitle.substr(0, chapterTitle.find_first_of("<"));
 			string chapter = chapterTitle.substr((chapterTitle[0] == 'C')?8:6);
 			outstring = "";
@@ -251,9 +251,9 @@
 		
 
 		//<SH>
-		if (!strncmp(buffer, "<SH>", 4)) {
+		if (!strncmp(outstring.c_str(), "<SH>", 4)) {
 			outstring = "";
-			string heading = buffer+4;
+			string heading = outstring.c_str()+4;
 			heading = heading.substr(0, heading.find("</SH>"));
 				
 			if (!strncmp(lookahead.c_str(), "<PM>", 4)) {
@@ -264,32 +264,18 @@
 				outstring += "</verse>\n";
 				inVerse = false;
 			}
-			const char *found = strstr(buffer+4, "L\\{ORD}/'\\{S}/");
-			int start = (found) ? (found - (buffer+4)) : -1;
-			if (start > -1)
-				heading.replace(start, 14, "<divineName>Lord's</divineName>");
-			else {
-				found = strstr(buffer+4, "L\\{ORD}/");
-				start = (found) ? (found - (buffer+4)) : -1;
-				if (start > -1)
-					heading.replace(start, 8, "<divineName>Lord</divineName>");
-			}
 			outstring += (string)"<title type=\"sub\" subType=\"x-Section\">" + heading + (string)"</title>";
 		}
-		if (!strncmp(buffer, "<SS>", 4)) {
-			string heading = (buffer+4);
-			const char *found = strstr(buffer+4, "L\\{ORD}/'\\{S}/");
-			int start = (found) ? (found - (buffer+4)) : -1;
-			if (start > -1)
-				heading.replace(start, 14, "<divineName>Lord's</divineName>");
-			else {
-				found = strstr(buffer+4, "L\\{ORD}/");
-				start = (found) ? (found - (buffer+4)) : -1;
-				if (start > -1)
-					heading.replace(start, 8, "<divineName>Lord</divineName>");
-			}
+		if (!strncmp(outstring.c_str(), "<SS>", 4)) {
+			string heading = (outstring.c_str()+4);
+			heading = heading.substr(0, heading.find("</SS>"));
 			outstring = (string)"<title type=\"sub\" subType=\"x-SS\">" + heading + (string)"</title>";
 		}
+		if (!strncmp(outstring.c_str(), "<SB>", 4)) {
+			string heading = (outstring.c_str()+4);
+			heading = heading.substr(0, heading.find("</SB>"));
+			outstring = (string)"<title type=\"sub\" subType=\"x-SB\">" + heading + (string)"</title>";
+		}
 
 
 
@@ -359,37 +345,50 @@
 				}
 			}
 
-			//  <C>
+			//  <SF>
 			outstr = outstring.c_str();
-			found = strstr(outstr, "<C>");
+			found = strstr(outstr, "<SF>");
 			start = (found) ? (found - outstr) : -1;
 
 			if (start > -1) {
-				outstring.replace(start, 3, (string)"");
+				outstring.replace(start, 4, (string)"<seg type=\"x-SF\">");
 				continue;
 				
 			}
 
-			//  <V>
+			//  <SF>
 			outstr = outstring.c_str();
-			found = strstr(outstr, "<V>");
+			found = strstr(outstr, "</SF>");
 			start = (found) ? (found - outstr) : -1;
 
 			if (start > -1) {
-				outstring.replace(start, 3, (string)"");
+				outstring.replace(start, 5, (string)"</seg>");
 				continue;
 				
 			}
+
+
 			//  <RS>
 			outstr = outstring.c_str();
 			found = strstr(outstr, "<RS>");
 			start = (found) ? (found - outstr) : -1;
 
 			if (start > -1) {
-				outstring.replace(start, 4, (string)"<milestone type=\"x-RS\"/>");
+				outstring.replace(start, 4, (string)"<q who=\"Jesus\">");
 				continue;
 				
 			}
+
+			//  <RS>
+			outstr = outstring.c_str();
+			found = strstr(outstr, "</RS>");
+			start = (found) ? (found - outstr) : -1;
+
+			if (start > -1) {
+				outstring.replace(start, 5, (string)"</q>");
+				continue;
+				
+			}
 			//  <RT>
 			outstr = outstring.c_str();
 			found = strstr(outstr, "<RT>");
@@ -458,16 +457,6 @@
 				continue;
 				
 			}
-			//  <SF>
-			outstr = outstring.c_str();
-			found = strstr(outstr, "<SF>");
-			start = (found) ? (found - outstr) : -1;
-
-			if (start > -1) {
-				outstring.replace(start, 4, (string)"<milestone type=\"x-SF\"/>");
-				continue;
-				
-			}
 			//  <NA>
 			outstr = outstring.c_str();
 			found = strstr(outstr, "<NA>");
@@ -514,7 +503,7 @@
 			start = (found) ? (found - outstr) : -1;
 
 			if (start > -1) {
-				outstring.replace(start, 4, (string)"<seg type=\"x-PN\" />");
+				outstring.replace(start, 4, (string)"<milestone type=\"x-PN\" />");
 				continue;
 				
 			}
@@ -544,7 +533,7 @@
 			start = (found) ? (found - outstr) : -1;
 
 			if (start > -1) {
-				outstring.replace(start, 4, (string)"<seg type=\"x-HL\" />");
+				outstring.replace(start, 4, (string)"<milestone type=\"x-HL\" />");
 				continue;
 				
 			}
@@ -601,6 +590,10 @@
 					strongsStart = i+1;
 					inNote = false;
 				}
+				if (!strncmp(lastToken.c_str(), "q who=\"Jesus\"", 13)) {
+					strongsFound = false;
+					strongsStart = i+1;
+				}
 				if (!strncmp(lastToken.c_str(), "seg type=\"otPassage\"", 19)) {
 					strongsFound = false;
 					strongsStart = i+1;
@@ -772,14 +765,76 @@
 void prepLine(string &outstring, int currentTestament, bool note) {
 		int end = 0;
 		while (1) {
+// ------------------------------------------
+// redundant markers
+			size_t s;
+			//  <V>
+			s = outstring.find("<V>");
+			if (s != string::npos) {
+				outstring.erase(s, 3);
+				continue;
+			}
+
+			//  <P>
+			s = outstring.find("<P>");
+			if (s != string::npos) {
+				outstring.erase(s, 3);
+				continue;
+			}
+
+			//  <C>
+			s = outstring.find("<C>");
+			if (s != string::npos) {
+				outstring.erase(s, 3);
+				continue;
+			}
+
+			//  <CC>
+			s = outstring.find("<CC>");
+			if (s != string::npos) {
+				outstring.erase(s, 4);
+				continue;
+			}
+
+			//  <CP>
+			s = outstring.find("<CP>");
+			if (s != string::npos) {
+				outstring.erase(s, 4);
+				continue;
+			}
+
+			//  <$F...>>
+			s = outstring.find("<$F");
+			if (s != string::npos) {
+				size_t e = outstring.find(">>", s);
+				outstring.erase(s, e-s+2);
+				continue;
+			}
+// ----------------------------------------------
+
+			//  <A>
+			s = outstring.find("<A>");
+			if (s != string::npos) {
+				outstring.replace(s, 3, "<milestone type=\"line\" subType=\"x-A\"/>");
+				continue;
+			}
+
+
 			const char *outstr = outstring.c_str();
-			const char *found = strstr(outstr, "L\\{ORD}/");
+			const char *found = strstr(outstr, "L\\{ORD}/'\\{S}/");
 			int start = (found) ? (found - outstr) : -1;
 			if (start > -1) {
-				outstring.replace(start, 8, "<divineName>Lord</divineName>");
+				outstring.replace(start, 14, "<divineName>Lord's</divineName>");
 				continue;
 			}
 			outstr = outstring.c_str();
+			found = strstr(outstr, "L\\{ORD}/");
+			start = (found) ? (found - outstr) : -1;
+			if (start > -1) {
+				outstring.replace(start, 8, "<divineName>Lord</divineName>,");
+				continue;
+			}
+			outstr = outstring.c_str();
 			found = strstr(outstr, "Y\\{AH,}/");
 			start = (found) ? (found - outstr) : -1;
 			if (start > -1) {
@@ -900,22 +955,27 @@
 				continue;
 			}
 
-		if (note) {
-			outstr = outstring.c_str();
-			found = strstr(outstr, "{");
-			start = (found) ? (found - outstr) : -1;
-			if (start > -1) {
-				outstring.replace(start, 1, "<hi type=\"italic\">");
-				continue;
+			if (note) {
+				outstr = outstring.c_str();
+				found = strstr(outstr, "{");
+				start = (found) ? (found - outstr) : -1;
+				if (start > -1) {
+					outstring.replace(start, 1, "<hi type=\"italic\">");
+					continue;
+				}
+				outstr = outstring.c_str();
+				found = strstr(outstr, "}");
+				start = (found) ? (found - outstr) : -1;
+				if (start > -1) {
+					outstring.replace(start, 1, "</hi>");
+					continue;
+				}
+				s = outstring.find("</reference></hi>");
+				if (s != string::npos) {
+					outstring.replace(s, 17, "</hi></reference>");
+					continue;
+				}
 			}
-			outstr = outstring.c_str();
-			found = strstr(outstr, "}");
-			start = (found) ? (found - outstr) : -1;
-			if (start > -1) {
-				outstring.replace(start, 1, "</hi>");
-				continue;
-			}
-		}
 			break;
 		}
 }
@@ -976,8 +1036,14 @@
 		if (start > -1) {
 			retVal.replace(start, 3, " ");
 		}
+		outstr = retVal.c_str();
+		found = strstr(outstr, ";}");
+		start = (found) ? (found - outstr) : -1;
+		if (start > -1) {
+			retVal.replace(start, 2, "};");
+		}
 		VerseKey key = osisID.c_str();
-		retVal = convertToOSIS(retVal.c_str(), &key);
+		retVal = VerseKey::convertToOSIS(retVal.c_str(), &key);
 	}
 #endif
 	prepLine(retVal, 0, true);
@@ -986,55 +1052,3 @@
 	return retVal;
 }
 
-#ifdef HAVESWORD
-const char *convertToOSIS(const char *inRef, const SWKey *key) {
-	static SWBuf outRef;
-
-	outRef = "";
-
-	VerseKey defLanguage;
-	ListKey verses = defLanguage.ParseVerseList(inRef, (*key), true);
-	const char *startFrag = inRef;
-	for (int i = 0; i < verses.Count(); i++) {
-		VerseKey *element = SWDYNAMIC_CAST(VerseKey, verses.GetElement(i));
-		char buf[5120];
-		char frag[800];
-		char preJunk[800];
-		char postJunk[800];
-		memset(buf, 0, 5120);
-		memset(frag, 0, 800);
-		memset(preJunk, 0, 800);
-		memset(postJunk, 0, 800);
-		while ((*startFrag) && (strchr(" {};,()[].", *startFrag))) {
-			outRef += *startFrag;
-			startFrag++;
-		}
-		if (element) {
-			memmove(frag, startFrag, ((const char *)element->userData - startFrag) + 1);
-			frag[((const char *)element->userData - startFrag) + 1] = 0;
-			int j;
-			for (j = strlen(frag)-1; j && (strchr(" {};,()[].", frag[j])); j--);
-			if (frag[j+1])
-				strcpy(postJunk, frag+j+1);
-			frag[j+1]=0;
-			startFrag += ((const char *)element->userData - startFrag) + 1;
-			sprintf(buf, "<reference osisRef=\"%s-%s\">%s</reference>%s", element->LowerBound().getOSISRef(), element->UpperBound().getOSISRef(), frag, postJunk);
-		}
-		else {
-			memmove(frag, startFrag, ((const char *)verses.GetElement(i)->userData - startFrag) + 1);
-			frag[((const char *)verses.GetElement(i)->userData - startFrag) + 1] = 0;
-			int j;
-			for (j = strlen(frag)-1; j && (strchr(" {};,()[].", frag[j])); j--);
-			if (frag[j+1])
-				strcpy(postJunk, frag+j+1);
-			frag[j+1]=0;
-			startFrag += ((const char *)verses.GetElement(i)->userData - startFrag) + 1;
-			sprintf(buf, "<reference osisRef=\"%s\">%s</reference>%s", VerseKey(*verses.GetElement(i)).getOSISRef(), frag, postJunk);
-		}
-		outRef+=buf;
-	}
-	if (startFrag < (inRef + strlen(inRef)))
-		outRef+=startFrag;
-	return outRef.c_str();
-}
-#endif




More information about the sword-cvs mailing list