[gtk+] cssvalue: Add a GtkCssValue for idents
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] cssvalue: Add a GtkCssValue for idents
- Date: Tue, 17 Apr 2012 07:16:42 +0000 (UTC)
commit 2ff47ed26d42dc62e58a0c07d93c595c038129a3
Author: Benjamin Otte <otte redhat com>
Date: Tue Apr 17 07:46:17 2012 +0200
cssvalue: Add a GtkCssValue for idents
gtk/gtkcssstringvalue.c | 87 ++++++++++++++++++++++++++++++++++++++++
gtk/gtkcssstringvalueprivate.h | 6 +++
2 files changed, 93 insertions(+), 0 deletions(-)
---
diff --git a/gtk/gtkcssstringvalue.c b/gtk/gtkcssstringvalue.c
index aaa3ebb..ec58ed9 100644
--- a/gtk/gtkcssstringvalue.c
+++ b/gtk/gtkcssstringvalue.c
@@ -88,6 +88,46 @@ gtk_css_value_string_print (const GtkCssValue *value,
g_string_append_c (str, '"');
}
+static void
+gtk_css_value_ident_print (const GtkCssValue *value,
+ GString *str)
+{
+ char *string = value->string;
+ gsize len;
+
+ 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;
+ case '\\':
+ g_string_append (str, "\\\\");
+ break;
+ default:
+ g_assert_not_reached ();
+ break;
+ }
+ } while (*string);
+}
+
static const GtkCssValueClass GTK_CSS_VALUE_STRING = {
gtk_css_value_string_free,
gtk_css_value_string_equal,
@@ -95,6 +135,13 @@ static const GtkCssValueClass GTK_CSS_VALUE_STRING = {
gtk_css_value_string_print
};
+static const GtkCssValueClass GTK_CSS_VALUE_IDENT = {
+ gtk_css_value_string_free,
+ gtk_css_value_string_equal,
+ gtk_css_value_string_transition,
+ gtk_css_value_ident_print
+};
+
GtkCssValue *
_gtk_css_string_value_new (const char *string)
{
@@ -135,3 +182,43 @@ _gtk_css_string_value_get (const GtkCssValue *value)
return value->string;
}
+GtkCssValue *
+_gtk_css_ident_value_new (const char *ident)
+{
+ return _gtk_css_ident_value_new_take (g_strdup (ident));
+}
+
+GtkCssValue *
+_gtk_css_ident_value_new_take (char *ident)
+{
+ GtkCssValue *result;
+
+ result = _gtk_css_value_new (GtkCssValue, >K_CSS_VALUE_IDENT);
+ result->string = ident;
+
+ return result;
+}
+
+GtkCssValue *
+_gtk_css_ident_value_try_parse (GtkCssParser *parser)
+{
+ char *ident;
+
+ g_return_val_if_fail (parser != NULL, NULL);
+
+ ident = _gtk_css_parser_try_ident (parser, TRUE);
+ if (ident == NULL)
+ return NULL;
+
+ return _gtk_css_ident_value_new_take (ident);
+}
+
+const char *
+_gtk_css_ident_value_get (const GtkCssValue *value)
+{
+ g_return_val_if_fail (value != NULL, NULL);
+ g_return_val_if_fail (value->class == >K_CSS_VALUE_IDENT, NULL);
+
+ return value->string;
+}
+
diff --git a/gtk/gtkcssstringvalueprivate.h b/gtk/gtkcssstringvalueprivate.h
index 5338f02..5fb703b 100644
--- a/gtk/gtkcssstringvalueprivate.h
+++ b/gtk/gtkcssstringvalueprivate.h
@@ -26,6 +26,12 @@
G_BEGIN_DECLS
+GtkCssValue * _gtk_css_ident_value_new (const char *ident);
+GtkCssValue * _gtk_css_ident_value_new_take (char *ident);
+GtkCssValue * _gtk_css_ident_value_try_parse (GtkCssParser *parser);
+
+const char * _gtk_css_ident_value_get (const GtkCssValue *ident);
+
GtkCssValue * _gtk_css_string_value_new (const char *string);
GtkCssValue * _gtk_css_string_value_new_take (char *string);
GtkCssValue * _gtk_css_string_value_parse (GtkCssParser *parser);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]