[sword-svn] r2168 - trunk/src/modules/common

scribe at www.crosswire.org scribe at www.crosswire.org
Sat May 17 15:40:36 MST 2008


Author: scribe
Date: 2008-05-17 15:40:35 -0700 (Sat, 17 May 2008)
New Revision: 2168

Modified:
   trunk/src/modules/common/rawstr.cpp
   trunk/src/modules/common/rawstr4.cpp
   trunk/src/modules/common/zstr.cpp
Log:
Fixed snap to closest match for lexica


Modified: trunk/src/modules/common/rawstr.cpp
===================================================================
--- trunk/src/modules/common/rawstr.cpp	2008-05-16 23:23:39 UTC (rev 2167)
+++ trunk/src/modules/common/rawstr.cpp	2008-05-17 22:40:35 UTC (rev 2168)
@@ -165,6 +165,9 @@
 			stdstr(&key, ikey, 3);
 			toupperstr_utf8(key, strlen(key)*3);
 
+			int keylen = strlen(key);
+			bool substr = false;
+
 			trybuf = 0;
 
 			while (headoff < tailoff) {
@@ -183,6 +186,8 @@
 				if (!diff)
 					break;
 
+				if (!strncmp(trybuf, key, keylen)) substr = true;
+
 				if (diff < 0)
 					tailoff = (tryoff == headoff) ? headoff : tryoff;
 				else headoff = tryoff;
@@ -196,7 +201,9 @@
 			// didn't find exact match
 			if (headoff >= tailoff) {
 				tryoff = headoff;
-				away--;	// prefer the previous entry over the next
+				if (!substr) {
+					away--;	// if our entry doesn't startwith out key, prefer the previous entry over the next
+				}
 			}
 			if (trybuf)
 				free(trybuf);

Modified: trunk/src/modules/common/rawstr4.cpp
===================================================================
--- trunk/src/modules/common/rawstr4.cpp	2008-05-16 23:23:39 UTC (rev 2167)
+++ trunk/src/modules/common/rawstr4.cpp	2008-05-17 22:40:35 UTC (rev 2168)
@@ -173,6 +173,9 @@
 			stdstr(&key, ikey, 3);
 			toupperstr_utf8(key, strlen(key)*3);
 
+			int keylen = strlen(key);
+			bool substr = false;
+
 			trybuf = 0;
 
 			while (headoff < tailoff) {
@@ -180,7 +183,7 @@
 				lastoff = -1;
 				getIDXBuf(tryoff, &trybuf);
 
-				if (!*trybuf) {		// In case of extra entry at end of idx
+				if (!*trybuf && tryoff) {		// In case of extra entry at end of idx (not first entry)
 					tryoff += (tryoff > (maxoff / 2))?-8:8;
 					retval = -1;
 					break;
@@ -191,6 +194,8 @@
 				if (!diff)
 					break;
 
+				if (!strncmp(trybuf, key, keylen)) substr = true;
+
 				if (diff < 0)
 					tailoff = (tryoff == headoff) ? headoff : tryoff;
 				else headoff = tryoff;
@@ -204,7 +209,9 @@
 			// didn't find exact match
 			if (headoff >= tailoff) {
 				tryoff = headoff;
-				away--;	// prefer the previous entry over the next
+				if (!substr) {
+					away--;	// if our entry doesn't startwith out key, prefer the previous entry over the next
+				}
 			}
 			if (trybuf)
 				free(trybuf);

Modified: trunk/src/modules/common/zstr.cpp
===================================================================
--- trunk/src/modules/common/zstr.cpp	2008-05-16 23:23:39 UTC (rev 2167)
+++ trunk/src/modules/common/zstr.cpp	2008-05-17 22:40:35 UTC (rev 2168)
@@ -182,6 +182,9 @@
 			stdstr(&key, ikey, 3);
 			toupperstr_utf8(key, strlen(key)*3);
 
+			int keylen = strlen(key);
+			bool substr = false;
+
 			while (headoff < tailoff) {
 				tryoff = (lastoff == -1) ? headoff + (((((tailoff / IDXENTRYSIZE) - (headoff / IDXENTRYSIZE))) / 2) * IDXENTRYSIZE) : lastoff;
 				lastoff = -1;
@@ -199,6 +202,8 @@
 				if (!diff)
 					break;
 
+				if (!strncmp(trybuf, key, keylen)) substr = true;
+
 				if (diff < 0)
 					tailoff = (tryoff == headoff) ? headoff : tryoff;
 				else headoff = tryoff;
@@ -212,7 +217,9 @@
 			// didn't find exact match
 			if (headoff >= tailoff) {
 				tryoff = headoff;
-				away--;	// prefer the previous entry over the next
+				if (!substr) {
+					away--;	// if our entry doesn't startwith out key, prefer the previous entry over the next
+				}
 			}
 			if (trybuf)
 				free(trybuf);




More information about the sword-cvs mailing list