[sword-svn] r1686 - in trunk: examples/cmdline include src/modules

scribe at crosswire.org scribe at crosswire.org
Wed Dec 22 18:37:17 MST 2004


Author: scribe
Date: 2004-12-22 18:37:16 -0700 (Wed, 22 Dec 2004)
New Revision: 1686

Modified:
   trunk/examples/cmdline/search.cpp
   trunk/include/swmodule.h
   trunk/src/modules/swmodule.cpp
Log:
Added SEARCHFLAG_MATCHWHOLEENTRY, currently only used in entryAttrib searches
so we don't find partial matches of things like Strong's numbers



Modified: trunk/examples/cmdline/search.cpp
===================================================================
--- trunk/examples/cmdline/search.cpp	2004-12-22 07:05:49 UTC (rev 1685)
+++ trunk/examples/cmdline/search.cpp	2004-12-23 01:37:16 UTC (rev 1686)
@@ -59,7 +59,7 @@
 
 	std::cout << "[0=================================50===============================100]\n ";
 	char lineLen = 70;
-	listkey = target->Search(argv[2], -2, 0/*REG_ICASE*/, 0, 0, &percentUpdate, &lineLen);
+	listkey = target->Search(argv[2], -3, SEARCHFLAG_MATCHWHOLEENTRY/*REG_ICASE*/, 0, 0, &percentUpdate, &lineLen);
 	std::cout << "\n";
 	while (!listkey.Error()) {
 		std::cout << (const char *)listkey << std::endl;

Modified: trunk/include/swmodule.h
===================================================================
--- trunk/include/swmodule.h	2004-12-22 07:05:49 UTC (rev 1685)
+++ trunk/include/swmodule.h	2004-12-23 01:37:16 UTC (rev 1686)
@@ -3,7 +3,7 @@
 *		  types of modules (e.g. texts, commentaries, maps, lexicons,
 *		  etc.)
 *
-* $Id: swmodule.h,v 1.72 2004/03/27 09:24:35 mgruner Exp $
+* $Id$
 *
 * Copyright 1998 CrossWire Bible Society (http://www.crosswire.org)
 *	CrossWire Bible Society
@@ -41,6 +41,8 @@
 
 SWORD_NAMESPACE_START
 
+#define SEARCHFLAG_MATCHWHOLEENTRY 4096
+
 #define SWMODULE_OPERATORS \
 	operator const char *() { return RenderText(); } \
 	operator SWKey &() { return *getKey(); } \
@@ -317,11 +319,14 @@
 
 
 	// search interface
-	/** Searches a module for a string
+    /** Searches a module for a string
 	*
 	* @param istr string for which to search
 	* @param searchType type of search to perform
-	*   >=0 ->regex;  -1 ->phrase; -2 ->multiword;
+	*			>=0 - regex
+	*			-1  - phrase
+	*			-2  - multiword
+	*			-3  - entryAttrib (eg. Word//Strongs/G1234/)
 	* @param flags options flags for search
 	* @param scope Key containing the scope. VerseKey or ListKey are useful here.
 	* @param justCheckIfSupported if set, don't search,
@@ -330,7 +335,7 @@
 	* @param percentUserData User data that is given to the callback function as parameter.
 	*
 	* @return listkey set to verses that contain istr
-	*/
+     */
 	virtual ListKey &search(const char *istr, int searchType = 0, int flags = 0,
 			SWKey * scope = 0,
 			bool * justCheckIfSupported = 0,

Modified: trunk/src/modules/swmodule.cpp
===================================================================
--- trunk/src/modules/swmodule.cpp	2004-12-22 07:05:49 UTC (rev 1685)
+++ trunk/src/modules/swmodule.cpp	2004-12-23 01:37:16 UTC (rev 1686)
@@ -365,7 +365,7 @@
  *				>=0 - regex
  *				-1  - phrase
  *				-2  - multiword
- *				-3  - entryAttrib
+ *				-3  - entryAttrib (eg. Word//Strongs/G1234/)
  * 	flags		- options flags for search
  *	justCheckIfSupported	- if set, don't search, only tell if this
  *							function supports requested search.
@@ -572,7 +572,13 @@
 						i3End   = i2Start->second.end();
 					}
 					for (;i3Start != i3End; i3Start++) {
-						sres = ((flags & REG_ICASE) == REG_ICASE) ? stristr(i3Start->second.c_str(), words[3]) : strstr(i3Start->second.c_str(), words[3]);
+						if (flags & SEARCHFLAG_MATCHWHOLEENTRY) {
+							bool found = !(((flags & REG_ICASE) == REG_ICASE) ? stricmp(i3Start->second.c_str(), words[3]) : strcmp(i3Start->second.c_str(), words[3]));
+							sres = (found) ? i3Start->second.c_str() : 0;
+						}
+						else {
+							sres = ((flags & REG_ICASE) == REG_ICASE) ? stristr(i3Start->second.c_str(), words[3]) : strstr(i3Start->second.c_str(), words[3]);
+						}
 						if (sres) {
 							textkey = KeyText();
 							listkey << textkey;



More information about the sword-cvs mailing list