mirror of
https://github.com/netsurf-browser/netsurf
synced 2024-11-27 08:50:02 +03:00
Add url_leafname()
Remove spurious * from url_host_is_ip_address() svn path=/trunk/netsurf/; revision=3691
This commit is contained in:
parent
76416f1964
commit
252ad5c476
34
utils/url.c
34
utils/url.c
@ -106,7 +106,7 @@ bool url_host_is_ip_address(const char *host) {
|
||||
} else {
|
||||
n = true;
|
||||
}
|
||||
*host++;
|
||||
host++;
|
||||
} while (1);
|
||||
}
|
||||
|
||||
@ -692,6 +692,38 @@ url_func_result url_path(const char *url, char **result)
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract leafname segment from an URL
|
||||
*
|
||||
* \param url an absolute URL
|
||||
* \param result pointer to pointer to buffer to hold result
|
||||
* \return URL_FUNC_OK on success
|
||||
*/
|
||||
|
||||
url_func_result url_leafname(const char *url, char **result)
|
||||
{
|
||||
url_func_result status;
|
||||
struct url_components components;
|
||||
|
||||
assert(url);
|
||||
|
||||
status = url_get_components(url, &components);
|
||||
if (status == URL_FUNC_OK) {
|
||||
if (!components.path) {
|
||||
status = URL_FUNC_FAILED;
|
||||
} else {
|
||||
char *slash = strrchr(components.path, '/');
|
||||
|
||||
assert (slash != NULL);
|
||||
|
||||
*result = strdup(slash + 1);
|
||||
if (!(*result))
|
||||
status = URL_FUNC_NOMEM;
|
||||
}
|
||||
}
|
||||
url_destroy_components(&components);
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to find a nice filename for a URL.
|
||||
|
@ -53,6 +53,7 @@ url_func_result url_canonical_root(const char *url, char **result);
|
||||
url_func_result url_parent(const char *url, char **result);
|
||||
url_func_result url_plq(const char *url, char **result);
|
||||
url_func_result url_path(const char *url, char **result);
|
||||
url_func_result url_leafname(const char *url, char **result);
|
||||
url_func_result url_compare(const char *url1, const char *url2,
|
||||
bool *result);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user