[sword-svn] r1991 - trunk/src/keys

scribe at www.crosswire.org scribe at www.crosswire.org
Sat Nov 11 15:11:39 MST 2006


Author: scribe
Date: 2006-11-11 15:11:37 -0700 (Sat, 11 Nov 2006)
New Revision: 1991

Modified:
   trunk/src/keys/versekey.cpp
Log:
Updated documentation and factored a condition to a more simple representation (per DM Smith)


Modified: trunk/src/keys/versekey.cpp
===================================================================
--- trunk/src/keys/versekey.cpp	2006-11-11 21:11:20 UTC (rev 1990)
+++ trunk/src/keys/versekey.cpp	2006-11-11 22:11:37 UTC (rev 1991)
@@ -336,17 +336,24 @@
 	StringMgr* stringMgr = StringMgr::getSystemStringMgr();
 	const bool hasUTF8Support = StringMgr::hasUTF8Support();
 
-		// TODO: Why do we loop twice?  once upper and once not?
-		// If you wrote this, please comment.
+	// The first iteration of this loop tries to uppercase
+	// the string. If we still fail to match, we try
+	// matching the string without any toupper logic.
+	// This is useful for, say, Chinese user input
+	// on a system that doesn't properly support
+	// a true Unicode-toupper function (!hasUTF8Support)
 	for (int i = 0; i < 2; i++) {
 		stdstr(&abbr, iabbr, 2);
 		strstrip(abbr);
-		if (!i && hasUTF8Support) { //we have support for UTF-8 handling; we expect UTF-8 encoded locales
-			abbr = stringMgr->upperUTF8(abbr, strlen(abbr)*2);
+
+		if (!i) {
+			if (hasUTF8Support) { //we have support for UTF-8 handling; we expect UTF-8 encoded locales
+				abbr = stringMgr->upperUTF8(abbr, strlen(abbr)*2);
+			}
+			else {
+				abbr = stringMgr->upperLatin1(abbr);
+			}
 		}
-		else if (!i) {
-			abbr = stringMgr->upperLatin1(abbr);
-		}
 
 		abLen = strlen(abbr);
 
@@ -354,6 +361,7 @@
 			min = 0;
 			max = abbrevsCnt;
 
+			// binary search for a match
 			while(1) {
 				target = min + ((max - min) / 2);
 				diff = strncmp(abbr, abbrevs[target].ab, abLen);
@@ -364,6 +372,7 @@
 				else	max = target;
 			}
 
+			// lets keep backing up till we find the 'first' valid match
 			for (; target > 0; target--) {
 				if (strncmp(abbr, abbrevs[target-1].ab, abLen))
 					break;




More information about the sword-cvs mailing list