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_free (value->string);
33 g_slice_free (GtkCssValue, value);
37 gtk_css_value_string_compute (GtkCssValue *value,
39 GtkStyleProviderPrivate *provider,
40 GtkCssComputedValues *values,
41 GtkCssComputedValues *parent_values,
42 GtkCssDependencies *dependencies)
44 return _gtk_css_value_ref (value);
48 gtk_css_value_string_equal (const GtkCssValue *value1,
49 const GtkCssValue *value2)
51 return g_strcmp0 (value1->string, value2->string) == 0;
55 gtk_css_value_string_transition (GtkCssValue *start,
64 gtk_css_value_string_print (const GtkCssValue *value,
67 char *string = value->string;
72 g_string_append (str, "none");
76 g_string_append_c (str, '"');
79 len = strcspn (string, "\"\n\r\f");
80 g_string_append_len (str, string, len);
87 g_string_append (str, "\\A ");
90 g_string_append (str, "\\D ");
93 g_string_append (str, "\\C ");
96 g_string_append (str, "\\\"");
99 g_string_append (str, "\\\\");
102 g_assert_not_reached ();
107 g_string_append_c (str, '"');
111 gtk_css_value_ident_print (const GtkCssValue *value,
114 char *string = value->string;
118 len = strcspn (string, "\"\n\r\f");
119 g_string_append_len (str, string, len);
126 g_string_append (str, "\\A ");
129 g_string_append (str, "\\D ");
132 g_string_append (str, "\\C ");
135 g_string_append (str, "\\\"");
138 g_string_append (str, "\\'");
141 g_string_append (str, "\\\\");
144 g_assert_not_reached ();
150 static const GtkCssValueClass GTK_CSS_VALUE_STRING = {
151 gtk_css_value_string_free,
152 gtk_css_value_string_compute,
153 gtk_css_value_string_equal,
154 gtk_css_value_string_transition,
155 gtk_css_value_string_print
158 static const GtkCssValueClass GTK_CSS_VALUE_IDENT = {
159 gtk_css_value_string_free,
160 gtk_css_value_string_compute,
161 gtk_css_value_string_equal,
162 gtk_css_value_string_transition,
163 gtk_css_value_ident_print
167 _gtk_css_string_value_new (const char *string)
169 return _gtk_css_string_value_new_take (g_strdup (string));
173 _gtk_css_string_value_new_take (char *string)
177 result = _gtk_css_value_new (GtkCssValue, >K_CSS_VALUE_STRING);
178 result->string = string;
184 _gtk_css_string_value_parse (GtkCssParser *parser)
188 g_return_val_if_fail (parser != NULL, NULL);
190 s = _gtk_css_parser_read_string (parser);
194 return _gtk_css_string_value_new_take (s);
198 _gtk_css_string_value_get (const GtkCssValue *value)
200 g_return_val_if_fail (value != NULL, NULL);
201 g_return_val_if_fail (value->class == >K_CSS_VALUE_STRING, NULL);
203 return value->string;
207 _gtk_css_ident_value_new (const char *ident)
209 return _gtk_css_ident_value_new_take (g_strdup (ident));
213 _gtk_css_ident_value_new_take (char *ident)
217 result = _gtk_css_value_new (GtkCssValue, >K_CSS_VALUE_IDENT);
218 result->string = ident;
224 _gtk_css_ident_value_try_parse (GtkCssParser *parser)
228 g_return_val_if_fail (parser != NULL, NULL);
230 ident = _gtk_css_parser_try_ident (parser, TRUE);
234 return _gtk_css_ident_value_new_take (ident);
238 _gtk_css_ident_value_get (const GtkCssValue *value)
240 g_return_val_if_fail (value != NULL, NULL);
241 g_return_val_if_fail (value->class == >K_CSS_VALUE_IDENT, NULL);
243 return value->string;