[gnome-calculator/gnome-3-14] search-provider: don't match plain numbers



commit 8c5f723265fe0e33613f5f1a5a5075476c8f587f
Author: Marcus Lundblad <ml update uu se>
Date:   Thu Oct 23 22:13:15 2014 +0200

    search-provider: don't match plain numbers
    
    Filter out plain number from search results, so that entering just a number
    doesn't show up as the number equaling itself. Also handle locale-specific
    thousands separator and decimal separator.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=737620

 search-provider/search-provider.vala |   21 ++++++++++++++++++++-
 1 files changed, 20 insertions(+), 1 deletions(-)
---
diff --git a/search-provider/search-provider.vala b/search-provider/search-provider.vala
index d93b955..eca8d77 100644
--- a/search-provider/search-provider.vala
+++ b/search-provider/search-provider.vala
@@ -22,8 +22,25 @@ public class SearchProvider : Object
         try
         {
             int exit_status;
+
+            var tsep_string = Posix.nl_langinfo (Posix.NLItem.THOUSEP);
+            if (tsep_string == null || tsep_string == "")
+                tsep_string = " ";
+
+            var decimal = Posix.nl_langinfo (Posix.NLItem.RADIXCHAR);
+            if (decimal == null)
+                decimal = "";
+
+            // "normalize" input to a format known to double.try_parse
+            var equation = terms_to_equation (terms).replace (tsep_string, "").replace (decimal, ".");
+
+            // if the search is a plain number, don't process it
+            if (double.try_parse (equation)) {
+                return false;
+            }
+
             Process.spawn_command_line_sync (
-                "gnome-calculator --solve " + Shell.quote (terms_to_equation (terms)),
+                "gnome-calculator --solve " + Shell.quote (equation),
                 null, null, out exit_status);
             Process.check_exit_status (exit_status);
         }
@@ -148,5 +165,7 @@ public class SearchProviderApp : Application
 
 int main ()
 {
+    Intl.setlocale (LocaleCategory.ALL, "");
+
     return new SearchProviderApp ().run ();
 }


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