[gnome-calculator] search-provider: don't match plain numbers
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calculator] search-provider: don't match plain numbers
- Date: Sun, 26 Oct 2014 20:17:36 +0000 (UTC)
commit 165cf3d3cedcdb48fbddf8702da668759c6af407
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]