utils: reworked uri splitting with help of libsoup
Currently we split a URI string with a Regex which is error prone. As libsoup already provides a facility to parse a URI into its parts we should use this instead. Therefore our utility method is not necessary anymore.
This commit is contained in:
@@ -874,86 +874,6 @@ fix_popover_menu_icons (GtkPopover *popover)
|
||||
g_list_free (menu_section_box_children);
|
||||
}
|
||||
|
||||
/**
|
||||
* uri_get_fields:
|
||||
* @uri: the URI
|
||||
* @schema: (nullable): return location for the schema of the URI
|
||||
* @host: (nullable): return location for the host of the URI
|
||||
* @path: (nullable): return location for the resource path
|
||||
*
|
||||
* Split the given URI into the fields.
|
||||
*
|
||||
* Returns: #TRUE if @uri could be parsed, #FALSE otherwise
|
||||
*/
|
||||
gboolean
|
||||
uri_get_fields (const gchar *uri,
|
||||
gchar **schema,
|
||||
gchar **host,
|
||||
gchar **path,
|
||||
gboolean *is_file)
|
||||
{
|
||||
GRegex *regex;
|
||||
GMatchInfo *match;
|
||||
gboolean valid;
|
||||
|
||||
g_return_val_if_fail (uri != NULL, FALSE);
|
||||
|
||||
match = NULL;
|
||||
valid = FALSE;
|
||||
|
||||
regex = g_regex_new ("([a-zA-Z0-9\\+\\.\\-]*:\\/\\/){0,1}([-a-zA-Z0-9@:%._\\+~#=]{2,256}\\.[a-z]{2,6}\\b)([-a-zA-Z0-9@:%_\\+.//=]*)",
|
||||
G_REGEX_CASELESS, 0, NULL);
|
||||
|
||||
/*
|
||||
* Retrieved matching URI. The whole url is
|
||||
* checked and the regex groups are:
|
||||
* 1. schema
|
||||
* 2. host
|
||||
* 3. server path
|
||||
*/
|
||||
if (g_regex_match (regex, uri, 0, &match))
|
||||
{
|
||||
valid = TRUE;
|
||||
|
||||
if (schema != NULL)
|
||||
*schema = g_match_info_fetch (match, 1);
|
||||
|
||||
if (host != NULL)
|
||||
*host = g_match_info_fetch (match, 2);
|
||||
|
||||
if (path != NULL)
|
||||
*path = g_match_info_fetch (match, 3);
|
||||
|
||||
g_match_info_free (match);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (schema != NULL)
|
||||
*schema = NULL;
|
||||
|
||||
if (host != NULL)
|
||||
*host = NULL;
|
||||
|
||||
if (path != NULL)
|
||||
*path = NULL;
|
||||
}
|
||||
|
||||
/* File extension */
|
||||
if (is_file)
|
||||
{
|
||||
GRegex *extension_regex;
|
||||
|
||||
extension_regex = g_regex_new ("(\\.[a-zA-Z0-9]+)$", G_REGEX_CASELESS, 0, NULL);
|
||||
|
||||
*is_file = g_regex_match (extension_regex, uri, 0, NULL);
|
||||
|
||||
g_regex_unref (extension_regex);
|
||||
}
|
||||
|
||||
g_regex_unref (regex);
|
||||
return valid;
|
||||
}
|
||||
|
||||
/**
|
||||
* get_source_parent_name_color:
|
||||
* @manager: a #GcalManager
|
||||
|
||||
Reference in New Issue
Block a user