[sword-svn] r2058 - in trunk: examples/classes include src/keys

scribe at www.crosswire.org scribe at www.crosswire.org
Sat Jul 7 21:24:44 MST 2007


Author: scribe
Date: 2007-07-07 21:24:42 -0700 (Sat, 07 Jul 2007)
New Revision: 2058

Modified:
   trunk/examples/classes/Makefile
   trunk/include/config.h
   trunk/include/versekey.h
   trunk/src/keys/versekey.cpp
Log:
Fixed a bug which wouldn't allow an individual VerseKey to change locale and parse correctly


Modified: trunk/examples/classes/Makefile
===================================================================
--- trunk/examples/classes/Makefile	2007-07-03 20:51:33 UTC (rev 2057)
+++ trunk/examples/classes/Makefile	2007-07-08 04:24:42 UTC (rev 2058)
@@ -5,6 +5,6 @@
 	rm $(TARGETS)
 
 .cpp:
-	g++ `pkg-config --cflags sword` $< -o $@ `pkg-config --libs sword`
+	g++ -g `pkg-config --cflags sword` $< -o $@ `pkg-config --libs sword`
 
 

Modified: trunk/include/config.h
===================================================================
--- trunk/include/config.h	2007-07-03 20:51:33 UTC (rev 2057)
+++ trunk/include/config.h	2007-07-08 04:24:42 UTC (rev 2058)
@@ -1,4 +1,4 @@
-/* include/config.h.  Generated by configure.  */
+/* include/config.h.  Generated from config.h.in by configure.  */
 /* include/config.h.in.  Generated from configure.ac by autoheader.  */
 
 /* Define to 1 if you have the <dlfcn.h> header file. */

Modified: trunk/include/versekey.h
===================================================================
--- trunk/include/versekey.h	2007-07-03 20:51:33 UTC (rev 2057)
+++ trunk/include/versekey.h	2007-07-08 04:24:42 UTC (rev 2058)
@@ -192,7 +192,7 @@
 	* @param ikey base key (will take various forms of 'BOOK CH:VS'.
 	*	See parse() for more detailed information)
 	*/	
-	VerseKey(const SWKey * ikey);
+	VerseKey(const SWKey *ikey);
 	
 	/** VerseKey Constructor - initializes instance of VerseKey
 	* with boundariess - see also LowerBound()
@@ -202,7 +202,14 @@
 	*/	
 	VerseKey(const char *min, const char *max);
 	
-	/**	VerseKey Copy Constructor - will create a new	VerseKey
+	/**	VerseKey Copy Constructor - will create a new VerseKey
+	* based on an existing SWKey
+	*
+	* @param k the	VerseKey to copy from
+	*/
+	VerseKey(const SWKey &k);
+
+	/**	VerseKey Copy Constructor - will create a new VerseKey
 	* based on an existing one
 	*
 	* @param k the	VerseKey to copy from
@@ -212,7 +219,7 @@
 	/**	VerseKey Destructor
 	* Cleans up an instance of VerseKey
 	*/
-	virtual ~ VerseKey();
+	virtual ~VerseKey();
 
 	/** sets the lower boundary for this	VerseKey
 	* and returns the new boundary
@@ -220,24 +227,24 @@
 	* @param lb the new lower boundary for this	VerseKey
 	* @return the lower boundary the key was set to
 	*/
-	VerseKey & LowerBound(const char *lb);
+	VerseKey &LowerBound(const char *lb);
 	
 	/** sets the upper boundary for this	VerseKey
 	* and returns the new boundary
 	* @param ub the new upper boundary for this	VerseKey
 	* @return the upper boundary the key was set to
 	*/
-	VerseKey & UpperBound(const char *ub);
+	VerseKey &UpperBound(const char *ub);
 	
 	/** gets the lower boundary of this	VerseKey
 	* @return the lower boundary of this	VerseKey
 	*/
-	VerseKey & LowerBound() const;
+	VerseKey &LowerBound() const;
 	
 	/** gets the upper boundary of this	VerseKey
 	* @return the upper boundary of this	VerseKey
 	*/
-	VerseKey & UpperBound() const;
+	VerseKey &UpperBound() const;
 	
 	/** clears the boundaries of this	VerseKey
 	*/
@@ -253,7 +260,7 @@
 	*/
 	virtual const char *getText() const;
 	virtual const char *getShortText() const;
-	virtual void setText(const char *ikey) { SWKey::setText(ikey); parse (); }
+	virtual void setText(const char *ikey) { SWKey::setText(ikey); parse(); }
 	virtual void copyFrom(const SWKey &ikey);
 	
 	/** Equates this VerseKey to another VerseKey
@@ -396,7 +403,7 @@
 	 */
 	static const char *convertToOSIS(const char *inRef, const SWKey *defaultKey);
 
-	virtual ListKey ParseVerseList(const char *buf, const char *defaultKey = "Genesis 1:1", bool expandRange = false);
+	virtual ListKey ParseVerseList(const char *buf, const char *defaultKey = 0, bool expandRange = false);
 	virtual const char *getRangeText() const;
 	/** Compares another	SWKey object
 	*
@@ -428,7 +435,7 @@
 
 	SWKEY_OPERATORS
 
-	virtual SWKey & operator = (const VerseKey & ikey) { copyFrom(ikey); return *this; }
+	virtual SWKey & operator =(const VerseKey & ikey) { copyFrom(ikey); return *this; }
 };
 
 SWORD_NAMESPACE_END

Modified: trunk/src/keys/versekey.cpp
===================================================================
--- trunk/src/keys/versekey.cpp	2007-07-03 20:51:33 UTC (rev 2057)
+++ trunk/src/keys/versekey.cpp	2007-07-08 04:24:42 UTC (rev 2058)
@@ -66,11 +66,18 @@
  *		VerseKey::parse for more detailed information)
  */
 
+VerseKey::VerseKey(const SWKey &ikey) : SWKey(ikey)
+{
+	init();
+	copyFrom(ikey);
+}
+
+
 VerseKey::VerseKey(const SWKey *ikey) : SWKey(*ikey)
 {
 	init();
 	if (ikey)
-		parse();
+		copyFrom(*ikey);
 }
 
 
@@ -81,10 +88,10 @@
  *		VerseKey::parse for more detailed information)
  */
 
-VerseKey::VerseKey(const char *ikey) : SWKey(ikey)
+VerseKey::VerseKey(const char *ikeyText) : SWKey(ikeyText)
 {
 	init();
-	if (ikey)
+	if (ikeyText)
 		parse();
 }
 
@@ -92,19 +99,52 @@
 VerseKey::VerseKey(VerseKey const &k) : SWKey(k)
 {
 	init();
-	autonorm = k.autonorm;
-	headings = k.headings;
-	testament = k.Testament();
-	book = k.Book();
-	chapter = k.Chapter();
-	verse = k.Verse();
-	if (k.isBoundSet()) {
-		LowerBound(k.LowerBound());
-		UpperBound(k.UpperBound());
+	copyFrom(k);
+}
+
+
+/******************************************************************************
+ * VerseKey::copyFrom - Equates this VerseKey to another VerseKey
+ */
+
+void VerseKey::copyFrom(const VerseKey &ikey) {
+	autonorm = ikey.autonorm;
+	headings = ikey.headings;
+	testament = ikey.Testament();
+	book = ikey.Book();
+	chapter = ikey.Chapter();
+	verse = ikey.Verse();
+	if (ikey.isBoundSet()) {
+		LowerBound(ikey.LowerBound());
+		UpperBound(ikey.UpperBound());
 	}
 }
 
 
+/******************************************************************************
+ * VerseKey::copyFrom - Equates this VerseKey to another SWKey
+ */
+
+void VerseKey::copyFrom(const SWKey &ikey) {
+	// check to see if we can do a more specific copy
+	// plus some optimizations
+	const SWKey *fromKey = &ikey;
+	ListKey *tryList = SWDYNAMIC_CAST(ListKey, fromKey);
+	if (tryList) {
+		SWKey *k = tryList->getElement();
+		if (k) fromKey = k;
+	}
+	VerseKey *tryVerse = SWDYNAMIC_CAST(VerseKey, fromKey);
+	if (tryVerse) {
+		copyFrom(*tryVerse);
+	}
+	else {
+		SWKey::copyFrom(*fromKey);
+		parse();
+	}
+}
+
+
 VerseKey::VerseKey(const char *min, const char *max) : SWKey()
 {
 	init();
@@ -405,17 +445,16 @@
  */
 
 ListKey VerseKey::ParseVerseList(const char *buf, const char *defaultKey, bool expandRange) {
-	SWKey textkey;
-
 	char book[2048];
 	char number[2048];
 	int tobook = 0;
 	int tonumber = 0;
 	int chap = -1, verse = -1;
 	int bookno = 0;
-	VerseKey curkey, lBound;
-	curkey.setLocale(getLocale());
+	VerseKey curKey, lBound, lastKey;
+	curKey.setLocale(getLocale());
 	lBound.setLocale(getLocale());
+	lastKey.setLocale(getLocale());
 	int loop;
 	char comma = 0;
 	char dash = 0;
@@ -423,14 +462,12 @@
 	int q;
 	ListKey tmpListKey;
 	ListKey internalListKey;
-	SWKey tmpDefaultKey = defaultKey;
 	char lastPartial = 0;
 	bool inTerm = true;
 	int notAllDigits = 0;
 
-	curkey.AutoNormalize(0);
-	tmpListKey << tmpDefaultKey;
-	tmpListKey.GetElement()->userData = (void *)buf;
+	curKey.AutoNormalize(0);
+	if (defaultKey) lastKey = defaultKey;
 	
 	while (*buf) {
 		switch (*buf) {
@@ -508,49 +545,49 @@
 				if ((!stricmp(book, "V")) || (!stricmp(book, "VER"))) {	// Verse abbrev
 					if (verse == -1) {
 						verse = chap;
-						chap = VerseKey(tmpListKey).Chapter();
+						chap = lastKey.Chapter();
 						*book = 0;
 					}
 				}
 				if ((!stricmp(book, "ch")) || (!stricmp(book, "chap"))) {	// Verse abbrev
-					strcpy(book, VerseKey(tmpListKey).getBookName());
+					strcpy(book, lastKey.getBookName());
 				}
 				bookno = getBookAbbrev(book);
 			}
 			if (((bookno > -1) || (!*book)) && ((*book) || (chap >= 0) || (verse >= 0))) {
 				char partial = 0;
-				curkey.Verse(1);
-				curkey.Chapter(1);
-				curkey.Book(1);
+				curKey.Verse(1);
+				curKey.Chapter(1);
+				curKey.Book(1);
 
 				if (bookno < 0) {
-					curkey.Testament(VerseKey(tmpListKey).Testament());
-					curkey.Book(VerseKey(tmpListKey).Book());
+					curKey.Testament(lastKey.Testament());
+					curKey.Book(lastKey.Book());
 				}
 				else {
-					curkey.Testament(1);
-					curkey.Book(bookno);
+					curKey.Testament(1);
+					curKey.Book(bookno);
 				}
 
 				if (((comma)||((verse < 0)&&(bookno < 0)))&&(!lastPartial)) {
 //				if (comma) {
-					curkey.Chapter(VerseKey(tmpListKey).Chapter());
-					curkey.Verse(chap);  // chap because this is the first number captured
+					curKey.Chapter(lastKey.Chapter());
+					curKey.Verse(chap);  // chap because this is the first number captured
 				}
 				else {
 					if (chap >= 0) {
-						curkey.Chapter(chap);
+						curKey.Chapter(chap);
 					}
 					else {
 						partial++;
-						curkey.Chapter(1);
+						curKey.Chapter(1);
 					}
 					if (verse >= 0) {
-						curkey.Verse(verse);
+						curKey.Verse(verse);
 					}
 					else {
 						partial++;
-						curkey.Verse(1);
+						curKey.Verse(1);
 					}
 				}
 
@@ -558,39 +595,41 @@
 				for (q = 0; ((buf[q]) && (buf[q] == ' ')); q++);
 				if ((buf[q] == '-') && (expandRange)) {	// if this is a dash save lowerBound and wait for upper
 					buf+=q;
-					VerseKey newElement;
-					newElement.LowerBound(curkey);
-					newElement.setPosition(TOP);
-					tmpListKey << newElement;
+					lastKey.LowerBound(curKey);
+					lastKey.setPosition(TOP);
+					tmpListKey << lastKey;
 					tmpListKey.GetElement()->userData = (void *)buf;
 				}
 				else {
 					if (!dash) { 	// if last separator was not a dash just add
 						if (expandRange && partial) {
-							VerseKey newElement;
-							newElement.LowerBound(curkey);
+							lastKey.LowerBound(curKey);
 							if (partial > 1)
-								curkey.setPosition(MAXCHAPTER);
+								curKey.setPosition(MAXCHAPTER);
 							if (partial > 0)
-								curkey = MAXVERSE;
-							newElement.UpperBound(curkey);
-							newElement = TOP;
-							tmpListKey << newElement;
+								curKey = MAXVERSE;
+							lastKey.UpperBound(curKey);
+							lastKey = TOP;
+							tmpListKey << lastKey;
 							tmpListKey.GetElement()->userData = (void *)buf;
 						}
 						else {
-							tmpListKey << (const SWKey &)(const SWKey)(const char *)curkey;
+							// we store non-range entries as strings so we don't traverse
+							// maybe we should consider just setting
+							// lowerBound and upperBound to the same value
+							tmpListKey << curKey.getText();
 							tmpListKey.GetElement()->userData = (void *)buf;
+							lastKey = curKey;
 						}
 					}
 					else	if (expandRange) {
 						VerseKey *newElement = SWDYNAMIC_CAST(VerseKey, tmpListKey.GetElement());
 						if (newElement) {
 							if (partial > 1)
-								curkey = MAXCHAPTER;
+								curKey = MAXCHAPTER;
 							if (partial > 0)
-								curkey = MAXVERSE;
-							newElement->UpperBound(curkey);
+								curKey = MAXVERSE;
+							newElement->UpperBound(curKey);
 							*newElement = TOP;
 							tmpListKey.GetElement()->userData = (void *)buf;
 						}
@@ -697,87 +736,85 @@
 		if ((!stricmp(book, "V")) || (!stricmp(book, "VER"))) {	// Verse abbrev.
 			if (verse == -1) {
 				verse = chap;
-				chap = VerseKey(tmpListKey).Chapter();
+				chap = lastKey.Chapter();
 				*book = 0;
 			}
 		}
 			
 		if ((!stricmp(book, "ch")) || (!stricmp(book, "chap"))) {	// Verse abbrev
-			strcpy(book, VerseKey(tmpListKey).getBookName());
+			strcpy(book, lastKey.getBookName());
 		}
 		bookno = getBookAbbrev(book);
 	}
 	if (((bookno > -1) || (!*book)) && ((*book) || (chap >= 0) || (verse >= 0))) {
 		char partial = 0;
-		curkey.Verse(1);
-		curkey.Chapter(1);
-		curkey.Book(1);
+		curKey.Verse(1);
+		curKey.Chapter(1);
+		curKey.Book(1);
 
 		if (bookno < 0) {
-			curkey.Testament(VerseKey(tmpListKey).Testament());
-			curkey.Book(VerseKey(tmpListKey).Book());
+			curKey.Testament(lastKey.Testament());
+			curKey.Book(lastKey.Book());
 		}
 		else {
-			curkey.Testament(1);
-			curkey.Book(bookno);
+			curKey.Testament(1);
+			curKey.Book(bookno);
 		}
 
 		if (((comma)||((verse < 0)&&(bookno < 0)))&&(!lastPartial)) {
-//		if (comma) {
-			curkey.Chapter(VerseKey(tmpListKey).Chapter());
-			curkey.Verse(chap);  // chap because this is the first number captured
+			curKey.Chapter(lastKey.Chapter());
+			curKey.Verse(chap);  // chap because this is the first number captured
 		}
 		else {
 			if (chap >= 0) {
-				curkey.Chapter(chap);
+				curKey.Chapter(chap);
 			}
 			else {
 				partial++;
-				curkey.Chapter(1);
+				curKey.Chapter(1);
 			}
 			if (verse >= 0) {
-				curkey.Verse(verse);
+				curKey.Verse(verse);
 			}
 			else {
 				partial++;
-				curkey.Verse(1);
+				curKey.Verse(1);
 			}
 		}
 
 		if ((*buf == '-') && (expandRange)) {	// if this is a dash save lowerBound and wait for upper
-			VerseKey newElement;
-			newElement.LowerBound(curkey);
-			newElement = TOP;
-			tmpListKey << newElement;
+			lastKey.LowerBound(curKey);
+			lastKey = TOP;
+			tmpListKey << lastKey;
 			tmpListKey.GetElement()->userData = (void *)buf;
 		}
 		else {
 			if (!dash) { 	// if last separator was not a dash just add
 				if (expandRange && partial) {
-					VerseKey newElement;
-					newElement.LowerBound(curkey);
+					lastKey.LowerBound(curKey);
 					if (partial > 1)
-						curkey = MAXCHAPTER;
+						curKey = MAXCHAPTER;
 					if (partial > 0)
-						curkey = MAXVERSE;
-					newElement.UpperBound(curkey);
-					newElement = TOP;
-					tmpListKey << newElement;
+						curKey = MAXVERSE;
+					lastKey.UpperBound(curKey);
+					lastKey = TOP;
+					tmpListKey << lastKey;
 					tmpListKey.GetElement()->userData = (void *)buf;
 				}
 				else {
-					tmpListKey << (const SWKey &)(const SWKey)(const char *)curkey;
+					tmpListKey << curKey.getText();
 					tmpListKey.GetElement()->userData = (void *)buf;
+					lastKey = curKey;
 				}
 			}
 			else if (expandRange) {
 				VerseKey *newElement = SWDYNAMIC_CAST(VerseKey, tmpListKey.GetElement());
 				if (newElement) {
 					if (partial > 1)
-						curkey = MAXCHAPTER;
+						curKey = MAXCHAPTER;
 					if (partial > 0)
-						curkey = MAXVERSE;
-					newElement->UpperBound(curkey);
+						curKey = MAXVERSE;
+					newElement->UpperBound(curKey);
 					*newElement = TOP;
 					tmpListKey.GetElement()->userData = (void *)buf;
 				}
@@ -786,7 +823,6 @@
 	}
 	*book = 0;
 	tmpListKey = TOP;
-	tmpListKey.Remove();	// remove defaultKey
 	internalListKey = tmpListKey;
 	internalListKey = TOP;	// Align internalListKey to first element before passing back;
 
@@ -915,28 +951,6 @@
 
 
 /******************************************************************************
- * VerseKey::copyFrom - Equates this VerseKey to another VerseKey
- */
-
-void VerseKey::copyFrom(const VerseKey &ikey) {
-	SWKey::copyFrom(ikey);
-
-	parse();
-}
-
-
-/******************************************************************************
- * VerseKey::copyFrom - Equates this VerseKey to another SWKey
- */
-
-void VerseKey::copyFrom(const SWKey &ikey) {
-	SWKey::copyFrom(ikey);
-
-	parse();
-}
-
-
-/******************************************************************************
  * VerseKey::getText - refreshes keytext before returning if cast to
  *				a (char *) is requested
  */




More information about the sword-cvs mailing list