diff options
author | Chris Young <chris@unsatisfactorysoftware.co.uk> | 2012-10-28 17:27:02 +0000 |
---|---|---|
committer | Chris Young <chris@unsatisfactorysoftware.co.uk> | 2012-10-28 17:27:02 +0000 |
commit | ca25116c3aa8e8099a987c0f320c9385f6044b80 (patch) | |
tree | 9a69615c04fc8b24a69a5328268fd725a472233f /utils | |
parent | 98cfc5835ccd643578a269a934e8e96487ac1bf8 (diff) | |
parent | 33d40a08af97bae7e12164c5df5c3d2029dcf182 (diff) | |
download | netsurf-ca25116c3aa8e8099a987c0f320c9385f6044b80.tar.gz netsurf-ca25116c3aa8e8099a987c0f320c9385f6044b80.tar.bz2 |
Merge branch 'master' of git://git.netsurf-browser.org/netsurf
Diffstat (limited to 'utils')
-rw-r--r-- | utils/nsurl.c | 32 | ||||
-rw-r--r-- | utils/nsurl.h | 14 |
2 files changed, 46 insertions, 0 deletions
diff --git a/utils/nsurl.c b/utils/nsurl.c index 47b7f5451..8c525452a 100644 --- a/utils/nsurl.c +++ b/utils/nsurl.c @@ -1564,6 +1564,38 @@ const char *nsurl_access(const nsurl *url) /* exported interface, documented in nsurl.h */ +const char *nsurl_access_leaf(const nsurl *url) +{ + size_t path_len; + const char *path; + const char *leaf; + + if (url->components.path == NULL) + return ""; + + path = lwc_string_data(url->components.path); + path_len = lwc_string_length(url->components.path); + + if (path_len == 0) + return ""; + + if (path_len == 1 && *path == '/') + return "/"; + + leaf = path + path_len; + + do { + leaf--; + } while ((leaf != path) && (*leaf != '/')); + + if (*leaf == '/') + leaf++; + + return leaf; +} + + +/* exported interface, documented in nsurl.h */ size_t nsurl_length(const nsurl *url) { assert(url != NULL); diff --git a/utils/nsurl.h b/utils/nsurl.h index 068d08b8d..b075c42a1 100644 --- a/utils/nsurl.h +++ b/utils/nsurl.h @@ -183,6 +183,20 @@ const char *nsurl_access(const nsurl *url); /** + * Access a URL's path leaf as a string + * + * \param url NetSurf URL to retrieve a string pointer for. + * \return the required string + * + * The returned string is owned by the NetSurf URL object. It will die + * with the NetSurf URL object. Keep a reference to the URL if you need it. + * + * The returned string has a trailing '\0'. + */ +const char *nsurl_access_leaf(const nsurl *url); + + +/** * Find the length of a NetSurf URL object's URL, as returned by nsurl_access * * \param url NetSurf URL to find length of. |