Commit 6c808c6d authored by Morten Welinder's avatar Morten Welinder

Parsing: drop unneeded value formats.

parent 043e2e62
......@@ -17,6 +17,7 @@ Morten:
* Fix leak in name dialog.
* Switch to using goffice's complex math.
* Fix graph axis problem. [Part of #599901]
* Drop unneeded value formats. [#651667]
--------------------------------------------------------------------------
Gnumeric 1.10.15
......
......@@ -97,8 +97,7 @@ gnm_cell_set_text (GnmCell *cell, char const *text)
g_return_if_fail (!gnm_cell_is_nonsingleton_array (cell));
parse_text_value_or_expr (parse_pos_init_cell (&pos, cell),
text, &val, &texpr, gnm_style_get_format (gnm_cell_get_style (cell)),
workbook_date_conv (cell->base.sheet->workbook));
text, &val, &texpr);
if (val != NULL) { /* String was a value */
gnm_cell_cleanout (cell);
......
......@@ -4178,9 +4178,7 @@ cmd_search_replace_do_cell (CmdSearchReplace *me, GnmEvalPos *ep,
GnmParsePos pp;
parse_pos_init_evalpos (&pp, ep);
parse_text_value_or_expr (&pp, cell_res.new_text, &val, &texpr,
gnm_style_get_format (gnm_cell_get_style (cell_res.cell)),
workbook_date_conv (cell_res.cell->base.sheet->workbook));
parse_text_value_or_expr (&pp, cell_res.new_text, &val, &texpr);
/*
* FIXME: this is a hack, but parse_text_value_or_expr
......
......@@ -36,6 +36,8 @@
#include "gnm-format.h"
#include "expr-name.h"
#include "func.h"
#include "mstyle.h"
#include "sheet-style.h"
/* For std_expr_name_handler: */
#include "expr-impl.h"
#include "gutils.h"
......@@ -723,26 +725,51 @@ gnm_expr_char_start_p (char const * c)
* @text: The text to be parsed.
* @val : Returns a GnmValue* if the text was a value, otherwise NULL.
* @texpr: Returns a GnmExprTop* if the text was an expression, otherwise NULL.
* @cur_fmt : Optional, current number format.
* @date_conv : Optional, date parse conventions
*
* If there is a parse failure for an expression an error GnmValue with the syntax
* error is returned.
*/
void
parse_text_value_or_expr (GnmParsePos const *pos, char const *text,
GnmValue **val, GnmExprTop const **texpr,
GOFormat const *cur_fmt,
GODateConventions const *date_conv)
GnmValue **val, GnmExprTop const **texpr)
{
char const *expr_start;
GODateConventions const *date_conv;
GOFormat const *cur_fmt;
GOFormat const *cell_fmt;
GnmStyle const *cell_style;
*texpr = NULL;
*val = NULL;
/* Determine context information. */
date_conv =
pos->sheet
? workbook_date_conv (pos->sheet->workbook)
: (pos->wb
? workbook_date_conv (pos->wb)
: NULL);
cell_style = pos->sheet
? sheet_style_get (pos->sheet, pos->eval.col, pos->eval.row)
: NULL;
cur_fmt = cell_fmt = cell_style ? gnm_style_get_format (cell_style) : NULL;
if (cell_fmt && go_format_is_general (cell_fmt)) {
GnmCell const *cell = pos->sheet
? sheet_cell_get (pos->sheet, pos->eval.col, pos->eval.row)
: NULL;
if (cell && cell->value && VALUE_FMT (cell->value))
cur_fmt = VALUE_FMT (cell->value);
}
/* Does it match any formats? */
*val = format_match (text, cur_fmt, date_conv);
if (*val != NULL)
if (*val != NULL) {
GOFormat const *val_fmt = VALUE_FMT (*val);
/* Avoid value formats we don't need. */
if (val_fmt && go_format_eq (cell_fmt, val_fmt))
value_set_fmt (*val, NULL);
return;
}
/* If it does not match known formats, see if it is an expression */
expr_start = gnm_expr_char_start_p (text);
......
......@@ -229,9 +229,7 @@ char const *gnm_expr_char_start_p (char const *c);
void parse_text_value_or_expr (GnmParsePos const *pos,
char const *text,
GnmValue **val,
GnmExprTop const **texpr,
GOFormat const *current_format,
GODateConventions const *date_conv);
GnmExprTop const **texpr);
GString *gnm_expr_conv_quote (GnmConventions const *conv, char const *str);
......
......@@ -2598,9 +2598,7 @@ sheet_range_set_text (GnmParsePos const *pos, GnmRange const *r, char const *str
{
closure_set_cell_value closure;
GSList *merged, *ptr;
GOFormat const *fmt;
Sheet *sheet;
GnmCell *cell;
g_return_if_fail (pos != NULL);
g_return_if_fail (r != NULL);
......@@ -2608,14 +2606,8 @@ sheet_range_set_text (GnmParsePos const *pos, GnmRange const *r, char const *str
sheet = pos->sheet;
/* Arbitrarily Use the format from upper left cell. */
cell = sheet_cell_get (sheet, r->start.col, r->start.row);
fmt = cell ? gnm_cell_get_format (cell) : NULL;
parse_text_value_or_expr (pos, str,
&closure.val, &closure.texpr,
fmt,
workbook_date_conv (sheet->workbook));
&closure.val, &closure.texpr);
if (closure.texpr) {
range_init_full_sheet (&closure.expr_bound, sheet);
......@@ -2763,9 +2755,7 @@ sheet_cell_set_text (GnmCell *cell, char const *text, PangoAttrList *markup)
g_return_if_fail (!gnm_cell_is_nonsingleton_array (cell));
parse_text_value_or_expr (parse_pos_init_cell (&pp, cell),
text, &val, &texpr,
gnm_cell_get_format (cell),
workbook_date_conv (cell->base.sheet->workbook));
text, &val, &texpr);
/* Queue a redraw before in case the span changes */
sheet_redraw_cell (cell);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment