2011-04-14 02:47:18 +00:00
|
|
|
/* GTK - The GIMP Toolkit
|
|
|
|
* Copyright (C) 2011 Benjamin Otte <otte@gnome.org>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2012-02-27 13:01:10 +00:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2011-04-14 02:47:18 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2020-10-03 02:28:17 +00:00
|
|
|
#include "gtkcssserializerprivate.h"
|
2012-04-04 16:25:43 +00:00
|
|
|
|
2020-10-03 02:28:17 +00:00
|
|
|
/* Escape a string so that it can be parsed
|
|
|
|
* as a css string again.
|
|
|
|
*/
|
2014-05-01 17:47:58 +00:00
|
|
|
void
|
2020-10-03 02:31:29 +00:00
|
|
|
gtk_css_print_string (GString *str,
|
|
|
|
const char *string,
|
|
|
|
gboolean multiline)
|
2014-05-01 17:47:58 +00:00
|
|
|
{
|
|
|
|
gsize len;
|
|
|
|
|
|
|
|
g_return_if_fail (str != NULL);
|
|
|
|
g_return_if_fail (string != NULL);
|
|
|
|
|
|
|
|
g_string_append_c (str, '"');
|
|
|
|
|
|
|
|
do {
|
2014-05-21 17:17:21 +00:00
|
|
|
len = strcspn (string, "\\\"\n\r\f");
|
2014-05-01 17:47:58 +00:00
|
|
|
g_string_append_len (str, string, len);
|
|
|
|
string += len;
|
|
|
|
switch (*string)
|
|
|
|
{
|
|
|
|
case '\0':
|
2014-05-21 17:17:21 +00:00
|
|
|
goto out;
|
2014-05-01 17:47:58 +00:00
|
|
|
case '\n':
|
2020-10-03 02:31:29 +00:00
|
|
|
if (multiline)
|
|
|
|
g_string_append (str, "\\A\\\n");
|
|
|
|
else
|
|
|
|
g_string_append (str, "\\A ");
|
2014-05-01 17:47:58 +00:00
|
|
|
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;
|
|
|
|
}
|
2014-05-01 17:48:40 +00:00
|
|
|
string++;
|
2014-05-01 17:47:58 +00:00
|
|
|
} while (*string);
|
|
|
|
|
2014-05-21 17:17:21 +00:00
|
|
|
out:
|
2014-05-01 17:47:58 +00:00
|
|
|
g_string_append_c (str, '"');
|
|
|
|
}
|