[gcalctool] Automatically add missing closing brackets (Bug #615243)
- From: Robert Ancell <rancell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gcalctool] Automatically add missing closing brackets (Bug #615243)
- Date: Fri, 23 Apr 2010 00:25:43 +0000 (UTC)
commit f578cbeef6888df5f6b5e61d7cdf47a9c7839bb6
Author: Robert Ancell <robert ancell gmail com>
Date: Fri Apr 23 10:23:39 2010 +1000
Automatically add missing closing brackets (Bug #615243)
NEWS | 2 ++
src/math-equation.c | 22 +++++++++++++++++++---
2 files changed, 21 insertions(+), 3 deletions(-)
---
diff --git a/NEWS b/NEWS
index 4e64e94..540859c 100644
--- a/NEWS
+++ b/NEWS
@@ -34,6 +34,8 @@ Overview of changes in gcalctool 5.31.1
* Add back in undo and redo
+ * Automatically add missing closing brackets (Bug #615243)
+
Overview of changes in gcalctool 5.30.0
* Fix errors in variable exponents (e.g. xy²)
diff --git a/src/math-equation.c b/src/math-equation.c
index c002766..5d46348 100644
--- a/src/math-equation.c
+++ b/src/math-equation.c
@@ -1085,8 +1085,9 @@ void
math_equation_solve(MathEquation *equation)
{
MPNumber z;
- int result;
- gchar *text, *error_token = NULL, *message = NULL;
+ gint result, n_brackets = 0;
+ gchar *c, *text, *error_token = NULL, *message = NULL;
+ GString *equation_text;
if (math_equation_is_empty(equation))
return;
@@ -1101,8 +1102,23 @@ math_equation_solve(MathEquation *equation)
math_equation_set_number_mode(equation, NORMAL);
text = math_equation_get_equation(equation);
- result = parse(equation, text, &z, &error_token);
+ equation_text = g_string_new(text);
g_free(text);
+ /* Count the number of brackets and automatically add missing closing brackets */
+ for (c = equation_text->str; *c; c++) {
+ if (*c == '(')
+ n_brackets++;
+ else if (*c == ')')
+ n_brackets--;
+ }
+ while (n_brackets > 0) {
+ g_string_append_c(equation_text, ')');
+ n_brackets--;
+ }
+
+
+ result = parse(equation, equation_text->str, &z, &error_token);
+ g_string_free(equation_text, TRUE);
switch (result) {
case PARSER_ERR_NONE:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]