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,
61 gtk_css_value_string_print (const GtkCssValue *value,
64 char *string = value->string;
67 g_string_append_c (str, '"');
70 len = strcspn (string, "\"\n\r\f");
71 g_string_append_len (str, string, len);
78 g_string_append (str, "\\A ");
81 g_string_append (str, "\\D ");
84 g_string_append (str, "\\C ");
87 g_string_append (str, "\\\"");
90 g_string_append (str, "\\\\");
93 g_assert_not_reached ();
98 g_string_append_c (str, '"');
102 gtk_css_value_ident_print (const GtkCssValue *value,
105 char *string = value->string;
109 len = strcspn (string, "\"\n\r\f");
110 g_string_append_len (str, string, len);
117 g_string_append (str, "\\A ");
120 g_string_append (str, "\\D ");
123 g_string_append (str, "\\C ");
126 g_string_append (str, "\\\"");
129 g_string_append (str, "\\'");
132 g_string_append (str, "\\\\");
135 g_assert_not_reached ();
141 static const GtkCssValueClass GTK_CSS_VALUE_STRING = {
142 gtk_css_value_string_free,
143 gtk_css_value_string_compute,
144 gtk_css_value_string_equal,
145 gtk_css_value_string_transition,
146 gtk_css_value_string_print
149 static const GtkCssValueClass GTK_CSS_VALUE_IDENT = {
150 gtk_css_value_string_free,
151 gtk_css_value_string_compute,
152 gtk_css_value_string_equal,
153 gtk_css_value_string_transition,
154 gtk_css_value_ident_print
158 _gtk_css_string_value_new (const char *string)
160 return _gtk_css_string_value_new_take (g_strdup (string));
164 _gtk_css_string_value_new_take (char *string)
168 result = _gtk_css_value_new (GtkCssValue, >K_CSS_VALUE_STRING);
169 result->string = string;
175 _gtk_css_string_value_parse (GtkCssParser *parser)
179 g_return_val_if_fail (parser != NULL, NULL);
181 s = _gtk_css_parser_read_string (parser);
185 return _gtk_css_string_value_new_take (s);
189 _gtk_css_string_value_get (const GtkCssValue *value)
191 g_return_val_if_fail (value != NULL, NULL);
192 g_return_val_if_fail (value->class == >K_CSS_VALUE_STRING, NULL);
194 return value->string;
198 _gtk_css_ident_value_new (const char *ident)
200 return _gtk_css_ident_value_new_take (g_strdup (ident));
204 _gtk_css_ident_value_new_take (char *ident)
208 result = _gtk_css_value_new (GtkCssValue, >K_CSS_VALUE_IDENT);
209 result->string = ident;
215 _gtk_css_ident_value_try_parse (GtkCssParser *parser)
219 g_return_val_if_fail (parser != NULL, NULL);
221 ident = _gtk_css_parser_try_ident (parser, TRUE);
225 return _gtk_css_ident_value_new_take (ident);
229 _gtk_css_ident_value_get (const GtkCssValue *value)
231 g_return_val_if_fail (value != NULL, NULL);
232 g_return_val_if_fail (value->class == >K_CSS_VALUE_IDENT, NULL);
234 return value->string;