Patch for str_uscore_equal problems



Michael,

Here's a little patch that fixes two problems -- one observed, one
determined by inspection -- in underscore-handling in menu item labels.
The observed one was that updating a menu item with label "foo" to
"foot" wouldn't work because str_uscore_equal thought the strings were
equal (didn't handle length-only differences). The by-inspection one was
that only the first underscore of a doubled underscore should be
ignored, since doubling the underscore is a way to escape a real
underscore character in the menu item label.

OK to commit this?

John

Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/bonobo/ChangeLog,v
retrieving revision 1.956
diff -u -p -u -r1.956 ChangeLog
--- ChangeLog	2001/02/09 18:10:41	1.956
+++ ChangeLog	2001/02/13 01:26:53
@@ -1,3 +1,10 @@
+2001-02-12  John Sullivan  <sullivan eazel com>
+
+	* bonobo/bonobo-ui-sync-menu.c: (str_uscore_equal):
+	Fix case where strings start with same characters but
+	one is longer -- was incorrectly returning TRUE. Also
+	made it handle doubled underscores correctly.
+
 2001-02-09  Cody Russell  <bratsche gnome org>
 	* bonobo/bonobo-ui-engine-config.c: Remove the Cancel button.
 	Since this dialog makes changes in real time, this button serves
Index: bonobo/bonobo-ui-sync-menu.c
===================================================================
RCS file: /cvs/gnome/bonobo/bonobo/bonobo-ui-sync-menu.c,v
retrieving revision 1.9
diff -u -p -u -r1.9 bonobo-ui-sync-menu.c
--- bonobo/bonobo-ui-sync-menu.c	2001/02/06 21:09:47	1.9
+++ bonobo/bonobo-ui-sync-menu.c	2001/02/13 01:26:56
@@ -279,19 +279,33 @@ cmd_get_menu_pixmap (BonoboUINode     *n
 	return NULL;
 }
 
+/*
+ * The second parameter uses underscores to escape keyboard
+ * shortcuts. We ignore the first underscore, but if there
+ * are two in a row, they are treated as if there was one.
+ */
 static gboolean
 str_uscore_equal (const char *plain, const char *scored)
 {
-	while (*plain && *scored) {
-		if (*scored == '_')
+	do {
+		if (*scored == '_') {
 			scored++;
-		else if (*scored != *plain)
+
+			/* must check for badly formed string (ending
+			 * with single underscore) or risk reading off end 
+			 */
+			if (!*scored) {
+				return FALSE;
+			}
+		}
+
+		if (*scored != *plain)
 			return FALSE;
 		else {
 			scored++;
 			plain++;
 		}
-	}
+	} while (*scored || *plain);
 
 	return TRUE;
 }




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]