1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 2011 Red Hat, Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
20 #include "gtkcssstringvalueprivate.h"
30 gtk_css_value_string_free (GtkCssValue *value)
32 g_slice_free (GtkCssValue, value);
36 gtk_css_value_string_compute (GtkCssValue *value,
38 GtkStyleContext *context,
39 GtkCssDependencies *dependencies)
41 return _gtk_css_value_ref (value);
45 gtk_css_value_string_equal (const GtkCssValue *value1,
46 const GtkCssValue *value2)
48 return g_strcmp0 (value1->string, value2->string) == 0;
52 gtk_css_value_string_transition (GtkCssValue *start,
60 gtk_css_value_string_print (const GtkCssValue *value,
63 char *string = value->string;
66 g_string_append_c (str, '"');
69 len = strcspn (string, "\"\n\r\f");
70 g_string_append_len (str, string, len);
77 g_string_append (str, "\\A ");
80 g_string_append (str, "\\D ");
83 g_string_append (str, "\\C ");
86 g_string_append (str, "\\\"");
89 g_string_append (str, "\\\\");
92 g_assert_not_reached ();
97 g_string_append_c (str, '"');
101 gtk_css_value_ident_print (const GtkCssValue *value,
104 char *string = value->string;
108 len = strcspn (string, "\"\n\r\f");
109 g_string_append_len (str, string, len);
116 g_string_append (str, "\\A ");
119 g_string_append (str, "\\D ");
122 g_string_append (str, "\\C ");
125 g_string_append (str, "\\\"");
128 g_string_append (str, "\\'");
131 g_string_append (str, "\\\\");
134 g_assert_not_reached ();
140 static const GtkCssValueClass GTK_CSS_VALUE_STRING = {
141 gtk_css_value_string_free,
142 gtk_css_value_string_compute,
143 gtk_css_value_string_equal,
144 gtk_css_value_string_transition,
145 gtk_css_value_string_print
148 static const GtkCssValueClass GTK_CSS_VALUE_IDENT = {
149 gtk_css_value_string_free,
150 gtk_css_value_string_compute,
151 gtk_css_value_string_equal,
152 gtk_css_value_string_transition,
153 gtk_css_value_ident_print
157 _gtk_css_string_value_new (const char *string)
159 return _gtk_css_string_value_new_take (g_strdup (string));
163 _gtk_css_string_value_new_take (char *string)
167 result = _gtk_css_value_new (GtkCssValue, >K_CSS_VALUE_STRING);
168 result->string = string;
174 _gtk_css_string_value_parse (GtkCssParser *parser)
178 g_return_val_if_fail (parser != NULL, NULL);
180 s = _gtk_css_parser_read_string (parser);
184 return _gtk_css_string_value_new_take (s);
188 _gtk_css_string_value_get (const GtkCssValue *value)
190 g_return_val_if_fail (value != NULL, NULL);
191 g_return_val_if_fail (value->class == >K_CSS_VALUE_STRING, NULL);
193 return value->string;
197 _gtk_css_ident_value_new (const char *ident)
199 return _gtk_css_ident_value_new_take (g_strdup (ident));
203 _gtk_css_ident_value_new_take (char *ident)
207 result = _gtk_css_value_new (GtkCssValue, >K_CSS_VALUE_IDENT);
208 result->string = ident;
214 _gtk_css_ident_value_try_parse (GtkCssParser *parser)
218 g_return_val_if_fail (parser != NULL, NULL);
220 ident = _gtk_css_parser_try_ident (parser, TRUE);
224 return _gtk_css_ident_value_new_take (ident);
228 _gtk_css_ident_value_get (const GtkCssValue *value)
230 g_return_val_if_fail (value != NULL, NULL);
231 g_return_val_if_fail (value->class == >K_CSS_VALUE_IDENT, NULL);
233 return value->string;