[gnome-builder/wip/chergert/perspective] libide: add some helpers to IdeUri.
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/chergert/perspective] libide: add some helpers to IdeUri.
- Date: Tue, 17 Nov 2015 00:28:46 +0000 (UTC)
commit e7f1a76ae5b3a723a6baa6afb4bea76fbb0ca9d7
Author: Christian Hergert <christian hergert me>
Date: Mon Nov 16 16:28:27 2015 -0800
libide: add some helpers to IdeUri.
libide/ide-uri.c | 32 ++++++++++++++++++++++++++++----
libide/ide-uri.h | 6 ++++--
2 files changed, 32 insertions(+), 6 deletions(-)
---
diff --git a/libide/ide-uri.c b/libide/ide-uri.c
index fe8f98a..166288e 100644
--- a/libide/ide-uri.c
+++ b/libide/ide-uri.c
@@ -746,7 +746,7 @@ ide_uri_to_string (IdeUri *uri,
if (g_strcmp0 (uri->scheme, "file") == 0)
{
- if (uri->fragment)
+ if (uri->fragment && !(flags & IDE_URI_HIDE_FRAGMENT))
return g_strdup_printf ("file://%s#%s", uri->path, uri->fragment);
else
return g_strdup_printf ("file://%s", uri->path);
@@ -758,14 +758,15 @@ ide_uri_to_string (IdeUri *uri,
if (uri->host)
{
g_string_append (str, "//");
- if (uri->encoded_userinfo)
+
+ if (uri->encoded_userinfo && !(flags & IDE_URI_HIDE_AUTH_PARAMS))
{
g_string_append (str, uri->encoded_userinfo);
g_string_append_c (str, '@');
}
if (uri->host)
- g_string_append (str, uri->host);
+ g_string_append (str, uri->host);
if (uri->port)
g_string_append_printf (str, ":%d", uri->port);
@@ -779,7 +780,7 @@ ide_uri_to_string (IdeUri *uri,
g_string_append_c (str, '?');
g_string_append (str, uri->encoded_query);
}
- if (uri->encoded_fragment)
+ if (uri->encoded_fragment && !(flags & IDE_URI_HIDE_FRAGMENT))
{
g_string_append_c (str, '#');
g_string_append (str, uri->encoded_fragment);
@@ -1550,3 +1551,26 @@ ide_uri_is_file (IdeUri *uri,
return ret;
}
+
+/**
+ * ide_uri_to_file:
+ * @uri: An #IdeUri
+ *
+ * Creates a #GFile that represents the resource @uri.
+ *
+ * Returns: (transfer full) (nullable): A #GFile or %NULL upon failure.
+ */
+GFile *
+ide_uri_to_file (IdeUri *uri)
+{
+ GFile *ret;
+ gchar *str;
+
+ g_return_val_if_fail (uri != NULL, NULL);
+
+ str = ide_uri_to_string (uri, IDE_URI_HIDE_FRAGMENT);
+ ret = g_file_new_for_uri (str);
+ g_free (str);
+
+ return ret;
+}
diff --git a/libide/ide-uri.h b/libide/ide-uri.h
index 1ac80c1..a92dc2e 100644
--- a/libide/ide-uri.h
+++ b/libide/ide-uri.h
@@ -50,8 +50,8 @@ IdeUri * ide_uri_new_from_file (GFile *file);
typedef enum
{
- IDE_URI_HIDE_PASSWORD = 1 << 0,
- IDE_URI_HIDE_AUTH_PARAMS = 1 << 1
+ IDE_URI_HIDE_AUTH_PARAMS = 1 << 0,
+ IDE_URI_HIDE_FRAGMENT = 1 << 1,
} IdeUriToStringFlags;
#define IDE_TYPE_URI (ide_uri_get_type())
@@ -133,6 +133,8 @@ gchar * ide_uri_build (const gchar *scheme,
gboolean ide_uri_is_file (IdeUri *uri,
GFile *file);
+GFile *ide_uri_to_file (IdeUri *uri);
+
/**
* IDE_URI_ERROR:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]