Merge lp:~embik/pantheon-calculator/locale-decimal-mark into lp:~elementary-apps/pantheon-calculator/trunk

Proposed by Marvin Beckers
Status: Merged
Approved by: Corentin Noël
Approved revision: 98
Merged at revision: 117
Proposed branch: lp:~embik/pantheon-calculator/locale-decimal-mark
Merge into: lp:~elementary-apps/pantheon-calculator/trunk
Diff against target: 102 lines (+17/-9)
4 files modified
CMakeLists.txt (+1/-0)
src/Core/Evaluation.vala (+2/-2)
src/Core/Scanner.vala (+12/-5)
src/MainWindow.vala (+2/-2)
To merge this branch: bzr merge lp:~embik/pantheon-calculator/locale-decimal-mark
Reviewer Review Type Date Requested Status
elementary Apps team Pending
Review via email: mp+249113@code.launchpad.net

Commit message

now using the current locale's decimal mark (fixed bug #1414721)

Description of the change

Replaces the hardcoded dot with the current locale's decimal mark.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'CMakeLists.txt'
2--- CMakeLists.txt 2015-01-24 15:37:13 +0000
3+++ CMakeLists.txt 2015-02-09 20:17:53 +0000
4@@ -48,6 +48,7 @@
5 PACKAGES
6 gtk+-3.0>=3.12
7 granite
8+ posix
9 CUSTOM_VAPIS
10 vapi/config.vapi
11 OPTIONS
12
13=== modified file 'src/Core/Evaluation.vala'
14--- src/Core/Evaluation.vala 2015-01-20 22:04:24 +0000
15+++ src/Core/Evaluation.vala 2015-02-09 20:17:53 +0000
16@@ -275,10 +275,10 @@
17 }
18
19 private string cut (double d, int d_places) {
20- var s = ("%.5f".printf (d)).replace (",", ".");
21+ var s = ("%.5f".printf (d));
22 while (s.last_index_of ("0") == s.length - 1)
23 s = s.slice (0, s.length - 1);
24- if (s.last_index_of (".") == s.length - 1)
25+ if (s.last_index_of (Posix.nl_langinfo (Posix.NLItem.RADIXCHAR)) == s.length - 1)
26 s = s.slice (0, s.length - 1);
27 return s;
28 }
29
30=== modified file 'src/Core/Scanner.vala'
31--- src/Core/Scanner.vala 2015-01-24 12:27:31 +0000
32+++ src/Core/Scanner.vala 2015-02-09 20:17:53 +0000
33@@ -27,10 +27,13 @@
34 public int pos;
35 public unichar[] uc;
36
37- public Scanner (string input_str) {
38- this.str = input_str;
39+ private unichar decimal_symbol;
40+
41+ public Scanner (string str) {
42+ this.str = str;
43 this.pos = 0;
44 this.uc = new unichar[0];
45+ this.decimal_symbol = Posix.nl_langinfo (Posix.NLItem.RADIXCHAR).to_utf8 ()[0];
46 }
47
48 public static List<Token> scan (string input) throws SCANNER_ERROR {
49@@ -57,8 +60,12 @@
50
51 type = scanner.next (out start, out len);
52 for (ssize_t i = start; i < (start + len); i++) {
53- substr = substr + scanner.uc[i].to_string ();
54+ if (scanner.uc[i] == scanner.decimal_symbol)
55+ substr += ".";
56+ else
57+ substr += scanner.uc[i].to_string ();
58 }
59+
60 Token t = new Token (substr, type);
61
62 //identifying multicharacter tokens via Evaluation class.
63@@ -106,7 +113,7 @@
64
65 private TokenType next (out ssize_t start, out ssize_t len) throws SCANNER_ERROR {
66 start = pos;
67- if (uc[pos] == '.') {
68+ if (uc[pos] == this.decimal_symbol) {
69 pos++;
70 while (uc[pos].isdigit ())
71 pos++;
72@@ -115,7 +122,7 @@
73 } else if (uc[pos].isdigit ()) {
74 while (uc[pos].isdigit ())
75 pos++;
76- if (uc[pos] == '.')
77+ if (uc[pos] == this.decimal_symbol)
78 pos++;
79 while (uc[pos].isdigit ())
80 pos++;
81
82=== modified file 'src/MainWindow.vala'
83--- src/MainWindow.vala 2015-01-24 15:37:13 +0000
84+++ src/MainWindow.vala 2015-02-09 20:17:53 +0000
85@@ -54,7 +54,7 @@
86 private string[] regular_buttons = { "0", "1", "2", "3", "4", "5",
87 "6", "7", "8", "9", "0", " + ",
88 " − ", " × ", " ÷ ", "%", ".", "(",
89- ")", "^", "π"};
90+ ")", "^", "π", "e", Posix.nl_langinfo (Posix.NLItem.RADIXCHAR)};
91
92 private string[] function_buttons = { "sin", "cos", "tan", "√", "sinh", "cosh",
93 "tanh" , "sqrt"};
94@@ -142,7 +142,7 @@
95 var button_div = new Gtk.Button.with_label (" ÷ ");
96
97 var button_0 = new Gtk.Button.with_label ("0");
98- var button_point = new Gtk.Button.with_label (".");
99+ var button_point = new Gtk.Button.with_label (Posix.nl_langinfo (Posix.NLItem.RADIXCHAR));
100 var button_percent = new Gtk.Button.with_label ("%");
101 var button_1 = new Gtk.Button.with_label ("1");
102 var button_2 = new Gtk.Button.with_label ("2");

Subscribers

People subscribed via source and target branches

to all changes: