Commit b356d814 authored by Benjamin Otte's avatar Benjamin Otte

css: Split out a common function

It's used in two places already, and Iwant to use it in a third one.
parent d495ab1c
......@@ -1012,3 +1012,47 @@ _gtk_css_parser_resync (GtkCssParser *parser,
gtk_css_parser_resync_internal (parser, sync_at_semicolon, TRUE, terminator);
}
void
_gtk_css_print_string (GString *str,
const char *string)
{
gsize len;
g_return_if_fail (str != NULL);
g_return_if_fail (string != NULL);
g_string_append_c (str, '"');
do {
len = strcspn (string, "\"\n\r\f");
g_string_append_len (str, string, len);
string += len;
switch (*string)
{
case '\0':
break;
case '\n':
g_string_append (str, "\\A ");
break;
case '\r':
g_string_append (str, "\\D ");
break;
case '\f':
g_string_append (str, "\\C ");
break;
case '\"':
g_string_append (str, "\\\"");
break;
case '\\':
g_string_append (str, "\\\\");
break;
default:
g_assert_not_reached ();
break;
}
} while (*string);
g_string_append_c (str, '"');
}
......@@ -97,6 +97,11 @@ void _gtk_css_parser_resync (GtkCssParser *parser
gboolean sync_at_semicolon,
char terminator);
/* XXX: Find better place to put it? */
void _gtk_css_print_string (GString *str,
const char *string);
G_END_DECLS
#endif /* __GTK_CSS_PARSER_PRIVATE_H__ */
......@@ -65,47 +65,13 @@ static void
gtk_css_value_string_print (const GtkCssValue *value,
GString *str)
{
char *string = value->string;
gsize len;
if (string == NULL)
if (value->string == NULL)
{
g_string_append (str, "none");
return;
}
g_string_append_c (str, '"');
do {
len = strcspn (string, "\"\n\r\f");
g_string_append_len (str, string, len);
string += len;
switch (*string)
{
case '\0':
break;
case '\n':
g_string_append (str, "\\A ");
break;
case '\r':
g_string_append (str, "\\D ");
break;
case '\f':
g_string_append (str, "\\C ");
break;
case '\"':
g_string_append (str, "\\\"");
break;
case '\\':
g_string_append (str, "\\\\");
break;
default:
g_assert_not_reached ();
break;
}
} while (*string);
g_string_append_c (str, '"');
_gtk_css_print_string (str, value->string);
}
static void
......
......@@ -89,37 +89,7 @@ static void
string_append_string (GString *str,
const char *string)
{
gsize len;
g_string_append_c (str, '"');
do {
len = strcspn (string, "\"\n\r\f");
g_string_append (str, string);
string += len;
switch (*string)
{
case '\0':
break;
case '\n':
g_string_append (str, "\\A ");
break;
case '\r':
g_string_append (str, "\\D ");
break;
case '\f':
g_string_append (str, "\\C ");
break;
case '\"':
g_string_append (str, "\\\"");
break;
default:
g_assert_not_reached ();
break;
}
} while (*string);
g_string_append_c (str, '"');
_gtk_css_print_string (str, string);
}
/*** IMPLEMENTATIONS ***/
......
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