[gtk/wip/otte/css: 14/26] csssection: Make printing functions public



commit e39196d9af298f34d517c5a0fc725c3127c03615
Author: Benjamin Otte <otte redhat com>
Date:   Wed Apr 10 17:23:14 2019 +0200

    csssection: Make printing functions public

 docs/reference/gtk/gtk4-sections.txt |  2 ++
 gtk/gtkcssanimatedstyle.c            |  1 -
 gtk/gtkcssnode.c                     |  1 -
 gtk/gtkcssprovider.c                 |  4 ++--
 gtk/gtkcsssection.c                  | 40 +++++++++++++++++++++++++++++-------
 gtk/gtkcsssection.h                  |  6 ++++++
 gtk/gtkcsssectionprivate.h           | 33 -----------------------------
 gtk/gtkcssstaticstyle.c              |  1 -
 gtk/gtkcssstyle.c                    |  4 ++--
 gtk/inspector/css-node-tree.c        |  4 ++--
 10 files changed, 47 insertions(+), 49 deletions(-)
---
diff --git a/docs/reference/gtk/gtk4-sections.txt b/docs/reference/gtk/gtk4-sections.txt
index 9797298262..32a1ad59f7 100644
--- a/docs/reference/gtk/gtk4-sections.txt
+++ b/docs/reference/gtk/gtk4-sections.txt
@@ -5095,6 +5095,8 @@ GtkCssSection
 gtk_css_section_new
 gtk_css_section_ref
 gtk_css_section_unref
+gtk_css_section_print
+gtk_css_section_to_string
 gtk_css_section_get_file
 gtk_css_section_get_parent
 gtk_css_section_get_start_location
diff --git a/gtk/gtkcssanimatedstyle.c b/gtk/gtkcssanimatedstyle.c
index 54dfa3684a..c09ddb01ce 100644
--- a/gtk/gtkcssanimatedstyle.c
+++ b/gtk/gtkcssanimatedstyle.c
@@ -28,7 +28,6 @@
 #include "gtkcssinheritvalueprivate.h"
 #include "gtkcssinitialvalueprivate.h"
 #include "gtkcssnumbervalueprivate.h"
-#include "gtkcsssectionprivate.h"
 #include "gtkcssshorthandpropertyprivate.h"
 #include "gtkcssstaticstyleprivate.h"
 #include "gtkcssstringvalueprivate.h"
diff --git a/gtk/gtkcssnode.c b/gtk/gtkcssnode.c
index f940c53b5d..8bcf5faa92 100644
--- a/gtk/gtkcssnode.c
+++ b/gtk/gtkcssnode.c
@@ -20,7 +20,6 @@
 #include "gtkcssnodeprivate.h"
 
 #include "gtkcssanimatedstyleprivate.h"
-#include "gtkcsssectionprivate.h"
 #include "gtkcssstylepropertyprivate.h"
 #include "gtkintl.h"
 #include "gtkmarshalers.h"
diff --git a/gtk/gtkcssprovider.c b/gtk/gtkcssprovider.c
index c16bfcb94b..8f1bb22f3d 100644
--- a/gtk/gtkcssprovider.c
+++ b/gtk/gtkcssprovider.c
@@ -30,7 +30,7 @@
 #include "gtkcsscolorvalueprivate.h"
 #include "gtkcsskeyframesprivate.h"
 #include "gtkcssparserprivate.h"
-#include "gtkcsssectionprivate.h"
+#include "gtkcsssection.h"
 #include "gtkcssselectorprivate.h"
 #include "gtkcssshorthandpropertyprivate.h"
 #include "gtksettingsprivate.h"
@@ -162,7 +162,7 @@ gtk_css_provider_parsing_error (GtkCssProvider  *provider,
                                      0,
                                      TRUE))
     {
-      char *s = _gtk_css_section_to_string (section);
+      char *s = gtk_css_section_to_string (section);
 
       g_warning ("Theme parsing error: %s: %s",
                  s,
diff --git a/gtk/gtkcsssection.c b/gtk/gtkcsssection.c
index a1f1249457..2371ab2ad6 100644
--- a/gtk/gtkcsssection.c
+++ b/gtk/gtkcsssection.c
@@ -17,7 +17,7 @@
 
 #include "config.h"
 
-#include "gtkcsssectionprivate.h"
+#include "gtkcsssection.h"
 
 #include "gtkcssparserprivate.h"
 #include "gtkprivate.h"
@@ -184,9 +184,18 @@ gtk_css_section_get_end_location (const GtkCssSection *section)
   return &section->end_location;
 }
 
+/**
+ * gtk_css_section_print:
+ * @section: a section
+ * @string: a #GString to print to
+ *
+ * Prints the @section into @string in a human-readable form. This
+ * is a form like `gtk.css:32:1-23` to denote line 32, characters
+ * 1 to 23 in the file gtk.css.
+ **/
 void
-_gtk_css_section_print (const GtkCssSection  *section,
-                        GString              *string)
+gtk_css_section_print (const GtkCssSection  *section,
+                       GString              *string)
 {
   if (section->file)
     {
@@ -210,19 +219,36 @@ _gtk_css_section_print (const GtkCssSection  *section,
     }
 
   g_string_append_printf (string, ":%zu:%zu", 
-                          section->end_location.lines + 1,
-                          section->end_location.line_chars + 1);
+                          section->start_location.lines + 1,
+                          section->start_location.line_chars + 1);
+  if (section->start_location.lines != section->end_location.lines ||
+      section->start_location.line_chars != section->end_location.line_chars)
+    {
+      g_string_append (string, "-");
+      if (section->start_location.lines != section->end_location.lines)
+        g_string_append_printf (string, "%zu:", section->end_location.lines + 1);
+      g_string_append_printf (string, "%zu", section->end_location.line_chars + 1);
+    }
 }
 
+/**
+ * gtk_css_section_to_string:
+ * @section: a #GtkCssSection
+ *
+ * Prints the section into a human-readable text form using
+ * gtk_css_section_print().
+ *
+ * Returns: (transfer full): A new string.
+ **/
 char *
-_gtk_css_section_to_string (const GtkCssSection *section)
+gtk_css_section_to_string (const GtkCssSection *section)
 {
   GString *string;
 
   gtk_internal_return_val_if_fail (section != NULL, NULL);
 
   string = g_string_new (NULL);
-  _gtk_css_section_print (section, string);
+  gtk_css_section_print (section, string);
 
   return g_string_free (string, FALSE);
 }
diff --git a/gtk/gtkcsssection.h b/gtk/gtkcsssection.h
index 1fd56eab3f..fbca82105b 100644
--- a/gtk/gtkcsssection.h
+++ b/gtk/gtkcsssection.h
@@ -46,6 +46,12 @@ GtkCssSection *    gtk_css_section_ref                 (GtkCssSection        *se
 GDK_AVAILABLE_IN_ALL
 void               gtk_css_section_unref               (GtkCssSection        *section);
 
+GDK_AVAILABLE_IN_ALL
+void               gtk_css_section_print               (const GtkCssSection  *section,
+                                                        GString              *string);
+GDK_AVAILABLE_IN_ALL
+char *             gtk_css_section_to_string           (const GtkCssSection  *section);
+
 GDK_AVAILABLE_IN_ALL
 GtkCssSection *    gtk_css_section_get_parent          (const GtkCssSection  *section);
 GDK_AVAILABLE_IN_ALL
diff --git a/gtk/gtkcssstaticstyle.c b/gtk/gtkcssstaticstyle.c
index e257296fd0..d0557597a3 100644
--- a/gtk/gtkcssstaticstyle.c
+++ b/gtk/gtkcssstaticstyle.c
@@ -27,7 +27,6 @@
 #include "gtkcssinheritvalueprivate.h"
 #include "gtkcssinitialvalueprivate.h"
 #include "gtkcssnumbervalueprivate.h"
-#include "gtkcsssectionprivate.h"
 #include "gtkcssshorthandpropertyprivate.h"
 #include "gtkcssstringvalueprivate.h"
 #include "gtkcssstylepropertyprivate.h"
diff --git a/gtk/gtkcssstyle.c b/gtk/gtkcssstyle.c
index d896aebed3..89f4a102a1 100644
--- a/gtk/gtkcssstyle.c
+++ b/gtk/gtkcssstyle.c
@@ -29,7 +29,7 @@
 #include "gtkcssinitialvalueprivate.h"
 #include "gtkcssnumbervalueprivate.h"
 #include "gtkcssrgbavalueprivate.h"
-#include "gtkcsssectionprivate.h"
+#include "gtkcsssection.h"
 #include "gtkcssshorthandpropertyprivate.h"
 #include "gtkcssstringvalueprivate.h"
 #include "gtkcssfontfeaturesvalueprivate.h"
@@ -162,7 +162,7 @@ gtk_css_style_print (GtkCssStyle *style,
       if (section)
         {
           g_string_append (string, " /* ");
-          _gtk_css_section_print (section, string);
+          gtk_css_section_print (section, string);
           g_string_append (string, " */");
         }
 
diff --git a/gtk/inspector/css-node-tree.c b/gtk/inspector/css-node-tree.c
index 6093c81d5f..a6d6a202bc 100644
--- a/gtk/inspector/css-node-tree.c
+++ b/gtk/inspector/css-node-tree.c
@@ -33,7 +33,7 @@
 #include "gtk/gtkwidgetprivate.h"
 #include "gtkcssproviderprivate.h"
 #include "gtkcssstylepropertyprivate.h"
-#include "gtkcsssectionprivate.h"
+#include "gtkcsssection.h"
 #include "gtkcssstyleprivate.h"
 #include "gtkcssvalueprivate.h"
 #include "gtkcssselectorprivate.h"
@@ -473,7 +473,7 @@ gtk_inspector_css_node_tree_update_style (GtkInspectorCssNodeTree *cnt,
 
           section = gtk_css_style_get_section (new_style, i);
           if (section)
-            location = _gtk_css_section_to_string (section);
+            location = gtk_css_section_to_string (section);
           else
             location = NULL;
         }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]