[gnumeric] xlsx: handle quotes inside formula strings.



commit 0357b2e3eaeb8677bdaf0b712cb407eed9662e27
Author: Morten Welinder <terra gnome org>
Date:   Fri Mar 21 15:15:52 2014 -0400

    xlsx: handle quotes inside formula strings.

 NEWS                           |    1 +
 plugins/excel/ChangeLog        |    3 ++
 plugins/excel/xlsx-utils.c     |   41 ++++++++++++++++++++++++++++++++++++++++
 samples/formula-tests.gnumeric |  Bin 4190 -> 4205 bytes
 4 files changed, 45 insertions(+), 0 deletions(-)
---
diff --git a/NEWS b/NEWS
index ff4cc2e..f25a190 100644
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,7 @@ Morten:
        * Plug leaks.
        * xlsx conditional format fixes.  [#726202]
        * Fix semantics of conditional format operators.  [#726806]
+       * Fix xlsx quotes in formula strings.  [#726824]
 
 --------------------------------------------------------------------------
 Gnumeric 1.12.13
diff --git a/plugins/excel/ChangeLog b/plugins/excel/ChangeLog
index e3e8622..98d9994 100644
--- a/plugins/excel/ChangeLog
+++ b/plugins/excel/ChangeLog
@@ -1,5 +1,8 @@
 2014-03-21  Morten Welinder  <terra gnome org>
 
+       * xlsx-utils.c (xlsx_output_string, xlsx_string_parser): New
+       function.  Fixes #726824.
+
        * xlsx-read.c (xlsx_cond_fmt_rule_begin): Match
        xlsx_write_cond_rule changes.
 
diff --git a/plugins/excel/xlsx-utils.c b/plugins/excel/xlsx-utils.c
index bfd6b9b..76834e8 100644
--- a/plugins/excel/xlsx-utils.c
+++ b/plugins/excel/xlsx-utils.c
@@ -494,6 +494,45 @@ xlsx_func_erf_output_handler (GnmConventionsOut *out, GnmExprFunction const *fun
        return FALSE;
 }
 
+static char const *
+xlsx_string_parser (char const *in, GString *target,
+                  G_GNUC_UNUSED GnmConventions const *convs)
+{
+       char quote = *in;
+       size_t oldlen = target->len;
+
+       if (quote != '"')
+               goto error;
+       in++;
+       while (*in) {
+               if (*in == quote) {
+                       if (in[1] == quote) {
+                               g_string_append_c (target, quote);
+                               in += 2;
+                       } else
+                               return in + 1;                  
+               } else
+                       g_string_append_c (target, *in++);
+       }
+
+ error:
+       g_string_truncate (target, oldlen);
+       return NULL;
+}
+
+static void
+xlsx_output_string (GnmConventionsOut *out, GOString const *str)
+{
+       const char *s = str->str;
+       g_string_append_c (out->accum, '"');
+       for (; *s; s++) {
+               if (*s == '"')
+                       g_string_append (out->accum, "\"\"");
+               else
+                       g_string_append_c (out->accum, *s);
+       }
+       g_string_append_c (out->accum, '"');
+}
 
 GnmConventions *
 xlsx_conventions_new (gboolean output)
@@ -578,8 +617,10 @@ xlsx_conventions_new (gboolean output)
        convs->decimal_sep_dot          = TRUE;
        convs->input.range_ref          = rangeref_parse;
        convs->input.external_wb        = xlsx_lookup_external_wb;
+       convs->input.string             = xlsx_string_parser;
        convs->output.cell_ref          = xlsx_cellref_as_string;
        convs->output.range_ref         = xlsx_rangeref_as_string;
+       convs->output.string            = xlsx_output_string;
        convs->range_sep_colon          = TRUE;
        convs->sheet_name_sep           = '!';
        convs->arg_sep                  = ',';
diff --git a/samples/formula-tests.gnumeric b/samples/formula-tests.gnumeric
index b441ea7..0cc0710 100644
Binary files a/samples/formula-tests.gnumeric and b/samples/formula-tests.gnumeric differ


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]