Skip to content

Commit e302bf3

Browse files
Merge pull request #63 from SubhadeepJasu/remediation
Remediation
2 parents fe8a046 + 19cb2dd commit e302bf3

32 files changed

+698
-230
lines changed

data/com.github.subhadeepjasu.pebbles.appdata.xml.in

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,20 @@
6060
</screenshot>
6161
</screenshots>
6262
<releases>
63+
<release date="2020-06-20" version="1.0.4">
64+
<description>
65+
<p>Fixed:</p>
66+
<ul>
67+
<li>[UI] Comma and Radix symbols now obey Language &amp; Region settings</li>
68+
<li>[UI] Backspace button should now check if input entry has text on start up</li>
69+
<li>[Core] Fix precedance with proper PEMDAS rule</li>
70+
</ul>
71+
<p>Improved:</p>
72+
<ul>
73+
<li>[UI] Better clipboard system for Scientific, Calculus, Statistics and converters</li>
74+
</ul>
75+
</description>
76+
</release>
6377
<release date="2020-03-20" version="1.0.3">
6478
<description>
6579
<p>New:</p>

debian/changelog

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
com.github.subhadeepjasu.pebbles (1.0.4) bionic; urgency=low
2+
3+
[FIXED]
4+
* Comma and Radix symbols now obey Language and Region settings
5+
* Backspace button should now check if input entry has text on start up
6+
* Fix precedance with proper PEMDAS rule
7+
[IMPROVED]
8+
* Better clipboard system for Scientific, Calculus, Statistics and converters
9+
10+
-- Subhadeep Jasu <[email protected]> Sat, 20 Jun 2020 21:03:05 +0530
11+
112
com.github.subhadeepjasu.pebbles (1.0.3) bionic; urgency=medium
213

314
[NEW]

meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
project (
33
'com.github.subhadeepjasu.pebbles',
44
'vala', 'c',
5-
version: '1.0.3',
5+
version: '1.0.4',
66
)
77

88
# GNOME module

src/ControlsScheme.vala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ namespace Pebbles {
5454
},
5555
{
5656
_("All Clear"), "Delete"
57+
},
58+
{
59+
_("Copy Result"), "<Ctrl>C"
60+
},
61+
{
62+
_("Paste Input Expression"), "<Ctrl>V"
5763
}
5864
};
5965
scientific = {

src/Core/Converter.vala

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ namespace Pebbles {
3232
}
3333
}
3434
Settings settings;
35-
public string convert (double input, int unit_a, int unit_b) {
35+
public string convert (string input_string, int unit_a, int unit_b) {
36+
string input_temp = input_string.replace (Utils.get_local_separator_symbol (), "");
37+
input_temp = input_temp.replace(Utils.get_local_radix_symbol (), ".");
38+
double input = double.parse (input_temp);
3639
settings = Settings.get_default ();
3740
double result = input * (unit_multipliers_list [unit_b] / unit_multipliers_list [unit_a]);
3841
string output = "";
@@ -42,15 +45,8 @@ namespace Pebbles {
4245
} else {
4346
output = Utils.manage_decimal_places (result, settings.decimal_places);
4447
}
45-
// Remove trailing 0s and decimals
46-
while (output.has_suffix ("0")) {
47-
output = output.slice (0, -1);
48-
}
49-
if (output.has_suffix (".")) {
50-
output = output.slice (0, -1);
51-
}
5248

53-
return output;
49+
return Utils.format_result (output);
5450
}
5551
public void update_multipliers (double[] multipliers) {
5652
unit_multipliers_list = multipliers;

src/Core/CurrencyConverter.vala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ namespace Pebbles {
118118
string data_set = settings.currency_multipliers;
119119
double[] multipliers;
120120
if (data_set != "") {
121-
string[] token = data_set.split (",");
121+
string[] token = data_set.split ("[&&]");
122122
multipliers = new double[token.length];
123123
for (int i = 0; i < token.length; i++) {
124124
multipliers [i] = double.parse (token [i]);
@@ -134,7 +134,7 @@ namespace Pebbles {
134134
for (int i = 0; i < multipliers.length; i++) {
135135
save_data = (save_data + multipliers[i].to_string ());
136136
if (i < multipliers.length - 1) {
137-
save_data += ",";
137+
save_data += "[&&]";
138138
}
139139
}
140140
var date_time = new DateTime.now_local ();

src/Core/ScientificCalculator.vala

Lines changed: 9 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,18 @@ namespace Pebbles {
3131

3232
public string get_result (string exp, GlobalAngleUnit angle_mode_in, int? float_accuracy = -1, bool? tokenize = true) {
3333
var result = exp;
34+
warning(result);
3435
if (tokenize) {
35-
result = Utils.st_tokenize (exp);
36+
result = Utils.st_tokenize (exp.replace (Utils.get_local_radix_symbol (), "."));
3637
}
3738
angle_mode_sci = angle_mode_in;
3839
if (result == "E") {
39-
return result;
40+
return "E";
4041
}
41-
string evaluated_result = evaluate_exp (result, float_accuracy);
42-
if (evaluated_result == "nan")
43-
evaluated_result = "E";
44-
if (evaluated_result == "inf")
45-
evaluated_result = "";
46-
return evaluated_result;
42+
return evaluate_exp (result, float_accuracy);
4743
}
4844

49-
private static bool has_precedence (char op1, char op2) {
45+
private static bool has_precedence_pemdas (char op1, char op2) {
5046
if (op2 == '(' || op2 == ')') {
5147
return false;
5248
}
@@ -69,10 +65,10 @@ namespace Pebbles {
6965
else if ((op1 == '^' || op1 == 'q') && (op2 == '*' || op2 == '/' || op2 == '-' || op2 == '+' || op2 == 'm')) {
7066
return false;
7167
}
72-
else if ((op1 == '*' || op1 == 'm') && (op2 == '/' || op2 == '+' || op2 == '-')) {
68+
else if ((op1 == 'm') && (op2 == '/' || op2 == '*' || op2 == '+' || op2 == '-')) {
7369
return false;
7470
}
75-
else if ((op1 == '/') && (op2 == '+' || op2 == '-')) {
71+
else if ((op1 == '/' || op1 == '*') && (op2 == '+' || op2 == '-')) {
7672
return false;
7773
}
7874
else {
@@ -285,7 +281,7 @@ namespace Pebbles {
285281

286282
// If token is an operator
287283
else if (is_operator(tokens[i])) {
288-
while (!r_l_associative (tokens[i]) && !ops.empty() && has_precedence(tokens[i].get(0), ops.peek())) {
284+
while (!r_l_associative (tokens[i]) && !ops.empty() && has_precedence_pemdas(tokens[i].get(0), ops.peek())) {
289285
string tmp = apply_op(ops.pop(), values.pop(), values.pop());
290286
if (tmp != "E") {
291287
values.push(double.parse(tmp));
@@ -311,35 +307,7 @@ namespace Pebbles {
311307

312308
// Take care of float accuracy of the result
313309
string output = Utils.manage_decimal_places (values.pop (), float_accuracy);
314-
315-
// Remove trailing 0s and decimals
316-
while (output.has_suffix ("0")) {
317-
output = output.slice (0, -1);
318-
}
319-
if (output.has_suffix (".")) {
320-
output = output.slice (0, -1);
321-
}
322-
323-
// Insert separator symbol in large numbers
324-
StringBuilder output_builder = new StringBuilder (output);
325-
var decimalPos = output.last_index_of (".");
326-
if (decimalPos == -1) {
327-
decimalPos = output.length;
328-
}
329-
int end_position = 0;
330-
331-
// Take care of minus sign at the beginning of string, if any
332-
if (output.has_prefix ("-")) {
333-
end_position = 1;
334-
}
335-
for (int i = decimalPos - 3; i > end_position; i -= 3) {
336-
output_builder.insert (i, ",");
337-
}
338-
339-
if (output_builder.str == "-0") {
340-
return "0";
341-
}
342-
return output_builder.str;
310+
return output;
343311
}
344312
private static bool r_l_associative (string operator) {
345313
if (operator == "u" || operator == "^" || operator == "") {

src/Core/Statistics.vala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ namespace Pebbles
3232
}
3333

3434
private void string_splitter (string input_vals){
35-
tokens = input_vals.split(",");
35+
tokens = input_vals.split("[&&]");
3636
x = new double [tokens.length];
3737
for(int i = 0; i < tokens.length; i++) {
3838
x[i] = double.parse(tokens[i]);

src/Core/Utils.vala

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,50 @@
2121

2222
namespace Pebbles {
2323
public class Utils {
24+
public static string get_local_radix_symbol () {
25+
return Posix.nl_langinfo (Posix.NLItem.RADIXCHAR);
26+
}
27+
28+
public static string get_local_separator_symbol () {
29+
return Posix.nl_langinfo (Posix.NLItem.THOUSEP);
30+
}
31+
32+
public static string format_result (string result) {
33+
string output = result.replace (".", Utils.get_local_radix_symbol ());
34+
35+
// Remove trailing 0s and decimals
36+
while (output.has_suffix ("0")) {
37+
output = output.slice (0, -1);
38+
}
39+
if (output.has_suffix (Utils.get_local_radix_symbol ())) {
40+
output = output.slice (0, -1);
41+
}
42+
43+
// Insert separator symbol in large numbers
44+
StringBuilder output_builder = new StringBuilder (output);
45+
var decimalPos = output.last_index_of (Utils.get_local_radix_symbol ());
46+
if (decimalPos == -1) {
47+
decimalPos = output.length;
48+
}
49+
int end_position = 0;
50+
51+
// Take care of minus sign at the beginning of string, if any
52+
if (output.has_prefix ("-")) {
53+
end_position = 1;
54+
}
55+
for (int i = decimalPos - 3; i > end_position; i -= 3) {
56+
output_builder.insert (i, Utils.get_local_separator_symbol ());
57+
}
58+
59+
if (output_builder.str == "-0") {
60+
return "0";
61+
}
62+
if (output_builder.str == "nan")
63+
output_builder.str = "E";
64+
if (output_builder.str == "inf")
65+
output_builder.str = "";
66+
return output_builder.str;
67+
}
2468
public static bool check_parenthesis (string exp) {
2569
int bracket_balance = 0;
2670
for (int i = 0; i < exp.length; i++) {
@@ -156,20 +200,24 @@ namespace Pebbles {
156200
return result;
157201
}
158202
private static string uniminus_convert (string exp) {
203+
print(">%s<\n", exp);
159204
string uniminus_converted = "";
160205
string[] tokens = exp.split (" ");
161-
for (int i = 1; i < tokens.length; i++) {
206+
for (int i = 0; i < tokens.length; i++) {
162207
if (tokens[i] == "-") {
163-
if (tokens [i - 1] == ")" || tokens [i - 1] == "x" || is_number (tokens [i - 1]) ) {
208+
print("token: %d\n", i);
209+
if (i == 0) {
210+
tokens [i] = "u";
211+
} else if (tokens [i - 1] == ")" || tokens [i - 1] == "x" || is_number (tokens [i - 1]) ) {
164212
tokens [i] = "-";
165-
}
166-
else {
213+
} else {
167214
tokens [i] = "u";
168215
}
169216
}
170217
}
171218
uniminus_converted = string.joinv (" ", tokens);
172219
uniminus_converted = uniminus_converted.replace ("u", "0 u");
220+
print("converted: %s\n", uniminus_converted);
173221
return uniminus_converted;
174222
}
175223

src/KeyboardHandler.vala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,9 @@ namespace Pebbles {
144144
RETURN = 65293,
145145
RETURN_NUMPAD= 65421,
146146
ESCAPE = 65307,
147-
SPACE_BAR = 32
147+
SPACE_BAR = 32,
148+
149+
CTRL = 65507
148150
}
149151
public static bool key_is_number (uint key) {
150152
if (((key >= KeyMap.NUMPAD_0) && (key <= KeyMap.NUMPAD_9))

0 commit comments

Comments
 (0)