[gnome-builder] libide: add ide_uri_is_file()



commit 41c9f6074020df9889bd99b77ab90cfb13fd6747
Author: Christian Hergert <chergert redhat com>
Date:   Sun Nov 15 21:01:15 2015 -0800

    libide: add ide_uri_is_file()
    
    This helper makes it convenient to see if IdeUri matches a particular
    GFile uri.

 libide/ide-uri.c |   25 +++++++++++++++++++++++++
 libide/ide-uri.h |    3 +++
 2 files changed, 28 insertions(+), 0 deletions(-)
---
diff --git a/libide/ide-uri.c b/libide/ide-uri.c
index fe99126..b3add6a 100644
--- a/libide/ide-uri.c
+++ b/libide/ide-uri.c
@@ -1517,3 +1517,28 @@ ide_uri_new_from_file (GFile *file)
 
   return uri;
 }
+
+gboolean
+ide_uri_is_file (IdeUri *uri,
+                 GFile  *file)
+{
+  gchar *file_uri;
+  gchar *str;
+  gboolean ret;
+
+  g_return_val_if_fail (uri != NULL, FALSE);
+  g_return_val_if_fail (G_IS_FILE (file), FALSE);
+
+  if (uri->host && uri->host [0])
+    return FALSE;
+
+  file_uri = g_file_get_uri (file);
+  str = g_strdup_printf ("%s://%s", uri->scheme ?: "", uri->path ?: "");
+
+  ret = (g_strcmp0 (file_uri, str) == 0);
+
+  g_free (file_uri);
+  g_free (str);
+
+  return ret;
+}
diff --git a/libide/ide-uri.h b/libide/ide-uri.h
index f3508e7..1ac80c1 100644
--- a/libide/ide-uri.h
+++ b/libide/ide-uri.h
@@ -130,6 +130,9 @@ gchar *      ide_uri_build           (const gchar        *scheme,
                                       const gchar        *query,
                                       const gchar        *fragment);
 
+gboolean     ide_uri_is_file         (IdeUri             *uri,
+                                      GFile              *file);
+
 
 /**
  * IDE_URI_ERROR:


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