diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/math-equation.c | 26 | ||||
| -rw-r--r-- | src/parser.c | 2 | ||||
| -rw-r--r-- | src/parserfunc.c | 6 |
3 files changed, 27 insertions, 7 deletions
diff --git a/src/math-equation.c b/src/math-equation.c index 2ce3ab8..1faee23 100644 --- a/src/math-equation.c +++ b/src/math-equation.c @@ -803,9 +803,29 @@ math_equation_get_equation(MathEquation *equation) continue; } - /* Ignore thousands separators */ - if (c == mp_serializer_get_thousands_separator(equation->priv->serializer) && last_is_digit && next_is_digit) - ; + /* Ignore thousands separators (including spaces between digits) */ + if (c == mp_serializer_get_thousands_separator(equation->priv->serializer) && last_is_digit && next_is_digit) { + /* Skip official thousands separator */ + } + else if (c == ' ' && last_is_digit) { + /* Skip consecutive spaces between digits - look ahead to find next non-space character */ + const gchar *lookahead = read_iter; + while (*lookahead != '\0' && g_utf8_get_char(lookahead) == ' ') { + lookahead = g_utf8_next_char(lookahead); + } + /* Only skip if the next non-space character is a digit */ + if (*lookahead != '\0' && g_unichar_isdigit(g_utf8_get_char(lookahead))) { + /* Skip all consecutive spaces - advance read_iter to the last space */ + while (g_utf8_get_char(g_utf8_next_char(read_iter)) == ' ') { + read_iter = g_utf8_next_char(read_iter); + offset++; + } + /* Current space will be skipped by not appending it */ + } else { + /* Keep this space - it's not between digits */ + g_string_append_unichar(eq_text, c); + } + } /* Substitute radix character */ else if (c == mp_serializer_get_radix(equation->priv->serializer) && (last_is_digit || next_is_digit)) g_string_append_unichar(eq_text, '.'); diff --git a/src/parser.c b/src/parser.c index d60c142..c9d711b 100644 --- a/src/parser.c +++ b/src/parser.c @@ -343,7 +343,7 @@ p_check_variable(ParserState* state, gchar* name) if(utf8_next_char(name)[0] != '\0') { result = 1; - buffer = (gchar*) malloc(sizeof(gchar) * strlen(name)); + buffer = (gchar*) malloc(sizeof(gchar) * (strlen(name) + 1)); for(c = name; *c != '\0'; c = next) { next = utf8_next_char(c); diff --git a/src/parserfunc.c b/src/parserfunc.c index dc28e7e..1d45467 100644 --- a/src/parserfunc.c +++ b/src/parserfunc.c @@ -191,7 +191,7 @@ pf_get_variable(ParseNode* self) if(utf8_next_char(self->token->string)[0] != '\0') { result = 1; - buffer = (gchar*) malloc(sizeof(gchar) * strlen(self->token->string)); + buffer = (gchar*) malloc(sizeof(gchar) * (strlen(self->token->string) + 1)); mp_set_from_integer(1, &value); for(c = self->token->string; *c != '\0'; c = next) { @@ -252,7 +252,7 @@ pf_get_variable_with_power(ParseNode* self) if(utf8_next_char(self->token->string)[0] != '\0') { result = 1; - buffer = (gchar*) malloc(sizeof(gchar) * strlen(self->token->string)); + buffer = (gchar*) malloc(sizeof(gchar) * (strlen(self->token->string) + 1)); mp_set_from_integer(1, &value); for(c = self->token->string; *c != '\0'; c = next) { @@ -362,7 +362,7 @@ pf_apply_func_with_npower(ParseNode* self) MPNumber* ans = mp_new_ptr(); gint pow; gchar* inv_name; - inv_name = (gchar*) malloc(sizeof(gchar) * strlen(self->token->string) + strlen("⁻¹") + 1); + inv_name = (gchar*) malloc(sizeof(gchar) * (strlen(self->token->string) + strlen("⁻¹") + 1)); strcpy(inv_name, self->token->string); strcat(inv_name, "⁻¹"); val = (MPNumber*) (*(self->right->evaluate))(self->right); |
