[sword-svn] r2377 - in trunk: include src/keys tests

scribe at crosswire.org scribe at crosswire.org
Mon May 4 01:04:55 MST 2009


Author: scribe
Date: 2009-05-04 01:04:55 -0700 (Mon, 04 May 2009)
New Revision: 2377

Modified:
   trunk/include/versekey.h
   trunk/src/keys/versekey.cpp
   trunk/tests/parsekey.cpp
Log:
added new optional arg of v11n on c-tor with range
fixed bugs where we assume that max book always lives in testament 2


Modified: trunk/include/versekey.h
===================================================================
--- trunk/include/versekey.h	2009-05-04 07:57:10 UTC (rev 2376)
+++ trunk/include/versekey.h	2009-05-04 08:04:55 UTC (rev 2377)
@@ -71,7 +71,7 @@
 
 	/** initializes this VerseKey()
 	*/
-	void init();
+	void init(const char *v11n = "KJV");
 
 	// bounds caching is mutable, thus const
 	void initBounds() const;
@@ -156,7 +156,7 @@
 	* @param min the lower boundary of the new	VerseKey
 	* @param max the upper boundary of the new	VerseKey
 	*/
-	VerseKey(const char *min, const char *max);
+	VerseKey(const char *min, const char *max, const char *v11n = "KJV");
 
 	/**	VerseKey Copy Constructor - will create a new VerseKey
 	* based on an existing SWKey

Modified: trunk/src/keys/versekey.cpp
===================================================================
--- trunk/src/keys/versekey.cpp	2009-05-04 07:57:10 UTC (rev 2376)
+++ trunk/src/keys/versekey.cpp	2009-05-04 08:04:55 UTC (rev 2377)
@@ -50,7 +50,7 @@
  * VerseKey::init - initializes instance of VerseKey
  */
 
-void VerseKey::init() {
+void VerseKey::init(const char *v11n) {
 	myclass = &classdef;
 
 	instance++;
@@ -65,8 +65,9 @@
 	verse = 1;
 	suffix = 0;
 	tmpClone = 0;
+	refSys = 0;
 
-	setVersificationSystem("KJV");
+	setVersificationSystem(v11n);
 }
 
 /******************************************************************************
@@ -200,9 +201,9 @@
 }
 
 
-VerseKey::VerseKey(const char *min, const char *max) : SWKey()
+VerseKey::VerseKey(const char *min, const char *max, const char *v11n) : SWKey()
 {
-	init();
+	init(v11n);
 	ListKey tmpListKey = ParseVerseList(min);
 	if (tmpListKey.Count()) {
 		VerseKey *newElement = SWDYNAMIC_CAST(VerseKey, tmpListKey.GetElement(0));
@@ -238,15 +239,19 @@
 
 
 void VerseKey::setVersificationSystem(const char *name) {
-	refSys = VerseMgr::getSystemVerseMgr()->getVersificationSystem(name);
+	const VerseMgr::System *newRefSys = VerseMgr::getSystemVerseMgr()->getVersificationSystem(name);
 	// TODO: cheese, but what should we do if requested v11n system isn't found?
-	if (!refSys) refSys = VerseMgr::getSystemVerseMgr()->getVersificationSystem("KJV");
-	BMAX[0] = refSys->getBMAX()[0];
-	BMAX[1] = refSys->getBMAX()[1];
+	if (!newRefSys)   newRefSys = VerseMgr::getSystemVerseMgr()->getVersificationSystem("KJV");
+	if (refSys != newRefSys) {
+		refSys = newRefSys;
+		BMAX[0] = refSys->getBMAX()[0];
+		BMAX[1] = refSys->getBMAX()[1];
 
-	// TODO: adjust bounds for versificaion system ???
-//	if (lowerBound) LowerBound().setVersificationSystem(name);
-//	if (upperBound) UpperBound().setVersificationSystem(name);
+		// TODO: adjust bounds for versificaion system ???
+		// TODO: when we have mapping done, rethink this
+		//necessary as our bounds might not mean anything in the new v11n system
+		ClearBounds();
+	}
 
 }
 
@@ -263,8 +268,8 @@
 
 char VerseKey::parse(bool checkAutoNormalize)
 {
-	testament = 2;
-	book      = BMAX[1];
+	testament = BMAX[1]?2:1;
+	book      = BMAX[BMAX[1]?1:0];
 	chapter   = 1;
 	verse     = 1;
 
@@ -1014,7 +1019,6 @@
 	delete tmpClone;
 	tmpClone = 0;
 	boundSet = false;
-	initBounds();
 }
 
 
@@ -1024,8 +1028,8 @@
 		tmpClone = (VerseKey *)this->clone();
 		tmpClone->AutoNormalize(0);
 		tmpClone->Headings(1);
-		tmpClone->Testament(2);
-		tmpClone->Book(BMAX[1]);
+		tmpClone->Testament((BMAX[1])?2:1);
+		tmpClone->Book(BMAX[(BMAX[1])?1:0]);
 		tmpClone->Chapter(tmpClone->getChapterMax());
 		tmpClone->Verse(tmpClone->getVerseMax());
 		upperBound = tmpClone->Index();
@@ -1262,8 +1266,8 @@
                break;  // If we've made it this far (all failure checks continue) we're ok
           }
 
-          if (testament > 2) {
-               testament = 2;
+          if (testament > (BMAX[1]?2:1)) {
+               testament = BMAX[1]?2:1;
                book      = BMAX[testament-1];
                chapter   = getChapterMax();
                verse     = getVerseMax();

Modified: trunk/tests/parsekey.cpp
===================================================================
--- trunk/tests/parsekey.cpp	2009-05-04 07:57:10 UTC (rev 2376)
+++ trunk/tests/parsekey.cpp	2009-05-04 08:04:55 UTC (rev 2377)
@@ -35,7 +35,7 @@
 		LocaleMgr::getSystemLocaleMgr()->setDefaultLocaleName(argv[2]);
 
 	VerseKey DefaultVSKey;
-	DefaultVSKey.AutoNormalize(0);
+//	DefaultVSKey.AutoNormalize(0);
 
 	if (argc > 3)
 		DefaultVSKey.setVersificationSystem(argv[3]);




More information about the sword-cvs mailing list