Commit f3b4b707 authored by Morten Welinder's avatar Morten Welinder Committed by Morten Welinder

Rename from gnumeric_strescape and take GString accumulator argument. All

2002-12-13  Morten Welinder  <terra@diku.dk>

	* src/gutils.c (gnm_strescape): Rename from gnumeric_strescape and
	take GString accumulator argument.  All callers changed.
parent 6d1e72f4
2002-12-13 Morten Welinder <terra@diku.dk>
* src/gutils.c (gnm_strescape): Rename from gnumeric_strescape and
take GString accumulator argument. All callers changed.
2002-12-13 Morten Welinder <terra@diku.dk>
* src/expr.c (gnm_expr_list_as_string): Take accumulator argument
......
2002-12-13 Morten Welinder <terra@diku.dk>
* src/gutils.c (gnm_strescape): Rename from gnumeric_strescape and
take GString accumulator argument. All callers changed.
2002-12-13 Morten Welinder <terra@diku.dk>
* src/expr.c (gnm_expr_list_as_string): Take accumulator argument
......
2002-12-13 Morten Welinder <terra@diku.dk>
* src/gutils.c (gnm_strescape): Rename from gnumeric_strescape and
take GString accumulator argument. All callers changed.
2002-12-13 Morten Welinder <terra@diku.dk>
* src/expr.c (gnm_expr_list_as_string): Take accumulator argument
......
......@@ -308,7 +308,7 @@ static char *
pln_convert_expr (ParsePos const *pp, guint8 const *ch)
{
GString *expr = g_string_new ("");
guint8 *str, *escaped;
guint8 *str;
guint8 const *end;
int i, len, code;
......@@ -333,13 +333,11 @@ pln_convert_expr (ParsePos const *pp, guint8 const *ch)
case 9: /* Text constant */
len = *ch;
str = pln_get_str (ch + 1, len);
escaped = gnumeric_strescape (str);
g_free (str);
g_string_append_c (expr, '\"');
g_string_append (expr, escaped);
gnm_strescape (expr, str);
g_string_append_c (expr, '\"');
g_free (escaped);
ch += len + 1;
g_free (str);
break;
case 10: /* Named block */
......
......@@ -3562,18 +3562,19 @@ cmd_search_replace_do_cell (CmdSearchReplace *me, EvalPos *ep,
} else {
switch (sr->error_behaviour) {
case SRE_error: {
char *tmp = gnumeric_strescape (cell_res.new_text);
/* FIXME: should go via expression. */
GString *s = g_string_new ("=ERROR(");
gnm_strescape (s, cell_res.new_text);
g_string_append_c (s, ')');
g_free (cell_res.new_text);
cell_res.new_text = g_strconcat ("=ERROR(", tmp, ")", NULL);
g_free (tmp);
cell_res.new_text = g_string_free (s, FALSE);
err = FALSE;
break;
}
case SRE_string: {
/* FIXME: quoting isn't right. */
char *tmp = gnumeric_strescape (cell_res.new_text);
g_free (cell_res.new_text);
cell_res.new_text = tmp;
GString *s = g_string_new ("");
gnm_strescape (s, cell_res.new_text);
cell_res.new_text = g_string_free (s, FALSE);
err = FALSE;
break;
}
......
......@@ -1238,9 +1238,7 @@ do_expr_as_string (GString *target, GnmExpr const *expr, ParsePos const *pp,
gboolean need_par;
if (v->type == VALUE_STRING) {
char *tmp = gnumeric_strescape (v->v_str.val->str);
g_string_append (target, tmp);
g_free (tmp);
gnm_strescape (target, v->v_str.val->str);
return;
}
......
......@@ -382,32 +382,21 @@ gnumeric_usr_plugin_dir (void)
*
* Also adds quotes around the result.
*/
char *
gnumeric_strescape (char const *string)
{
char *q, *escaped;
int escapechars = 0;
char const *p;
g_return_val_if_fail (string != NULL, NULL);
for (p = string; *p; p = g_utf8_next_char (p))
if (*p == '\\' || *p == '\"')
escapechars++;
q = escaped = g_new (char, (p - string) + escapechars + 3);
*q++ = '\"';
for (p = string; *p; ) {
char *next = g_utf8_next_char (p);
if (*p == '\\' || *p == '\"')
*q++ = '\\';
while (p < next)
*q++ = *p++;
void
gnm_strescape (GString *target, char const *string)
{
g_string_append_c (target, '"');
/* This loop should be UTF-8 safe. */
for (; *string; string++) {
switch (*string) {
case '"':
case '\\':
g_string_append_c (target, '\\');
default:
g_string_append_c (target, *string);
}
}
*q++ = '\"';
*q = 0;
return escaped;
g_string_append_c (target, '"');
}
/* ------------------------------------------------------------------------- */
......
......@@ -86,7 +86,7 @@ char * gnumeric_sys_plugin_dir (void);
char * gnumeric_usr_dir (const char *subdir);
char * gnumeric_usr_plugin_dir (void);
char * gnumeric_strescape (const char *string);
void gnm_strescape (GString *target, const char *string);
char * gnumeric_utf8_strcapital (const char *p, ssize_t len);
......
......@@ -673,11 +673,9 @@ value_get_as_string (Value const *v)
g_string_append_c (str, row_sep);
/* quote strings */
if (val->type == VALUE_STRING) {
char *tmp = gnumeric_strescape (val->v_str.val->str);
g_string_append (str, tmp);
g_free (tmp);
} else
if (val->type == VALUE_STRING)
gnm_strescape (str, val->v_str.val->str);
else
g_string_append (str, value_peek_string (val));
}
if (y < v->v_array.y-1)
......
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