[f-spot] Support for multi-word tags in find bar.



commit 5ec95fef9224c482879979e630b0977f3da03d20
Author: Daniel Köb <daniel koeb peony at>
Date:   Sun Jun 13 16:59:33 2010 +0200

    Support for multi-word tags in find bar.
    
    Fixes this bug: https://bugzilla.gnome.org/show_bug.cgi?id=621450

 src/Widgets/FindBar.cs            |   14 ++++++++++++--
 src/Widgets/Tests/FindBarTests.cs |   34 ++++++++++++++++++++++++++++++++--
 2 files changed, 44 insertions(+), 4 deletions(-)
---
diff --git a/src/Widgets/FindBar.cs b/src/Widgets/FindBar.cs
index ba3ae2c..e469f2a 100644
--- a/src/Widgets/FindBar.cs
+++ b/src/Widgets/FindBar.cs
@@ -530,6 +530,12 @@ namespace FSpot.Widgets {
 		string transformed_key = String.Empty;
 		int start = 0;
 
+		private static string or_op = " " + Catalog.GetString ("or") + " ";
+		private static string and_op = " " + Catalog.GetString ("and") + " ";
+
+		private static int or_op_len = or_op.Length;
+		private static int and_op_len = and_op.Length;
+
 		public bool MatchFunc (string name, string key, int pos)
 		{
 			// If this is the fist comparison for this key, convert the key (which is the entire search string)
@@ -544,7 +550,9 @@ namespace FSpot.Widgets {
 				else {
 					start = 0;
 					for (int i = pos; i >= 0; i--) {
-						if (key [i] == ' ' || key [i] == ')' || key [i] == '(') {
+						if (key [i] == ')' || key [i] == '(' ||
+						   (i >= and_op_len - 1 && String.Compare (key.Substring (i - and_op_len + 1, and_op_len), and_op, true) == 0) ||
+						   (i >= or_op_len - 1 && String.Compare (key.Substring (i - or_op_len + 1, or_op_len), or_op, true) == 0)) {
 							//Log.DebugFormat ("have start break char at {0}", i);
 							start = i + 1;
 							break;
@@ -553,7 +561,9 @@ namespace FSpot.Widgets {
 
 					int end = key.Length - 1;
 					for (int j = pos; j < key.Length; j++) {
-						if (key [j] == ' ' || key [j] == ')' || key [j] == '(') {
+						if (key [j] == ')' || key [j] == '(' ||
+						   (key.Length >= j + and_op_len && String.Compare (key.Substring (j, and_op_len), and_op, true) == 0) ||
+						   (key.Length >= j + or_op_len && String.Compare (key.Substring (j, or_op_len), or_op, true) == 0)) {
 							end = j - 1;
 							break;
 						}
diff --git a/src/Widgets/Tests/FindBarTests.cs b/src/Widgets/Tests/FindBarTests.cs
index 76082ee..a52ac6e 100644
--- a/src/Widgets/Tests/FindBarTests.cs
+++ b/src/Widgets/Tests/FindBarTests.cs
@@ -31,6 +31,23 @@ namespace FSpot.Widgets.Tests
 		}
 
 		[Test]
+		public void MatchTagsWithSpaces ()
+		{
+			CompletionLogic logic = new CompletionLogic ();
+
+			Assert.IsTrue (logic.MatchFunc ("Tag with spaces", "Ta", 1), "");
+			Assert.IsTrue (logic.MatchFunc ("Tag with spaces", "Tag", 2), "");
+			Assert.IsTrue (logic.MatchFunc ("Tag with spaces", "Tag ", 3), "");
+			Assert.IsTrue (logic.MatchFunc ("Tag with spaces", "Tag w", 4), "");
+			Assert.IsTrue (logic.MatchFunc ("Tag with spaces", "Tag with", 7), "");
+
+			Assert.IsFalse (logic.MatchFunc ("Tag with spaces", "Tag with spaces", 14), "");
+
+			Assert.IsFalse (logic.MatchFunc ("Tag with spaces", "wit", 2), "");
+			Assert.IsFalse (logic.MatchFunc ("Tag with spaces", "with s", 5), "");
+		}
+
+		[Test]
 		public void UnsuccessfulCompletionTest ()
 		{
 			CompletionLogic logic = new CompletionLogic ();
@@ -57,8 +74,21 @@ namespace FSpot.Widgets.Tests
 		{
 			CompletionLogic logic = new CompletionLogic ();
 
-			Assert.IsTrue (logic.MatchFunc ("Tagname", "XY and T", 7), "first char");
-			Assert.IsTrue (logic.MatchFunc ("Tagname", "XY and tagnam", 12), "except one char, different casing");
+			Assert.IsTrue (logic.MatchFunc ("Tagname", "XY and T", 7), "first char, after operator");
+			Assert.IsTrue (logic.MatchFunc ("Tagname", "XY and tagnam", 12), "except one char, different casing, after operator");
+			Assert.IsTrue (logic.MatchFunc ("Tagname", "T and XY", 0), "first char, before operator");
+			Assert.IsTrue (logic.MatchFunc ("Tagname", "tagnam and XY", 5), "except one char, different casing, before operator");
+		}
+
+		[Test]
+		public void SuccessfulCompletionTestWithOrOperator ()
+		{
+			CompletionLogic logic = new CompletionLogic ();
+
+			Assert.IsTrue (logic.MatchFunc ("Tagname", "XY or T", 6), "first char");
+			Assert.IsTrue (logic.MatchFunc ("Tagname", "XY or tagnam", 11), "except one char, different casing");
+			Assert.IsTrue (logic.MatchFunc ("Tagname", "T or XY", 0), "first char");
+			Assert.IsTrue (logic.MatchFunc ("Tagname", "tagnam or XY", 5), "except one char, different casing");
 		}
 
 		[Test]



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