[f-spot] Remove diacritics from tag names.



commit 64b85bb050d3e84d1c7a8570217a5d688b652605
Author: Daniel Köb <daniel koeb peony at>
Date:   Sun Jun 13 10:50:09 2010 +0200

    Remove diacritics from tag names.
    
    When comparing the query text in the find bar with tag names,
    also compare it to the tag names with diacritics removed.
    Also includes updated unit tests.

 src/Widgets/FindBar.cs            |   11 ++++++++++-
 src/Widgets/Tests/FindBarTests.cs |   11 +++++++++++
 2 files changed, 21 insertions(+), 1 deletions(-)
---
diff --git a/src/Widgets/FindBar.cs b/src/Widgets/FindBar.cs
index 8716f29..ba3ae2c 100644
--- a/src/Widgets/FindBar.cs
+++ b/src/Widgets/FindBar.cs
@@ -578,7 +578,16 @@ namespace FSpot.Widgets {
 				return false;
 
 			//Log.DebugFormat ("entered = {0} compared to {1}", transformed_key, name);
-			return (String.Compare (transformed_key, name.Substring(0, transformed_key.Length), true) == 0);
+
+			// Try to match key and name case insensitive
+			if (String.Compare (transformed_key, name.Substring (0, transformed_key.Length), true) == 0) {
+				return true;
+			}
+
+			// Try to match with diacritics removed from name
+			string simplified_name = StringUtil.SearchKey (name.Substring (0, transformed_key.Length));
+			//Log.DebugFormat ("entered = {0} compared to {1}", transformed_key, simplified_name);
+			return (String.Compare (transformed_key, simplified_name, true) == 0);
 		}
 
 		public string ReplaceKey (string query, string name, ref int pos)
diff --git a/src/Widgets/Tests/FindBarTests.cs b/src/Widgets/Tests/FindBarTests.cs
index 4a9b83a..76082ee 100644
--- a/src/Widgets/Tests/FindBarTests.cs
+++ b/src/Widgets/Tests/FindBarTests.cs
@@ -20,6 +20,17 @@ namespace FSpot.Widgets.Tests
 		}
 
 		[Test]
+		public void MatchTagsWithDiacritics ()
+		{
+			CompletionLogic logic = new CompletionLogic ();
+
+			Assert.IsTrue (logic.MatchFunc ("àáâãäåa", "àáâãäå", 5), "chars with diacritics");
+			Assert.IsTrue (logic.MatchFunc ("������O", "òóôõöø", 5), "chars with diacritics, different casing");
+			Assert.IsTrue (logic.MatchFunc ("àáâãäåa", "aaaaaa", 5), "remove diacritics");
+			Assert.IsTrue (logic.MatchFunc ("Ã?Ã?Ã?Ã?Ã?Ã?O", "oooooo", 5), "remove diacritics, different casing");
+		}
+
+		[Test]
 		public void UnsuccessfulCompletionTest ()
 		{
 			CompletionLogic logic = new CompletionLogic ();



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