Commit 5260ac76 authored by Martin Sheppard's avatar Martin Sheppard Committed by Arturo Espinosa

new function to escape strings (do_expr_decode_tree) : fixed so strings

2000-01-03  Martin Sheppard <martin.sheppard@iname.com>

	* src/expr.c (strescape) : new function to escape strings
	(do_expr_decode_tree) : fixed so strings are escaped properly
parent 328d9010
2000-01-03 Martin Sheppard <martin.sheppard@iname.com>
* src/expr.c (strescape) : new function to escape strings
(do_expr_decode_tree) : fixed so strings are escaped properly
2000-01-03 Miguel de Icaza <miguel@gnu.org>
* src/gnumeric-sheet.c (move_cursor): Fixed the annoying flashing
of the cursor/selection problem by reverting to the old code setup.
I also eliminated some animation of the cursor while doing this.
2000-01-03 Michael Meeks <mmeeks@gnu.org>
* src/func.c (function_remove, function_is_unused): implement.
......
2000-01-03 Martin Sheppard <martin.sheppard@iname.com>
* src/expr.c (strescape) : new function to escape strings
(do_expr_decode_tree) : fixed so strings are escaped properly
2000-01-03 Miguel de Icaza <miguel@gnu.org>
* src/gnumeric-sheet.c (move_cursor): Fixed the annoying flashing
of the cursor/selection problem by reverting to the old code setup.
I also eliminated some animation of the cursor while doing this.
2000-01-03 Michael Meeks <mmeeks@gnu.org>
* src/func.c (function_remove, function_is_unused): implement.
......
......@@ -1117,14 +1117,50 @@ cell_get_abs_col_row (CellRef const * const cell_ref,
*row = cell_ref->row;
}
/*
* Escapes all backslashes and quotes in a string. It is based on glib's
* g_strescape.
*/
static char *
strescape (char *string)
{
char *q;
char *escaped;
int escapechars = 0;
char *p = string;
g_return_val_if_fail (string != NULL, NULL);
while (*p != '\000') {
if (*p == '\\' || *p == '\"')
escapechars++;
p++;
}
if (!escapechars)
return g_strdup (string);
escaped = g_new (char, strlen (string) + escapechars + 1);
p = string;
q = escaped;
while (*p != '\000'){
if (*p == '\\' || *p == '\"')
*q++ = '\\';
*q++ = *p++;
}
*q = '\000';
return escaped;
}
/*
* Converts a parsed tree into its string representation
* assuming that we are evaluating at col, row
*
* This routine is pretty simple: it walks the ExprTree and
* creates a string representation.
*
* FIXME: strings containing quotes will come out wrong.
*/
static char *
do_expr_decode_tree (ExprTree *tree, ParsePosition const *pp,
......@@ -1278,9 +1314,13 @@ do_expr_decode_tree (ExprTree *tree, ParsePosition const *pp,
return res;
}
case VALUE_STRING:
/* FIXME: handle quotes in string. */
return g_strconcat ("\"", v->v.str->str, "\"", NULL);
case VALUE_STRING: {
char *str1, *str2;
str1 = strescape(v->v.str->str);
str2 = g_strconcat ("\"", str1, "\"", NULL);
g_free(str1);
return str2;
}
case VALUE_EMPTY:
return g_strdup ("");
......
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