[gedit] Utils: deprecate decode_uri(), use the tepl one
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit] Utils: deprecate decode_uri(), use the tepl one
- Date: Mon, 23 Mar 2020 13:03:25 +0000 (UTC)
commit 7a442c766c0305402908c659f5db091f06849a29
Author: Sébastien Wilmet <swilmet gnome org>
Date: Mon Mar 23 13:52:50 2020 +0100
Utils: deprecate decode_uri(), use the tepl one
This requires Tepl git master.
tepl_utils_decode_uri() has exactly the same implementation as
gedit_utils_decode_uri() (the code in Tepl was copied from gedit).
docs/reference/gedit-sections.txt | 2 +-
gedit/gedit-utils.c | 134 +-------------------------------------
gedit/gedit-utils.h | 15 +++--
3 files changed, 11 insertions(+), 140 deletions(-)
---
diff --git a/docs/reference/gedit-sections.txt b/docs/reference/gedit-sections.txt
index 403ba4f0d..00a3246aa 100644
--- a/docs/reference/gedit-sections.txt
+++ b/docs/reference/gedit-sections.txt
@@ -349,7 +349,6 @@ gedit_menu_extension_get_type
gedit_utils_menu_position_under_tree_view
gedit_utils_set_atk_name_description
gedit_utils_basename_for_display
-gedit_utils_decode_uri
gedit_utils_drop_get_uris
gedit_utils_get_compression_type_from_content_type
gedit_utils_is_valid_location
@@ -357,4 +356,5 @@ gedit_utils_location_get_dirname_for_display
gedit_utils_set_direct_save_filename
gedit_utils_newline_type_to_string
gedit_warning
+gedit_utils_decode_uri
</SECTION>
diff --git a/gedit/gedit-utils.c b/gedit/gedit-utils.c
index 60fc8438c..c72a8abf3 100644
--- a/gedit/gedit-utils.c
+++ b/gedit/gedit-utils.c
@@ -487,13 +487,6 @@ gedit_utils_drop_get_uris (GtkSelectionData *selection_data)
return uri_list;
}
-static void
-null_ptr (gchar **ptr)
-{
- if (ptr)
- *ptr = NULL;
-}
-
/**
* gedit_utils_decode_uri:
* @uri: the uri to decode
@@ -510,6 +503,7 @@ null_ptr (gchar **ptr)
* all return value pointers should be freed using g_free
*
* Return value: %TRUE if the uri could be properly decoded, %FALSE otherwise.
+ * Deprecated: 3.38: Use tepl_utils_decode_uri() instead.
*/
gboolean
gedit_utils_decode_uri (const gchar *uri,
@@ -519,131 +513,7 @@ gedit_utils_decode_uri (const gchar *uri,
gchar **port,
gchar **path)
{
- /* Largely copied from glib/gio/gdummyfile.c:_g_decode_uri. This
- * functionality should be in glib/gio, but for now we implement it
- * ourselves (see bug #546182) */
-
- const char *p, *in, *hier_part_start, *hier_part_end;
- char *out;
- char c;
-
- /* From RFC 3986 Decodes:
- * URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
- */
-
- p = uri;
-
- null_ptr (scheme);
- null_ptr (user);
- null_ptr (port);
- null_ptr (host);
- null_ptr (path);
-
- /* Decode scheme:
- * scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
- */
-
- if (!g_ascii_isalpha (*p))
- return FALSE;
-
- while (1)
- {
- c = *p++;
-
- if (c == ':')
- break;
-
- if (!(g_ascii_isalnum(c) ||
- c == '+' ||
- c == '-' ||
- c == '.'))
- {
- return FALSE;
- }
- }
-
- if (scheme)
- {
- *scheme = g_malloc (p - uri);
- out = *scheme;
-
- for (in = uri; in < p - 1; in++)
- {
- *out++ = g_ascii_tolower (*in);
- }
-
- *out = '\0';
- }
-
- hier_part_start = p;
- hier_part_end = p + strlen (p);
-
- if (hier_part_start[0] == '/' && hier_part_start[1] == '/')
- {
- const char *authority_start, *authority_end;
- const char *userinfo_start, *userinfo_end;
- const char *host_start, *host_end;
- const char *port_start;
-
- authority_start = hier_part_start + 2;
- /* authority is always followed by / or nothing */
- authority_end = memchr (authority_start, '/', hier_part_end - authority_start);
-
- if (authority_end == NULL)
- authority_end = hier_part_end;
-
- /* 3.2:
- * authority = [ userinfo "@" ] host [ ":" port ]
- */
-
- userinfo_end = memchr (authority_start, '@', authority_end - authority_start);
-
- if (userinfo_end)
- {
- userinfo_start = authority_start;
-
- if (user)
- *user = g_uri_unescape_segment (userinfo_start, userinfo_end, NULL);
-
- if (user && *user == NULL)
- {
- if (scheme)
- g_free (*scheme);
-
- return FALSE;
- }
-
- host_start = userinfo_end + 1;
- }
- else
- {
- host_start = authority_start;
- }
-
- port_start = memchr (host_start, ':', authority_end - host_start);
-
- if (port_start)
- {
- host_end = port_start++;
-
- if (port)
- *port = g_strndup (port_start, authority_end - port_start);
- }
- else
- {
- host_end = authority_end;
- }
-
- if (host)
- *host = g_strndup (host_start, host_end - host_start);
-
- hier_part_start = authority_end;
- }
-
- if (path)
- *path = g_uri_unescape_segment (hier_part_start, hier_part_end, "/");
-
- return TRUE;
+ return tepl_utils_decode_uri (uri, scheme, user, host, port, path);
}
GtkSourceCompressionType
diff --git a/gedit/gedit-utils.h b/gedit/gedit-utils.h
index f6a042f83..9869ab629 100644
--- a/gedit/gedit-utils.h
+++ b/gedit/gedit-utils.h
@@ -40,13 +40,6 @@ gboolean gedit_utils_is_valid_location (G
gchar *gedit_utils_basename_for_display (GFile *location);
-gboolean gedit_utils_decode_uri (const gchar *uri,
- gchar **scheme,
- gchar **user,
- gchar **host,
- gchar **port,
- gchar **path);
-
/* Turns data from a drop into a list of well formatted uris */
gchar **gedit_utils_drop_get_uris (GtkSelectionData
*selection_data);
@@ -61,6 +54,14 @@ void gedit_warning (G
const gchar *format,
...) G_GNUC_PRINTF(2, 3);
+G_DEPRECATED_FOR (tepl_utils_decode_uri)
+gboolean gedit_utils_decode_uri (const gchar *uri,
+ gchar **scheme,
+ gchar **user,
+ gchar **host,
+ gchar **port,
+ gchar **path);
+
G_END_DECLS
#endif /* GEDIT_UTILS_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]