[sword-svn] r2275 - in trunk: include src/keys src/modules tests tests/testsuite

scribe at crosswire.org scribe at crosswire.org
Thu Mar 5 16:17:56 MST 2009


Author: scribe
Date: 2009-03-05 16:17:56 -0700 (Thu, 05 Mar 2009)
New Revision: 2275

Modified:
   trunk/include/versekey.h
   trunk/include/versetreekey.h
   trunk/src/keys/versekey.cpp
   trunk/src/keys/versetreekey.cpp
   trunk/src/modules/swmodule.cpp
   trunk/tests/mgrtest.cpp
   trunk/tests/testsuite/versekey.good
   trunk/tests/versekeytest.cpp
Log:
Fixed Lang() issue which was always returning null
Fixed VerseKey(min, max) to parse max with expand range
Closer to working VerseTreeKey



Modified: trunk/include/versekey.h
===================================================================
--- trunk/include/versekey.h	2009-03-03 23:53:05 UTC (rev 2274)
+++ trunk/include/versekey.h	2009-03-05 23:17:56 UTC (rev 2275)
@@ -57,14 +57,6 @@
 
 	const VerseMgr::System *refSys;
 
-	/** The Testament: 0 - Module Heading; 1 - Old; 2 - New
-	*/
-	signed char testament;
-	mutable signed char book;
-	mutable signed int chapter;
-	mutable signed int verse;
-	mutable char suffix;
-
 	/** flag for auto normalization
 	*/
 	char autonorm;
@@ -104,6 +96,14 @@
 
 protected:
 
+	/** The Testament: 0 - Module Heading; 1 - Old; 2 - New
+	*/
+	signed char testament;
+	signed char book;
+	signed int chapter;
+	signed int verse;
+	signed char suffix;
+
 	/************************************************************************
 	 * VerseKey::getBookAbbrev - Attempts to find a book no from a name or
 	 *                           abbreviation

Modified: trunk/include/versetreekey.h
===================================================================
--- trunk/include/versetreekey.h	2009-03-03 23:53:05 UTC (rev 2274)
+++ trunk/include/versetreekey.h	2009-03-05 23:17:56 UTC (rev 2275)
@@ -117,6 +117,7 @@
 	SWKEY_OPERATORS
 
 	virtual SWKey & operator = (const VerseKey & ikey) { copyFrom(ikey); return *this; }
+//	virtual void copyFrom(const VerseTreeKey &ikey);
 };
 
 SWORD_NAMESPACE_END

Modified: trunk/src/keys/versekey.cpp
===================================================================
--- trunk/src/keys/versekey.cpp	2009-03-03 23:53:05 UTC (rev 2274)
+++ trunk/src/keys/versekey.cpp	2009-03-05 23:17:56 UTC (rev 2275)
@@ -188,8 +188,16 @@
 VerseKey::VerseKey(const char *min, const char *max) : SWKey()
 {
 	init();
-	LowerBound(min);
-	UpperBound(max);
+	ListKey tmpListKey = ParseVerseList(min);
+	if (tmpListKey.Count()) {
+		VerseKey *newElement = SWDYNAMIC_CAST(VerseKey, tmpListKey.GetElement(0));
+		LowerBound(*newElement);
+	}
+	tmpListKey = ParseVerseList(max, min, true);
+	if (tmpListKey.Count()) {
+		VerseKey *newElement = SWDYNAMIC_CAST(VerseKey, tmpListKey.GetElement(0));
+		UpperBound((newElement->isBoundSet())?newElement->UpperBound():*newElement);
+	}
 	setPosition(TOP);
 }
 
@@ -238,42 +246,18 @@
 
 char VerseKey::parse(bool checkAutoNormalize)
 {
-
-
 	testament = 2;
 	book      = BMAX[1];
 	chapter   = 1;
 	verse     = 1;
-	//int booklen   = 0;
 
 	int error = 0;
 
 	if (keytext) {
-		ListKey tmpListKey = VerseKey::ParseVerseList(keytext);
+		ListKey tmpListKey = ParseVerseList(keytext);
 		if (tmpListKey.Count()) {
-
 			this->positionFrom(tmpListKey.getElement(0));
 			error = this->error;
-/*
-			SWKey::setText((const char *)tmpListKey);
-			for (int i = 1; i < 3; i++) {
-				for (int j = 1; j <= BMAX[i-1]; j++) {
-					int matchlen = strlen(books[i-1][j-1].name);
-					if (!strncmp(keytext, books[i-1][j-1].name, matchlen)) {
-						if (matchlen > booklen) {
-							booklen = matchlen;
-							testament = i;
-							book = j;
-						}
-					}
-				}
-			}
-
-			if (booklen) {
-				sscanf(&keytext[booklen], "%d:%d", &chapter, &verse);
-			}
-			else	error = 1;
-*/
 		} else error = 1;
 	}
 	if (checkAutoNormalize) {
@@ -517,7 +501,7 @@
 	while (*buf) {
 		switch (*buf) {
 		case ':':
-			if (buf[1] != ' ') {		// for silly Mat 1:1: this verse....
+			if (buf[1] != ' ') {		// for silly "Mat 1:1: this verse...."
 				number[tonumber] = 0;
 				tonumber = 0;
 				if (*number)
@@ -990,6 +974,7 @@
 		upperBound = tmpClone->Index();
 		lowerBound = 0;
 	}
+	else tmpClone->setLocale(getLocale());
 }
 
 
@@ -1288,7 +1273,7 @@
 
 
 /******************************************************************************
- * VerseKey::Testament - Sets/gets testament
+ * VerseKey::setTestament - Sets/gets testament
  *
  * ENT:	itestament - value which to set testament
  *		[MAXPOS(char)] - only get
@@ -1463,19 +1448,11 @@
 
 	if (!testament) { // if we want module heading
 		offset = 0;
-		verse  = 0;
-		chapter = 0;
-		book = 0;
 	}
 	else if (!book) {	// we want testament heading
-			offset = ((testament == 2) ? refSys->getNTStartOffset():0) + 1;
-			chapter = 0;
-			verse = 0;
+		offset = ((testament == 2) ? refSys->getNTStartOffset():0) + 1;
 	}
 	else {
-		if (!chapter) {
-			verse   = 0;
-		}
 		offset = refSys->getOffsetFromVerse((((testament>1)?BMAX[0]:0)+book-1), chapter, verse);
 	}
 	return offset;

Modified: trunk/src/keys/versetreekey.cpp
===================================================================
--- trunk/src/keys/versetreekey.cpp	2009-03-03 23:53:05 UTC (rev 2274)
+++ trunk/src/keys/versetreekey.cpp	2009-03-05 23:17:56 UTC (rev 2275)
@@ -21,6 +21,7 @@
 
 
 #include <versetreekey.h>
+#include <ctype.h>
 
 SWORD_NAMESPACE_START
 
@@ -165,16 +166,36 @@
 		TreeKey *tkey = this->TreeKey::PositionChangeListener::getTreeKey();
 		int saveError = tkey->Error();
 		long bookmark = tkey->getOffset();
-		SWBuf path;
+		SWBuf seg[4];
 		internalPosChange = true;
 		int legs = 0;
 		do {
-			path = (SWBuf)tkey->getLocalName() + "." + path;
+			seg[legs] = tkey->getLocalName();
 			legs++;
-		} while (tkey->parent());
-		path--;
-		path << 1;
-		setText(path);
+		} while (tkey->parent() && (legs < 4));
+
+		if ((legs < 2) && (!seg[0].length() || seg[0] == "/")) {		//"[ Module Heading ]";
+			testament = 0;
+			book      = 0;
+			chapter   = 0;
+			setVerse(0);
+		}
+		else if ((legs < 2)
+			&& ((!strncmp(seg[0].c_str(), "[ Testament ", 12)) &&		//"[ Testament n Heading ]";
+			    (isdigit(seg[0][12])) &&
+			    (!strcmp(seg[0].c_str()+13, " Heading ]")))) {
+			testament = (seg[0][12]-48);
+			book      = 0;
+			chapter   = 0;
+			setVerse(0);
+		}	//path = "[ Module Heading ]";
+		else {
+			setBookName(seg[legs--]);
+			chapter = (legs > -1) ? atoi(seg[legs--]) : 0;
+			setVerse((legs > -1) ? atoi(seg[legs--]) : 0);
+		}
+
+//		setText(path);
 		if (saveError) {
 			error = saveError;
 		}
@@ -188,7 +209,9 @@
 void VerseTreeKey::syncVerseToTree() {
 	internalPosChange = true;
 	SWBuf path;
-	path.setFormatted("/%s/%d/%d", getOSISBookName(), Chapter(), Verse());
+	if (!Testament()) path = "/"; // "[ Module Heading ]";
+	else if (!Book()) path.setFormatted("/[ Testament %d Heading ]", Testament());
+	else path.setFormatted("/%s/%d/%d", getOSISBookName(), getChapter(), getVerse());
 	if (getSuffix()) path += getSuffix();
 	long bookmark = treeKey->getOffset();
 	treeKey->setText(path);
@@ -247,4 +270,13 @@
 	}
 }
 
+
+/******************************************************************************
+ * VerseTreeKey::copyFrom - Equates this VerseTreeKey to another VerseTreeKey
+
+void VerseTreeKey::copyFrom(const VerseTreeKey &ikey) {
+	VerseKey::copyFrom(ikey);
+}
+ */
+
 SWORD_NAMESPACE_END

Modified: trunk/src/modules/swmodule.cpp
===================================================================
--- trunk/src/modules/swmodule.cpp	2009-03-03 23:53:05 UTC (rev 2274)
+++ trunk/src/modules/swmodule.cpp	2009-03-05 23:17:56 UTC (rev 2275)
@@ -273,7 +273,8 @@
 
 char *SWModule::Lang(const char *imodlang)
 {
-	return stdstr(&modlang, imodlang);
+	if (imodlang) stdstr(&modlang, imodlang);
+	return modlang;
 }
 
 

Modified: trunk/tests/mgrtest.cpp
===================================================================
--- trunk/tests/mgrtest.cpp	2009-03-03 23:53:05 UTC (rev 2274)
+++ trunk/tests/mgrtest.cpp	2009-03-05 23:17:56 UTC (rev 2275)
@@ -37,6 +37,7 @@
 	std::cerr << "\nconfigPath: " << mymgr.configPath << "\n\n";
 
 
+
 	ModMap::iterator it;
 
 	for (it = mymgr.Modules.begin(); it != mymgr.Modules.end(); it++) {
@@ -48,8 +49,11 @@
 			std::cout << (const char *) *(*it).second << "\n\n";
 		}
 	}
+
 	SWModule *mhc = mymgr.Modules["MHC"];
+
 	if (mhc) {
+		std::cout << "MHC, Lang = " << mhc->Lang() << "\n\n";
 		for (mhc->Key("Gen 1:1"); mhc->Key() < (VerseKey) "Gen 1:10"; (*mhc)++)
 			std::cout << (const char *) *mhc << "\n";
 	}

Modified: trunk/tests/testsuite/versekey.good
===================================================================
--- trunk/tests/testsuite/versekey.good	2009-03-03 23:53:05 UTC (rev 2274)
+++ trunk/tests/testsuite/versekey.good	2009-03-05 23:17:56 UTC (rev 2275)
@@ -3,3 +3,5 @@
 Amos 1:5
 Error: 1: Luke 1:1
 Error: 1: Luke 1:1
+Error: 0: Acts 5:1
+Error: 1: Acts 28:31

Modified: trunk/tests/versekeytest.cpp
===================================================================
--- trunk/tests/versekeytest.cpp	2009-03-03 23:53:05 UTC (rev 2274)
+++ trunk/tests/versekeytest.cpp	2009-03-05 23:17:56 UTC (rev 2275)
@@ -77,6 +77,10 @@
      std::cout << "Error: " << (int)boundTest.Error() << ": " << boundTest << "\n";
      boundTest.setText("1Sam.21.1");
      std::cout << "Error: " << (int)boundTest.Error() << ": " << boundTest << "\n";
+     boundTest.setText("acts.5.1");
+     std::cout << "Error: " << (int)boundTest.Error() << ": " << boundTest << "\n";
+     boundTest.setText("rom.5.1");
+     std::cout << "Error: " << (int)boundTest.Error() << ": " << boundTest << "\n";
 
 
      *x = "Is.1.13";




More information about the sword-cvs mailing list