[gnumeric] Parsing: drop unneeded value formats.
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] Parsing: drop unneeded value formats.
- Date: Sat, 4 Jun 2011 15:08:53 +0000 (UTC)
commit 6c808c6dd947468cd9fdd8fd1481e0e109c0bbce
Author: Morten Welinder <terra gnome org>
Date: Sat Jun 4 11:08:39 2011 -0400
Parsing: drop unneeded value formats.
NEWS | 1 +
src/cell.c | 3 +--
src/commands.c | 4 +---
src/parse-util.c | 39 +++++++++++++++++++++++++++++++++------
src/parse-util.h | 4 +---
src/sheet.c | 14 ++------------
6 files changed, 39 insertions(+), 26 deletions(-)
---
diff --git a/NEWS b/NEWS
index 918f3b0..ee2092a 100644
--- a/NEWS
+++ b/NEWS
@@ -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
diff --git a/src/cell.c b/src/cell.c
index e6bd1a6..ca0ce1a 100644
--- a/src/cell.c
+++ b/src/cell.c
@@ -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);
diff --git a/src/commands.c b/src/commands.c
index deb28e1..362b7fa 100644
--- a/src/commands.c
+++ b/src/commands.c
@@ -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
diff --git a/src/parse-util.c b/src/parse-util.c
index ac00a83..af54686 100644
--- a/src/parse-util.c
+++ b/src/parse-util.c
@@ -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);
diff --git a/src/parse-util.h b/src/parse-util.h
index 1b0b39c..318f196 100644
--- a/src/parse-util.h
+++ b/src/parse-util.h
@@ -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);
diff --git a/src/sheet.c b/src/sheet.c
index c44e21f..32ec828 100644
--- a/src/sheet.c
+++ b/src/sheet.c
@@ -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);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]