[gtk/wip/otte/css: 36/66] cssparser: Add gtk_css_parser_resolve_url()



commit 9cefb0020f0f84b747e63a59c11fd7eee2276fd6
Author: Benjamin Otte <otte redhat com>
Date:   Tue Apr 9 02:15:12 2019 +0200

    cssparser: Add gtk_css_parser_resolve_url()
    
    Another slight change of semantics and naming for the new parser.

 gtk/gtkcssparser.c        | 30 +++++++++++++++---------------
 gtk/gtkcssparserprivate.h |  4 ++--
 gtk/gtkcssprovider.c      |  8 ++++----
 3 files changed, 21 insertions(+), 21 deletions(-)
---
diff --git a/gtk/gtkcssparser.c b/gtk/gtkcssparser.c
index 2b05cb0e24..fa613464a4 100644
--- a/gtk/gtkcssparser.c
+++ b/gtk/gtkcssparser.c
@@ -126,16 +126,26 @@ gtk_css_parser_get_base_file (GtkCssParser *parser)
 }
 
 GFile *
-_gtk_css_parser_get_file_for_path (GtkCssParser *parser,
-                                   const char   *path)
+gtk_css_parser_resolve_url (GtkCssParser *parser,
+                            const char   *url)
 {
   GFile *base, *file;
+  char *scheme;
 
   g_return_val_if_fail (parser != NULL, NULL);
-  g_return_val_if_fail (path != NULL, NULL);
+  g_return_val_if_fail (url != NULL, NULL);
+
+  scheme = g_uri_parse_scheme (url);
+  if (scheme != NULL)
+    {
+      file = g_file_new_for_uri (url);
+      g_free (scheme);
+      return file;
+    }
+  g_free (scheme);
 
   base = gtk_css_parser_get_base_file (parser);
-  file = g_file_resolve_relative_path (base, path);
+  file = g_file_resolve_relative_path (base, url);
   g_object_unref (base);
 
   return file;
@@ -1029,7 +1039,6 @@ GFile *
 _gtk_css_parser_read_url (GtkCssParser *parser)
 {
   gchar *path;
-  char *scheme;
   GFile *file;
 
   if (_gtk_css_parser_try (parser, "url", FALSE))
@@ -1050,15 +1059,6 @@ _gtk_css_parser_read_url (GtkCssParser *parser)
           g_free (path);
           return NULL;
         }
-
-      scheme = g_uri_parse_scheme (path);
-      if (scheme != NULL)
-       {
-         file = g_file_new_for_uri (path);
-         g_free (path);
-         g_free (scheme);
-         return file;
-       }
     }
   else
     {
@@ -1070,7 +1070,7 @@ _gtk_css_parser_read_url (GtkCssParser *parser)
         }
     }
 
-  file = _gtk_css_parser_get_file_for_path (parser, path);
+  file = gtk_css_parser_resolve_url (parser, path);
   g_free (path);
 
   return file;
diff --git a/gtk/gtkcssparserprivate.h b/gtk/gtkcssparserprivate.h
index 0bcba1159c..9dd518d531 100644
--- a/gtk/gtkcssparserprivate.h
+++ b/gtk/gtkcssparserprivate.h
@@ -59,8 +59,8 @@ void            _gtk_css_parser_error             (GtkCssParser          *parser
 guint           _gtk_css_parser_get_line          (GtkCssParser          *parser);
 guint           _gtk_css_parser_get_position      (GtkCssParser          *parser);
 GFile *         _gtk_css_parser_get_file          (GtkCssParser          *parser);
-GFile *         _gtk_css_parser_get_file_for_path (GtkCssParser          *parser,
-                                                   const char            *path);
+GFile *         gtk_css_parser_resolve_url        (GtkCssParser          *parser,
+                                                   const char            *url);
 
 gboolean        gtk_css_parser_has_token          (GtkCssParser          *parser,
                                                    GtkCssTokenType        token_type);
diff --git a/gtk/gtkcssprovider.c b/gtk/gtkcssprovider.c
index e119e61a30..bb77fcdbaa 100644
--- a/gtk/gtkcssprovider.c
+++ b/gtk/gtkcssprovider.c
@@ -784,11 +784,11 @@ parse_import (GtkCssScanner *scanner)
 
   if (gtk_css_parser_has_token (scanner->parser, GTK_CSS_TOKEN_STRING))
     {
-      char *uri;
+      char *url;
 
-      uri = gtk_css_parser_consume_string (scanner->parser);
-      file = _gtk_css_parser_get_file_for_path (scanner->parser, uri);
-      g_free (uri);
+      url = gtk_css_parser_consume_string (scanner->parser);
+      file = gtk_css_parser_resolve_url (scanner->parser, url);
+      g_free (url);
     }
   else
     {


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